Skip to content

Gate P4 — Hooks and action gating

Status: Passed 2026-11-02. G6 dogfood closed by owner decision at 11.8 days instead of ≥ 2 weeks (SPEC v1.6.12): real use had stopped on 10-24 (audit, report, kit). Coverage passes. False-deny is 30.6% with shell enforced, but 0.11% with mode = "enforce" and shell_mode = "warn". Enforce for file edits is therefore recommendable; warn stays the default. G0 passed 2026-10-21 (ADR 0010 rev 3.2, four review rounds); the implementation passed an independent review and closure check (rev 3.4 §18). P4 was marked Passed only with the dogfood report (SPEC v1.6.0 A11).

0. Scope

SPEC sections: - §5 P4; - §6.3 ctx_check (action, context_update); - §6.4 TOCTOU; - §6.5 hook contract; - §10 risks; - T38–T41b, T66; I6.

Owner decisions (2026-10-21): - Harnesses: Claude Code 2.1.306 and Codex CLI 0.163.0 are both supported, with their hook protocols pinned. - G6 dogfood (≥ 2 weeks, ≥ 2 parallel agents) stays Pending until the agent-generated evidence report. P5a G0 and implementation may start in parallel (A11), but P4 is marked Passed only after the report.

Deferred to later phases:

Item Phase
path-filtered PreToolUse P5a (T46c)
ctx check --range and the pre-push hook P5a
DriftReport as a kernel artifact P5a revisit
branches P6
validators P7
principals and ACL P9

1. Gate matrix

