Repository navigation
fix(codex): keep deny/resubmit de-duplication working on the rollout-fallback path - #1539
Merged
Merged
Conversation
…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.
1 task
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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'sstop_hook_activede-duplication anchors onfindLastHookPromptIndex, which needs arole: "user"message containing<hook_prompt. That item does not exist before rust-v0.117.0:git grep -l hook_prompt -- codex-rs→ 0 files atrust-v0.114.0,rust-v0.115.0,rust-v0.116.0; 10 files atrust-v0.117.0, wherecodex-rs/protocol/src/items.rsgainsbuild_hook_prompt_message, returningResponseItem::Message { role: "user", … }.rust-v0.116.0,codex-rs/core/src/codex.rs:5741-5752records a blockingStop hook's continuation as
DeveloperInstructions::new(continuation_prompt).into(),which
codex-rs/protocol/src/models.rs:838-850turns intoResponseItem::Message { role: "developer", content: [InputText] }(the text isthe hook's
reason, verbatim —into_text()is the identity). It then setsstop_hook_active = trueandcontinues the same turn, with no iteration cap.codex-rs/core/src/rollout/policy.rsshould_persist_response_itemreturns true for everyResponseItem::Message.rust-v0.117.0:codex-rs/core/src/codex.rs:5956-5966shows the same site nowcalling
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;rollout-fallback path (a Stop payload carrying no
turn_id, i.e. Codex< 0.117). Every Codex that sends
turn_idkeeps byte-identical behaviour byconstruction.
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 viaprompts.plan.denied— so the role is all there is to key on. The narrow cost isa 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.rsat each tag (the 0.127/0.128 tagswere missing from the local mirror and were fetched):
rust-v0.125.0rust-v0.124.0(firstStage::Stable+default_enabled: truetag isrust-v0.124.0-alpha.3;rust-v0.123.0is stillStage::UnderDevelopment/false)codex_hooks→hookskey renamerust-v0.131.0rust-v0.129.0(key: "hooks"+ thecodex_hookslegacy alias infeatures/src/legacy.rsfirst appear atrust-v0.129.0-alpha.5;rust-v0.128.0is stillkey: "codex_hooks")The derived prose said
hooks = truealone "has no effect" onrust-v0.114.0–rust-v0.130.x, which was false for ~0.129–0.130; it now namesrust-v0.114.0–rust-v0.128.x. AGENTS.md carries the matching note for theboundary shapes.
INFO — non-string
turn_idthrew instead of failing closedoptions.turnId?.trim()raised aTypeErrorfor any non-string that is notnull/undefined; onlyapps/hook/server/index.ts's own coercion kept the hooksafe, so a second entry point passing
event.turn_idstraight through would havecrashed on a malformed payload. The coercion now lives in
resolveCodexStopPlan,and the
missing-turn-idbreadcrumb — which since #1534 fires only for apresent 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 payloadignores developer messages,
turn_id-carrying payload still de-duplicatesacross its hook prompt,
<hook_prompt>preferred over a later developermessage, and non-string
turn_idfailing closed rather than throwing.bun run typecheck→ clean.tsc --noEmitoverapps/hook/server/codex-session.ts,codex-session.test.tsandindex.tsunderapps/hook/tsconfig.jsonwithstrict→ 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.