Skip to content

fix(codex): accept U+00BB prompt marker (0.154) and wait through TUI cold start - #1767

Closed
47seek wants to merge 4 commits into
deepcoldy:masterfrom
47seek:fix/codex-prompt-glyph-20261009
Closed

47seek wants to merge 4 commits into
deepcoldy:masterfrom
47seek:fix/codex-prompt-glyph-20261009

Conversation

@47seek

@47seek 47seek commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

Urgent fix for the fleet after the 3.37 deployment: every Lark message to a Codex TUI failed closed with "消息没有安全写入 Codex".

Two independent causes:

  1. Prompt glyph change in Codex 0.154.0-alpha.3: the empty-composer marker is now » (U+00BB) instead of › (U+203A). All readiness/identity probes only matched U+203A, so detectCodexComposerState returned unknown and the terminal identity gate rejected every write. Accept either glyph in all probes:

    • services/codex-composer-state.ts composer/draft detection
    • services/codex-terminal-session.ts empty-composer footer
    • adapters/cli/codex.ts readiness patterns
    • adapters/cli/codex-app.ts ready pattern
    • utils/codex-update-dialog.ts picker selection + resume redraw
  2. Cold-start first-message race: a fresh/resumed TUI paints the banner for seconds (on a slow model endpoint, model: loading for over 30s on our fleet) and the thread-id footer renders a few frames after the composer. The session's first message hit the gate during that window. awaitReadyCodexTerminalSession now bounded-polls up to 90s, covering:

    • no composer marker yet
    • explicit loading / Resuming session rows
    • composer painted but thread-id footer not rendered yet (non-atomic paint)

    Waiting stops immediately on a non-empty composer (human draft/picker/dialog) or a running turn (esc to interrupt), so messages are never written past a draft; configuration problems still fail after the bounded wait with the existing /statusline guidance.

Tests

  • New unit cases for U+00BB marker, half-painted footer, draft/picker non-wait, running-turn non-wait, and wait timeout
  • codex-terminal-session / codex-composer-state / write-input / startup readiness suites: 300+ tests pass; tsc --noEmit clean

Verification (live fleet)

  • Deployed as self-compiled binary; gate now passes on 0.154 terminals with » + thread-id footer
  • Cold-start E2E: after fleet restart, first message to a fresh worker was written and the agent executed and replied (before the fix: rejected)
  • One more live incident during rollout (slow endpoint, >30s loading) led to the 90s/half-paint follow-up commit

Notes

🤖 Generated with Claude Code

47seek and others added 4 commits October 9, 2026 14:39
Codex 0.154 renders the empty-composer marker as » (U+00BB) instead of
› (U+203A). The readiness patterns, composer-state detector, terminal
identity gate and update dialog selectors only matched U+203A, so every
Lark input failed closed before writing to the TUI. Accept either glyph
in all five probes; cover both markers in the composer and terminal
identity tests.

Co-Authored-By: Claude Code <[email protected]>
The session's first Lark message lands while a freshly spawned/resumed
Codex is still painting the banner: the composer marker and thread-id
footer do not exist yet and the rollout fd is absent until first submit,
so refreshCodexTerminalSession failed closed immediately. awaitReadyCodex
TerminalSession bounded-polls (30s) only while the screen shows a
loading row or no composer marker at all; a settled composer without a
thread ID, a human draft, or a running turn (esc to interrupt) still
fails without waiting.
The model line stayed on "loading" for over 30s against a slow
endpoint, so the bounded wait expired while startup was genuinely still
in progress (live session 622a1a92, 0.154.0-alpha.3). Also wait when
the composer is already painted and empty but its thread-id footer has
not rendered yet — the two are not atomic. Only a non-empty composer
(draft/picker/dialog) or a running turn stop the wait immediately.
@47seek

47seek commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator Author

Note for @deepcoldy (delivery-minimal line):

The glyph hunks are byte-equivalent to the ones in fix/codex-delivery-minimal-20261009 — take either.

The only hunk unique to this PR is the cold-start bounded wait (commit 9d92ee6), which needs adaptation against minimal because minimal removed the unavailable → reject branch in writeInput:

  • services/codex-terminal-session.ts: awaitReadyCodexTerminalSession(terminal, 90_000, 1_000) — bounded polls, only while the screen shows loading / no composer / empty composer with unrendered footer; stops immediately on non-empty composer (draft/picker) or esc to interrupt.
  • Wire point under minimal: call it right before the PTY paste in writeInput (it currently calls refreshCodexTerminalSession first line). Value with minimal's delivery-first logic: avoids pasting into a half-painted TUI while model: loading is up (measured >30s on our fleet due to the developers.openai.com MCP initialize timeout) — rollout ownership checks can only catch that after the fact.
  • Tests: test/codex-terminal-session.test.ts cold-start describe block (loading→ready, half-painted footer, draft non-wait, busy non-wait, timeout) + the fake-timer adjustment in test/write-input.test.ts.

Context: live fleet incident chain 2026-10-09 (session 622a1a92) — composer painted, footer ID rendered later, model loading >30s. Happy to close this PR once the wait is ported into the minimal line.

@deepcoldy

Copy link
Copy Markdown
Owner

自动评审初步意见,最终以维护者审阅为准。

整体看,本 PR 三个 commit 解决 3.37 部署后 Codex TUI(0.154-alpha)写入全部 fail-closed 的问题,方向正确:五处字形探针(composer-state / terminal-session / codex / codex-app / update-dialog)改动完整一致;冷启动等待保持了 fail-safe 边界(人工草稿、picker/dialog、运行中的 turn 都不会被越过写入)。本地在最新 master 的 rebase 合成树上 tsc 干净,相关单元套件与 worker 启动集成场景(banner/resume/slow-resume/tmux/coloured 共 5 例)均通过,并对新测试做了变异验证(字形、等待循环、draft 早停、turn 忙碌守卫四处变异分别只杀对应新用例)。

一个合入阻断项:bun-test CI 腿为红

  • 失败用例:codex writeInput submission confirmation > explains the missing footer ID without writing a command or the message,bun 下 180s 超时挂死;node/vitest 三个分片全绿。本地用 bun 1.4.0 复现一致。

  • 根因:用例中的单次 await vi.advanceTimersByTimeAsync(95_000) 在 bun 下无法推进 90 个串行 await delay(1_000) 组成的定时器链——bun 的假时钟一次 advance 只排一层微任务,后续 setTimeout 全停在假时钟上,Promise 永不结清。

  • 建议修法(本地已验证:bun / vitest 双腿各 157/157 全绿,6s 完成):该文件顶部已 import 的 flushFakeTimers 正是为这个跨 runner 差异准备的,将

    await vi.advanceTimersByTimeAsync(95_000);

    改为

    await flushFakeTimers(95_000, 1_000);

非阻断,知会即可

  1. 第三个 commit 之后,永久缺少 thread-id footer 的错误配置 Codex,每条消息都会等满 90s 才返回失败指引(此前立即失败)。失败路径仍会自动 ensure statusline 配置来自愈,取舍可以理解,代价仅是失败通知延迟变长,确认符合预期即可。
  2. 等待期间每秒至多 2 次 capture-pane(慢端点场景单次冷启动约 180 次子进程调用),量级可接受。
  3. 本 PR 含 fix(update): 支持自部署二进制更新与版本回退 #1756 的堆叠 commit,合入顺序上建议 fix(update): 支持自部署二进制更新与版本回退 #1756 先合,之后本 PR 的 diff 即只剩 Codex 部分。

@deepcoldy

Copy link
Copy Markdown
Owner

补充一条同范围的可选加固(非合入阻断,复审交叉核对时发现):

src/services/submit-failure-diagnosis.ts:69 的编号菜单兜底规则仍是 /[›❯]\s*\d+\s*[.)]/,不含 0.154 的 »。它是"英文文本认不出的编号菜单"的唯一兜底(认得出的 update/trust 菜单另有文本规则,不受影响)。实测探针:

  • 屏幕为 Choose an option:\n\n» 1. Continue\n 2. Start over 时,当前诊断结果退化为 unknown(旧 › 同屏正确命中 interactive_menu:numbered_cursor)。
  • 影响仅是 submit 失败卡片的归因变模糊,不影响写入安全(不会因此误写输入)。

如果顺手,一行闭环即可,也可避免下个版本再追一次字形:

{ id: 'interactive_menu:numbered_cursor', re: /(?:^|[\n\r])\s*[›❯»]\s*\d+\s*[.)]/ },

(你在本 PR codexUpdateDialogSafeKeys 里把 » 加进选中光标字符类,正好佐证 0.154 的编号菜单确实会用 » 作光标。)

其余同前一条评论:bun-test 用例的假时钟修法是合入阻断项;另合前需要再 rebase 一次最新 master(#1756 合入后本 PR 搭车的 update commit 会自动从 diff 消失)。

@deepcoldy

Copy link
Copy Markdown
Owner

你好,同步一个去重情况:本 PR 里的 U+00BB(»)提示符识别部分已经随 #1770 合入 master(codex-app.ts / codex.ts / codex-composer-state.ts / codex-terminal-session.ts / codex-update-dialog.ts 及对应两个测试文件,改动与本分支逐字一致),#1770 还额外补了两处同字形问题:

  • 启动期 hooks 三选屏的选中光标识别 [›>]? → [›>»]?(旧正则在 0.154 下会让输入暂存安全门 fail-open);
  • 提交失败归因里的编号菜单光标正则也补上了 »。

建议把本分支 rebase 到最新 master:U+00BB 字形相关的 hunks 主干已包含,rebase 时这些部分会变为空 / 冲突,丢弃即可;冷启动 readiness 等待等其余独立改动保留,继续在本 PR 评审。这是自动评审的初步意见,最终以维护者审阅为准。谢谢!

@47seek

47seek commented Oct 10, 2026

Copy link
Copy Markdown
Collaborator Author

Closing — superseded:

Thanks for the review; leaving the branch in place for reference.

@47seek 47seek closed this Oct 10, 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.

2 participants