Skip to content

[codex] Continue agent work in a new session - #9170

Merged
brennanb2025 merged 6 commits into
stablyai:mainfrom
dacongming0425:codex/continue-session-in-codex
Jul 22, 2026
Merged

brennanb2025 merged 6 commits into
stablyai:mainfrom
dacongming0425:codex/continue-session-in-codex

Conversation

@dacongming0425

@dacongming0425 dacongming0425 commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Have you ever been deep in a coding task when the current agent suddenly hits its usage limit? Today that breaks the flow: find the provider's session file, open another agent, paste a path, and explain where the work stopped. The same friction appears when a long session starts losing focus and the user wants a clean context window without abandoning the task.

This PR adds Continue in New Session… as a provider-neutral workflow:

  • start from an active terminal, Native Chat, or an AI Vault session
  • keep the original session unchanged
  • default to the original agent, or switch to any detected agent on the same workspace host
  • choose Focused handoff for the latest progress or Full session transcript when a transcript is available
  • preserve the workspace and original working directory
  • work across local, SSH, WSL, and paired runtime launch paths using the existing host-aware agent detection and tab startup infrastructure

This is intentionally different from resume and fork:

  • Resume reopens the provider's original session.
  • Fork creates parallel work from an existing session.
  • Continue in New Session creates a fresh sequential session for the same unfinished task.

Screenshots

Choose the Agent and context

Start with the original Agent or switch to another detected Agent. Focused handoff is recommended for a clean context window; the full transcript remains available when more history is needed.

Choose the Agent and context for a new session

Testing

  • pnpm lint — changed-file lint, React Doctor, styled-scrollbar, reliability, max-lines, skill-manifest, and localization checks pass. The aggregate command currently stops on two unchanged upstream/main switch-exhaustiveness errors in native-chat-session-option-labels.ts and skill-freshness-group.tsx.
  • pnpm typecheck
  • pnpm test — Node 24 full run executed 31,326 tests successfully with 54 skipped. Three environment-sensitive tests initially failed because /usr/sbin/lsof was absent from a narrowed PATH and an SSH fixture timed out; both affected files passed when rerun with the complete system PATH.
  • pnpm build
  • Added regression tests for Agent selection, focused/full context generation, terminal and AI Vault entry points, host-scoped detection, unavailable Agents, original cwd propagation, and paired web runtime launches.

AI Review Report

The review checked:

  • Cross-platform compatibility: no new hard-coded keyboard modifiers or platform labels; cwd propagation uses existing tab/runtime APIs and remains opaque to renderer code. Windows shell selection continues through the existing launch path.
  • Local/SSH/runtime compatibility: Agent availability is detected on the host that owns the workspace. SSH uses remote detection, paired runtimes use runtime detection and host launch, and local workspaces use local detection.
  • Agent compatibility: behavior is generic over TuiAgent; it does not special-case Claude-to-Codex or assume a particular provider's resume command.
  • Performance: Agent detection runs only while opening the dialog. The renderer does not parse full transcripts; it passes the transcript path to the selected Agent. Terminal fallback capture remains bounded.
  • UI quality: uses the existing style tokens, shadcn primitives, and Agent combobox. Live QA caught and fixed long AI Vault session titles expanding the dialog beyond its bounds.
  • Main risks: the feature touches several UI entry points. Shared request/prompt/launch modules and targeted tests keep those entry points on the same behavior.

Security Audit

  • Transcript content and transcript paths are delivered to the Agent after its TUI is ready; they are not interpolated into shell startup commands.
  • Generated instructions explicitly treat prior transcript/tool output as historical, potentially untrusted reference data and tell the new Agent to use the current repository state as authoritative.
  • Full transcripts are read only by the selected Agent and are never modified or deleted by Orca.
  • Working-directory values flow through the existing local/WSL/SSH/runtime cwd mechanisms rather than new shell quoting or command construction.
  • Agent trust preflight reuses the existing scoped IPC and is best-effort; this PR adds no dependency, credential, token, auth, or secret handling.

Notes

  • Full-session mode is available only when Orca has a provider transcript path. Otherwise the focused mode uses a bounded recent terminal capture.
  • The original session remains available for resume or reference after the continuation launches.
  • X (Twitter) handle: not provided yet.

