Skip to content

fix(runtime): resume pending headless agents from host session identity - #23919

Open
JustTalDevelops wants to merge 1 commit into
stablyai:mainfrom
JustTalDevelops:fix/headless-agent-resume-on-reopen
Open

JustTalDevelops wants to merge 1 commit into
stablyai:mainfrom
JustTalDevelops:fix/headless-agent-resume-on-reopen

Conversation

@JustTalDevelops

Copy link
Copy Markdown

ELI5

If a headless server has to recreate an agent tab after its terminal disappears, it can start a new empty conversation even though the server still knows the old conversation ID. Reopen that conversation when the ID is available.

What Changed

  • On pending terminal activation, read the provider session ID and agent type from the host's hook store for that exact pane.
  • Build the existing agent resume command with the host's settings and pass the provider session ID through terminal creation.
  • Recover the agent type from that same hook record when the saved tab lacks launchAgent. Keep the current launch behavior when no matching resume identity exists.
  • Cover saved and missing agent types, plus a Claude tab carrying an unrelated Codex ID.

Why

The host already owns the provider identity. Using its pane-scoped record preserves the intended conversation without guessing from titles, transcript directories, or a paired client's state. Checking the hook's agent type prevents a session ID from crossing agents.

Linked Issue

Related to #21743. This addresses pending tab activation when the host still has a pane-scoped provider ID; it does not add headless capture for IDs absent from the hook store.

Visual Proof

N/A for screenshots: this is a headless server activation path with no renderer. The focused tests compare the before and after terminal launch requests: a fresh agent command becomes a provider-specific resume command with the same tab and pane identity.

Testing

  • I manually tested these changes locally. The source change has not been deployed to a live server with active terminals.
  • Automated tests added/updated.

On macOS: three focused Vitest cases pass; node TypeScript check, changed-code quality gate, formatting and git diff --check pass. I inspected a Linux orca serve host where a reopened Codex tab was empty and confirmed its original Codex transcript remained on disk. Windows and SSH execution were considered through the existing shared resume-plan builder but were not run against this patch.

AI Disclosure

OpenAI Codex assisted with investigation, implementation, and tests.

Review

Agent skill upstream boundary

  • Not applicable; no agent skill source is copied or translated.

Notes

The observed Linux host has active terminals inside the Orca service cgroup, so I did not restart or upgrade it to test this patch. The change adds no RPC fields or platform-specific command construction.

Checklist

  • This PR is small and focused.
  • I explained the user-visible change, mechanism, and rationale.
  • Headless behavior has no screenshot surface; the launch difference is covered by focused tests.
  • Self-reviewed for correctness, security, and performance.
  • Cross-platform, remote, and compatibility impact considered.
  • Full pnpm lint, pnpm typecheck, pnpm test, and pnpm build remain for CI; focused local checks pass.

@greptile-apps

greptile-apps Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 4/5

[Medium risk] Adds agent session resumption to terminal creation.

The PR is not safe to merge until pending activation looks up hook identities with the canonical pane key.

Findings

  1. P1 Hook pane key does not match ▶

Summary

The PR adds host-hook provider-session lookup to pending headless terminal activation, then builds and forwards an agent resume launch when an identity is found.

  • It also recovers a missing saved agent type from the hook row and adds focused activation tests.
  • The new lookup uses a different pane-key format from the host hook store, preventing the intended resume path.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Pending terminal tab] --> B["getLeafKey: tabId::leafId"]
  B --> C[Host hook pane lookup]
  D["Stored hook key: tabId:leafId"] -. does not match .-> C
  C --> E[No provider session found]
  E --> F[Fresh agent or plain shell]
Loading

Reviews (1) · Last reviewed commit: "fix(runtime): resume pending headless ag..."

resumeProviderSession?: AgentProviderSessionMetadata
} = {}
const status = publicTab?.type === 'terminal' ? publicTab.agentStatus : null
const paneKey = this.getLeafKey(tab.parentTabId, tab.leafId)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Hook pane key does not match When a pending headless terminal has a saved provider session, this code looks it up with tabId::leafId, but terminal hook rows use tabId:leafId. The lookup finds no session, so activation starts a fresh agent instead of resuming the conversation. If the saved agent type is also missing, it opens a plain shell. The new tests miss this because their hook-row mock returns a row regardless of the requested key.

@coderabbitai

coderabbitai Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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

📝 Walkthrough

Walkthrough

Pending mobile terminal activation can now use eligible provider-session metadata to resume a TUI agent when the tab has no saved launch agent. The runtime checks the selected hook identity, session metadata, eligibility flag, and agent settings before building startup data. Terminal creation receives the resume metadata when available. Tests cover Codex session resumption with and without a saved launch agent, and a Claude tab with a Codex session identity.

Priority: ➖ Normal

Merge Risk: 🟡 Moderate · up to 66c64

A resumed agent can bypass the workspace-trust prompt when its tab has no saved launch agent. Restrict pre-granting trust before merging.

Security Architecture Review

Security architecture risk: 🟡 Moderate · up to 66c64

Resuming the right conversation is useful, but the recovered identity can also cause the host to start an agent and pre-approve its workspace. The new path checks agent compatibility; it is not yet clear that every retained or remote identity has sufficient authority for that decision.

Retained concerns

  • Medium · security · inferred: A pane-scoped provider-session row can now authorize agent startup and persistent workspace trust for a tab with no saved launch-agent identity. Selection and resume checks do not establish that a retained or remote row still belongs to the current workspace, connection, and pane owner.
Security review details

Security Blast Radius

  • inferred — The affected authority is host-side terminal execution, a provider conversation, and the trust artifact for the selected local or remote workspace. The evidence does not establish cross-tenant access or unauthenticated external reachability.

Security Findings and Attack Paths

  • inferred — If a retained or remotely supplied row can be associated with a pending pane without preserving its current owner and host identity, activation can turn that row into a trusted workspace and resumed agent. Whether an attacker can cause that association remains unproven; no Security finding is verified by the supplied candidate.

Trust Boundaries and Controls

  • observed — Local hook ingestion authenticates its hook token, and resume rejects mismatched agent identities and unsupported or empty session metadata. Those controls do not, by themselves, attest the retained row's current connection or worktree ownership at activation.

Hardening Proposals

  • proposed — Before a hook-only row can grant workspace trust, bind its resume identity to the current pane, worktree, and execution connection using authority evidence that remains meaningful for retained rows. Verify the activation caller's authorization and exercise failure and retry after the trust write.
🚥 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 4 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: resuming pending headless agents from the host session identity.
Description check ✅ Passed The description includes all required sections, explains the user-facing change and rationale, identifies the linked issue, documents testing limits, and records checklist status. It clearly states th…
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

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


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 8fcdddaa-0bd1-4b0d-99d0-d1c8eb91f9ba

📥 Commits

Reviewing files that changed from the base of the PR and between f442b16 and 66c6415.

📒 Files selected for processing (4)
  • src/main/runtime/orca-runtime-create-runtime-owned-mobile-session-terminal.ts
  • src/main/runtime/orca-runtime-perform-mobile-session-pty-records-refresh.ts
  • src/main/runtime/orca-runtime-test-scenario-builders.spec.ts
  • src/main/runtime/orca-runtime-tests/mobile-session-tabs-part-07.spec.ts

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

