Skip to content

feat: turn-end stop hook (--on-turnend) — deterministic gate that blocks finishing the turn #145

Closed

Description

@ajianaz

What (description of the change)

Extend the opt-in process-hook surface (issue #110) with a third trigger: --on-turnend <command> (repeatable, default OFF). It fires when the provider produces ProviderOutput::Final inside drive() (turn.rs), before the final assistant MESSAGE commits.

Contract — same process discipline as tool hooks (one JSON object on stdin, env scrubbed, argv-only, 32 KiB output cap), with three deltas:

  • Payload: { "event": "turnend", "final_text_preview": "...", "tools": [ {"tool": ..., "risk": ...} ] } — the per-turn tool/risk summary lets a script gate only writing turns; the final-text preview is capped at 8 KiB.
  • Timeout 30s (verification gates legitimately run lint/tests; the 5s tool-hook default is too tight).
  • Deny (exit 2) = gate-forces-continuation: the Final is NOT committed; the deny reason is appended as a user-role entry (stop gate: <reason>) and the loop continues so the model can fix and re-attempt. Bounded by a denial cap of 3 per turn — cap trip → durable error entry + new TurnOutcome::StopGateBlocked { reason }, host prints the resume hint. Hook failures (non-2 exit, timeout, spawn error) stay non-blocking per the feat: opt-in process hooks at the tool boundary (PreToolUse/PostToolUse, default OFF) #110 contract.

Design agreed in the 2026-10-01 CTO/owner discussion: gate-forces-continuation + cap (abort-only semantics are recoverable from the capped gate; the reverse is not). Guard-interaction rule applies in full: the loop guard, the denial cap, and the step budget each need a test where IT alone trips (E10 lesson).

Mechanical fallout: new TurnOutcome variant → ~6 match sites updated (mechanical, proven cheap in the 22Sep burst).

Lands AFTER the decision-journal issue (#143; same files: turn.rs, main.rs — stacked-PR order).

Why (the problem you're solving)

Layered verification is the differentiating layer in the software-factory landscape: "verification is the next battleground, not models" (Oct 2026 research). The Claude Code playbook names the missing piece precisely: a stop hook — a deterministic script gate that blocks ending the turn until it passes — plus a second-verifier pattern. Tool hooks gate individual calls; the stop gate verifies the TURN OUTCOME (tests green, lint clean, format ok). That is the layer between tool policy (#110) and evals (#73) — and the deterministic building block for the L3 "agent per ticket with a verification loop" discipline the research roadmap prescribes.

Testing (how you verified this works)

  • Tier-1 contracts: deny → Final never committed, feedback entry replay-visible; pass → behavior byte-identical; cap trip → durable error + StopGateBlocked; hook failure → non-blocking, turn proceeds; denial-cap and loop-guard each trip in isolation.
  • Live E2E: mission with --on-turnend running cargo check in a fixture repo → first Final denied (broken code), model fixes, second pass green → session closes; transcript shows both cycles.
  • Suites green both profiles; no new deps.

Activity

  1. added
    enhancement
    harness
    on Oct 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementharness

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions