Skip to content

fix(cursor): retire the session when the agent process dies - #13422

Open
ValeraZSD wants to merge 1 commit into
pingdotgg:mainfrom
ValeraZSD:fix/cursor-retire-dead-session
Open

ValeraZSD wants to merge 1 commit into
pingdotgg:mainfrom
ValeraZSD:fix/cursor-retire-dead-session

Conversation

@ValeraZSD

@ValeraZSD ValeraZSD commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

When the cursor-agent process dies (crash, OOM, killed from outside), the ACP runtime emits ConnectionTerminated, but CursorAdapter has no case for it and drops it. The session stays in sessions and hasSession stays true, and no session.exited is published, so the thread never goes to stopped. On the next message ProviderCommandReactor sees a live session and reuses it, and every prompt fails straight away with the stored "process exited" error. That lasts until the idle reaper stops the session after 30 minutes, the model/mode/cwd changes, or the server restarts.

Cursor now handles ConnectionTerminated the way Antigravity does, and the way #10607 does for Grok: it marks the session terminated, stops it outside the notification fiber, and emits session.exited with exitKind: "error", so the next message starts a fresh process. The test crashes the mock agent mid-prompt using the same T3_ACP_CRASH_PROMPT hook as #10607 (identical lines, so the two merge cleanly).

Summary by CodeRabbit

  • Bug Fixes
    • Cursor sessions are now retired when the agent process terminates unexpectedly and reported as errors. Retired sessions no longer appear in session listings, and further turns on them fail instead of continuing.
  • Tests
    • Added coverage for unexpected agent termination and its effects on session status and retries.

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:M 30-99 changed lines (additions + deletions). labels Sep 24, 2026
@macroscopeapp

macroscopeapp Bot commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at ed6473a

Macroscope's review found this PR approvable — This is a narrowly scoped Cursor session-lifecycle bug fix with a regression test: unexpected agent termination now retires the session, reports an error exit, and prevents reuse of the dead process. The other changes are test-only, with no product-default, schema, security, billing, or static-analysis-suppression impact.

You can add or adjust custom eligibility rules. Learn more.

@coderabbitai

coderabbitai Bot commented Sep 24, 2026

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: pingdotgg/t3code/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: e4961ba0-4611-49aa-aa07-08d02b0e76b1

📥 Commits

Reviewing files that changed from the base of the PR and between b2b43be and ed6473a.

📒 Files selected for processing (3)
  • apps/server/scripts/acp-mock-agent.ts
  • apps/server/src/provider/Layers/CursorAdapter.test.ts
  • apps/server/src/provider/Layers/CursorAdapter.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The Cursor adapter now retires sessions when the agent connection terminates, reports an error exit, and excludes terminated sessions from session queries. A mock-agent crash trigger and a test cover this behavior.

Changes

Cursor session termination

Layer / File(s) Summary
Detect and retire terminated sessions
apps/server/src/provider/Layers/CursorAdapter.ts
The adapter marks a session terminated when its connection ends, stops the session, reports an error exit, and excludes it from requireSession, listSessions, and hasSession.
Trigger and test agent termination
apps/server/scripts/acp-mock-agent.ts, apps/server/src/provider/Layers/CursorAdapter.test.ts
The mock agent exits when enabled and receives the exact prompt text crash now. The test verifies the error exit event, session removal, and failure of a later sendTurn.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant MockAgent as ACP mock agent
  participant Adapter as CursorAdapter notification loop
  participant Session as Cursor session
  participant Consumer as Event consumer
  MockAgent->>Adapter: ConnectionTerminated notification
  Adapter->>Session: Mark terminated and stop session
  Session->>Consumer: Emit session.exited with error
Loading

Suggested reviewers: maria-rcks

Merge Risk: ⚪ Minimal · up to ed647

The change can proceed through normal checks; no actionable merge-blocking issue was established.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: retiring the Cursor session when the agent process dies.
Description check ✅ Passed The description clearly explains what changed and why. It omits the template headings and checklist, but it provides the required change rationale and does not involve UI changes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

Comment @coderabbitai help to get the list of available commands.

This branch has not been deployed

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

Labels

size:M 30-99 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant