Skip to content

fix(codex): show resumed Chat before session hooks arrive - #23739

Open
JustTalDevelops wants to merge 1 commit into
stablyai:mainfrom
JustTalDevelops:fix/codex-resume-chat-identity
Open

JustTalDevelops wants to merge 1 commit into
stablyai:mainfrom
JustTalDevelops:fix/codex-resume-chat-identity

Conversation

@JustTalDevelops

Copy link
Copy Markdown

ELI5

When Orca resumes a Codex conversation, it already knows that conversation's exact ID. Chat currently waits for Codex to report the ID again. If that report is delayed or misattributed, Terminal works while Chat opens empty. This change lets Chat use the ID from the resume until Codex reports its own ID.

What Changed

Before: an explicitly resumed Codex conversation could show an empty Chat view even though its transcript existed. After: Chat opens the resumed transcript immediately. A later hook report takes precedence. Fresh sessions still wait for their own hook report.

The renderer reads Orca's existing resume claim for the tab. It uses that ID only for the owning pane while an agent remains in the foreground, and clears the claim when that pane returns to the shell. Tests cover the initial resume, later hook, split sibling, and shell transition.

Why

This reuses an exact session ID Orca already captured when it launched the resume. It does not guess from a tab title or scan transcript files, and it does not add another agent-status producer. The execution host's hook status remains authoritative when present.

This is a supplemental fix for resumed desktop sessions. It does not fix fresh sessions or the shared Codex daemon's incorrect pane identity; #23411 addresses that root cause. A local --no-daemon launch workaround remains useful until the daemon fix lands.

Linked Issue

Related to #22873. Complements #23411; does not close either.

Visual Proof

The behavior is a timing window: the regression component test renders the Chat bridge before any hook entry and asserts that it receives the resumed session ID; after a hook entry arrives, it asserts that the hook ID wins. No screenshot is attached because the user's active fresh-session recovery came from a server-side backfill, not from this change.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated

pnpm test on four focused files: 32 tests passed. pnpm tc passed. pnpm run check:code-quality:changed passed with 0 findings. git diff --check passed.

The focused tests ran on macOS. The code is renderer-only and uses existing tab metadata, with no new RPC fields or SSH commands. Linux, Windows, mobile, and a live delayed-hook replay were not manually tested.

AI Disclosure

OpenAI Codex (GPT-6) prepared the change and tests under user direction. I reviewed the source diff and verification output.

Review

Please check that the resume claim is scoped to the owning pane and cleared when that pane returns to its shell.

Agent skill upstream boundary

  • Not applicable; no upstream skill-installer material is copied or translated.

Notes

Security: the fallback accepts only the session ID already recorded for this tab's explicit resume. Performance: two existing store selectors; no polling or file scan. Backwards compatibility: no wire or persistence change. Remote SSH: the client only reads its existing resume claim; host status still wins. Mobile: this renderer change does not modify the iOS client.

Checklist

  • This PR is small and focused
  • I explained the before/after, mechanism, and alternatives
  • Before/after screenshots or video attached; see Visual Proof
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and mobile impact considered
  • Focused tests, typecheck, and changed-code quality passed; full build and suite left to CI

@greptile-apps

greptile-apps Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 4/5

[Medium risk] Adds session resume logic to the chat pane.

The PR should not merge until a resumed pane’s shell transition retires its claim in split layouts.

Findings

  1. P1 Old resume claim survives splits ▶

Summary

The PR lets Chat open an explicitly resumed Codex transcript before its hook reports, while preferring the hook’s identity once available.

  • It scopes the fallback to the tab-wide owning pane and adds shell-transition cleanup.
  • The cleanup misses a shell transition that occurs while the tab is split, leaving an old claim available after the layout collapses.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Resume claim] --> B{Owning pane and not shell foreground?}
  B -- Yes --> C[Use claim until hook identity arrives]
  C --> D[Hook identity takes precedence]
  B -- No --> E[Do not use claim]
  A --> F{Owning pane returns to shell}
  F -- Single leaf --> G[Retire claim]
  F -- Split layout --> H[Claim retained]
  H --> I[Collapse and fresh Codex launch]
  I --> C
Loading

Reviews (1) · Last reviewed commit: "fix: show resumed Codex chat before hook..."

Comment on lines +52 to +53
layout?.root?.type === 'leaf' &&
layout.root.leafId === pane.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 Old resume claim survives splits If the resumed pane returns to its shell while the tab is split, this check leaves its resume claim in place. After the split collapses back to that pane, a fresh Codex launch can use the old claim before its own hook reports, causing Chat to show the previous conversation. Retire the claim when its owning pane is confirmed back at the shell, even while the tab is split.

@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

Native chat now uses an eligible automatic resume claim as a fallback session identity until live status data is available. A live provider session takes precedence, and resume metadata applies only when its agent matches. When the matching root pane reports shell foreground, the store clears that tab’s resume claim. Tests cover claim eligibility, identity selection, and draft persistence.

Priority: ➖ Normal

Merge Risk: 🟡 Moderate · up to 5dd96

After a resumed Codex pane returns to the shell, Chat can keep showing the old conversation. Reset the gate's retained resolution on that transition and add a regression test before merging.

Security Architecture Review

Security architecture risk: 🟡 Moderate · up to 5dd96

A resumed conversation may remain visible after its terminal pane returns to the shell. The apparent exposure is limited to the local chat pane, but the conversation should be retired when the resume ends.

Retained concerns

  • Medium · security · inferred: Clearing a resume claim on shell return may leave its previously displayed conversation identity retained in the mounted chat gate, allowing the prior transcript to remain visible and read.
Security review details

Security Blast Radius

  • inferred — The identified stale-identity path is scoped to a mounted chat view for the same pane and agent. Evidence does not establish cross-tenant access or a broader service-level exposure.

Security Findings and Attack Paths

  • inferred — If an already displayed resumed pane returns to the shell without unmounting, removing the claim can still leave the old session ID in the gate. The retained ID can continue to select its transcript while the chat view is visible.

Trust Boundaries and Controls

  • observed — Ownership, shell-foreground, and agent-match checks limit which claim reaches resolution; hook-reported provider-session metadata wins when present. The inspected code does not establish claim-creation authority or independent transcript-transport authorization.

Resilience and Maintainability Implications

  • inferred — Unmounting ends the gate's component-local retention, but the shell-transition test starts without a displayed resume identity and does not establish that an already displayed identity is revoked.

Hardening Proposals

  • proposed — Make an explicit shell or claim-retirement transition invalidate the gate's retained resume identity, while preserving retention for transient hook gaps; verify the transition from an already displayed resumed conversation.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 7 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 identifies the Codex resume behavior being fixed: Chat now shows resumed conversations before session hooks arrive.
Description check ✅ Passed The description is complete and explains the user impact, implementation, rationale, linked issues, testing, scope, and compatibility considerations. It clearly records that required visual proof was …
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: c9ef5ab5-1f44-445a-967f-63763613f1db

📥 Commits

Reviewing files that changed from the base of the PR and between bd5dca4 and 5dd9664.

📒 Files selected for processing (7)
  • src/renderer/src/components/native-chat/NativeChatView-resume-claim.test.tsx
  • src/renderer/src/components/native-chat/NativeChatView.test.tsx
  • src/renderer/src/components/native-chat/NativeChatView.tsx
  • src/renderer/src/components/native-chat/native-chat-pane-resolution.test.ts
  • src/renderer/src/components/native-chat/native-chat-pane-resolution.ts
  • src/renderer/src/store/slices/pane-foreground-agent.test.ts
  • src/renderer/src/store/slices/pane-foreground-agent.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 +52 to +54
ownsTabWideLaunchDraft && !shellForeground && resumeClaim
? { agent: resumeClaim.launchAgent, providerSession: resumeClaim.providerSession }
: null

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

🔎 Supported by static analysis

🏁 Script executed:

sed -n '1,120p' src/renderer/src/components/native-chat/NativeChatSessionGate.tsx
sed -n '20,90p' src/renderer/src/components/native-chat/NativeChatView.tsx

Repository: stablyai/orca

Length of output: 3945


🏁 Script executed:

set -eu
printf '%s\n' '--- relevant files ---'
fd -t f 'NativeChat(View|SessionGate|ResolvedView).*\.tsx$|native-chat-pane-resolution.*' src/renderer/src/components/native-chat
printf '%s\n' '--- declarations and usages ---'
rg -n -A8 -B8 'NativeChatSessionGate|function NativeChatBridgeView|function NativeChatResolvedView|resolveNativeChatSession|shellForeground' src/renderer/src/components/native-chat

Repository: stablyai/orca

Length of output: 42010


🏁 Script executed:

set -eu
fd -t f -i 'NativeChat' src/renderer/src/components/native-chat
printf '%s\n' '--- relevant symbols ---'
rg -n -A10 -B10 'NativeChatSessionGate|function NativeChatBridgeView|function NativeChatResolvedView|resolveNativeChatSession|shellForeground' src/renderer/src/components/native-chat

Repository: stablyai/orca

Length of output: 41893


🏁 Script executed:

set -eu
sed -n '1,115p' src/renderer/src/components/native-chat/NativeChatView-resume-claim.test.tsx
sed -n '43,72p' src/renderer/src/components/native-chat/native-chat-pane-resolution.ts

Repository: stablyai/orca

Length of output: 4103


Clear the retained session when the pane returns to the shell.

When shellForeground becomes true, NativeChatBridgeView passes null for resumeSession. resolveNativeChatSession still returns the codex launch agent with a null session ID, so NativeChatSessionGate reuses the previous session for the same pane and agent. The old session can remain visible after the resume claim becomes ineligible.

Reset the retained resolution on the shell transition. Add a regression test that starts with the resumed session already displayed.

@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 critical issues — one retirement gap inline, plus a couple of small notes.

Reviewed changes

  • Resume-identity fallback: resolveNativeChatSession returns the hook's providerSession first and only falls back to a new resumeSession input when its agent matches the resolved agent (native-chat-pane-resolution.ts:55-57).
  • Bridge wiring: NativeChatBridgeView supplies that fallback from automaticAgentResumeClaimsByTabId[terminalTabId], gated to the owning pane (ownsTabWideLaunchDraft) and to !shellForeground (NativeChatView.tsx:41-55).
  • Claim retirement: setPaneForegroundAgent deletes the tab's resume claim when the pane is proven back at the shell and the tab is a single leaf (pane-foreground-agent.ts:47-76), so a fresh launch in that pane stops reusing the resumed identity.
  • Tests: retirement (store), hook precedence plus agent mismatch (resolver), and pre-hook display plus hook-wins (bridge view).

ℹ️ Nitpicks

  • The new NativeChatView.test.tsx case ("keeps a resumed Codex conversation open when its hook reports later") asserts Session resumed-codex only after an entry with the same id is supplied, so it still passes with the fallback removed; the pre-hook assertion lives in NativeChatView-resume-claim.test.tsx. Consider asserting the pre-hook resolution here too, or dropping it as a duplicate.

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

const clearResumeClaim = Boolean(
entry.shellForeground &&
pane &&
layout?.root?.type === 'leaf' &&

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.

Retiring the claim only while the tab is already a single leaf misses every shell transition that happens during a split: clearResumeClaim requires layout.root.type === 'leaf' here, so the claim survives the resumed agent exiting in a split tab and is never retired when the split later collapses. Because the owner-leaf routing helper re-satisfies ownsTabWideLaunchDraft once the tab is a single leaf again, a fresh same-type agent launched in the surviving leaf can be rendered with the previous resumed session's transcript until its own hook arrives.

Technical details
# Retire the resume claim on the owning pane's shell return, not only on a single-leaf tab

## Affected sites
- `src/renderer/src/store/slices/pane-foreground-agent.ts:49-55` — `clearResumeClaim` requires `layout?.root?.type === 'leaf'`, so a `shellForeground: true` publish while the tab is split does not retire the claim.
- `src/renderer/src/components/native-chat/use-terminal-pane-chat-state.ts:79-100` — `tabWideAgentHintLeafId` settles once and is never updated, so after a split collapses the owner is still the original resume leaf.
- `src/renderer/src/components/native-chat/native-chat-leaf-routing.ts:49-61` — `nativeChatLeafOwnsTabWideEvidence` then returns true again for that leaf.
- `src/renderer/src/components/native-chat/NativeChatView.tsx:51-55` — `ownsTabWideLaunchDraft && !shellForeground && resumeClaim` re-supplies the stale claim.
- `src/renderer/src/components/native-chat/native-chat-pane-resolution.ts:55-57` — the fallback populates `sessionId` from the stale claim before any hook reports.

## Required outcome
- A shell-foreground publish for the claim's owning pane should retire the claim even when the tab is split, so the identity cannot outlive the agent it was created for.

## Suggested approach (optional)
- The claim carries no leaf id, which is why retirement is shape-gated. Recording the owning leaf on `AutomaticAgentResumeClaim` (created at `src/renderer/src/lib/sleeping-agent-session-launch.ts:101-124`) would let `setPaneForegroundAgent` retire it for the exact pane instead of inferring from layout shape.

## Open questions for the human (optional)
- Is the single-leaf gate meant to cover only split/resize races, or should a split tab also retire the claim when the resumed pane exits?
- Related (and already raised in another review thread): `NativeChatSessionGate` retains the last rendered `sessionId` for the same pane and agent when the new resolution has `sessionId: null` (`src/renderer/src/components/native-chat/NativeChatSessionGate.tsx:27-42`), so the resumed transcript can stay on screen after `resumeSession` turns null even without a split.

@LeonMAG

LeonMAG commented Oct 9, 2026

Copy link
Copy Markdown

Hi @JustTalDevelops — I reproduced the resumed-session Chat issue locally on macOS with a Codex Desktop-origin session opened through Agent Session History → Resume in Worktree.

I have a local proof-of-concept patch that builds on the approach in this PR and addresses the two retirement gaps called out by the automated reviews:

  • records the exact provider session claim for an explicit AI Vault resume;
  • scopes the claim to the owning pane/leaf, including split layouts;
  • lets live hook identity override the fallback;
  • marks the claim once process evidence confirms the resumed agent;
  • retires it on a definitive shell transition; and
  • invalidates a previously retained Chat resolution so the old transcript cannot remain visible after returning to the shell.

I manually validated the real UI flow:

  1. Resume the imported Codex session in the worktree.
  2. Switch from Terminal to Chat.
  3. Verify the full transcript and latest message load.
  4. Switch Chat → Terminal → Chat and verify the transcript remains intact.

Focused verification currently passes (44 tests plus typecheck) on the local branch. The patch still needs to be rebased onto current main, preserving the newer native-chat visual-owner changes, before it would be PR-ready.

Would you and the Orca maintainers prefer that I:

  1. prepare a follow-up/replacement PR linked to [Bug]: "Resume in Worktree" opens in Terminal despite Default view = Native, and chat view stays empty until a message is sent #12904 and crediting this PR; or
  2. share the patch/commit here so this PR can be updated?

I will not open a competing PR until you advise.

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.

2 participants