Skip to content

fix(codex): keep deny/resubmit de-duplication working on the rollout-fallback path - #1539

Merged
backnotprop merged 1 commit into
mainfrom
fix/codex-fallback-deny-dedup
Sep 15, 2026
Merged

backnotprop merged 1 commit into
mainfrom
fix/codex-fallback-deny-dedup

Conversation

@backnotprop

Copy link
Copy Markdown
Owner

Verification QA follow-up on #1534. Three findings, one behavioural and two doc/robustness.

MEDIUM — the deny/resubmit guard was inert on Codex 0.114–0.116

findPlanInTurn's stop_hook_active de-duplication anchors on
findLastHookPromptIndex, which needs a role: "user" message containing
<hook_prompt. That item does not exist before rust-v0.117.0:

  • git grep -l hook_prompt -- codex-rs → 0 files at rust-v0.114.0,
    rust-v0.115.0, rust-v0.116.0; 10 files at rust-v0.117.0, where
    codex-rs/protocol/src/items.rs gains build_hook_prompt_message, returning
    ResponseItem::Message { role: "user", … }.
  • At rust-v0.116.0, codex-rs/core/src/codex.rs:5741-5752 records a blocking
    Stop hook's continuation as DeveloperInstructions::new(continuation_prompt).into(),
    which codex-rs/protocol/src/models.rs:838-850 turns into
    ResponseItem::Message { role: "developer", content: [InputText] } (the text is
    the hook's reason, verbatim — into_text() is the identity). It then sets
    stop_hook_active = true and continues the same turn, with no iteration cap.
  • That message is persisted: codex-rs/core/src/rollout/policy.rs
    should_persist_response_item returns true for every ResponseItem::Message.
  • rust-v0.117.0:codex-rs/core/src/codex.rs:5956-5966 shows the same site now
    calling build_hook_prompt_message, so a blocked turn on ≥ 0.117 always has the
    <hook_prompt> boundary and the developer fallback can never be reached there.

So on exactly the versions #1534's rollout turn-id fallback exists to support, a
user who clicked "Request changes" got the unchanged denied plan re-opened for
review whenever the model replied without emitting a fresh <proposed_plan> —
and again on every subsequent Stop of that turn.

Fix. The boundary is now "whatever the previous blocking Stop left in this
turn", in the two shapes Codex actually writes:

  • <hook_prompt> user message → authoritative, checked first;
  • last developer-role message in the turn → accepted only on the
    rollout-fallback path
    (a Stop payload carrying no turn_id, i.e. Codex
    < 0.117). Every Codex that sends turn_id keeps byte-identical behaviour by
    construction.

The after/before comparison itself is unchanged, extracted to
planChangedAcrossBoundary. The last developer message is the right anchor:
Codex records the continuation and immediately re-runs the model, and turn-setup
developer instructions (policy, personality, collaboration mode) precede the
plan.

Nothing in the developer message identifies the hook that wrote it — the text is
the hook's own reason, which Plannotator lets users re-template via
prompts.plan.denied — so the role is all there is to key on. The narrow cost is
a rollout where a non-hook developer message (an execpolicy/network amendment,
an image-save note) lands after the newest plan of a re-entered turn; that plan is
then treated as already-reviewed. Those are recorded when a command is approved
mid-turn, i.e. before the model proposes, so the realistic ordering keeps the
revised plan visible — and the failure direction is "does not reopen" rather than
"reopens something already decided".

LOW — troubleshooting version table named the wrong Codex releases

Verified against codex-rs/features/src/lib.rs at each tag (the 0.127/0.128 tags
were missing from the local mirror and were fetched):

table said actually
hooks default-enabled rust-v0.125.0 rust-v0.124.0 (first Stage::Stable + default_enabled: true tag is rust-v0.124.0-alpha.3; rust-v0.123.0 is still Stage::UnderDevelopment / false)
codex_hooks → hooks key rename rust-v0.131.0 rust-v0.129.0 (key: "hooks" + the codex_hooks legacy alias in features/src/legacy.rs first appear at rust-v0.129.0-alpha.5; rust-v0.128.0 is still key: "codex_hooks")

The derived prose said hooks = true alone "has no effect" on
rust-v0.114.0–rust-v0.130.x, which was false for ~0.129–0.130; it now names
rust-v0.114.0–rust-v0.128.x. AGENTS.md carries the matching note for the
boundary shapes.

INFO — non-string turn_id threw instead of failing closed

options.turnId?.trim() raised a TypeError for any non-string that is not
null/undefined; only apps/hook/server/index.ts's own coercion kept the hook
safe, so a second entry point passing event.turn_id straight through would have
crashed on a malformed payload. The coercion now lives in resolveCodexStopPlan,
and the missing-turn-id breadcrumb — which since #1534 fires only for a
present but unusable id — says so.

Testing

  • bun test apps/hook/server/ → 271 pass / 0 fail (was 262), 9 new cases:
    unchanged denied plan not re-served, unchanged resubmission not re-served,
    revised plan served, last-developer-message anchoring vs turn-setup
    instructions, first Stop of a turn unaffected, turn_id-carrying payload
    ignores developer messages, turn_id-carrying payload still de-duplicates
    across its hook prompt, <hook_prompt> preferred over a later developer
    message, and non-string turn_id failing closed rather than throwing.
  • bun run typecheck → clean.
  • Scoped tsc --noEmit over apps/hook/server/codex-session.ts,
    codex-session.test.ts and index.ts under apps/hook/tsconfig.json with
    strict → clean.

No live 0.114–0.116 Codex binary was available, so the loop itself was reproduced
from rollout fixtures built to the shapes read out of the tags above, not by
running an old Codex.

…fallback path

The `stop_hook_active` guard in `findPlanInTurn` anchors on the
`<hook_prompt>` USER message Codex records when a Stop hook blocks. That item
only arrived in rust-v0.117.0 (`build_hook_prompt_message`): rust-v0.114.0,
v0.115.0 and v0.116.0 — the exact versions #1534's rollout turn-id fallback
newly enables — record the continuation as
`DeveloperInstructions::new(continuation_prompt)`, i.e. a developer-role
message, and then continue the SAME turn with `stop_hook_active = true`.

The guard was therefore inert there: after "Request changes", if the model
answered without emitting a fresh `<proposed_plan>`, the next Stop resolved the
same turn, found no boundary, and re-served the unchanged denied plan for
review. Codex's continuation loop has no iteration cap, so denying again just
repeated it.

Generalize the boundary: the `<hook_prompt>` item stays authoritative, and the
last developer-role message in the turn is accepted as the boundary only on the
rollout-fallback path (a Stop payload with no `turn_id`), so every Codex that
sends `turn_id` keeps byte-identical behaviour.

Also:

- Correct the troubleshooting version table. Hooks became default-enabled at
  rust-v0.124.0 (`0.124.0-alpha.3`, `Stage::Stable` + `default_enabled: true`),
  not 0.125.0, and the `codex_hooks` -> `hooks` key rename landed at
  rust-v0.129.0 (`0.129.0-alpha.5`), not 0.131.0 — verified against
  `codex-rs/features/src/lib.rs` at each tag, with 0.128.0 still on
  `codex_hooks`. The derived prose now names the real codex_hooks-only range.
- Fail closed instead of throwing on a non-string `turn_id`: the coercion now
  lives inside `resolveCodexStopPlan` rather than only at the CLI call site, and
  the debug breadcrumb says the id was present but unusable rather than missing.
@backnotprop
backnotprop merged commit 9f77a2b into main Sep 15, 2026
28 checks passed
@backnotprop
backnotprop deleted the fix/codex-fallback-deny-dedup branch September 15, 2026 14:16
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