@dacongming0425
dacongming0425 marked this pull request as ready for review July 17, 2026 09:05
@coderabbitai

coderabbitai Bot commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: d406f7e7-eecb-44bd-8cb5-7082bccce9aa

📥 Commits

Reviewing files that changed from the base of the PR and between e1085b7 and ec0a550.

📒 Files selected for processing (18)
  • src/main/ai-vault/runtime-session-scanner.ts
  • src/main/ai-vault/session-scanner-accumulator.ts
  • src/main/ai-vault/session-scanner-codex-parser.test.ts
  • src/main/ai-vault/session-scanner-codex-parser.ts
  • src/main/ai-vault/session-scanner-injected-title.test.ts
  • src/main/ai-vault/session-scanner-primary-parsers.ts
  • src/main/ai-vault/session-scanner-types.ts
  • src/renderer/src/components/agent-session-continuation/AgentSessionContinuationDialog.tsx
  • src/renderer/src/components/right-sidebar/ai-vault-session-continuation.test.ts
  • src/renderer/src/components/right-sidebar/ai-vault-session-continuation.ts
  • src/renderer/src/components/terminal-pane/terminal-agent-session-continuation.test.ts
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/zh.json
  • src/renderer/src/lib/agent-session-continuation.ts
  • src/shared/ai-vault-types.ts
🚧 Files skipped from review as they are similar to previous changes (10)
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/components/right-sidebar/ai-vault-session-continuation.test.ts
  • src/renderer/src/components/terminal-pane/terminal-agent-session-continuation.test.ts
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/components/right-sidebar/ai-vault-session-continuation.ts
  • src/renderer/src/lib/agent-session-continuation.ts
  • src/renderer/src/i18n/locales/zh.json
  • src/renderer/src/components/agent-session-continuation/AgentSessionContinuationDialog.tsx
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/ja.json

📝 Walkthrough

Walkthrough

Adds end-to-end continuation of interrupted agent sessions from terminal panes and AI Vault sessions. The changes create continuation request and prompt utilities, detect available TUI agents, launch new sessions with optional working directories, and add continuation actions to menus, pane headers, sidebar rows, and dialogs. They also add agent selection, focused/full context modes, localized strings, session prompt metadata, and tests covering request preparation, eligibility, launch behavior, UI actions, and detection retry handling.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 4.55% which is insufficient. The required threshold is 80.00%. 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 is concise and accurately summarizes the main change: continuing agent work in a new session.
Description check ✅ Passed The description follows the template and includes all required sections with detailed summary, screenshots, testing, review, security, and notes.
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.

@dacongming0425

Copy link
Copy Markdown
Contributor Author

Hi @brennanb2025, gentle ping when you have a chance. This workflow has become a common need across our team.

When an agent reaches its usage limit, people currently have to manually find and carry the context into another session before they can continue working. Some teammates also prefer to use one session for planning, then start a fresh session for implementation while retaining the important context and current workspace.

This PR aims to make both workflows a one-click handoff instead of a manual process. We'd really appreciate your review when you have time, and I'm happy to adjust the implementation based on your feedback. Thanks!

@brennanb2025

Copy link
Copy Markdown
Contributor

Taking a look!

@dacongming0425
dacongming0425 force-pushed the codex/continue-session-in-codex branch from 05a6601 to 97f1ada Compare July 20, 2026 11:40
@dacongming0425

Copy link
Copy Markdown
Contributor Author

Rebased this branch onto the latest upstream/main and resolved the merge conflicts. The updated branch is now pushed and ready for review.

@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 (3)
src/renderer/src/components/right-sidebar/ai-vault-session-launch-actions.ts (1)

150-195: 📐 Maintainability & Code Quality | 🔵 Trivial

Duplicate target-resolution/error-toast logic with handleResume.

handleContinueInNewSession repeats the same resolveAiVaultSessionLaunchTarget → missing/unsupported → toast.error + return pattern already in handleResume (lines 88-110). Consider extracting a shared helper (e.g. resolveAiVaultLaunchTargetOrToast) that both callbacks call.

