Skip to content

Cursor ACP session/load fallback not triggered due to unrecognized error code #161

@log-li

Description

@log-li

Issue: Cursor ACP session/load fallback not triggered due to unrecognized error code

Summary

Cursor CLI's ACP implementation returns error code -32602 (Invalid Params) with message "Session \"xxx\" not found" when session/load fails, but acpx's shouldFallbackToNewSession() only recognizes -32002 (Resource Not Found) or -32603 (Internal Error). This prevents the automatic fallback to session/new, causing all Cursor ACP sessions to fail when spawned through OpenClaw.

Steps to Reproduce

  1. Install Cursor CLI and authenticate: agent login
  2. Install acpx: npm install -g acpx@latest (v0.3.1)
  3. Try to spawn a Cursor ACP session through OpenClaw's sessions_spawn(runtime="acp", agentId="cursor")
  4. Observe the error: Invalid params - Session "xxx" not found

Alternatively, test directly:

cursor-agent acp <<'EOF'
{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":1,"clientCapabilities":{"fs":{"readTextFile":true,"writeTextFile":true},"terminal":true},"clientInfo":{"name":"test","version":"1.0"}}}
{"jsonrpc":"2.0","id":2,"method":"session/load","params":{"sessionId":"nonexistent-session-id","cwd":"/tmp","mcpServers":[]}}
EOF

Response:

{"jsonrpc":"2.0","id":2,"error":{"code":-32602,"message":"Invalid params","data":{"message":"Session \"nonexistent-session-id\" not found"}}}

Expected Behavior

acpx should recognize this error as a "session not found" condition and fallback to session/new, creating a fresh session.

Actual Behavior

acpx throws RUNTIME: Invalid params - Session "xxx" not found and does not fallback.

Root Cause

In src/session-runtime/connect-load.ts, the shouldFallbackToNewSession() function checks:

function shouldFallbackToNewSession(error, record) {
  if (error instanceof TimeoutError || error instanceof InterruptedError) return false;
  if (isAcpResourceNotFoundError(error)) return true;  // checks for -32002
  if (!sessionHasAgentMessages(record)) {
    if (isAcpQueryClosedBeforeResponseError(error)) return true;
    if (extractAcpError(error)?.code === -32603) return true;  // only -32603, not -32602
  }
  return false;
}

Cursor returns -32602 (Invalid Params), which doesn't match any condition.

Comparison with Similar Fixes

This is similar to the issues fixed in:

Cursor's error format differs from both:

  • Error code: -32602 (not -32603 or -32002)
  • Error message: "Session \"xxx\" not found" in data.message

Suggested Fix

Add text-based matching for Cursor's error message pattern, similar to PR #35. Options:

  1. Add -32602 to fallback conditions when session has no agent messages
  2. Add text pattern matching for "session" ... "not found" in error data

Example fix (option 2):

function isSessionNotFoundError(error) {
  const acp = extractAcpError(error);
  if (!acp) return false;
  
  // Check error message in data
  const data = acp.data;
  if (data && typeof data.message === 'string') {
    const msg = data.message.toLowerCase();
    if (msg.includes('session') && msg.includes('not found')) {
      return true;
    }
  }
  return false;
}

function shouldFallbackToNewSession(error, record) {
  if (error instanceof TimeoutError || error instanceof InterruptedError) return false;
  if (isAcpResourceNotFoundError(error)) return true;
  if (isSessionNotFoundError(error)) return true;  // new check
  // ... rest of function
}

Environment

  • acpx version: 0.3.1
  • Cursor CLI version: 2026.03.11-6dfa30c
  • Cursor subscription: Pro
  • OpenClaw version: latest (with acpx backend)

Workaround

Using acpx cursor exec directly works because it creates a fresh session without attempting session/load first.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions