Skip to content

fix(agent-resume): resume OMP sessions after worktree sleep - #16276

Closed
CodeHourra wants to merge 1 commit into
stablyai:mainfrom
CodeHourra:fix/omp-worktree-sleep-resume-upstream
Closed

CodeHourra wants to merge 1 commit into
stablyai:mainfrom
CodeHourra:fix/omp-worktree-sleep-resume-upstream

Conversation

@CodeHourra

Copy link
Copy Markdown

ELI5

Sleeping a worktree used to bring Claude back with --resume. OMP (and other Pi-compatible TUI agents) woke into a blank shell instead. After this change, Orca types --resume into the restored shell, using the on-disk session_file the agent reported. Restoring from AI Vault also keeps the previous conversation title.

What Changed

  • Treat OMP as Pi-compatible: capture session_file as transcriptPath, keep providerSession across done → working, and prefer ompResumeFilePath / transcriptPath / id when building --resume.
  • Process OMP session_start hooks so the sleeping record has a resume locator.
  • After worktree-sleep (or completed passive hibernation) restore, type the resume command into the adopted shell. createOrAttach(sessionId) drops argv, so we no longer send resume argv on connect({ sessionId }) and we never inject when a live snapshot/replay is still on screen.
  • AI Vault restore seeds aiVaultTitle for Claude/Codex and pins customTitle for other agents so a later OSC title cannot overwrite the conversation name.

Why

Worktree sleep/wake reattaches an existing PTY session id. The daemon drops spawn argv on that path, so Claude only resumed because a later path typed --resume into the shell. OMP never captured session_file and skipped session_start, so that inject had nothing to type.

Linked Issue

No existing issue.

Visual Proof

N/A — restore injects a --resume line into an existing terminal; there is no new UI chrome.

  • Before: sleep a worktree with an OMP session → wake → blank shell, previous conversation gone
  • After: same flow types --resume <session_file> into the restored shell; AI Vault history keeps the original title

Testing

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

Covered in unit tests:

  • OMP --resume prefers ompResumeFilePath, then transcriptPath, then id
  • OMP session_start is processed (Pi-compatible)
  • provider session survives done → working for Pi-compatible agents
  • hydrate validation accepts Pi-compatible providerSessionOnly
  • worktree-sleep reattach injects resume and does not pass argv on connect({ sessionId })
  • AI Vault restore pins titles for non-Claude/Codex agents
pnpm exec vitest run --config config/vitest.config.ts \
  src/shared/agent-session-resume.test.ts \
  src/shared/agent-hook-listener-pi-compatible.test.ts \
  src/main/pi/agent-status-extension-source.test.ts \
  src/renderer/src/store/slices/agent-status-provider-session.test.ts \
  src/renderer/src/lib/launch-ai-vault-session.test.ts \
  src/renderer/src/components/terminal-pane/pty-connection-cold-restore-resume-command.test.ts \
  src/main/agent-hooks/server-last-status-hydrate-validation.test.ts \
  src/renderer/src/components/terminal-pane/pty-connection/reattach-payload-context.test.ts

8 files, 136 tests passed.

AI Disclosure

Cursor Grok authored the implementation, tests, and this PR description.

Review

  • Cross-platform: resume argv and inject path are host-agnostic; no new hardcoded modifiers or path separators.
  • SSH / remote / folder: inject still waits for the restored shell; loss of contact is not treated as process death. Folder workspaces use the same sleeping-record origin as git worktrees.
  • Remote wire: no new RPC opcodes; transcriptPath / ompResumeFilePath remain optional fields.

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

Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

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)

Summary

  • OMP (and other Pi-compatible TUI agents) now capture session_file and --resume after worktree sleep instead of waking into a blank shell.
  • AI Vault restore keeps the previous conversation title for agents that are not Claude/Codex.

Test plan

  • Start OMP in a worktree, let it create a session, sleep the worktree, wake it → terminal types --resume and continues the same conversation
  • Repeat with Claude → still resumes (no regression)
  • Restore an OMP (or Pi) conversation from AI Vault → tab title stays the history title after the agent prints its OSC title
  • A live snapshot/replay restore does not type --resume into a still-running TUI

Made with Cursor

OMP 的 session_start 现在会带上 session_file,休眠唤醒时把 --resume 打进已恢复的 shell,并从 AI Vault 历史恢复时保留原会话标题。
@coderabbitai