♻️ Sketch of a shared helper
+function resolveTargetOrToast(args: {
+  session: AiVaultSession
+  activeWorktreeId: string | null
+  targetWorktreeId?: string
+  targetState: AiVaultSessionResumeTargetState
+}): { worktreeId: string } | null {
+  const targetId = resolveAiVaultSessionLaunchTarget({
+    sessionFilePath: args.session.filePath,
+    sessionExecutionHostId: args.session.executionHostId,
+    activeWorktreeId: args.activeWorktreeId,
+    targetWorktreeId: args.targetWorktreeId,
+    targetState: args.targetState
+  })
+  if (targetId.status === 'missing') {
+    toast.error(translate(/* ... */))
+    return null
+  }
+  if (targetId.status === 'unsupported') {
+    toast.error(aiVaultResumeUnsupportedMessage(targetId.targetStatus))
+    return null
+  }
+  return { worktreeId: targetId.worktreeId }
+}
src/renderer/src/components/agent-session-continuation/AgentSessionContinuationDialog.tsx (1)

108-115: 📐 Maintainability & Code Quality | 🔵 Trivial

Add a "why" comment for the 200ms starting-indicator delay.

Per coding guidelines, non-obvious TypeScript code should explain why the constraint exists. The separate showStarting state and its 200ms delay exist to avoid a loading-spinner flicker on fast launches, but that rationale isn't documented.

As per coding guidelines, "For non-obvious TypeScript code, add a concise comment explaining why the constraint exists, not how the code works."

Source: Coding guidelines

src/renderer/src/components/agent-session-continuation/AgentSessionContinuationDialog.test.ts (1)

1-32: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

File name doesn't match what it tests.

This file tests chooseInitialContinuationAgent from agent-session-continuation-selection.ts, not the AgentSessionContinuationDialog component. Consider renaming to agent-session-continuation-selection.test.ts for discoverability, since the Dialog component itself currently has no dedicated test coverage.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: ea1568ba-25a3-4a11-ba7d-836c8c6515f8

📥 Commits

Reviewing files that changed from the base of the PR and between 633cad3 and 97f1ada5e957c3f873ab7a31ac96895a57735492.

📒 Files selected for processing (37)
  • src/renderer/src/components/agent-session-continuation/AgentSessionContinuationDialog.test.ts
  • src/renderer/src/components/agent-session-continuation/AgentSessionContinuationDialog.tsx
  • src/renderer/src/components/agent-session-continuation/agent-session-continuation-selection.ts
  • src/renderer/src/components/agent/AgentCombobox.test.tsx
  • src/renderer/src/components/agent/AgentCombobox.tsx
  • src/renderer/src/components/native-chat/use-native-chat-context-menu.tsx
  • src/renderer/src/components/right-sidebar/AiVaultPanel.tsx
  • src/renderer/src/components/right-sidebar/AiVaultSessionActionMenuItems.tsx
  • src/renderer/src/components/right-sidebar/AiVaultSessionDetails.tsx
  • src/renderer/src/components/right-sidebar/AiVaultSessionRow.tsx
  • src/renderer/src/components/right-sidebar/AiVaultSessionVirtualList.tsx
  • src/renderer/src/components/right-sidebar/SessionRowTrailingActions.test.tsx
  • src/renderer/src/components/right-sidebar/SessionRowTrailingActions.tsx
  • src/renderer/src/components/right-sidebar/ai-vault-session-continuation.test.ts
  • src/renderer/src/components/right-sidebar/ai-vault-session-continuation.ts
  • src/renderer/src/components/right-sidebar/ai-vault-session-launch-actions.ts
  • src/renderer/src/components/terminal-pane/AgentSessionContinuationMenuItem.tsx
  • src/renderer/src/components/terminal-pane/TerminalContextMenu.test.tsx
  • src/renderer/src/components/terminal-pane/TerminalContextMenu.tsx
  • src/renderer/src/components/terminal-pane/TerminalPane.tsx
  • src/renderer/src/components/terminal-pane/TerminalPaneHeaderOverlay.test.tsx
  • src/renderer/src/components/terminal-pane/TerminalPaneHeaderOverlay.tsx
  • src/renderer/src/components/terminal-pane/terminal-agent-session-continuation.test.ts
  • src/renderer/src/components/terminal-pane/terminal-agent-session-continuation.ts
  • src/renderer/src/components/terminal-pane/use-terminal-pane-context-menu.ts
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/zh.json
  • src/renderer/src/lib/agent-session-continuation.ts
  • src/renderer/src/lib/launch-agent-in-new-tab-cwd.test.ts
  • src/renderer/src/lib/launch-agent-in-new-tab.test.ts
  • src/renderer/src/lib/launch-agent-in-new-tab.ts
  • src/renderer/src/lib/launch-agent-session-continuation.test.ts
  • src/renderer/src/lib/launch-agent-session-continuation.ts
  • src/renderer/src/lib/launch-agent-web-host-tab.ts

