Repository navigation
fix(mobile): keep a Codex chat on screen when Codex shows its idle title on a headless host #31460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
158 changes: 158 additions & 0 deletions
158
src/main/runtime/orca-runtime-codex-idle-title-chat-address.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| // #31136: on a headless `orca serve` host, Codex's own idle title is its project name (no agent | ||
| // marker), captured from Codex 0.163. Only a shell title may retire the hook's transcript address. | ||
| import { describe, expect, it, vi } from 'vitest' | ||
| import { OrcaRuntimeService } from './orca-runtime' | ||
| import type { AgentStatusIpcPayload } from '../../shared/agent-status-types' | ||
| import { makePaneKey } from '../../shared/stable-pane-id' | ||
|
|
||
| vi.mock('electron', () => ({ | ||
| BrowserWindow: { fromId: vi.fn(() => null) }, | ||
| webContents: { fromId: vi.fn(() => null) }, | ||
| ipcMain: { on: vi.fn(), removeListener: vi.fn() }, | ||
| app: { getPath: vi.fn(() => '/tmp') } | ||
| })) | ||
|
|
||
| const LEAF_ID = '11111111-1111-4111-8111-111111111111' | ||
| const TAB_ID = 'codex-tab' | ||
| const WORKTREE_ID = 'wt-1' | ||
| const PANE_KEY = makePaneKey(TAB_ID, LEAF_ID) | ||
| const PTY_ID = 'pty-codex' | ||
| const PROVIDER_SESSION = { | ||
| key: 'session_id' as const, | ||
| id: '01a15d4e-5a65-7c20-9442-73a471f43654', | ||
| transcriptPath: | ||
| '/home/u/.codex/sessions/2026/10/21/rollout-2026-10-21T00-12-58-01a15d4e-5a65-7c20-9442-73a471f43654.jsonl' | ||
| } | ||
|
|
||
| function codexRow(overrides: Partial<AgentStatusIpcPayload>): AgentStatusIpcPayload { | ||
| const now = Date.now() | ||
| return { | ||
| paneKey: PANE_KEY, | ||
| state: 'done', | ||
| prompt: '', | ||
| agentType: 'codex', | ||
| connectionId: null, | ||
| receivedAt: now, | ||
| stateStartedAt: now, | ||
| tabId: TAB_ID, | ||
| worktreeId: WORKTREE_ID, | ||
| providerSession: PROVIDER_SESSION, | ||
| ...overrides | ||
| } | ||
| } | ||
|
|
||
| // Codex 0.163 frames: its window title, and the OSC 7501 program state it paints beside it. | ||
| const title = (text: string): string => `\x1b]0;${text}\x07` | ||
| const programState = (state: 'working' | 'idle'): string => | ||
| `\x1b]7501;state=${state}:app=codex\x1b\\` | ||
|
|
||
| async function codexPaneAfterOutput( | ||
| rows: AgentStatusIpcPayload[], | ||
| frames: string[], | ||
| /** The host's verdict when a title drops the agent marker, as the hook server reports it. */ | ||
| presence: 'live' | 'exited' = 'live' | ||
| ): Promise<unknown> { | ||
| const runtime = new OrcaRuntimeService(null, undefined, { | ||
| getAgentStatusSnapshot: () => rows, | ||
| getAgentProviderSessionRowsForPane: () => rows, | ||
| checkHookAgentPresence: async () => presence | ||
| }) | ||
| // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: OrcaRuntimeService defines this protected method; the spy only stubs workspace resolution. | ||
| const internals = runtime as unknown as { | ||
| resolveTerminalWorkspaceLaunchScope: (selector: string) => Promise<unknown> | ||
| } | ||
| vi.spyOn(internals, 'resolveTerminalWorkspaceLaunchScope').mockResolvedValue({ | ||
| id: WORKTREE_ID, | ||
| path: '/repo/app', | ||
| connectionId: null, | ||
| repo: null, | ||
| folderWorkspace: null | ||
| }) | ||
| runtime.setPtyController({ | ||
| spawn: vi.fn().mockResolvedValue({ id: PTY_ID }), | ||
| write: () => true, | ||
| kill: () => true, | ||
| getForegroundProcess: async () => null | ||
| }) | ||
| await runtime.createTerminal(`id:${WORKTREE_ID}`, { | ||
| tabId: TAB_ID, | ||
| leafId: LEAF_ID, | ||
| launchAgent: 'codex', | ||
| title: 'Terminal' | ||
| }) | ||
| for (const frame of frames) { | ||
| runtime.onPtyData(PTY_ID, frame, Date.now()) | ||
| // The presence recheck a dropped marker starts settles before the next frame. | ||
| await new Promise((resolve) => setImmediate(resolve)) | ||
| } | ||
| const { tabs } = await runtime.listMobileSessionTabs(`id:${WORKTREE_ID}`) | ||
| const tab = tabs[0] | ||
| return tab?.type === 'terminal' ? tab.agentStatus : undefined | ||
| } | ||
|
|
||
| describe('headless Codex chat address under Codex idle titles (#31136)', () => { | ||
| it('keeps the transcript address once a turn with no tool call ends', async () => { | ||
| const agentStatus = await codexPaneAfterOutput( | ||
| [codexRow({ state: 'done' })], | ||
| [ | ||
| programState('working'), | ||
| title('⠋ repo'), | ||
| title('⠸ Reply with hi | repo'), | ||
| title('Reply with hi | repo'), | ||
| programState('idle') | ||
| ] | ||
| ) | ||
|
|
||
| expect(agentStatus).toMatchObject({ | ||
| agentType: 'codex', | ||
| state: 'done', | ||
| providerSession: PROVIDER_SESSION | ||
| }) | ||
| }) | ||
|
|
||
| it('keeps the transcript address while a new turn starts under the idle title', async () => { | ||
| const agentStatus = await codexPaneAfterOutput( | ||
| [codexRow({ state: 'working', prompt: 'explain the parser' })], | ||
| [title('Reply with hi | repo'), programState('idle')] | ||
| ) | ||
|
|
||
| // The newer idle title outranks the older hook state, as under any other title. | ||
| expect(agentStatus).toMatchObject({ | ||
| agentType: 'codex', | ||
| state: 'done', | ||
| providerSession: PROVIDER_SESSION | ||
| }) | ||
| }) | ||
|
|
||
| it('follows OSC 7501 working under a title with no agent marker', async () => { | ||
| const agentStatus = await codexPaneAfterOutput( | ||
| [codexRow({ state: 'working', prompt: 'explain the parser' })], | ||
| [title('⠋ repo'), title('Reply with hi | repo'), programState('working')] | ||
| ) | ||
|
|
||
| expect(agentStatus).toMatchObject({ | ||
| agentType: 'codex', | ||
| state: 'working', | ||
| providerSession: PROVIDER_SESSION | ||
| }) | ||
| }) | ||
|
|
||
| it('keeps an identity-only session address under the idle title', async () => { | ||
| const agentStatus = await codexPaneAfterOutput( | ||
| [codexRow({ state: 'done', providerSessionOnly: true })], | ||
| [title('⠋ repo'), title('Reply with hi | repo'), programState('idle')] | ||
| ) | ||
|
|
||
| expect(agentStatus).toMatchObject({ state: 'done', providerSession: PROVIDER_SESSION }) | ||
| }) | ||
|
|
||
| it('still retires the pane when the shell reclaims its title', async () => { | ||
| const agentStatus = await codexPaneAfterOutput( | ||
| [codexRow({ state: 'done' })], | ||
| [title('⠋ repo'), title('Reply with hi | repo'), programState('idle'), title('zsh')], | ||
| 'exited' | ||
| ) | ||
|
|
||
| expect(agentStatus).toBeUndefined() | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: stablyai/orca
Length of output: 7815
🏁 Script executed:
Repository: stablyai/orca
Length of output: 34459
🏁 Script executed:
Repository: stablyai/orca
Length of output: 43364
🏁 Script executed:
Repository: stablyai/orca
Length of output: 7444
Match the hook session agent before using neutral-title evidence.
selectRuntimeHookAgentRowForPanekeepsproviderSessionafter the hook agent becomes stale. The builder can then emitpty.foregroundAgentasagentTypewhile attaching the stale CodexproviderSession. Native Chat uses both fields andproviderSession.idto resolve the conversation, so Chat can open the Codex conversation for a different foreground agent. Compare the known hook session agent with the effective owner before accepting and emitting that provider session. This still accepts same-agent Codex idle-title rows.Suggested fix
if (!pty?.lastAgentStatus && !retained && !hookRow.agentType && !hookRow.providerSession) { return {} } - const providerSession = hookRow.providerSession - ? { providerSession: hookRow.providerSession } + const ownerRecord = resolvePaneAgentOwnerRecord({ + launchAgent: tab.launchAgent ?? pty?.launchAgent ?? null, + hookAgent: retained?.payload.agentType ?? hookRow.agentType + }) + const ownerAgent = ownerRecord?.agent ?? pty?.foregroundAgent ?? null + const hookProviderSessionMatchesOwner = + hookRow.providerSessionAgentType == null || + ownerAgent == null || + hookRow.providerSessionAgentType === ownerAgent + const providerSession = + hookRow.providerSession && hookProviderSessionMatchesOwner + ? { providerSession: hookRow.providerSession } : retained?.providerSession ? { providerSession: retained.providerSession } : {} @@ ((!pty?.lastAgentStatus || !terminalTitleBlocksExplicitAgentStatus(ptyTitle)) && - (hookRow.agentType != null || hookRow.providerSession != null)) + (hookRow.agentType != null || + (hookRow.providerSession != null && hookProviderSessionMatchesOwner))) @@ - const ownerRecord = resolvePaneAgentOwnerRecord({ - launchAgent: tab.launchAgent ?? pty?.launchAgent ?? null, - hookAgent: retained?.payload.agentType ?? hookRow.agentType - }) - const ownerAgent = ownerRecord?.agent ?? pty?.foregroundAgent ?? null const ownerOptions = { ownerIsLaunch: ownerRecord?.ownerIsLaunch === true }