Skip to content

fix(agents): resume Cursor TUI sessions after Orca restart - #19552

Closed
rashad wants to merge 7 commits into
stablyai:mainfrom
rashad:fix/cursor-session-restore
Closed

rashad wants to merge 7 commits into
stablyai:mainfrom
rashad:fix/cursor-session-restore

Conversation

@rashad

@rashad rashad commented Sep 8, 2026 •

Copy link
Copy Markdown

ELI5

After an Orca restart, a Cursor pane used to come back as an empty shell. It now relaunches cursor-agent --resume <id>, the same way a Claude pane already relaunches claude --resume <id>.

What Changed

  • Add cursor to RESUMABLE_TUI_AGENTS.
  • Extract the Cursor hook conversation id (conversation_id / session_id, snake or camel) and store it as { key: 'session_id', id }.
  • Build resume argv as cursor-agent --resume <id>.
  • Gate remote host authority on a new runtime capability, agent-session.cursor-resume.v1, so an older host does not see an unknown ensureAgentSession enum member and fail with invalid_argument.

Why

Quit capture never wrote a Cursor provider session, so restore had nothing to inject into the PTY. launchAgent: "cursor" is identity metadata, not a command replay. Restore now follows the same --resume path Claude already uses. Remote hosts probe a new capability so an older server degrades instead of failing.

Linked Issue

Fixes #18668

Visual Proof

N/A — no chrome or layout change. Restore injects a PTY command after restart. Verified locally: Cursor pane → one prompt → quit Orca → restore relaunches cursor-agent --resume <id>.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Unit coverage: session extract + argv, quit-time sleeping record, hook payload normalize, TUI startup quoting (linux + win32 + command override), host-authority capability map, remote launch fallback on an old host, AI Vault + mobile resume command, hibernation live-anchor list derived from RESUMABLE_TUI_AGENTS.

Platforms actually tested: macOS local restart. Linux/Windows quoting is unit-tested; SSH is covered by the capability gate (old host keeps the legacy launch path).

Review

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Known gap (out of scope): quit before the first prompt still has no conversation_id, so restore still creates an empty shell. Same class as a pane that never posted a hook id.

Remote wire: new optional capability only. Mixed client/host is safe; an old host is probed and then uses legacy launch.

Checklist

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

Quit capture never recorded a Cursor provider session, so restore
recreated an empty shell. Extract the hook conversation id, add
cursor to the resumable-agent path, and gate remote hosts on a
new capability so older servers degrade instead of failing.
Thermo cycle 1 asked for the missing camelCase assertion and for one table per cloned Kimi/Cursor path.
Keep the public diff from drifting when a new resumable agent lands, and lock the override append path.
@rashad
rashad marked this pull request as ready for review September 8, 2026 12:51

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

  • cursor joins RESUMABLE_TUI_AGENTS — the single source of truth; every resume/quit-capture/hibernation consumer (isResumableTuiAgent, getAgentResumeArgv, the sleeping-record and live-anchor slices) picks it up automatically.
  • Provider-session extraction — extractAgentProviderSession gains a cursor case reading conversation_id / conversationId / session_id / sessionId into { key: 'session_id', id }, and getAgentResumeArgv emits cursor-agent --resume <id> (a spelling already documented and used by the AI Vault fallback).
  • Remote wire gating — a new optional agent-session.cursor-resume.v1 capability is advertised and probed before the host-authority ensureAgentSession path, so an older host degrades to the legacy launch instead of rejecting the widened agent enum. This matches the Kimi precedent exactly, and the exhaustive satisfies Record<ResumableTuiAgent, …> map makes the next agent a deliberate decision.
  • Test coverage — new/updated cases for session extraction and argv, quit-time sleeping record, hook-payload normalization, TUI startup quoting (linux/win32/cmd override), host-authority capability map, remote fallback on an old host, AI Vault + mobile resume, and the hibernation live-anchor list now derived from RESUMABLE_TUI_AGENTS.

The change is small, focused, and follows the established Kimi pattern. Assertions are exact rather than loose, the capability gate preserves mixed client/host version safety, and the one known gap (no conversation_id before the first prompt) is documented as out of scope.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@coderabbitai

coderabbitai Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 360928d0-661a-4e38-9c1a-45f08f35434b

📥 Commits

Reviewing files that changed from the base of the PR and between 7d01ebd and ae81906.

📒 Files selected for processing (1)
  • src/shared/agent-session-resume.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/shared/agent-session-resume.ts

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


📝 Walkthrough

Walkthrough

Cursor is now registered as a resumable TUI agent. Session extraction accepts Cursor payload fields and generates cursor-agent --resume arguments. A dedicated runtime capability gates host-authority resume behavior. Restore, hibernation, mobile launch, hook normalization, and quit-time capture tests now cover Cursor and related fallback paths.

Priority: ➖ Normal — Schedule the Cursor session restoration fix because Orca currently restores Cursor panes as empty shells when session IDs are not persisted or relaunched.

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to ae819

Cursor session restoration adds persisted session IDs and resume commands, with no outstanding merge-blocking risk identified.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description check ✅ Passed The description is complete and follows the repository template. It explains the change, reason, linked issue, visual impact, testing, known limitation, compatibility considerations, and checklist sta…
Linked Issues check ✅ Passed The changes satisfy issue #18668. Cursor is registered as resumable, session IDs are captured and normalized, restore builds cursor-agent --resume commands, and remote hosts use a capability gate for …
Out of Scope Changes check ✅ Passed The changes are related to Cursor session restoration and its supporting paths. The added tests, capability handling, mobile and AI Vault coverage, and synchronized hibernation agent list support the …
Title check ✅ Passed The title clearly and concisely describes the primary change: resuming Cursor TUI sessions after an Orca restart.
Docstring Coverage ✅ Passed Docstring coverage is 91.67% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 12 files.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

CodeRabbit scores docstring coverage on functions this diff touches and fails below 80%.
CodeRabbit re-scored 7 exports at 71%. These two were the gap to 80%.
CodeRabbit raises the function set on each push. Document the remaining locals so coverage cannot stay under 80%.
Cover readSessionId and withTranscriptPath so every function in the touched file has a docstring.
@rashad

rashad commented Sep 14, 2026

Copy link
Copy Markdown
Author

@brennanb2025 an easy one 😁

@nwparker

nwparker commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

Thank you @rashad for the Cursor conversation identity and restart/resume work. The independently reviewed successor #24670 has now merged as9a1bef48e4d78cdcab7758d604400f7601fd9dbb and retains explicit credit to your PR. Its exact-head hosted checks passed, including the existing restart dispatch tests and cross-version host checks. Closing this predecessor after the replacement merge; authenticated Cursor continuation and broader native Chat/history acceptance remain separately scoped.

@nwparker nwparker closed this Oct 3, 2026
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.

[Bug]: Cursor (cursor-agent) sessions are not restored after Orca restart — pane comes back as an empty terminal

2 participants