Comment on lines +69 to +106
useEffect(() => {
if (!open || !request) {
return
}
let cancelled = false
void detectAgentSessionContinuationAgents(request.worktreeId)
.then((detected) => {
if (cancelled) {
return
}
const enabled = detected.filter((agent) => isTuiAgentEnabled(agent, disabledAgents))
setDetectedAgents(enabled)
setSelectedAgent(
chooseInitialContinuationAgent({
availableAgents: enabled,
sourceAgent: request.source.sourceAgent,
defaultAgent: settings?.defaultTuiAgent
})
)
})
.catch((error) => {
console.error('Agent detection failed for continuation dialog', error)
if (!cancelled) {
setDetectedAgents([])
setSelectedAgent(null)
setDetectionFailed(true)
}
})
.finally(() => {
if (!cancelled) {
setDetecting(false)
}
})

return () => {
cancelled = true
}
}, [disabledAgents, open, request, settings?.defaultTuiAgent])

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 | ⚡ Quick win

Detection state (detecting, detectionFailed, detectedAgents) is never reset at the start of a new detection run.

The effect only flips detecting to false in .finally and detectionFailed to true in .catch — it never sets detecting back to true or detectionFailed back to false when a new run starts (including on the success path). Since the component takes open as a controlled prop rather than being unmounted per request, any caller that keeps this dialog mounted across multiple continuation requests (toggling open/request) will show a stale "Could not detect Agents" banner forever after one failure, and briefly expose the previous request's stale detectedAgents/selectedAgent during the next request's async detection window.

🐛 Reset detection state at the start of each run
     let cancelled = false
