Skip to content

fix(mobile): keep a finished Codex chat's history on the phone after 30 minutes (STA-7370) - #30408

Closed
Jinwoo-H wants to merge 2 commits into
mainfrom
jinwoo/sta-7370-codex-session-id
Closed

Jinwoo-H wants to merge 2 commits into
mainfrom
jinwoo/sta-7370-codex-session-id

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​167 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​167
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​13 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​9

ELI5

On the phone, a Codex chat that finished more than about 30 minutes ago opened as an empty "Start a chat with Codex" screen, even though the conversation was still there in the terminal. The server had stopped telling the phone which Codex conversation the pane belongs to. Now it keeps telling it.

What Changed

Before: Open a Codex pane on the phone after its last reply is over ~30 minutes old (for example after restarting the phone app). Chat view shows "Start a chat with Codex" with no history. A recent Codex chat, or any Claude chat, looks fine. Sending a new message brings the history back until it goes stale again.

After: The phone gets the Codex conversation's session ID no matter how old the last turn is, so chat view loads the history. The pane shows as finished, which is what it already showed during the first 30 minutes.

Mechanism: The phone finds a chat's history through agentStatus.providerSession on each session.tabs terminal tab. The server builds that status in buildRuntimeMobileAgentStatus. When a pane's current title is not an agent title, that function returns no status at all unless there is a fresh hook signal, so it can't bring back a stuck spinner after the shell takes over (#1437).

Codex goes idle under a plain <task> | <cwd> title (see the captured codex-0-158-0-timed-turn fixture). On top of that, the runtime deliberately sets the PTY's status back to idle when Codex's last spinner clears after its done hook (terminal-agent-status-and-submission.ts, the Codex-only confirmedStatus branch). That combination is plain title plus a PTY status, which doesn't qualify for the existing hook-only exemption. So once the hook row aged out of the 30-minute live window, the function returned {} and the session ID went with it. The session ID is kept in the hook store with no time limit, but nothing published it. Claude isn't affected because it never goes through that Codex idle-restore path.

The fix: when that branch would return nothing but the pane's hook row still has a provider session, publish the existing identity-only fallback instead. That means agent type plus session, with the state forced to done, while skipping the live row and the PTY's working/blocked state.

Why

  • Server-side. Every phone build gets the fix, including already-shipped native shells and the OTA page, as soon as the host (desktop, orca serve, or the SSH host's managed server) updates. No phone change is needed.
  • Doesn't depend on the title. It keys on the hook store's provider session, which is the authority for agent identity, rather than teaching the title classifier about Codex's plain idle title. Any agent that idles under a plain title gets the same behaviour.
  • Doesn't fake liveness. The state is always done. A stale working/permission PTY status under a plain title cannot become a spinner (there's a test for this). That rules out the simpler alternative of just loosening the !pty?.lastAgentStatus check: that would have fallen through and published working.
  • Wire-compatible. Same fields and the same shape the fresh case already sent, so old phones and old desktops see nothing new. The status just stops disappearing at 30 minutes.

Linked Issue

Fixes #20408 (Linear STA-7370)

Visual Proof

N/A. This is a server-side status projection fix, checked with runtime tests. It was not tried on a real phone (see Testing).

Testing

  • New src/main/runtime/codex-stale-session-mobile-chat-identity.test.ts runs a real AgentHookServer that receives Codex hook POSTs (SessionStart, UserPromptSubmit, PreToolUse, Stop) and a runtime that receives Codex's captured title sequence. It then lists mobile session tabs:

    • fresh turn: session published (passed before and after the fix)
    • 31 minutes later: failed before the fix (no agentStatus), passes after
    • stale PTY working under the plain title: published as done, never working
  • src/main/runtime/orca-runtime.test.ts (1434 runtime specs, including all mobile-session-tabs and agent-status specs), hook projection, builder, title-truthfulness, ordering, permission-renewal, row-selection and Codex readiness transcript tests: all pass.

  • pnpm tc:node, oxlint, oxfmt, and check:code-quality:changed all pass.

  • Not done: no manual check on a real phone against a real orca serve / Codex install. The repro is a test harness built from the reported symptom (session.tabs.list with launchAgent: "codex" and no agentStatus).

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Cross-platform: no platform-specific code. SSH: the builder runs on whichever host executes the terminal (local runtime or the SSH host's managed server), so SSH panes get the same fix once that host updates. Folder workspaces: not touched by the change. Performance: no new lookups. It reuses the hook row this function already read.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • 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)

…30 minutes (STA-7370)

A Codex pane idles under a plain title with a restored idle terminal status. Once
its hook row left the 30-minute live window, session.tabs dropped the status and
the provider session with it, so phone chat showed an empty new-chat screen.
Publish the same identity-only done status (agent + session) instead.
@coderabbitai

coderabbitai Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

The runtime status builder now preserves a Codex provider session when no live hook signal survives. It emits identity-only status with state done, independent of PTY status. Regression tests check that the session remains published while the hook row is fresh and after it becomes stale, including when PTY status changes to working. The tests also cover a stale session in a pane without a Codex launch agent.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: 🔵 Low · up to b4417

Finished Codex history remains available, but the change can also offer a resume action for a completed session. Exclude completed rows from move candidates before merging.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: preserving finished Codex chat history on mobile after it becomes stale.
Description check Passed The description includes the required sections, explains the user-visible behavior and implementation, links issue #20408, documents testing and limitations, and addresses compatibility and scope.
Linked Issues check Passed Issue #20408 requires the Codex transcript to reappear after the mobile app restarts. buildRuntimeMobileAgentStatus now preserves hookRow.providerSession when the live status is stale and the pane…
Out of Scope Changes check Passed The pull request changes one mobile agent-status projection and adds one focused regression test file. The production change directly preserves the session identity required by issue #20408. The tests…
Full details: Linked Issues check

Explanation

Issue #20408 requires the Codex transcript to reappear after the mobile app restarts. buildRuntimeMobileAgentStatus now preserves hookRow.providerSession when the live status is stale and the pane has a non-agent title. It publishes agentType, the provider session, and state: 'done' without publishing stale PTY activity. The new regression tests cover fresh status, stale status after the freshness window, stale PTY working, and typed Codex sessions.

Full details: Out of Scope Changes check

Explanation

The pull request changes one mobile agent-status projection and adds one focused regression test file. The production change directly preserves the session identity required by issue #20408. The tests cover the affected mobile status behavior and stale-state safety. No unrelated production behavior or unrelated files appear in the reviewed diff.

  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

🟡 Minor · Exclude completed status rows from move… · runtime-mobile-agent-status-builder.ts:176-204

src/main/runtime/runtime-mobile-agent-status-builder.ts:176-204
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Exclude completed status rows from move candidates.

runningAgentsOnly still scans agentStatusByPaneKey without checking entry.state. The new fallback publishes a resumable Codex session as agentType: 'codex' with state: 'done', so it can create a history candidate and expose “Resume in New Native Chat” after the remaining gates pass. Keep the completed row for transcript resolution, but exclude it from move candidates.

Suggested fix
   for (const [paneKey, entry] of Object.entries(state.agentStatusByPaneKey)) {
+    if (runningAgentsOnly && entry.state === 'done') continue
     registerCandidate(paneKey, entry)
   }

ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 420d064f-70ef-4e34-b373-ec540fb46dbf
📥 Commits

Reviewing files that changed from the base of the PR and between a61f672 and b44173e.

📒 Files selected for processing: 1
  • src/main/runtime/codex-stale-session-mobile-chat-identity.test.ts

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

@OrcaWin

OrcaWin commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator

Closing because #31460 covers the neutral-title Codex chat-identity objective while preserving newer activity and shell-ownership rules.

Current main retains the provider-session address for neutral Codex titles, including identity-only rows after live hook evidence expires. Its integration tests cover completed turns, identity-only addresses, explicit OSC 7501 Working under neutral titles, and retirement when the shell reclaims the pane. Provider identity survives without overriding valid current program activity.

This PR's remaining differences force Done after rejecting live signals even when PTY activity still reports Working/Permission, and retain identity under actual shell titles. Those policies conflict with the current activity/ownership contract. Its stale-working test directly mutates internal PTY state after completion; that alone does not establish a reachable current regression. I reviewed the full two-file patch at b44173e06a9b68071908bce4fbfed0bdab47b271 and current builder/integration tests against main b1d1200ddabcdd28ab2bcbcf29b363c4d5eba0fb. This retires the superseded intent and obsolete fallback, rather than claiming identical behavior. The branch is preserved.

@OrcaWin OrcaWin closed this Oct 27, 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.

Mobile: Codex pane on a remote server loses its transcript after the phone app restarts (Claude pane keeps it)

2 participants