coderabbitai Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The change extends Pi-compatible provider-session handling to OMP. OMP session metadata now includes transcript paths across hooks, status events, persistence, hydration, and resume argument generation. Reattached worktree-sleep sessions keep their PTYs and receive resume commands after restore. AI Vault launches now pass session metadata, configure agent-specific startup behavior, claim automatic resumes, and seed tab titles. Tests cover these flows for OMP, Codex, Claude, Gemini, Pi, and Prime Agent.

Merge Risk: 🟡 Moderate · up to ef2df

Restoring conversations through the web runtime can lose the saved conversation title, causing an inconsistent restored-session experience. The PR should address this bounded correctness issue before merge.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the primary change: resuming OMP sessions after worktree sleep.
Description check ✅ Passed The description covers the change, rationale, testing, compatibility, and checklist; it is mostly complete despite no linked issue.
Docstring Coverage ✅ Passed Docstring check was indeterminate for this PR — some files could not be analyzed in time. Not blocking.
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.

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.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/renderer/src/lib/launch-ai-vault-session.ts (1)

41-43: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Condense the rationale comments.

Use one concise line for each comment.

  • src/renderer/src/lib/launch-ai-vault-session.ts#L41-L43: reduce the title-persistence rationale to one line.
  • src/renderer/src/lib/launch-ai-vault-session.test.ts#L175-L176: reduce the test rationale to one line.

As per coding guidelines, “Comments must be concise, non-obvious, and brief—prefer one line.”

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 15dae804-f06e-4efe-bdf9-d9bd4faf1755

📥 Commits

Reviewing files that changed from the base of the PR and between c618ec7 and ef2df33.

📒 Files selected for processing (25)
  • src/main/agent-hooks/server-last-status-hydrate-validation.test.ts
  • src/main/agent-hooks/server.ts
  • src/main/pi/agent-status-extension-source.test.ts
  • src/main/pi/agent-status-extension-source.ts
  • src/main/pi/agent-status-handler-source.ts
  • src/main/runtime/orca-runtime.ts
  • src/renderer/src/components/right-sidebar/ai-vault-session-launch-actions.ts
  • src/renderer/src/components/tab-group/AiVaultSessionDropLayer.tsx
  • src/renderer/src/components/terminal-pane/pty-connection-cold-restore-resume-command.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection/apply-reattach-payload.ts
  • src/renderer/src/components/terminal-pane/pty-connection/deferred-session-attach.ts
  • src/renderer/src/components/terminal-pane/pty-connection/deferred-session-reattach-connect.ts
  • src/renderer/src/components/terminal-pane/pty-connection/reattach-payload-context.test.ts
  • src/renderer/src/components/terminal-pane/pty-connection/reattach-payload-context.ts
  • src/renderer/src/components/terminal-pane/pty-connection/reattach-result-handler.ts
  • src/renderer/src/hooks/useIpcEvents.ts
  • src/renderer/src/lib/launch-ai-vault-session.test.ts
  • src/renderer/src/lib/launch-ai-vault-session.ts
  • src/renderer/src/lib/sleeping-agent-pane-ownership.ts
  • src/renderer/src/store/slices/agent-status-provider-session.test.ts
  • src/renderer/src/store/slices/agent-status.ts
  • src/shared/agent-hook-listener-pi-compatible.test.ts
  • src/shared/agent-hook-listener.ts
  • src/shared/agent-session-resume.test.ts
  • src/shared/agent-session-resume.ts

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

Comment on lines +56 to +57
title?: string
sessionId?: string

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.

🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Preserve titles for web-runtime resumes.

title and sessionId are ignored when isWebRuntimeSessionActive(...) is true. createWebRuntimeSessionTerminal receives neither field, and this branch returns before seedAiVaultResumeTabTitle. A resumed web-runtime tab therefore loses its restored title. Pass title metadata through the web-runtime creation path and add web-runtime coverage.

@nwparker

Copy link
Copy Markdown
Contributor

The bounded recorded-transcript-path resume proposal is carried forward in #20634, with credit to @CodeHourra and the original Git author stevelliu. Final review identified producer dependencies #20611 → #20615 → #20634, so the replacement is not merged yet. Your broader sleep/replay/title changes are not adopted wholesale; this PR remains open until the replacement is actually merged.

nwparker added a commit that referenced this pull request Sep 19, 2026
Based on the resume-locator proposal in #16276 by @CodeHourra. Retains UUID-based ownership and existing reattach behavior.
@nwparker

Copy link
Copy Markdown
Contributor

Superseded by #20634 (OMP transcript-path resume), which contains the current implementation and verification on . Closing this stale duplicate so review stays on the maintained PR.

@nwparker

Copy link
Copy Markdown
Contributor

Superseded by #20634.

@nwparker nwparker closed this Sep 19, 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.

2 participants