codex-plugin-cc icon indicating copy to clipboard operation
codex-plugin-cc copied to clipboard

Stop-review gate hook loops until CLAUDE_CODE_STOP_HOOK_BLOCK_CAP (missing `stop_hook_active` guard)

Open blaircullen opened this issue 4 months ago • 4 comments

File: scripts/stop-review-gate-hook.mjs (v1.0.6)

Problem

When stopReviewGate is enabled, main() runs the review and emits {"decision":"block"} whenever the review is not ok — including the non-ok cases where the review task returns no output, times out (15 min), fails, or returns invalid JSON.

After a Stop hook blocks, Claude Code re-runs the turn with stop_hook_active: true in the hook input. This hook never checks that flag, so it re-runs the review and blocks again on every retry. The result is the harness message:

A hook blocked the turn from ending 9 consecutive times — overriding and ending turn. For Stop/SubagentStop hooks, check stop_hook_active in the input and return success while it's true.

The failure is worst in exactly the cases the gate is least useful — a Codex review that errors or times out blocks the session 9× before the cap force-ends it.

Fix

Honor stop_hook_active before running the blocking review:

if (input.stop_hook_active) {
  logNote(runningTaskNote);
  return;
}

const review = runStopReview(cwd, input);

This lets the gate review once; on the harness's forced retry it returns success instead of blocking again.

codex-companion.mjs has the same config.stopReviewGate branch — worth auditing it for the same issue.

blaircullen avatar Jul 24 '26 12:07 blaircullen

Confirming the fix as proposed, applied as a local patch to plugin 1.0.6 on macOS 15.7.7 (Claude Code 2.1.236, Node v26.8.1): the guard inserted immediately before const review = runStopReview(cwd, input);, exactly as in the issue body, and logNote(runningTaskNote) kept so the still-running note is not lost on the retry.

Two facts from doing it:

  • stop_hook_active appears nowhere in the plugin's scripts/ on 1.0.6, so the issue is still open in the shipped code as of 2026-09-08.
  • The patched file passes node --check and a fixture test suite (apply, idempotent re-apply, byte-exact revert against the pinned sha256 of the upstream file, refusal on any other content). It has not yet been exercised by a live blocked-then-allowed cycle: the gate is off on this machine after the loop described in #695 and #517, and we are turning it back on only now that this guard is in place. I will follow up here if the retry path misbehaves.

For anyone carrying this locally until it merges: the patch also has to be re-applied after every plugin update, and a hash check against the upstream file is the only thing that stops it being applied blind to a version that may already contain the fix.

Related, same failure chain: #695 (the failure reason is discarded, so the loop looks like a toolchain error), #483 (no fail-closed reason names --disable-review-gate), #684 (/codex:cancel reads a different state root than the hook).

stephan-nb avatar Sep 08 '26 18:09 stephan-nb

Follow-up, as promised: the retry path has now been exercised live on 1.0.6 with the guard in place.

A deliberately unsafe staged file made the gate block once (28 s review). Claude's reply on the harness retry carried stop_hook_active: true, the hook returned without reviewing, the turn ended, and the job table shows exactly one review job for that stop. Before the guard, the same retry re-reviewed and re-blocked until the consecutive-block cap.

So the five-line fix in the issue body does what it says. Worth noting for anyone weighing it: this makes the gate block at most once per continuation chain, so a finding is delivered once and not re-verified after it is addressed. That trade seems right, since the alternative is a block that nothing inside the session can satisfy, but it is a behaviour change and deserves a line in the changelog if merged.

stephan-nb avatar Sep 08 '26 19:09 stephan-nb

This is addressed in the CBEPX fork release v1.3.0; see the changelog for the full list of changes. The stop-review gate hook now uses the host's stop_hook_active flag when counting prior rounds, and CODEX_REVIEW_GATE_MAX_ROUNDS defaults to 3 (previously unbounded) so the hook stops re-invoking itself past that cap; set it to 0 explicitly to keep the old unbounded behavior. Thanks @mittalpk for the PR, which we used as reference.

claude plugin marketplace add CBEPX/codex-plugin-cc && claude plugin install codex@cbepx

This is a fork release, not an upstream fix, so I'm leaving this issue open for the maintainers here.

CBEPX avatar Sep 27 '26 21:09 CBEPX

Current-source confirmation, checked November 4, 2026: main at db52e28f4d9ded852ab3942cea316258ae4ef346 still invokes the fifteen-minute review path without inspecting stop_hook_active.

Adding to the existing live evidence above: a durable fix should bound duplicate attempts for the same turn as well as honor the host's continuation flag. A fake reviewer can cover these cases without consuming model quota:

  • Gate disabled: zero reviewer calls.
  • stop_hook_active true: exit successfully without another reviewer call.
  • First review allows, blocks, fails, times out or returns invalid output: verify the intended one-time result and continuation behavior.
  • Duplicate delivery for the same turn: no second expensive review attempt; a later genuine turn remains eligible.
  • Preserve the running-task note and configured review policy.

Both saved local states inspected during this audit had the optional gate disabled. It was left disabled, and no live review loop was run. This is a conditional expensive-review defect, separate from the unbounded input problem in #530 and not evidence that this gate caused ten-second Codex hook warnings.

Existing fork releases are not an upstream fix; this comment refers to the unchanged upstream source.

Shinzor avatar Nov 03 '26 16:11 Shinzor