Layer Requirement Result Evidence
G0 Spec ADR 0010 accepted after independent review; SDs unchanged or amended in SPEC appendix C; no SPEC §3.5 prohibited mechanism Pass ADR 0010 rev 3.2 §14, §15, §17; SPEC v1.6.0 (A1–A11); the reviewer found no §3.5 prohibited mechanism
G1 Build & lint fmt, Clippy -D warnings, tests, cargo-deny, dependency policy (proto, hooks, cli; light clients do not reach the store) Pass bash scripts/check.sh on macOS and on Linux (remote host, Ubuntu 24.04) for the final tree, incl. the dependency-policy negatives for proto/hooks/cli and the light-client rule. GitHub Actions still starts no job (account billing)
G2 Golden T38, T39, T40, T41, T41b (Claude Code 2.1.306 and Codex 0.163.0 schemas, plus the _meta contract), T66; binding, context_update, patch parser, predicate Pass (local); _meta live capture in the dogfood T38/T39 end to end with the real ctx-hook and ctxd for both harnesses, including a deny that still names the stale read after the update was acknowledged (hooks/tests/e2e.rs); T40: idempotent Facts and crash windows (daemon/tests/hooks.rs), MCP client_txn_id retries (P3); T41 on agent and admin Raw (cli/tests/p4_cli.rs); T41b: 23 vendored Codex schemas validate every input fixture and rendered output, validator negatives, Claude fixtures (hooks/tests/t41b.rs); T66 (daemon/tests/hooks.rs, property (e)); _meta mapping and one-server isolation (mcp/tests/binding.rs). The _meta keys are verified from the Codex 0.163.0 source (sessionId, threadId, callId) and the Claude Code 2.1.306 binary (claudecode/toolUseId), not from captured traffic. Live check, 2026-10-21, at the start of the dogfood: a real Claude Code 2.1.306 session's ctx_check through the installed ctx-mcp returned binding: claimed, so the PreToolUse claim and the _meta claudecode/toolUseId matched. During the dogfood, the MCP calls without a claim count must stay near zero
G3 Oracle properties (a)–(f) at 10,000 seeds; mutation of the hooks library, proto and the daemon session code Pass (a) outbox scan, (b) seq/delivery interleavings with kills, torn appends, failures and lost marks (proto/tests/outbox_props.rs; found and fixed two seq-reuse paths); (c) gate monotone (proto/src/gate.rs); (d) Updates and (e) per-agent verdicts vs oracle with coverage floors (daemon/tests/p4_props.rs: 8,555 Empty / 9,323 Valid / 3,508 Invalid checks, 3,077 non-empty updates, 129 root checks with a differing child read); (f) path normalisation (hooks/src/paths.rs). Mutation: 675 mutants over gate.rs, outbox.rs, the hooks library and daemon service.rs; after adding tests (service_details.rs, hook_details.rs, outbox unit tests) 0 unwaived survivors, 14 waived with reasons (p4-mutation-summary.json). A first run was discarded: a shared CARGO_TARGET_DIR let parallel mutants overwrite each other's binaries
G4 Robustness hook and daemon kill points; restart; corrupt middle record; doctor truncation; 16 × 8 hook stress for 10 min; fuzz ≥ 1 h (adapters, patch parser, _meta, GateConfig, OutboxRecord) Pass Hook killed (abort) at every outbox step, re-exec test; daemon crash before and after the stream-mark sync (hooks.rs); lost marks and corrupt records in property (b); sweeper delivers leftovers once (server.rs). Stress: 413,722 hook runs in 600 s, every stream applied seq == runs, 0 failures (p4-g4-hook-stress.txt). Fuzz on the final tree: six targets (IPC, MCP JSON, hook stdin, patch paths, _meta, Wire records) ≥ 3,600 s each, 0 crashes/timeouts/OOMs (p4-g4-fuzz.txt)
G5 Performance PreToolUse end-to-end p95 ≤ 50 ms, p99 ≤ 100 ms (initial) Pass p4-g5-hooks.txt (after the review fixes): p95 ≤ 12.0 ms, p99 ≤ 38.0 ms in every cell (fullfsync on/off × 1/8 sessions × 10/100/1,000 reads, every 10th check re-issuing); claim hook p95 3.0 ms, PostToolUse 12.4 ms, UserPromptSubmit 9.4 ms; Codex $SHELL -lc launch p50 4.7 ms reported as harness cost
G6 Scenario two-harness scripted scenario (ADR 0010 §11 G6) Pass hooks/tests/g6.rs: Claude A and Codex B share db; A supersedes; B's apply_patch warned then denied naming db; a Bash file is undeclared drift; A's subagent read (claimed MCP call) backs A and its change denies A; sessions stay apart
G6 Dogfood false-deny ≤ 2 % (to recommend enforce), dependency coverage ≥ 60 % over ≥ 2 weeks with ≥ 2 agents Pass with a disclosed deviation: 11.8 days (owner decision, SPEC v1.6.12); enforce recommendable for file edits only (shell_mode = "warn") Report: 12 sessions, Claude Code and Codex in parallel 10-22 – 10-24; coverage 69.6 % (16/23, 8/8 organic writes); false-deny 30.6 % (1,370/4,475; mostly read-only shell commands warned for Empty), 0.11 % (5/4,475) with shell_mode = "warn"; 64 stale-action intercepts, 5 of them changing the repository after a parallel agent's supersede; 0 unclaimed MCP calls (the live _meta check). All 1,783 warns and 126 sampled allows labelled by rules, checked blind: 95.2 % agreement on a fresh sample. Follow-ups: adoption collapse after 10-24, repeated Invalid warnings, gating read-only commands, drift re-reporting the dirty tree, missing Claude version (audit §5)
G7 Regression P0–P3 G2/G3/G4 at gate counts; P3 stress and fuzz on protocol v2; P3 session-log replay under P4 Pass P1 G5 memory identical to P3 (hot 81.73 / 77.78 ≤ 90 …); P2 store bench g5_initial_pass=true; P3 MCP bench on protocol v2 g5_pass=true (p4-g7-mcp.txt); P3 session-log events decode as root (store/tests/session_log.rs). Remote (scripts/gate-regression.sh): paranoid testkit (P0 goldens, P1–P3 properties at 10,000 seeds), exhaustive depth 6 (770 states) and depth 8 (1,711 states) with 0 violations, store/daemon crash injection at 1,000 per point and PROP10, P4 suites in release. P1–P3 core mutation rerun with per-mutant target dirs: 0 survivors after one new core test
G8 Docs README hooks section, CHANGELOG, IMPLEMENTATION_STATUS, upgrade notes Pass README §Hooks 与 action gating (install, binding, subagents, gating, fail modes, outbox/drift, policy, TOCTOU, upgrade notes); CHANGELOG; docs/IMPLEMENTATION_STATUS.md; dogfood kit
Independent review non-implementing reviewer (SPEC §4.2) Pass Review of 4df803a..aa8dd1a: 1 blocker (reproduced deadlock), 7 majors, 12 minors; all fixed or recorded with reasons. Closure check of 06a4d42: all closed, implementation acceptable (excluding the outstanding real dogfood); its four new minors N1–N4 fixed with tests (ADR 0010 §18)