Skip to content

Commit b4f56b1

Browse files
fix: throw resourceNotFound when loadSession fails to resume (#363)
## Summary - When `loadSession` calls `createSession({ resume: sessionId })` and the CLI subprocess can't find persisted session data (no `.jsonl` file), the subprocess exits immediately and `createSession` rejects with a generic `-32603` ("Query closed before response received") - ACP clients like [acpx](https://github.com/openclaw/acpx) check for `-32001`/`-32002` (resource not found) to fall back to `session/new` — the generic `-32603` bypasses this, causing the turn to fail entirely - This commonly happens when `session/new` creates an ACP session but the subprocess exits before writing session data (no prompt to process), then `session/prompt` tries `session/load` to resume a session that was never persisted ## Fix Wrap the `createSession({ resume })` call in `loadSession()` with try/catch and re-throw as `RequestError.resourceNotFound()` (code `-32002`). This lets callers handle it with their existing fallback logic. ## Verification Confirmed working in production with the [OpenClaw](https://github.com/openclaw/openclaw) gateway + acpx integration. Before the fix, all ACP tasks failed silently. After patching both this code path and acpx's `shouldFallbackToNewSession()` ([openclaw/acpx#30](openclaw/acpx#30)), sessions fall back to `session/new` correctly. Fixes #338 Closes #361 Closes #362 --------- Co-authored-by: Ben Brandt <benjamin.j.brandt@gmail.com>
1 parent c2e45e6 commit b4f56b1

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

src/acp-agent.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1218,7 +1218,19 @@ export class ClaudeAcpAgent implements Agent {
12181218
nextPendingOrder: 0,
12191219
};
12201220

1221-
const initializationResult = await q.initializationResult();
1221+
let initializationResult;
1222+
try {
1223+
initializationResult = await q.initializationResult();
1224+
} catch (error) {
1225+
if (
1226+
creationOpts.resume &&
1227+
error instanceof Error &&
1228+
error.message === "Query closed before response received"
1229+
) {
1230+
throw RequestError.resourceNotFound(sessionId);
1231+
}
1232+
throw error;
1233+
}
12221234

12231235
const models = await getAvailableModels(q, initializationResult.models, settingsManager);
12241236

0 commit comments

Comments
 (0)