+    setDetecting(true)
+    setDetectionFailed(false)
     void detectAgentSessionContinuationAgents(request.worktreeId)
       .then((detected) => {
         if (cancelled) {
           return
         }
         const enabled = detected.filter((agent) => isTuiAgentEnabled(agent, disabledAgents))
         setDetectedAgents(enabled)
+        setDetectionFailed(false)
         setSelectedAgent(
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
useEffect(() => {
if (!open || !request) {
return
}
let cancelled = false
void detectAgentSessionContinuationAgents(request.worktreeId)
.then((detected) => {
if (cancelled) {
return
}
const enabled = detected.filter((agent) => isTuiAgentEnabled(agent, disabledAgents))
setDetectedAgents(enabled)
setSelectedAgent(
chooseInitialContinuationAgent({
availableAgents: enabled,
sourceAgent: request.source.sourceAgent,
defaultAgent: settings?.defaultTuiAgent
})
)
})
.catch((error) => {
console.error('Agent detection failed for continuation dialog', error)
if (!cancelled) {
setDetectedAgents([])
setSelectedAgent(null)
setDetectionFailed(true)
}
})
.finally(() => {
if (!cancelled) {
setDetecting(false)
}
})
return () => {
cancelled = true
}
}, [disabledAgents, open, request, settings?.defaultTuiAgent])
useEffect(() => {
if (!open || !request) {
return
}
let cancelled = false
setDetecting(true)
setDetectionFailed(false)
void detectAgentSessionContinuationAgents(request.worktreeId)
.then((detected) => {
if (cancelled) {
return
}
const enabled = detected.filter((agent) => isTuiAgentEnabled(agent, disabledAgents))
setDetectedAgents(enabled)
setDetectionFailed(false)
setSelectedAgent(
chooseInitialContinuationAgent({
availableAgents: enabled,
sourceAgent: request.source.sourceAgent,
defaultAgent: settings?.defaultTuiAgent
})
)
})
.catch((error) => {
console.error('Agent detection failed for continuation dialog', error)
if (!cancelled) {
setDetectedAgents([])
setSelectedAgent(null)
setDetectionFailed(true)
}
})
.finally(() => {
if (!cancelled) {
setDetecting(false)
}
})
return () => {
cancelled = true
}
}, [disabledAgents, open, request, settings?.defaultTuiAgent])

@brennanb2025
brennanb2025 force-pushed the codex/continue-session-in-codex branch from 97f1ada to e1085b7 Compare July 21, 2026 01:46
@brennanb2025

Copy link
Copy Markdown
Contributor

Thanks for the contribution — I rebased this onto the current main branch and tightened the implementation before handing it back. The update now resets detection state for each request, detects agents in the target workspace runtime, preserves terminal context safely, and routes paired-runtime launches plus post-ready prompt delivery through the host that owns the session; it also distinguishes launch failures from context-delivery failures and applies the review's naming, comment, and AI Vault deduplication nits. I added regression coverage for those paths; the full typecheck, 135 focused tests, and touched-file lint/localization/max-lines checks pass.

@dacongming0425

Copy link
Copy Markdown
Contributor Author

Thanks for taking the time to harden the implementation and add the regression coverage. The target-runtime detection and host-owned context delivery changes make a lot of sense. I also really appreciate you and the team maintaining such a great tool. I noticed the PR workflows are currently awaiting approval to run—please let me know if there’s anything else you’d like me to adjust on my side.

Preview user entries can be tool results or harness-injected skill text,
so the continuation prompt's last-prompt hint now comes from the vault
scanner's provider-authenticated lastUserPrompt. Also softens the
continuation instructions for already-complete tasks and adds a cost
warning to the full-transcript option.
@brennanb2025

Copy link
Copy Markdown
Contributor

Live QA — maintainer verification on merge head (851e36d)

Ran the AI Vault → Continue in New Session flow end-to-end in a dev build (macOS, isolated profile) against a real Claude session.

Dialog — Focused handoff default

Original agent pre-selected, Focused handoff recommended, original working directory preserved.

Continue in New Session dialog with Focused handoff selected

Full session transcript — cost warning

The full-transcript option now warns about context/plan/API cost before opting in.

Full session transcript option showing the cost warning

Launch verified

Starting the session opened a new tab in the original cwd and delivered the focused handoff prompt (source lines, transcript path, provider-authenticated status hints, untrusted-transcript framing). The receiving agent read the transcript tail, correctly recognized the prior task was already complete, summarized where it stopped, and waited for instruction — exercising the already-complete path added in ec0a550. (Terminal screenshot withheld: it contains real session content.)

Edge-usage action; keep the resting row at three icons and reveal it with
the other session actions on hover, matching Resume's gating.
@brennanb2025
brennanb2025 force-pushed the codex/continue-session-in-codex branch from 0e8f2cb to 78dd4d2 Compare July 21, 2026 22:09
…n-in-codex

# Conflicts:
#	src/renderer/src/components/terminal-pane/TerminalPane.tsx
@brennanb2025
brennanb2025 merged commit 44f77a3 into stablyai:main Jul 22, 2026
3 checks passed
@brennanb2025

Copy link
Copy Markdown
Contributor

Thanks for the PR, just merged it!

Just added a small change: moved the row action into the hover group. The Continue in New Session icon on session rows previously sat with the always-visible controls; since it's an edge-usage action, it now reveals on hover alongside Jump to Pane / Jump to Worktree / Resume. Rows at rest are back to just the details chevron and overflow menu, and the action remains reachable from … without hovering. A test now locks in the hover gating.

P.S. your gh profile picture made me laugh, it's so awesome 😂

@dacongming0425

Copy link
Copy Markdown
Contributor Author

Thanks again for the thoughtful review! The hover-group change makes perfect sense, and I learned a lot from the improvements you made. I switched to this profile picture back in college when studying computer science was driving me a little crazy. I thought it was hilarious, so I’ve kept it ever since 😂

enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
* feat: continue agent work in a new session

* fix: harden new-session continuation

* fix: source last prompt from provider-authenticated transcript records

Preview user entries can be tool results or harness-injected skill text,
so the continuation prompt's last-prompt hint now comes from the vault
scanner's provider-authenticated lastUserPrompt. Also softens the
continuation instructions for already-complete tasks and adds a cost
warning to the full-transcript option.

* fix: move Continue in New Session row action into the hover group

Edge-usage action; keep the resting row at three icons and reveal it with
the other session actions on hover, matching Resume's gating.

---------

Co-authored-by: jz.feng <[email protected]>
Co-authored-by: Brennan Benson <[email protected]>
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