Comment on lines 170 to 237
// bare materialize would put a plain shell under the agent icon.
// Re-resolve the launch like the create path; providers skip startup
// commands when attaching to live sessions, so this cannot double-launch.
let agentStartup: Awaited<
ReturnType<OrcaRuntimeService['resolveMobileSessionTerminalCommand']>
> = {}
if (tab.launchAgent) {
let agentStartup: {
command?: string
env?: Record<string, string>
launchConfig?: SleepingAgentLaunchConfig
launchAgent?: TuiAgent
startupCommandDelivery?: WorktreeStartupLaunch['startupCommandDelivery']
resumeProviderSession?: AgentProviderSessionMetadata
} = {}
const status = publicTab?.type === 'terminal' ? publicTab.agentStatus : null
const paneKey = this.getLeafKey(tab.parentTabId, tab.leafId)
const hookRows =
this.getAgentProviderSessionRowsForPaneFn?.(paneKey) ??
this.getAgentProviderSessionSnapshotFn?.().filter((row) => row.paneKey === paneKey) ??
[]
const hook = selectRuntimeHookAgentRowForPane(hookRows)
const agent =
tab.launchAgent ??
(isResumableTuiAgent(hook.providerSessionAgentType)
? hook.providerSessionAgentType
: undefined)
const providerSession =
agent &&
hook.providerSessionAgentType === agent &&
status?.terminalResumeEligible !== false
? normalizeAgentProviderSession(hook.providerSession)
: null
// A hook's provider identity can restore tabs that lost launchAgent without mixing agents.
if (agent) {
try {
const workspace = await this.resolveTerminalWorkspaceLaunchScope(`id:${worktreeId}`)
agentStartup = await this.resolveMobileSessionTerminalCommand(workspace, {
agent: tab.launchAgent
})
const settings = this.store?.getSettings()
const canResume =
settings &&
providerSession &&
isResumableTuiAgent(agent) &&
isTuiAgentEnabled(agent, settings.disabledTuiAgents)
const resume = canResume
? buildAgentResumeStartupPlan({
...resolveAgentStartupPlanInputs({
agent,
settings,
platform: this.getAgentLaunchPlatformForWorkspace(workspace),
isRemote: Boolean(workspace.connectionId)
}),
providerSession
})
: null
if (resume) {
await this.markWorkspaceTrustedForAgent(agent, workspace.connectionId, workspace.path)
agentStartup = {
command: resume.launchCommand,
env: resume.env,
launchConfig: resume.launchConfig,
launchAgent: agent,
startupCommandDelivery: resume.startupCommandDelivery,
resumeProviderSession: providerSession
}
} else if (tab.launchAgent) {
agentStartup = await this.resolveMobileSessionTerminalCommand(workspace, {
agent: tab.launchAgent
})
}
} catch {
// Why: a disabled or unresolvable agent must not make the tab
// untappable; fall back to the plain-shell materialize.

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.

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

rg -n 'markWorkspaceTrusted|ensureWorkspaceTrusted|workspaceTrusted|trustedWorkspace' src/main/runtime/orca-runtime-perform-mobile-session-pty-records-refresh.ts src/main/runtime | head -100

Repository: stablyai/orca

Length of output: 2478


🏁 Script executed:

set -eu
printf '%s\n' '--- target function ---'
sed -n '120,280p' src/main/runtime/orca-runtime-perform-mobile-session-pty-records-refresh.ts
printf '%s\n' '--- trust helper ---'
sed -n '130,215p' src/main/runtime/orca-runtime-activate-managed-worktree.ts
printf '%s\n' '--- create-agent caller ---'
sed -n '130,195p' src/main/runtime/orca-runtime-create-agent-session.ts
printf '%s\n' '--- mobile command caller ---'
sed -n '1,105p' src/main/runtime/orca-runtime-resolve-mobile-session-terminal-command.ts
printf '%s\n' '--- target symbols and tests ---'
rg -n -C 4 'selectRuntimeHookAgentRowForPane|providerSessionAgentType|terminalResumeEligible|launchAgent|markWorkspaceTrustedForAgent|getAgentProviderSessionRowsForPaneFn|getAgentProviderSessionSnapshotFn' src/main/runtime/orca-runtime-perform-mobile-session-pty-records-refresh.ts src/main/runtime/orca-runtime-tests src/main/runtime/*test.ts
printf '%s\n' '--- base target function ---'
git show a5c7dd9671e9f3675ac36c2e99f1c5cecddda853:src/main/runtime/orca-runtime-perform-mobile-session-pty-records-refresh.ts | sed -n '120,280p'

Repository: stablyai/orca

Length of output: 42206


🏁 Script executed:

printf '%s\n' '--- target function ---'
sed -n '120,280p' src/main/runtime/orca-runtime-perform-mobile-session-pty-records-refresh.ts
printf '%s\n' '--- trust helper ---'
sed -n '130,215p' src/main/runtime/orca-runtime-activate-managed-worktree.ts
printf '%s\n' '--- create-agent caller ---'
sed -n '130,195p' src/main/runtime/orca-runtime-create-agent-session.ts
printf '%s\n' '--- mobile command caller ---'
sed -n '1,105p' src/main/runtime/orca-runtime-resolve-mobile-session-terminal-command.ts
printf '%s\n' '--- target symbols and tests ---'
rg -n -C 4 'selectRuntimeHookAgentRowForPane|providerSessionAgentType|terminalResumeEligible|launchAgent|markWorkspaceTrustedForAgent|getAgentProviderSessionRowsForPaneFn|getAgentProviderSessionSnapshotFn' src/main/runtime/orca-runtime-perform-mobile-session-pty-records-refresh.ts src/main/runtime/orca-runtime-tests src/main/runtime/*test.ts
printf '%s\n' '--- base target function ---'
git show a5c7dd9671e9f3675ac36c2e99f1c5cecddda853:src/main/runtime/orca-runtime-perform-mobile-session-pty-records-refresh.ts | sed -n '120,280p'

Repository: stablyai/orca

Length of output: 41917


🤖 get_repo_knowledge executed:

get_repo_knowledge stablyai/orca /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/learnings /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/conventions

Length of output: 22652


🏁 Script executed:

set -eu
sed -n '120,280p' src/main/runtime/orca-runtime-perform-mobile-session-pty-records-refresh.ts
sed -n '130,215p' src/main/runtime/orca-runtime-activate-managed-worktree.ts
git show a5c7dd9671e9f3675ac36c2e99f1c5cecddda853:src/main/runtime/orca-runtime-perform-mobile-session-pty-records-refresh.ts | sed -n '120,280p'
rg -n -C 5 'selectRuntimeHookAgentRowForPane|terminalResumeEligible|providerSessionAgentType|launchAgent|markWorkspaceTrustedForAgent' src/main/runtime/orca-runtime-tests src/main/runtime

Repository: stablyai/orca

Length of output: 45663


🏁 Script executed:

set -eu
printf '%s\n' '--- mobile hook-only activation fixture ---'
sed -n '630,735p' src/main/runtime/orca-runtime-tests/mobile-session-tabs-part-07.spec.ts
printf '%s\n' '--- hook identity contract fixtures ---'
sed -n '60,185p' src/main/runtime/orca-runtime-tests/terminal-handles-and-agent-status-part-05.spec.ts
printf '%s\n' '--- trust marking definitions and focused tests ---'
rg -n -C 5 'function mark(Local|Remote)WorktreeTrusted|const mark(Local|Remote)WorktreeTrusted|markLocalWorktreeTrusted|markRemoteWorktreeTrusted|workspace.*trust|trusted.*worktree' src/main src/shared src/main/runtime/orca-runtime-tests

Repository: stablyai/orca

Length of output: 42214


🏁 Script executed:

set -eu
rg -n -C 8 'markLocalWorktreeTrusted|markRemoteWorktreeTrusted|markWorkspaceTrustedForAgent|launch-trust|trust.*agent|agent.*trust' src/main src/shared --glob '*.ts' --glob '*.tsx'
printf '%s\n' '--- launch trust tests ---'
sed -n '1,180p' src/main/runtime/agent-terminal-launch-trust-host.test.ts
printf '%s\n' '--- hook-only mobile fixture ---'
sed -n '640,730p' src/main/runtime/orca-runtime-tests/mobile-session-tabs-part-07.spec.ts

Repository: stablyai/orca

Length of output: 42423


🏁 Script executed:

set -eu
sed -n '1,80p' src/main/runtime/runtime-worktree-agent-startup.ts
sed -n '170,245p' src/main/runtime/runtime-worktree-agent-startup.ts
sed -n '1,125p' src/main/agent-trust-presets.ts
sed -n '1,70p' src/main/agent-trust-write-deadline.ts
rg -n -C 8 'trust|preflight|markWorkspaceTrustedForAgent|resumeProviderSession|buildAgentResumeStartupPlan' src/main/runtime/orca-runtime-tests/mobile-session-tabs-part-07.spec.ts src/main/runtime/orca-runtime-tests/terminal-creation-and-readiness-part-07.spec.ts src/main/runtime/runtime-worktree-agent-startup.ts src/main/startup/codex-session-resume-launch.ts

Repository: stablyai/orca

Length of output: 41989


Do not pre-grant workspace trust for hook-only recovery.

When tab.launchAgent is absent, the hook row supplies agent. A valid resume plan then calls markWorkspaceTrustedForAgent before materialization. That writer pre-creates the provider’s trust artifact and bypasses the user’s workspace-trust prompt. The hook row establishes agent identity and session metadata, but it does not establish that the user accepted workspace trust.

Keep hook-based resume, but pre-mark trust only for tabs with the existing explicit launchAgent authorization.

Suggested fix
            if (resume) {
-              await this.markWorkspaceTrustedForAgent(agent, workspace.connectionId, workspace.path)
+              if (tab.launchAgent) {
+                await this.markWorkspaceTrustedForAgent(
+                  agent,
+                  workspace.connectionId,
+                  workspace.path
+                )
+              }
              agentStartup = {
📝 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
// bare materialize would put a plain shell under the agent icon.
// Re-resolve the launch like the create path; providers skip startup
// commands when attaching to live sessions, so this cannot double-launch.
let agentStartup: Awaited<
ReturnType<OrcaRuntimeService['resolveMobileSessionTerminalCommand']>
> = {}
if (tab.launchAgent) {
let agentStartup: {
command?: string
env?: Record<string, string>
launchConfig?: SleepingAgentLaunchConfig
launchAgent?: TuiAgent
startupCommandDelivery?: WorktreeStartupLaunch['startupCommandDelivery']
resumeProviderSession?: AgentProviderSessionMetadata
} = {}
const status = publicTab?.type === 'terminal' ? publicTab.agentStatus : null
const paneKey = this.getLeafKey(tab.parentTabId, tab.leafId)
const hookRows =
this.getAgentProviderSessionRowsForPaneFn?.(paneKey) ??
this.getAgentProviderSessionSnapshotFn?.().filter((row) => row.paneKey === paneKey) ??
[]
const hook = selectRuntimeHookAgentRowForPane(hookRows)
const agent =
tab.launchAgent ??
(isResumableTuiAgent(hook.providerSessionAgentType)
? hook.providerSessionAgentType
: undefined)
const providerSession =
agent &&
hook.providerSessionAgentType === agent &&
status?.terminalResumeEligible !== false
? normalizeAgentProviderSession(hook.providerSession)
: null
// A hook's provider identity can restore tabs that lost launchAgent without mixing agents.
if (agent) {
try {
const workspace = await this.resolveTerminalWorkspaceLaunchScope(`id:${worktreeId}`)
agentStartup = await this.resolveMobileSessionTerminalCommand(workspace, {
agent: tab.launchAgent
})
const settings = this.store?.getSettings()
const canResume =
settings &&
providerSession &&
isResumableTuiAgent(agent) &&
isTuiAgentEnabled(agent, settings.disabledTuiAgents)
const resume = canResume
? buildAgentResumeStartupPlan({
...resolveAgentStartupPlanInputs({
agent,
settings,
platform: this.getAgentLaunchPlatformForWorkspace(workspace),
isRemote: Boolean(workspace.connectionId)
}),
providerSession
})
: null
if (resume) {
await this.markWorkspaceTrustedForAgent(agent, workspace.connectionId, workspace.path)
agentStartup = {
command: resume.launchCommand,
env: resume.env,
launchConfig: resume.launchConfig,
launchAgent: agent,
startupCommandDelivery: resume.startupCommandDelivery,
resumeProviderSession: providerSession
}
} else if (tab.launchAgent) {
agentStartup = await this.resolveMobileSessionTerminalCommand(workspace, {
agent: tab.launchAgent
})
}
} catch {
// Why: a disabled or unresolvable agent must not make the tab
// untappable; fall back to the plain-shell materialize.
// bare materialize would put a plain shell under the agent icon.
// Re-resolve the launch like the create path; providers skip startup
// commands when attaching to live sessions, so this cannot double-launch.
let agentStartup: {
command?: string
env?: Record<string, string>
launchConfig?: SleepingAgentLaunchConfig
launchAgent?: TuiAgent
startupCommandDelivery?: WorktreeStartupLaunch['startupCommandDelivery']
resumeProviderSession?: AgentProviderSessionMetadata
} = {}
const status = publicTab?.type === 'terminal' ? publicTab.agentStatus : null
const paneKey = this.getLeafKey(tab.parentTabId, tab.leafId)
const hookRows =
this.getAgentProviderSessionRowsForPaneFn?.(paneKey) ??
this.getAgentProviderSessionSnapshotFn?.().filter((row) => row.paneKey === paneKey) ??
[]
const hook = selectRuntimeHookAgentRowForPane(hookRows)
const agent =
tab.launchAgent ??
(isResumableTuiAgent(hook.providerSessionAgentType)
? hook.providerSessionAgentType
: undefined)
const providerSession =
agent &&
hook.providerSessionAgentType === agent &&
status?.terminalResumeEligible !== false
? normalizeAgentProviderSession(hook.providerSession)
: null
// A hook's provider identity can restore tabs that lost launchAgent without mixing agents.
if (agent) {
try {
const workspace = await this.resolveTerminalWorkspaceLaunchScope(`id:${worktreeId}`)
const settings = this.store?.getSettings()
const canResume =
settings &&
providerSession &&
isResumableTuiAgent(agent) &&
isTuiAgentEnabled(agent, settings.disabledTuiAgents)
const resume = canResume
? buildAgentResumeStartupPlan({
...resolveAgentStartupPlanInputs({
agent,
settings,
platform: this.getAgentLaunchPlatformForWorkspace(workspace),
isRemote: Boolean(workspace.connectionId)
}),
providerSession
})
: null
if (resume) {
if (tab.launchAgent) {
await this.markWorkspaceTrustedForAgent(
agent,
workspace.connectionId,
workspace.path
)
}
agentStartup = {
command: resume.launchCommand,
env: resume.env,
launchConfig: resume.launchConfig,
launchAgent: agent,
startupCommandDelivery: resume.startupCommandDelivery,
resumeProviderSession: providerSession
}
} else if (tab.launchAgent) {
agentStartup = await this.resolveMobileSessionTerminalCommand(workspace, {
agent: tab.launchAgent
})
}
} catch {
// Why: a disabled or unresolvable agent must not make the tab
// untappable; fall back to the plain-shell materialize.

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

Caution

activateMobileSessionTab looks up the pane's hook row under the wrong pane key, so the lookup returns nothing in production and the resume behavior this PR adds never runs.

Reviewed changes

  • Hook-identity resume on pending activation — activateMobileSessionTab reads the pane's agent-hook row, recovers the agent type when the persisted tab lacks launchAgent, and rebuilds a provider resume command via buildAgentResumeStartupPlan over resolveAgentStartupPlanInputs.
  • Resume metadata threaded to spawn — resumeProviderSession is added to createRuntimeOwnedMobileSessionTerminal's options and forwarded through createTerminal to ptyController.spawn.
  • Gating — resume requires the hook's providerSessionAgentType to equal the resolved agent, terminalResumeEligible !== false, and the agent to be enabled.
  • Tests — the pending-tab scenario builder gains hook-row wiring; new specs cover saved vs. missing launchAgent and the Claude-tab-with-Codex-id guard.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

resumeProviderSession?: AgentProviderSessionMetadata
} = {}
const status = publicTab?.type === 'terminal' ? publicTab.agentStatus : null
const paneKey = this.getLeafKey(tab.parentTabId, tab.leafId)

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.

getLeafKey builds the runtime's internal tabId::leafId key, but agent-hook rows are indexed by the single-colon makePaneKey value (tabId:leafId). Both this per-pane lookup and the snapshot fallback (row.paneKey === paneKey) therefore miss on every host, so hook is always empty, providerSession is always null, and the resume path never runs — the exact bug this PR sets out to fix.

Technical details
# Pending-terminal resume reads hooks under the wrong pane key

## Affected sites
- `src/main/runtime/orca-runtime-perform-mobile-session-pty-records-refresh.ts:182` — `this.getLeafKey(tab.parentTabId, tab.leafId)` returns `${tabId}::${leafId}` (see `orca-runtime-resolve-waiter.ts:25`).
- `src/main/runtime/orca-runtime-perform-mobile-session-pty-records-refresh.ts:183-198` — passes that key to `getAgentProviderSessionRowsForPaneFn` and filters the snapshot by `row.paneKey === paneKey`.
- Production wiring: `src/main/startup/main-process-runtime-service.ts:113` and `src/main/orcad/orcad-entry.ts:227` -> `AgentHookServer.getStatusSnapshotForPane` (`src/main/agent-hooks/server/server-listeners.ts:212`), which looks the key up verbatim in `lastStatusByPaneKey`.
- Hooks/PTY env use `makePaneKey` = `${tabId}:${leafId}` (`src/shared/stable-pane-id.ts:22-30`; `ORCA_PANE_KEY`).
- Canonical derivation: `getMobileTerminalPaneKey` (`src/main/runtime/orca-runtime-prune-mobile-session-tab-group-layout.ts:201-207`) and `projectRuntimeMobileSessionTabs` (`src/main/runtime/runtime-mobile-session-projection.ts:133-143`).
- Test masking: `src/main/runtime/orca-runtime-test-scenario-builders.spec.ts:346` ignores the passed key; the row uses the single-colon form at `:321`.

## Required outcome
- The pane key used for the hook lookup must equal the key hooks are stored under, on desktop, `orca serve`/orcad, and SSH relays.
- Tabs with a saved `launchAgent` resume their provider session; tabs that lost `launchAgent` recover the agent type and resume.

## Suggested approach
- `getMobileTerminalPaneKey` is defined on `OrcaRuntimeWithPruneMobileSessionTabGroupLayout`, a subclass of this mixin, so it is not in scope here. Derive the key inline as that helper does, importing `isTerminalLeafId`/`makePaneKey` from `../../shared/stable-pane-id`:
  `isTerminalLeafId(tab.leafId) ? makePaneKey(tab.parentTabId, tab.leafId) : `${tab.parentTabId}:${legacyPaneId ?? tab.leafId}``

statusRow
? {
getAgentStatusSnapshot: () => [statusRow],
getAgentProviderSessionRowsForPane: () => [statusRow]

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.

The fixture ignores the key it is handed, and the row it returns uses the single-colon makePaneKey form. That is why the suite stays green even though the activation path passes a :: key; filtering the mock on the argument (or asserting through the snapshot fallback) would give this path real coverage.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant