Repository navigation
Partial fix (#19589): retire closed Codex model-picker observations so a walled pane stops gating input #19590
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,12 @@ import { | |
| import { detectTerminalWaitBlockedReason } from './terminal-wait-detection' | ||
| import { getTerminalState } from './terminal-wait-results' | ||
| import { buildTerminalWaitText } from './terminal-wait-tail-state' | ||
| import { | ||
| TerminalCodexModalObservation, | ||
| hasCodexModelPickerTail, | ||
| type TerminalModalFence | ||
| } from './terminal-codex-modal-observation' | ||
| import type { RuntimeVisibleTerminalState } from './runtime-terminal-state-records' | ||
|
|
||
| export type RuntimeTerminalAgentStatusSnapshot = { | ||
| waitText: string | ||
|
|
@@ -26,6 +32,9 @@ export type RuntimeTerminalAgentStatusSnapshot = { | |
| } | ||
|
|
||
| type Dependencies = { | ||
| getModalFence(ptyId: string): TerminalModalFence | ||
| readVisibleState(ptyId: string): Promise<RuntimeVisibleTerminalState | null> | ||
| isCodex(ptyId: string): boolean | ||
| getController(): RuntimePtyController | null | ||
| getLivePty(handle: string): { pty: RuntimePtyWorktreeRecord } | null | ||
| getLiveLeaf(handle: string): { leaf: RuntimeLeafRecord } | ||
|
|
@@ -41,6 +50,7 @@ type Dependencies = { | |
| } | ||
|
|
||
| export class RuntimeTerminalAgentStatusQuery { | ||
| private readonly modal = new TerminalCodexModalObservation() | ||
| private readonly inFlight = new Map<string, Promise<RuntimeTerminalAgentStatus>>() | ||
|
|
||
| constructor(private readonly deps: Dependencies) {} | ||
|
|
@@ -63,6 +73,7 @@ export class RuntimeTerminalAgentStatusQuery { | |
|
|
||
| private async readStatus(handle: string): Promise<RuntimeTerminalAgentStatus> { | ||
| const ptyId = this.getPtyId(handle) | ||
| await this.refreshModal(handle, ptyId) | ||
| const terminal = this.getSnapshot(handle, ptyId) | ||
| const explicitStatus = this.deps.getExplicitStatus(handle) | ||
| const lifecycle = this.deps.getLifecycleStatus(ptyId) | ||
|
|
@@ -129,6 +140,49 @@ export class RuntimeTerminalAgentStatusQuery { | |
| return { handle, isRunningAgent, status: null } | ||
| } | ||
|
|
||
| hasModalToRefresh(handle: string, ptyId: string): boolean { | ||
| return ( | ||
| this.deps.isCodex(ptyId) && hasCodexModelPickerTail(this.getSnapshot(handle, ptyId).waitText) | ||
| ) | ||
| } | ||
|
|
||
| async refreshModal(handle: string, ptyId: string): Promise<void> { | ||
| if (!this.hasModalToRefresh(handle, ptyId)) { | ||
| return | ||
| } | ||
| const snapshot = this.getSnapshot(handle, ptyId) | ||
| const record = this.deps.getLivePty(handle)?.pty ?? this.deps.getLiveLeaf(handle).leaf | ||
| const before = this.deps.getModalFence(ptyId) | ||
| const screen = await this.deps.readVisibleState(ptyId).catch(() => null) | ||
| this.assertTerminalAgentStatusPtyBinding(handle, ptyId) | ||
| const current = this.deps.getLivePty(handle)?.pty ?? this.deps.getLiveLeaf(handle).leaf | ||
| if (record !== current) { | ||
| return | ||
| } | ||
| this.modal.reconcile(record, snapshot.waitText, before, this.deps.getModalFence(ptyId), screen) | ||
| } | ||
|
|
||
| getWaitText(record: RuntimePtyWorktreeRecord | RuntimeLeafRecord, ptyId: string | null): string { | ||
| const text = buildTerminalWaitText(record.tailBuffer, record.tailPartialLine, record.preview) | ||
| return ptyId ? this.modal.read(record, text, this.deps.getModalFence(ptyId)) : text | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win Reconcile a reopened picker before applying retirement.
|
||
| } | ||
|
|
||
| isModalComposerReady(handle: string): boolean { | ||
| const ptyId = this.getPtyId(handle) | ||
| const record = this.deps.getLivePty(handle)?.pty ?? this.deps.getLiveLeaf(handle).leaf | ||
| const text = buildTerminalWaitText(record.tailBuffer, record.tailPartialLine, record.preview) | ||
| const terminal = this.getSnapshot(handle, ptyId) | ||
| const statuses = [ | ||
| terminal.titleStatus, | ||
| this.deps.getExplicitStatus(handle)?.status, | ||
| this.deps.getLifecycleStatus(ptyId)?.status | ||
| ] | ||
| return ( | ||
| !statuses.some((status) => status === 'permission' || status === 'working') && | ||
| this.modal.isReady(record, text, this.deps.getModalFence(ptyId)) | ||
| ) | ||
| } | ||
|
|
||
| getPtyId(handle: string): string { | ||
| const pty = this.deps.getLivePty(handle) | ||
| if (pty) { | ||
|
|
@@ -184,11 +238,7 @@ export class RuntimeTerminalAgentStatusQuery { | |
| { title: pty.pty.title, updatedAt: pty.pty.titleUpdatedAt }, | ||
| { title: pty.pty.lastOscTitle, updatedAt: pty.pty.lastOscTitleAt } | ||
| ) | ||
| const waitText = buildTerminalWaitText( | ||
| pty.pty.tailBuffer, | ||
| pty.pty.tailPartialLine, | ||
| pty.pty.preview | ||
| ) | ||
| const waitText = this.getWaitText(pty.pty, expectedPtyId) | ||
| return { | ||
| waitText, | ||
| waitBlockedAt: pty.pty.waitBlockedAt, | ||
|
|
@@ -216,7 +266,7 @@ export class RuntimeTerminalAgentStatusQuery { | |
| { title: this.deps.getTabTitle(leaf.tabId), updatedAt: 0 } | ||
| ) | ||
| return { | ||
| waitText: buildTerminalWaitText(leaf.tailBuffer, leaf.tailPartialLine, leaf.preview), | ||
| waitText: this.getWaitText(leaf, expectedPtyId), | ||
| waitBlockedAt: leaf.waitBlockedAt, | ||
| title: title?.title ?? null, | ||
| titleStatus: title ? detectAgentStatusFromTitle(title.title) : leaf.lastAgentStatus, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| import { describe, expect, it } from 'vitest' | ||
| import { | ||
| TerminalCodexModalObservation, | ||
| type TerminalModalFence | ||
| } from './terminal-codex-modal-observation' | ||
| import type { RuntimeVisibleTerminalState } from './runtime-terminal-state-records' | ||
|
|
||
| const text = | ||
| 'Select model for Codex\nPress enter to confirm or esc to go back\nModel changed to gpt-6-astra medium' | ||
| const fence: TerminalModalFence = { generation: 1, outputSequence: 20, permissionSequence: 4 } | ||
| const screen: RuntimeVisibleTerminalState = { | ||
| lines: ['› Ask Codex to do anything', 'gpt-6-astra · medium'], | ||
| codexComposer: true, | ||
| generation: 1, | ||
| sequence: 20, | ||
| isAlternateScreen: false | ||
| } | ||
|
|
||
| describe('model modal evidence fences', () => { | ||
| it.each([ | ||
| ['unavailable screen', null, fence], | ||
| ['unreadable composer', { ...screen, codexComposer: undefined }, fence], | ||
| ['stale output', { ...screen, sequence: 19 }, fence], | ||
| ['future output', { ...screen, sequence: 21 }, fence], | ||
| ['stale incarnation', { ...screen, generation: 0 }, fence], | ||
| ['generation changes during read', screen, { ...fence, generation: 2 }], | ||
| ['output changes during read', screen, { ...fence, outputSequence: 21 }], | ||
| ['permission arrives during read', screen, { ...fence, permissionSequence: 5 }], | ||
| [ | ||
| 'approval above the composer', | ||
| { ...screen, lines: ['Codex permission required', 'Allow once', 'Reject', ...screen.lines] }, | ||
| fence | ||
| ] | ||
| ])('keeps %s fail closed', (_name, visible, after) => { | ||
| const observation = new TerminalCodexModalObservation() | ||
| const record = {} | ||
| observation.reconcile(record, text, fence, after, visible) | ||
| expect(observation.read(record, text, after)).toBe(text) | ||
| }) | ||
|
|
||
| it('does not retire a real approval even when it has disappeared', () => { | ||
| const observation = new TerminalCodexModalObservation() | ||
| const record = {} | ||
| const approval = 'Codex permission required\nAllow once\nReject' | ||
| observation.reconcile(record, approval, fence, fence, screen) | ||
| expect(observation.read(record, approval, fence)).toBe(approval) | ||
| const newerApproval = `${text}\n${approval}` | ||
| observation.reconcile(record, newerApproval, fence, fence, screen) | ||
| expect(observation.read(record, newerApproval, fence)).toBe(newerApproval) | ||
| }) | ||
|
|
||
| it('fences a retirement by pane, generation, permission sequence and the exact retained prefix', () => { | ||
| const observation = new TerminalCodexModalObservation() | ||
| const record = {} | ||
| observation.reconcile(record, text, fence, fence, screen) | ||
| expect(observation.read(record, text, fence)).toBe('Model changed to gpt-6-astra medium') | ||
| expect(observation.read({}, text, fence)).toBe(text) | ||
| expect(observation.read(record, text, { ...fence, generation: 2 })).toBe(text) | ||
| expect(observation.read(record, text, { ...fence, permissionSequence: 5 })).toBe(text) | ||
| expect(observation.read(record, `different history\n${text}`, fence)).toContain('Press enter') | ||
| const next = `${text}\nCodex permission required\nAllow once\nReject` | ||
| expect(observation.read(record, next, fence)).toContain('Codex permission required') | ||
| expect(observation.isReady(record, text, { ...fence, outputSequence: 21 })).toBe(false) | ||
| }) | ||
| }) |
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.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: stablyai/orca
Length of output: 50370
🏁 Script executed:
Repository: stablyai/orca
Length of output: 10423
🏁 Script executed:
Repository: stablyai/orca
Length of output: 50369
🏁 Script executed:
Repository: stablyai/orca
Length of output: 42651
🏁 Script executed:
Repository: stablyai/orca
Length of output: 50369
🏁 Script executed:
Repository: stablyai/orca
Length of output: 46085
🏁 Script executed:
Repository: stablyai/orca
Length of output: 50370
🏁 Script executed:
Repository: stablyai/orca
Length of output: 45808
🏁 Script executed:
Repository: stablyai/orca
Length of output: 27401
Preserve timeout and abort during modal refresh.
refreshModaldoes not use the caller'ssignalor deadline. Its provider path has a separate 750 ms timeout, while its headless path awaitswriteChainwithout that deadline. Because this runs beforeterminalWait.waitbinds the options, a short timeout or abort cannot take effect until the refresh returns. Register the waiter first, or apply the same signal and remaining timeout to the refresh.