Repository navigation
feat(harness): turn-end stop hooks (--on-turnend) — deterministic gate on the final message - #154
Merged
Merged
Conversation
…e on the final message Third hook trigger beside --on-pretool/--on-posttool (issue #110): the gate fires when the provider produces the final message, BEFORE it commits. Deny (exit 2) = gate-forces-continuation: the Final is not committed, the reason enters the log as user-role feedback, and the loop re-runs — the model must satisfy the gate (run tests, lint, format) before it may finish. Bounded by a per-turn denial cap (3) that settles durably as TurnOutcome::StopGateBlocked (post-#84 pc=Final: prompt-resumable); hook failures stay non-blocking per the #110 contract; 30s per-hook timeout for real verification gates. Payload: final-text preview (8 KiB cap) + per-turn tool/risk summary so scripts can gate only writing turns. Closes #145
…ction) The first live E2E disproved the exit-2-only contract borrowed from tool hooks: cargo check exits 101 on a broken crate, which the old semantics classified as a non-blocking hook failure — a premature 'fixed!' Final sailed through a failing gate. Gate semantics now: exit 0 = pass, ANY non-zero exit = deny with stdout as the reason (a verification gate's exit code IS its verdict); only true infrastructure failures (spawn error, timeout) stay non-blocking. ProcessHook::run_raw added; test updated to the corrected contract.
🔍 Cora AI Code Review✅ No issues found. Code looks good! Review powered by cora-code · BYOK · MIT |
…a CI) tools_seen was built from ALL session entries, so in multi-turn chat or resumed sessions earlier turns' tools re-appeared in every later Final's gate payload — a history-keyed gate would re-fire forever. Now scoped to entries after the last user message. Regression test: two turns (turn 1 writes, turn 2 answers plain), gate dumps its payload, turn 2's payload must not contain turn 1's tools (verified against the real dumped payload).
| let turn_start = s | ||
| .entries() | ||
| .iter() | ||
| .rposition(|e| { |
…(cora CI round 2)
Two findings from the CI Cora Review, both real:
1. The deny feedback entry is itself user-role; on the second Final it
became the turn window start, hiding the turn's earlier tool calls
from the payload — a presence-keyed gate ('deny if write_file ran')
was defeated by just re-finalizing. Fixed with an explicit
stop_gate_feedback marker that the window scan skips.
2. The tool filter matched kind == 'tool_call', but intents are stored
as generic entries whose payload carries 'tool' — tools_seen was
always empty (found by the new test's payload dump, not by reading
code). Fixed by filtering on the payload key.
Regression test: gate always-denies with a prior write_file — all four
payloads must keep listing write_file.
This was referenced Oct 2, 2026
Merged
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.
What (description of the change)
Turn-end stop gates (#145): a third hook trigger beside
--on-pretool/--on-posttool(#110).--on-turnend <command>(repeatable, default OFF, global flag) fires when the provider produces the final message, before it commits.cargo checkexits 101, test runners exit 1) — the exit-2-only rule borrowed from tool hooks classified real verdicts as non-blocking failures; the first live E2E disproved it and the contract was corrected with a regression test. Only true infrastructure failures (spawn error, timeout) stay non-blocking, per the feat: opt-in process hooks at the tool boundary (PreToolUse/PostToolUse, default OFF) #110 contract.STOP_GATE_DENIAL_CAP = 3denials per turn, then the turn settles durably asTurnOutcome::StopGateBlocked { reason }(post-Provider 502 mid-turn wedges session at pc=Planning; recovery is interactive-only #84 pc=Final → prompt-resumable, exit code 6 inrun). The cap is proven to trip in isolation (guard-interaction rule).StopGateBlockedarms in report_outcome (run), chat, and session_host (ACP).Why (the problem you're solving)
Layered verification is the differentiating layer in the software-factory landscape. Tool hooks gate individual calls; evals score whole missions; the missing layer was the deterministic gate on the TURN OUTCOME.
--on-turnend "cargo check"makes "the agent may not claim done until the gate passes" a harness guarantee instead of a prompt hope.Testing (how you verified this works)
StopGateBlocked+ durable error + pc=Final; non-zero exit (101) denies with the stdout reason (corrected contract); infrastructure failures stay non-blocking.-D warningsclean, fmt clean.--on-turnend "cargo check --manifest-path ..."→ first mission: model self-verified then passed the gate cleanly (pass → identical). Second mission (model instructed to answer "planning to fix" first): gate DENIED the premature Final, reason entered the log, model continued, actually fixed the code, gate passed — 3 stop-gate denial entries in the session log,cargo checkexit 0, Cargo.toml untouched.--no-verify; CI Cora Review is the gate.