-
Notifications
You must be signed in to change notification settings - Fork 142
Description
Problem
When using acpx with cursor-agent (Cursor IDE CLI) in prompt mode (persistent sessions), session reconnection fails with:
AcpRuntimeError: acpx exited with code 1: code=ACP_TURN_FAILED
The exec mode works fine because it always creates a new session via session/new.
Root Cause
cursor-agentreportsagentCapabilities.loadSession = trueduring ACPinitialize- When
acpxtries to restore a previous session viasession/load, cursor-agent returns JSON-RPC error-32602(Invalid params) — itssession/loadimplementation appears incomplete shouldFallbackToNewSession()insrc/session-runtime/connect-load.tsonly handles-32603(Internal Error) for the fallback-to-new-session logic, but does not handle-32602- The
-32602error propagates up uncaught, causing the process to exit with code 1
Expected Behavior
When session/load returns -32602 (Invalid params) or -32601 (Method not found), acpx should gracefully fallback to session/new instead of crashing.
Suggested Fix
The constant SESSION_CONTROL_UNSUPPORTED_ACP_CODES (containing -32601 and -32602) already exists in the codebase but is not used in shouldFallbackToNewSession. The fix is to check it before the sessionHasAgentMessages guard:
function shouldFallbackToNewSession(error, record) {
if (error instanceof TimeoutError || error instanceof InterruptedError) return false;
if (isAcpResourceNotFoundError(error)) return true;
+ const acpErr = extractAcpError(error);
+ if (acpErr && SESSION_CONTROL_UNSUPPORTED_ACP_CODES.has(acpErr.code)) return true;
if (!sessionHasAgentMessages(record)) {
if (isAcpQueryClosedBeforeResponseError(error)) return true;
- if (extractAcpError(error)?.code === -32603) return true;
+ if (acpErr?.code === -32603) return true;
}
return false;
}Why this works
SESSION_CONTROL_UNSUPPORTED_ACP_CODES = new Set([-32601, -32602])already exists in the codebase-32601= JSON-RPC Method not found (agent doesn't support the method at all)-32602= JSON-RPC Invalid params (method exists but params validation fails — this is what cursor-agent returns forsession/load)- Checking these codes unconditionally (not gated behind
sessionHasAgentMessages) ensures that even sessions with prior agent messages can gracefully recover when the agent simply doesn't supportsession/load - As a bonus, the
extractAcpError(error)call is now cached in a local variable to avoid redundant extraction
Steps to Reproduce
- Configure acpx with cursor-agent as the backend
- Run
acpx cursor exec "hello"— works (usessession/new) - Run
acpx cursor promptand send a message — works (first run, creates new session) - Run
acpx cursor promptagain — crashes (triessession/loadon existing session, gets-32602)
Workaround
Manually patch the compiled dist/session-*.js file to add the SESSION_CONTROL_UNSUPPORTED_ACP_CODES check, or delete ~/.acpx/sessions/* before each run (forces fresh sessions every time).
Environment
- acpx: 0.3.0
- cursor-agent (Cursor CLI): 2026.03.11-6dfa30c
- OS: Windows 10
- Node.js: v24.14.0
- Integration: OpenClaw gateway calling acpx in prompt mode