Gate P7 — Semantic validation, conflicts, handoff and changes¶
Status: Gate P7 passed (2026-11-03). G0 passed 2026-11-02; milestones 1–9 are done and G1–G8 all pass. G5's commit budget was restated by owner decision D4, and the independent implementation review found no blocker (§3). Design: ADR 0015 r0.3; SPEC v1.7.1.
ADR review history (non-implementing reviewer):
| Round | Findings | Result |
|---|---|---|
| r0.1 review | 4 blockers, 7 majors, 7 minors | not acceptable |
| r0.2 closure | all blockers closed; 4 partly closed; 2 new majors, 5 minors (N1–N7) | acceptable after text fixes |
| r0.3 check | N1–N7 closed; 3 text gaps fixed in place | G0 acceptable |
Owner decisions (2026-11-02):
- D1: the real LLM evaluation uses the local claude -p.
- D2: op_log format 4 stores only a metadata hash.
- D3: agents and admin may open gating Conflicts.
- D4 (2026-11-03): the G5 commit budget is restated (§G5): measured at a realistic premise-move rate, pooled over interleaved rounds, p50 ≤ 1.10× and p99 ≤ 1.25× idle.
Implementation milestones (planned):
- Done. Format 4 in model, kernel and oracle:
meta,if_absent,ValidationExists,ResolveArtifact.note, canonical tags 18/19. AlsoMissingBlobfor the new fields andctx migrate3 → 4 (T77, T81). - Done. Daemon: the
RecordValidationrefusal on the agent channel (T80),Validatewith label, evidence andfrom_review, and protocol 5. - Done (real-CLI smoke check passed 2026-11-03 with claude 2.1.317:
conflictin 3.5 s, 1,371 tokens).contextdb-validate: the trait,Mock,Command, andClaudeCliwith the sandbox (T82). - Done. Job table (
jobs.sqlite), discovery from the op_log, the worker pool, leases, recovery,validators.tomlandctx validators(T49, T50, T53, T84; the discovery quiescence property). The candidate half of T84 came with milestone 6. - Done. SD20 conflict pairs,
ctx_conflicts(list, open),ctx_resolve, MCP tools andctx conflicts; review listing withstale curvec(T78). The review lookup is an in-memory decode cache instead of a SQLite projection (ADR 0015 §6 note). - Done. Lexical candidates: a per-branch recall index with OR queries and bm25 scores,
candidates.sqlite, the indexer-thread generator and sweep,ctx_conflictslisting andopen{from: candidate}(the candidate half of T84). - 6b. Done. Validators with
pairs = truejudge candidate pairs: pair tasks (conflictornone), a separateclaude -ppair prompt, the judging lease and retries incandidates.sqlite, and a non-gating PendingReview onconflict. - Done. Handoff in the session log (T52, T79, T83):
ctx_handoff_begin/ctx_handoff_accept, session-log format 3, the daemon-levelsession_log_failedrefusal, read-set copy into the acceptor's ledger. - Done.
ctx_changesfromdiff_log, with long-poll (T76): pages on epoch boundaries,Truncatedonly when unservable, the actor's epoch signal, at most 64 waiters,ctx changes --follow. - Done. Properties (G3), stress and crash injection (G4), budgets (G5), and the G6 evaluation with real
claude -p. Fixes it produced: - A store failure (a full disk, a poisoned store) used one of the job's attempts, so a poisoned daemon burnt every attempt and left the job
Failedacross the restart. The job is now requeued without an attempt (Ran::Requeued,store_errorscounter). - The recall index deleted a logical's rows through an UNINDEXED column (a full scan per update) and counted rows on the FTS table per head: an indexed
recall_map(rid, logical)table now serves both; an older index is dropped and rebuilt on open. - The candidate sweep's
a_logical = ? OR b_logical = ?scanned the table (28 ms per head at 4·10⁴ pairs); it is two indexed arms now. - Discovery inserted each job row in its own transaction (20 s for 10⁵ rows); one pass is one transaction now (0.48 s).
0. Scope¶
- SPEC sections: §5 P7, SD10, SD17, SD20, §6.1 contract 14, §6.2, §6.3, §7, §8.1, §10.
- Explicitly out of scope: embedding candidates (P8); validator ACLs (P9); automatic resolution; per-revision union vectors (O2: measured, not decided).
1. Gate checklist¶
| Gate | Requirement | Result | Evidence |
|---|---|---|---|
| G0 Spec | SD20; SD10 extended; ADR 0015 accepted; no SPEC §3.5 mechanism introduced | ☑ | ADR 0015 §13; SPEC v1.7.0 |
| G1 Build & Lint | fmt, clippy -D warnings, tests, cargo deny | ☑ | 2026-11-03: fmt, clippy -D warnings, 130 test suites, cargo deny all pass |
| G2 Golden | T49, T50, T52, T53, T76–T84 | ☑ | §G2 |
| G3 Oracle | PROP1 with artifact ops and meta/if_absent; PROP7 with meta and notes; discovery quiescence property; P6 properties |
☑ | §G3, p7-g3-properties.txt, p7-g7-p6-g3.txt |
| G4 Robustness | stress on 2 branches with 4 workers; kill -9 at each job step; disk-full | ☑ | §G4, p7-g4-stress.txt |
| G5 Performance | commit p99 with busy workers within 5% of idle; candidates p99 < 20 ms; long-poll wake p99 < 10 ms; memory at 10⁵ pending rules | ☑ (commit budget restated, D4) | §G5, p7-g5-bench.txt |
| G6 Scenario | mock scenarios; real claude -p run (about 100 jobs and 100 candidate pairs) with reference labels; O2 numbers; score calibration |
☑ | §G6, p7-g6-score.txt |
| G7 Regression | earlier phases' G2/G3/G4 | ☑ | §G7, p7-g7-regression.txt |
| G8 Docs | README, CHANGELOG, SPEC | ☑ | README P7 section; CHANGELOG; SPEC v1.7.1; ADR 0015 corrections; §3 review |
2. Evidence¶
G2¶
Every item has a named test; all pass in the workspace run (cargo test --workspace --locked, 129 suites).
| Item | Tests |
|---|---|
| T49 | p7_jobs::t49_curvec_moved_during_validation_supersedes_and_requeues |
| T50 | p7_jobs::t50_llm_conflict_opens_a_review_only, p7_jobs::t50_property_llm_batches_never_carry_a_record (10,000 outcomes); the daemon-side guard in validators.rs and judge.rs |
| T52 | p7_handoff::t52_accepted_once_under_concurrency_and_after_restart |
| T53 | p7_jobs::t53_exactly_one_of_concurrent_claimers_wins, t53_crash_after_claim_requeues, t53_crash_after_commit_before_finish, t53_lease_expiry_late_result_commits_once; process death at each step in p7_g4 (G4) |
| T76 | p7_changes::t76_pages_equal_the_replayed_status_diffs |
| T77 | migration::t77_format3_log_migrates_to_format4_byte_identical (batches, hashes, idempotency, digest, frame checksums) |
| T78 | p7_conflicts::t78_pair_one_side_superseded_then_resolved, t78_conflicts_are_per_branch, t78_open_refusals |
| T79 | p7_handoff::t79_reads_are_copied_and_the_acceptor_turns_invalid_when_one_changes, t79_refusals |
| T80 | p7_validate::t80_agent_batches_with_record_validation_are_refused |
| T81 | p7_validation::t81_if_absent_never_overwrites_an_existing_verdict (kernel); PROP1 with if_absent (G3) |
| T82 | t82_sandbox: t82_argv_environment_and_directories, t82_isolated_login_is_private_and_removed, t82_only_one_turn_with_one_outcome_object_is_accepted, t82_deadline_kills_the_process_group, t82_token_file_is_private_and_passed_by_environment, t82_pair_task_uses_the_pair_template |
| T83 | p7_handoff::t83_a_crash_between_claim_and_flush_never_lets_two_accepts_succeed |
| T84 | p7_jobs::t84_two_branches_two_jobs_two_records, t84_validator_reviews_dedup_by_curvec; p7_candidates::t84_candidates_never_pair_a_revision_invisible_on_the_branch |
Deviation from ADR 0015 §9 (T77): the ADR said a certificate issued before the 3 → 4 migration reads Invalid(LogMismatch). Format 4 adds no frame field, so the frame checksums are unchanged and such a certificate stays valid; no format-3 op changes meaning, so this is the correct result. T77 now asserts the equal checksums, and the ADR text is corrected.
G3¶
p7_g3_properties (testkit), 10,000 seeds each, all pass:
- PROP1 over
generate_p7:generate_p1's cases, where a quarter of the tail's Ops are instead Conflict and PendingReview opens and resolves (with and without a note), andRecordValidations withmetaandif_absent. The incremental kernel, a replay and full recomputation are compared exactly with the input model and both derived oracles (Jacobi, Kahn). Committed: 4,434OpenArtifact, 1,083ResolveArtifact(548 with a note), 7,926RecordValidation(5,547 withmeta); 2,527ValidationExistsrejections. Deviation from ADR 0015 §11:generate_p1itself is unchanged so its seeds keep their traces;generate_p7is the extended generator. - PROP7 metamorphic: every
metaand note rewritten (to another hash, to none, or from none) changes no commit outcome, no derived digest and no input but the metadata, on one branch (10,000 seeds) and through forks and merges (2,500 multi-branch histories: 5,372 merges, 6,314 records, 2,120 resolves committed). - Discovery quiescence:
p7_jobs(milestone 4).
G4¶
ctxd-validate-stress 1800on the remote Linux host: 4 socket writers (2 onmain, 2 ondev) and 4 workers with command validators (trusted onmain, untrusted ondev). The invariants checked:- no duplicate record or review per
(branch, rule, curvec); - no record from the LLM principal;
- no Pending rule left on
main, and every Pending rule ondevhas a review naming its vector; - no job left queued, running or failed.
Results:
- Rerun (2026-11-03, with batched discovery; p7-g4-stress.txt): 96,576 premise moves, 11,614 records and 17,495 worker reviews, 29,109 jobs done and 136,590 superseded, 35,085 validator calls, 0 store errors and 0 violations.
- First run: 99,253 moves, 0 violations.
- Process death at each job step (p7_g4, 25 runs per step and kind): a real ctxd child aborts at claimed, called, committed or done (CTX_JOB_CRASH, debug builds). Each restart ends with exactly one record (trusted) or one PendingReview (LLM). The validator is called twice only after called, and once otherwise.
- Disk full (p7_g4):
- The blob store fails the worker's commit at append, sync and write. The store poisons; the job is requeued without using an attempt; after a restart it records once, with at most one repeated call.
- The job table cannot grow (limit_pages). Discovery fails without losing its place; claims and finishes fail and are retried after restart. All 400 rules end with exactly one record, with no Failed row.
G5¶
p7-g5-bench.txt: p7_bench 5 1000 10000 100000, M1 Pro, 2026-11-03, after the review fixes, with no other build running (load average 5–14). All four items pass, p7_g5_pass: true. A first run under load average 150–190 is kept in brackets.
| Item | Budget | Result |
|---|---|---|
| Commit latency, workers busy vs idle (D4) | pooled p50 ≤ 1.10×, p99 ≤ 1.25× | p50 6.10 → 6.19 ms (1.015×), p99 17.96 → 18.42 ms (1.026×), 54–62 worker records per round: pass |
| Candidates per new head, 10⁴-record corpus (index + pairs + sweep, on the indexer thread) | p99 < 20 ms | p50 3.1 ms, p99 6.8 ms, max 9.3 ms: pass [p99 9.7 ms; 204 ms before the sweep and recall fixes] |
ctx_changes long-poll wake after publication |
p99 < 10 ms | p50 0.05 ms, p99 0.14 ms: pass |
| Job table at 10⁵ Pending rules | reported, bounded by keys | discovery 0.34 s, 10⁵ rows, 0 new on a second pass, jobs.sqlite 23 MiB (236 B/row); candidates 37,694 rows for 10,500 heads (≤ 5 per head): pass |
Commit budget (owner decision D4). ADR 0015 asked for busy p99 within 5% of idle, with the measured writer itself moving premises of 128 rules every 5 ms. That bound could not be measured. Idle p99 alone moved from 27 to 58 ms between rounds, from per-commit F_FULLFSYNC jitter, and that setup gave 1.88×.
The owner restated the budget: - Measured commits: ordinary records, outside every rule. - Background load: a second connection moves Sem premises twice a second, at 2 jobs per move. G6's generator averages 0.61 jobs per move. - Rounds: 5 interleaved idle/busy rounds, pooled. - Budget: p50 ≤ 1.10×, p99 ≤ 1.25×.
Reported, not gated: at 16 jobs per move (about 50 worker record commits a second), p50 is 1.06× and p99 1.56×. Each validator record is its own durable commit through the shared group-commit writer.
G6¶
Real claude -p (claude 2.1.317, claude-haiku-5-5, the sandboxed ClaudeCli, 4 workers), 2026-11-03. The items were built by p7_g6 collect:
- 125 rule tasks: 5 real premise changes from the three dogfood stores, plus 120 generated (20 domains × 3 conclusions × {moved, re-confirmed}). The dogfood stores cite with Cur and Pin only, so no real Sem rule exists.
- 128 candidate pairs: the 88 real candidates in the dogfood stores, plus 40 generated (20 domains × {contradicting, compatible}).
Generated items are labelled by construction. The dogfood items were labelled by two independent agents that never saw the LLM output; an item where they differ is disputed. Raw items and outcomes contain project text and stay out of the repository; p7-g6-score.txt has the scores by item id.
- Calls. 253 ok, 0 errors; 384,214 tokens in and 90,200 out; latency p50 3.2 s, p95 6.0 s.
- Agreement:
- generated pairs 40/40;
- dogfood pairs 86/88: two
nonepairs judgedconflict, which become non-gating PendingReviews; - generated rules 114/120: four
movedcases labellednew_ruleinstead ofconflict, both of which give a review; twore-confirmedcases labellednoneinstead ofreinforcement; - dogfood rules 3/4 (1 disputed, the other mislabelled
conflictforboundary_change).
Kernel correctness is separate: no LLM outcome can write a record (T50).
- O2. The dogfood stores have no Sem rule, so 0 jobs over 173 head-moving epochs. The generator (1,000 generate_p7 seeds) gives 2,131 jobs over 3,513 head-moving epochs (mean 0.61, max 2 per move). A per-revision union vector would save 0 calls (no two Pending rules share a conclusion revision). No case for union vectors yet; validation stays per rule.
- candidate_min_score. Every one of the 20 reference conflicts is a generated pair; none of the 88 real candidates was labelled a conflict. Every threshold up to 5.0 keeps all 20 conflicts. At 5.0, 32 of the 108 non-conflicts remain (at 1.0, all 108). The generated scores come from a 60-record index, so they do not transfer to real stores. The default stays at 1.0, and the calibration is redone once real conflicts exist.
G7¶
On the remote Linux host, 2026-11-03, after milestone 9's first part:
- p7-g7-regression.txt (scripts/gate-regression.sh) ends with G7 PASS. It runs:
- the paranoid testkit (P0 goldens, P1–P3 properties at 10,000 seeds);
- exhaustive depth 6 (gate) and depth 8 (report);
- store and daemon crash injection, 1,000 per point;
- PROP10 at 10,000 seeds;
- the P4, P5a and P5b suites in release.
- p7-g7-p6-g3.txt (scripts/g3-p6.sh) passes:
- PROP13 against the branch oracle;
- PROP7 and PROP11 for branches;
- the branch fuzz and the Conflict gate;
- PROP10 per branch.
- The review fixes that followed are covered by the local workspace run (G1).
3. Independent implementation review (2026-11-03)¶
A reviewer who did not implement P7 read commits 69a9522..cf556e0 against ADR 0015 and SPEC SD10/SD17/SD20 and §6.1 contract 14, and ran scratch tests outside the repository. No blocker. It found these invariants intact:
- an LLM never records;
- exactly once per key;
- an admin verdict is never overwritten;
- handoff is accepted at most once;
- candidates are visible on the branch;
- ctx_changes pages are correct;
- the claude -p sandbox holds.
| # | Severity | Finding | Disposition |
|---|---|---|---|
| M1 | major (confirmed by a scratch test) | claim read only the 256 oldest claimable rows. Rows no validator's filter takes stay Queued, so 256 of them (another branch, kind or scope) blocked every later job. |
Fixed: claim pages through the rows by rowid. Test declined_rows_never_hide_a_claimable_one (600 declined rows). |
| m1 | minor | Pair judging used an attempt on a store error, so pairs were left Failed after recovery. |
Fixed: pair_defer releases the pair without an attempt (counted in store_errors), as defer does for rule jobs. |
| m2 | minor | The validator deadline was now + lease, taken after the setup, so a call could outlive its lease and a second worker could call again. Commit safety held. | Fixed: the deadline is the lease's end, both for rule jobs and pairs. |
| m3 | minor | An LLM permit was spent before the TooLarge check. |
Fixed: the size check comes first, both for rule jobs and pairs. |
| m4 | minor | A pair review can target a revision that stopped being the head during the call; it is non-gating and listed as stale. A skipped pair's short claim can race judge_expire. |
Open; non-gating; follow-up. |
| m5 | minor | jobs.sqlite Done/Superseded rows, candidates.sqlite Gone pairs and the review-key cache are never pruned. |
Open; follow-up (P10 GC/compaction). Measured size: 236 B per job row (G5). |
| m6 | minor | run_process_raw joins pipe readers after killpg, so a child that leaves the group can hang a worker. Output over 1 MiB times out instead of failing as malformed. command validators inherit the daemon's environment and cwd. |
Open; follow-up. command validators are configured by the owner, and the ADR asks for the minimal sandbox only for claude. |
| m7 | minor | The duplicate-Conflict check compares the whole document hash, so the same pair with a different reason opens twice. | Open; follow-up. |
| m8 | minor | handoff_accept did not refuse an ended session. A failed flush leaves the accept in memory until restart; handoffs are refused after it, as designed. |
Fixed: an ended session is refused. The flush case is open. |