fix(acp): ignore Cursor worktree stdout banner#1087
Open
heavygee wants to merge 1 commit into
Open
Conversation
…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>
There was a problem hiding this comment.
Findings
- [Major] Keep malformed JSON-RPC fatal outside the Cursor banner —
handleLinenow catches everyJSON.parsefailure 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/promptis sent withtimeoutMs: Infinity, so a malformed prompt response can keep the remote ACP session stuck instead of surfacing a protocol failure. Evidencecli/src/agent/backends/acp/AcpStdioTransport.ts:229, contextcli/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(bunxnot found in this runner shell)
HAPI Bot
| this.rejectAllPending(protocolError); | ||
| this.process.stdin.end(); | ||
| void killProcessByChildProcess(this.process); | ||
| } catch { |
There was a problem hiding this comment.
[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;
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
agent acp --worktreeprints a plain-textUsing worktree: …banner on stdout before JSON-RPC.AcpStdioTransporttreated JSON.parse failures as fatal and killed the session beforecursorSessionIdexisted.errorresponses still reject pending requests.Fixes #1085
Test plan
bunx vitest run src/agent/backends/acp/AcpStdioTransport.test.ts(cli) — includes regression forUsing worktree: …bun typechecksessionType: worktreeafter merge / soup promote