GeezerVison is showing github.com — ACP: `session/prompt` never returns after the disk fills up during a turn · Issue #60065 · anomalyco/opencode
ACP: session/prompt never returns after the disk fills up during a turn #60065DescriptionDescription
If the disk holding OpenCode's data directory (~/.local/share/opencode) fills up for a moment during a turn and a database write fails, the ACP session/prompt request never returns, even after space is freed. The client gets no error, and every new prompt in that session is refused with "Session already has an active ACP prompt" (turn.ts#L378-L384) until the user cancels or restarts. Failing the turn would be fine; the problem is that its outcome never arrives.
Why (at dae4077):
- A failed SQLite write in a durable publish becomes a defect (bus.ts#L435-L437), and subscribers are only notified after the commit (bus.ts#L473-L476). So a
SQLITE_FULL during the turn ends the drain, and that event never reaches the client.
- The turn's outcome is another durable event (execution.ts#L135-L142, session-event.ts#L244-L264), published once, right after the failure, while the disk is most likely still full. If that write fails, it is only logged (execution.ts#L62-L72) and dropped as the coordinator goes idle (run-coordinator.ts#L96-L103). Nothing retries it once space is back.
- The ACP adapter waits for that event to end the prompt (translate.ts#L226-L231), with no timeout or idle check (turn.ts#L209-L217). It also ignores every event, terminal ones included, until its prompt's
session.inbox.delivered arrives (translate.ts#L126-L128). So if the failure comes before delivery (the execution.started write or the inbox promotion), the prompt hangs even when the failure event is written.
The unmerged branch fix/disk-full-session-recovery (96871b8, e7d4987) adds storage retries in core, which looks like it covers point 2 for most outages. It is not on dev, though, and it does not change point 3.
Possible fix on the ACP side: also end the turn when the session goes idle (session.wait resolves through awaitIdle even when the outcome event was lost, session.ts#L278-L281). If the prompt was never delivered by then, report the session.execution.failed seen before delivery, as opencode run does (noninteractive.ts#L253-L256, #L761-L763).
Plugins
No response
OpenCode version
2.1.4 (analysed on dev at dae4077, 2026-10-27; the same lifecycle and ACP code is in the v2.1.4 tag)
Steps to reproduce
No script attached. The conditions are the ones in the description: OpenCode used through ACP (opencode acp), and the filesystem holding ~/.local/share/opencode runs out of space while a turn is running (SQLite returns SQLITE_FULL), then has space again a few seconds later.
Expected: the prompt ends, with an error if the turn failed.
Actual: session/prompt stays pending after space is back, until session/cancel or a restart.
Screenshot
No response
Operating System
Linux (the code path is not OS-specific)
Terminal
Not applicable (OpenCode used through an ACP client) Activityopencodejr commented on Oct 29, 2026 Thanks for the detailed analysis. I was able to reproduce this on the latest dev (c5d9c30) by injecting SQLITE_FULL into durable event writes, with opencode acp driven over JSON-RPC against a mock provider:
- Mid-turn failure: all durable writes fail for 5 s once the model request starts, so
session.execution.failed is lost too (the log shows Failed to publish Session execution lifecycle). session/prompt was still pending 30 s later, and the next prompt was refused with Session already has an active ACP prompt.
- Failure before delivery: only the
session.execution.started write fails, for 3 s. The prompt also never resolved and the session stayed locked.
One difference from the report: with a real full disk on 2.1.4 (data dir on a small tmpfs filled to ENOSPC), I didn't get a hang. The turn either completed or session/prompt returned Internal error: Failed to execute statement, because the small failure event still fit in SQLite's existing WAL. The hang shows up when that outcome write also fails, or when the failure hits before the prompt is delivered, as you described.
The script below reproduces it. It includes the small test-only patch to packages/core/src/bus.ts that it needs. Related: #53704 (core storage-retry PR) and #52796 (tool stuck pending on SQLITE_FULL).
Reproduction script (inject.ts)
// #60065 with fault injection: requires a checkout with the test-only fault-injection hook below in packages/core/src/bus.ts
// (die with SQLITE_FULL when /tmp/opencode/inject-full exists and its regex matches the durable event type).
// Apply in the checkout first (git apply), then run: OC_DEV=/path/to/opencode bun inject.ts (as root: mounts a tmpfs)
/* Patch:
diff --git a/packages/core/src/bus.ts b/packages/core/src/bus.ts
index 7b37335ea..99e1d9052 100644
--- a/packages/core/src/bus.ts
+++ b/packages/core/src/bus.ts
@@ -398,6 +398,12 @@ export function configured(options?: Options) {
...event,
durable: { aggregateID, seq, version: durable.version },
} as Event.Payload
+ {
+ const fsx = require("node:fs") as typeof import("node:fs")
+ const f = "/tmp/opencode/inject-full"
+ if (fsx.existsSync(f) && new RegExp(fsx.readFileSync(f, "utf8").trim()).test(definition.type))
+ yield* Effect.die(Object.assign(new Error(`SQLITE_FULL: database or disk is full (injected, ${definition.type})`), { code: "SQLITE_FULL" }))
+ }
const route = yield* prepareRoutes([committed])
for (const projector of list) {
yield* projector(committed)
*/
import { spawn, execSync } from "node:child_process"
import fs from "node:fs"
import path from "node:path"
const base = "/tmp/opencode/acp60065"
const data = path.join(base, "data") // tmpfs: holds ~/.local/share/opencode
execSync(`umount ${data} 2>/dev/null || true; rm -rf ${base}; mkdir -p ${data} ${base}/home ${base}/config/opencode ${base}/state ${base}/project`, { shell: "/bin/bash" })
execSync(`mount -t tmpfs -o size=64m tmpfs ${data}`)
const filler = path.join(data, "filler")
let onRequest: () => Promise<void> = async () => {}
let big = false
const server = Bun.serve({
port: 0,
async fetch(req) {
const url = new URL(req.url)
if (url.pathname.endsWith("/models")) return Response.json({ data: [{ id: "mock", object: "model" }] })
if (!url.pathname.endsWith("/chat/completions")) return new Response("nf", { status: 404 })
await onRequest()
const chunk = (d: any) => `data: ${JSON.stringify({ id: "c1", object: "chat.completion.chunk", created: 1, model: "mock", choices: [d] })}\n\n`
const parts = [
chunk({ index: 0, delta: { role: "assistant", content: "Hello " }, finish_reason: null }),
...Array.from({ length: big ? 300 : 2 }, (_, i) => chunk({ index: 0, delta: { content: `word${i} `.repeat(10000) }, finish_reason: null })),
chunk({ index: 0, delta: {}, finish_reason: "stop" }),
"data: [DONE]\n\n",
]
const enc = new TextEncoder()
const stream = new ReadableStream({ async start(c) { for (const p of parts) { c.enqueue(enc.encode(p)); await new Promise((r) => setTimeout(r, 30)) } c.close() } })
return new Response(stream, { headers: { "content-type": "text/event-stream" } })
},
})
fs.writeFileSync(path.join(base, "config/opencode/opencode.json"), JSON.stringify({
$schema: "https://opencode.ai/config.json", autoupdate: false, model: "mock/mock",
provider: { mock: { npm: "@ai-sdk/openai-compatible", name: "Mock", options: { baseURL: `http://127.0.0.1:${server.port}/v1`, apiKey: "x" }, models: { mock: { name: "Mock", limit: { context: 100000000, output: 100000 } } } } },
}))
const env = { ...process.env, ...(process.env.OC_DEV ? { BUN_OPTIONS: `--conditions=browser --preload=${process.env.OC_DEV}/packages/tui/node_modules/@opentui/solid/scripts/preload.js` } : {}), HOME: `${base}/home`, XDG_DATA_HOME: data, XDG_CONFIG_HOME: `${base}/config`, XDG_STATE_HOME: `${base}/state`, OPENCODE_DISABLE_AUTOUPDATE: "1" }
const dev = process.env.OC_DEV
const cmd = dev
? ["bun", ["--conditions=browser", `--preload=${dev}/packages/tui/node_modules/@opentui/solid/scripts/preload.js`, `${dev}/packages/cli/src/index.ts`, "acp"]]
: ["opencode", ["acp"]]
const proc = spawn(cmd[0] as string, cmd[1] as string[], { cwd: `${base}/project`, env, stdio: ["pipe", "pipe", "inherit"] })
let id = 0
const pending = new Map<number, (m: any) => void>()
let buf = ""
proc.stdout.on("data", (d) => {
buf += d
let i
while ((i = buf.indexOf("\n")) >= 0) {
const line = buf.slice(0, i); buf = buf.slice(i + 1)
if (!line.trim()) continue
const m = JSON.parse(line)
if (m.id !== undefined && pending.has(m.id) && !m.method) { pending.get(m.id)!(m); pending.delete(m.id) }
else if (m.method === "session/update") { if (m.params.update.sessionUpdate !== "agent_message_chunk") console.log("update:", m.params.update.sessionUpdate, JSON.stringify(m.params.update).slice(0, 200)) }
else if (m.method) { console.log("client request:", m.method); proc.stdin.write(JSON.stringify({ jsonrpc: "2.0", id: m.id, result: null }) + "\n") }
}
})
const rpc = (method: string, params: any) => new Promise<any>((res) => { const n = ++id; pending.set(n, res); proc.stdin.write(JSON.stringify({ jsonrpc: "2.0", id: n, method, params }) + "\n") })
const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms))
const withTimeout = <T,>(p: Promise<T>, ms: number) => Promise.race([p, sleep(ms).then(() => "TIMEOUT" as const)])
const fillDisk = () => { try { const fd = fs.openSync(filler, "w"); const b = Buffer.alloc(1 << 20); while (true) fs.writeSync(fd, b) } catch (e: any) { console.log(execSync(`find ${data} -maxdepth 3 -type f -not -name filler | xargs ls -la`).toString()); console.log("disk filled:", e.code, execSync(`df -h ${data} | tail -1`).toString().trim()) } }
console.log("initialize:", JSON.stringify((await rpc("initialize", { protocolVersion: 1, clientCapabilities: {} })).result?.agentInfo ?? {}))
const s = await rpc("session/new", { cwd: `${base}/project`, mcpServers: [] })
const sessionId = s.result?.sessionId
console.log("session/new:", sessionId ?? JSON.stringify(s))
const inj = "/tmp/opencode/inject-full"
fs.rmSync(inj, { force: true })
console.log("prompt 1 (healthy):", JSON.stringify(await withTimeout(rpc("session/prompt", { sessionId, prompt: [{ type: "text", text: "hi" }] }), 30000)))
// A: every durable write fails from the model request until 5s later (mid-turn failure; outcome event also fails)
let armed = true
onRequest = async () => { if (!armed) return; armed = false; fs.writeFileSync(inj, "."); console.log("injecting SQLITE_FULL for all durable events"); setTimeout(() => { fs.rmSync(inj, { force: true }); console.log("injection removed (space back)") }, 5000) }
let t = Date.now()
const a = await withTimeout(rpc("session/prompt", { sessionId, prompt: [{ type: "text", text: "turn A" }] }), 30000)
console.log(`prompt A (mid-turn failure) after ${((Date.now() - t) / 1000).toFixed(1)}s:`, JSON.stringify(a))
if (a === "TIMEOUT") console.log("next prompt in same session:", JSON.stringify(await withTimeout(rpc("session/prompt", { sessionId, prompt: [{ type: "text", text: "after A" }] }), 10000)))
// B: fresh session; only session.execution.started fails (before inbox delivery), removed after 3s
const s2 = (await rpc("session/new", { cwd: `${base}/project`, mcpServers: [] })).result.sessionId
fs.writeFileSync(inj, "^session\\.execution\\.started")
setTimeout(() => { fs.rmSync(inj, { force: true }); console.log("injection removed (space back)") }, 3000)
t = Date.now()
const b = await withTimeout(rpc("session/prompt", { sessionId: s2, prompt: [{ type: "text", text: "turn B" }] }), 30000)
console.log(`prompt B (execution.started write fails) after ${((Date.now() - t) / 1000).toFixed(1)}s:`, JSON.stringify(b))
if (b === "TIMEOUT") console.log("next prompt in same session:", JSON.stringify(await withTimeout(rpc("session/prompt", { sessionId: s2, prompt: [{ type: "text", text: "after B" }] }), 10000)))
console.log(execSync(`grep -h "Failed to publish\\|SQLITE_FULL" ${data}/opencode/log/*.log | cut -c1-300 | tail -8; true`).toString())
proc.kill(); server.stop(true); fs.rmSync(inj, { force: true })
await sleep(1000)
execSync(`umount -l ${data} || true`, { shell: "/bin/bash" })
process.exit(0)
Run it: bun inject.ts
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|