Skip to content

fix: fallback to new session on Internal error (-32603) during session/load#30

Open
voidborne-d wants to merge 1 commit intoopenclaw:mainfrom
voidborne-d:fix/session-load-internal-error-fallback
Open

fix: fallback to new session on Internal error (-32603) during session/load#30
voidborne-d wants to merge 1 commit intoopenclaw:mainfrom
voidborne-d:fix/session-load-internal-error-fallback

Conversation

@voidborne-d
Copy link

Problem

Some ACP agents (e.g. claude-agent-acp) cannot restore sessions after a process restart. When session/load is attempted on a reconnect, they return a JSON-RPC Internal error (-32603) instead of a resource-not-found error.

shouldFallbackToNewSession() only recognized resource-not-found errors, so the Internal error propagated as an unrecoverable failure — breaking persistent session mode entirely.

Root Cause

claude-agent-acp returns:

{"code": -32603, "message": "Internal error", "data": {"details": "Query closed before response received"}}

This error code was not in the fallback allowlist.

Fix

  • Add isAcpInternalError() helper in acp-error-shapes.ts to detect -32603
  • Update shouldFallbackToNewSession() in session-runtime.ts to treat Internal errors as recoverable, falling back to createSession

This matches the existing recovery path for resource-not-found errors.

Testing

Manually verified: after patching, acpx --approve-all claude "hello" successfully falls back to a fresh session when session/load returns -32603, instead of crashing with [error] RUNTIME: Internal error.

…n/load

Some ACP agents (e.g. claude-agent-acp) cannot restore sessions after a
process restart. When session/load is attempted, they return a JSON-RPC
Internal error (-32603) instead of a resource-not-found error.

Previously, shouldFallbackToNewSession() only recognized resource-not-found
errors, causing the Internal error to propagate and break persistent session
mode entirely.

This change adds isAcpInternalError() and uses it in
shouldFallbackToNewSession() so that -32603 errors trigger a graceful
fallback to createSession, matching the existing recovery path.
@maskedband1t
Copy link

Can confirm this fixes the issue. We hit the exact same failure path with claude-agent-acp@0.19.2 + acpx@0.1.13.

For additional context on why -32603 occurs here: claude-agent-acp wraps the Claude Code CLI via @anthropic-ai/claude-agent-sdk. When session/load is forwarded to a freshly spawned Claude Code subprocess, it can't find the session data (which lived in the previous process), so the subprocess exits. The SDK's transport cleanup converts the dangling response into {code: -32603, data: {details: "Query closed before response received"}}.

PR #22 added detection for data.details: "Session not found" but this error uses different text. Catching all -32603 on the session/load path is the right call — if the agent can't load a session for any internal reason, falling back to a fresh session is always preferable to failing the entire prompt.

The upstream fix on claude-agent-acp's side would be returning -32001 (resource not found) instead of letting the subprocess crash propagate as -32603, but that's a separate issue (zed-industries/claude-agent-acp#338).

@voidborne-d
Copy link
Author

Thanks for confirming and for the detailed context on the -32603 path — that's really helpful. Good to know the root cause is the subprocess not finding session data from the previous process.

Hopefully this can get merged soon so the fix lands in the next release.

@maskedband1t
Copy link

FYI: we also filed the upstream fix — zed-industries/claude-agent-acp#363. It makes loadSession() return -32002 instead of -32603, so this PR's broader catch becomes a defense-in-depth layer rather than the only fix.

@voidborne-d
Copy link
Author

Nice, thanks for the heads-up! Good to have this as defense-in-depth either way — the broader catch ensures we handle any unexpected session errors gracefully regardless of the upstream error code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants