Skip to content

fix: wake and ring a resting Codex CLI cleanly - #1823

Merged
yansfil merged 11 commits into
mainfrom
fix/codex-wake-input
Oct 29, 2026
Merged

yansfil merged 11 commits into
mainfrom
fix/codex-wake-input

Conversation

@yansfil

@yansfil yansfil commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Closes with-hide/hide-private#37
Closes with-hide/hide-private#38
Closes with-hide/hide-private#307

Summary

A resting Codex CLI was hard to wake and to write to.

스크린샷 없음: 화면을 바꾸지 않는 변경입니다 (셸 입력, 편지 재시도, journey 판정).

Review

  • 판단해 주세요: the wake clears nothing from the shell's line before it types. Two cases can still leave text there:
    • a quit key the agent never read before the node ended it; only after agent_sleep.exit_keys_unanswered, and no measured run reached it;
    • a terminal's answer to the agent's query arriving after it exited; never seen in a run.
  • 판단해 주세요: after a node end, Herdr keeps the agent's terminal modes for the shell; filed as with-hide/hide-private#320 (Herdr upstream report needed).
  • 판단해 주세요: Windows has no real-Herdr sleep-and-wake test (cell in docs/INSTALL.md).
    • Codex CLI 0.165.0 never turns the keyboard protocol on there: its crossterm fork (openai-oss-forks/crossterm at ed1cdab3) answers PushKeyboardEnhancementFlags with an unsupported error on a Windows console.
    • So a quit press reaches PowerShell as Ctrl+C, never as ESC[99;5u. The press decision is the same code, with unit tests in the Windows lane.
  • fish 4.9.3 agent_pane_busy, a fixture fault:
    • fish 4 runs its man-page completion generator (bash, Python) in its own foreground group for about 3 s after its first prompt, unless ~/.cache/fish/generated_completions exists; fish 3 checked ~/.local/share/fish.
    • The test sent its first agent.start without the shell wait every product start has, and Herdr refused. It now starts through start_within, and the fixture makes both folders.
    • A product start waits on that state for up to 30 s (SHELL_WAIT). The generator runs only on a user's first fish start; how long it takes over a full set of man pages is not measured.
  • 조심해서 볼 파일:
    • herdr-core/src/agent_sleep_herdr.rs - failure path: quit presses follow the screen and the foreground group.
    • herdr-core/src/delivery/doorbell.rs - failure path: only a failure before agent.prompt retries on the timer.
    • scripts/agent_journey/cells.py, journey.py - only a NO_ANSWER verdict asks the provider log, and a start prefers any other failure.
    • herdr-core/src/agent_start/real_herdr_tests.rs - the stand-in's release (Release, Watched).
  • 비용 검토: sleep reads the screen every 100 ms while quitting, inside its 5 s grace.

Evidence

  • 확인한 것:
    • Real Herdr 0.9.5: a stand-in Codex CLI (kitty keyboard on, quits on the first Ctrl+C) is slept and woken by Hide.
      • It hands its terminal back only when the test releases it: after the sleep's screen read shows it quitting, or after a second press is answered. No timer orders the steps.
      • It reads its input a byte at a time up to the first whole Ctrl+C, so a second press queued with the first stays for the shell.
      • Old sleep: 10 of 10 fail (5 runs, zsh and bash), the wake running 9;5ucodex resume slept-session; also 10 of 10 when both presses are queued before the stand-in reads (a local-only hold).
      • New sleep: 15 of 15 pass (5 runs, zsh, bash and fish 4.9.3); Linux CI runs zsh, bash and fish.
    • Unit tests: a second press only on the agent's hint or an emptied draft; an agent quitting on its first press gets one press.
    • Unit test: a failed reservation rings again on the timer (0 bells typed before the fix).
    • Provider log: cursor boundary in the same second, another thread, a later non-429 retry.
    • Start composition: an emitter failure beside an unanswered turn and a 429 stays a failure (read not measured before the fix).
    • Fake-model journey at 698b118, codex row alone (codex-cli 0.163.0): 12 of 12 cells; sleep ended Codex CLI by its own key (no exit_keys_unanswered).
  • 확인하지 못한 것:
Verification record
  • base 047d094, head 2397a4e.
  • CI run 40860922492 at 2397a4e, attempt 1: green, 41 pass, 3 skipping (full run, pr.yml changed); windows check step "Agent sleep ends the agent's process tree" 4 of 4, the three quit press tests included.
  • CI run 40853614406 at f837d75, attempt 1: green, 21 pass, 10 skipping; rust workspace 5560 of 5560, real-Herdr shell step 10 of 10 (sleep and wake on zsh, bash and fish).
  • CI run 40844861122 at 391c939: attempt 1 failed only web e2e windows, in setup before any test (spawnSync powershell.exe ETIMEDOUT); attempt 2 green, 21 pass, 10 skipping; rust workspace 5560 of 5560, real-Herdr shell step 10 of 10 (sleep and wake on zsh, bash and fish).
  • CI run 40839420249 at 698b118, attempt 1: green; rust workspace 5560 of 5560 tests, real-Herdr shell step 10 of 10.
  • Local full nextest -p herdr-core -p hide-agent-adapter: not run since 923c430 (3461 of 3461); the build at 698b118 hit a full disk, and CI covers it.
  • Python at 698b118: test_agent_journey_provider_limit and test_agent_journey_cells 36 OK; test_agent_live_protection 53 OK alone (it timed out in a full run while the disk filled).
  • fmt-check, clippy -p herdr-core --all-targets -D warnings at 391c939: clean.
  • Sleep and wake on real Herdr at f837d75: base sleep code 10 of 10 fail (zsh, bash, 5 runs each), and 10 of 10 with both presses queued before the stand-in's first read; head 15 of 15 pass (zsh, bash, fish 4.9.3, 5 runs each). With that hold and 391c939's one-call read, the base sleep passed 4 of 4, the hole the byte read closes.
  • Sleep and wake on real Herdr at 391c939: base sleep code 10 of 10 fail (zsh, bash, 5 runs each); head 15 of 15 pass (zsh, bash, fish 4.9.3, 5 runs each); fish also passes with fish 4's marker folder removed (7.4 s, the start waiting out the generator).
  • Local fake-model journey, codex row, at 698b118: 12 of 12 pass.
  • Review: letter-16881 addressed in 923c430 and ca3db1c; letter-16914 in aed2c51 and 698b118; letter-16977 and letter-16979 in 391c939; letter-17055 in f837d75; the Windows lane runs the quit press tests from 2397a4e.

Sleep pressed the quit key a second time 150 ms after the first. Codex CLI
0.165.0 quits on the first press when its composer is empty, so the second
press reached the shell still kitty-encoded (ESC[99;5u) and left `9;5u` in
front of the resume line the wake typed later (with-hide/hide-private#37).

Sleep now presses the quit key again only while the agent asks for it:
its own "again" hint appears, or the press emptied a draft. It stops as
soon as the shell holds the terminal, at most three presses. A wake or
reopen in the pane its agent ended in abandons the shell's line with a raw
interrupt before typing, which clears it in zsh, bash and fish whatever
the line editing mode.

Herdr keeps an ended agent's keyboard and screen modes for the shell that
takes the pane back; with-hide/hide-private#320 carries that upstream.
A Codex CLI turn its provider refused with 429 Too Many Requests waits
minutes before its retry, so the cell timed out and read as a product
failure (with-hide/hide-private#38). A failed Codex CLI cell now reads the
CLI's own log database in its CODEX_HOME for a 429 retry logged since the
step began, and settles that cell and the agent's open cells not measured
with the provider's reason.
A bell whose reservation the delivery store refused or did not answer in
time typed nothing, but the doorbell treated it like a prompt that may
have been typed and waited for the pane to move. A resting agent's pane
has no reason to move, so the letter stayed pending until its deadline;
the v1.0.3 local journey met it with a resting Codex CLI
(with-hide/hide-private#307).

A failure before agent.prompt now retries on the doorbell's backoff
timer, each try spending one of the letter's three bells, and only a
failed prompt waits for the pane to move. doorbell.failed says which it
was, and doorbell.reservation_failed keeps the store's own code, which
the old record dropped. The failure type the mission answers already
used is now shared by both.
The wake sent a raw Ctrl+C as soon as the shell wait passed, before
Herdr's own busy check, so a prompt hook or another program that took
the terminal in between, or a Windows child Herdr does not name, could
receive it. The interrupt now goes only when a read made right before it
shows the shell alone in the foreground and its terminal out of line
mode, which a Unix shell's line editor sets only while it reads at its
prompt. A Windows console, a terminal in line mode, another foreground
program or a read that failed keep the line, log agent_start.line_kept
and start as before. Only a wake asks for it, since the sleep record
keeps Hide's input gate closed; a Reopen keeps the line.

The first-press quit test now ends its stand-in only after the sleep
has read it quitting, instead of after a fixed 600 ms.
The journey turned every failed Codex CLI cell into not measured when
any 429 had been logged since the second the step began: a session
mismatch, a transport failure or a 429 already retried past read as a
provider limit, and a 429 from earlier in the same second counted.

Verdicts now carry their kind, and only a turn the agent never answered
after its prompt asks the provider's log. The log is read from a row-id
cursor taken as the step begins, for the agent's own conversation only,
and only when that conversation's newest retry since is a 429.
… key against real Herdr

The sleep's second Ctrl+C was the cause of the stray 9;5u (with-hide/hide-private#37),
and it is no longer sent. The wake's raw interrupt could still reach a program that
took the foreground after its read, so it goes. A real-Herdr test sleeps and wakes a
stand-in Codex CLI that turns the kitty keyboard protocol on and quits on its first
Ctrl+C; on the old sleep its resume line ran as 9;5ucodex in zsh and bash.
A start whose Herdr session report failed beside an unanswered turn read the turn's
failure first, and a 429 then made the whole start not measured.
…after a delay

The stand-in now hands its terminal back only when the test opens its FIFO:
after a screen read shows it quitting, or after a second press is answered,
so the old sleep fails every run instead of racing a 600 ms sleep. The first
start waits for the shell as every product start does: fish 4 runs its
completion generator in its own foreground group after the first prompt,
and the fixture now also makes fish 4's marker folder. The Windows cell says
why the test runs on Unix shells only.
It read its input in one call, so two presses queued together were both
consumed and the old sleep's second key never reached the shell. It now
reads a byte at a time and stops at the first whole Ctrl+C.
The Windows sleep step ran only the node-end test, so the press decision the
pull request and docs/INSTALL.md cite had no Windows run.
@yansfil
yansfil merged commit bbafdca into main Oct 29, 2026
64 checks passed
@yansfil
yansfil deleted the fix/codex-wake-input branch October 29, 2026 13:02
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.

1 participant