Skip to content

fix(acp): ignore Cursor worktree stdout banner#1087

Open
heavygee wants to merge 1 commit into
tiann:mainfrom
heavygee:fix/cursor-worktree-acp-stdout-banner
Open

fix(acp): ignore Cursor worktree stdout banner#1087
heavygee wants to merge 1 commit into
tiann:mainfrom
heavygee:fix/cursor-worktree-acp-stdout-banner

Conversation

@heavygee

Copy link
Copy Markdown
Collaborator

Summary

  • Cursor agent acp --worktree prints a plain-text Using worktree: … banner on stdout before JSON-RPC.
  • AcpStdioTransport treated JSON.parse failures as fatal and killed the session before cursorSessionId existed.
  • Fail-soft: ignore non-JSON stdout lines (log + continue), matching the existing ignore of non-object JSON for Gemini. JSON-RPC error responses still reject pending requests.

Fixes #1085

Test plan

  • bunx vitest run src/agent/backends/acp/AcpStdioTransport.test.ts (cli) — includes regression for Using worktree: …
  • bun typecheck
  • Dogfood: remote Cursor spawn with sessionType: worktree after merge / soup promote

…ill ACP

Cursor agent prints `Using worktree: …` on stdout before JSON-RPC when
started with --worktree; fail-soft that line instead of treating parse
failure as a fatal protocol error. Fixes tiann#1085.

Co-authored-by: Cursor <cursoragent@cursor.com>

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Findings

  • [Major] Keep malformed JSON-RPC fatal outside the Cursor banner — handleLine now catches every JSON.parse failure and returns, so a corrupted/truncated JSON-RPC response is treated the same as Cursor's known banner. That can leave the matching pending request unresolved; session/prompt is sent with timeoutMs: Infinity, so a malformed prompt response can keep the remote ACP session stuck instead of surfacing a protocol failure. Evidence cli/src/agent/backends/acp/AcpStdioTransport.ts:229, context cli/src/agent/backends/acp/AcpSdkBackend.ts:452.
    Suggested fix:
            } catch (error) {
                if (this.shouldGuardAgentCli && line.startsWith('Using worktree: ')) {
                    logger.debug('[ACP] Ignoring Cursor worktree stdout banner', { line });
                    return;
                }
    
                const protocolError = new Error('Failed to parse JSON-RPC from ACP agent');
                logger.debug('[ACP] Failed to parse JSON-RPC line', { line, error });
                this.markClosed(protocolError);
                this.process.stdin.end();
                void killProcessByChildProcess(this.process);
                return;
            }

Questions

  • None.

Summary

  • Review mode: initial
  • One major issue found: the fix needs to ignore the known Cursor worktree banner without masking malformed JSON-RPC frames. The current tests cover the banner and non-object JSON noise, but not an unknown malformed stdout line after initialization.

Testing

  • git diff --check
  • Not run: bunx vitest run src/agent/backends/acp/AcpStdioTransport.test.ts (bunx not found in this runner shell)

HAPI Bot

this.rejectAllPending(protocolError);
this.process.stdin.end();
void killProcessByChildProcess(this.process);
} catch {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[MAJOR] This now ignores every unparsable stdout line, not just Cursor's known Using worktree: banner. If the ACP agent emits a corrupted/truncated JSON-RPC response, the pending request is never rejected; for session/prompt that request has timeoutMs: Infinity, so the remote session can stay stuck instead of failing fast.

Suggested fix:

        } catch (error) {
            if (this.shouldGuardAgentCli && line.startsWith('Using worktree: ')) {
                logger.debug('[ACP] Ignoring Cursor worktree stdout banner', { line });
                return;
            }

            const protocolError = new Error('Failed to parse JSON-RPC from ACP agent');
            logger.debug('[ACP] Failed to parse JSON-RPC line', { line, error });
            this.markClosed(protocolError);
            this.process.stdin.end();
            void killProcessByChildProcess(this.process);
            return;
        }

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.

fix(cli): Cursor sessionType=worktree crashes ACP on "Using worktree" stdout banner

1 participant