Skip to content

#747 Move the correctness-rule database into this repo - #749

Merged
nockawa merged 2 commits into
mainfrom
feature/move-rules
Aug 10, 2026
Merged

nockawa merged 2 commits into
mainfrom
feature/move-rules

Conversation

@nockawa

@nockawa nockawa commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Companion: Log2n-io/Typhon-Claude#feature/move-rules. Deliberately order-independent — that the two used to require a merge order is the defect this closes, so please do not reintroduce one. Either can land first.

Why

claude/rules/ was in the private docs repo because it is markdown, and everything markdown lived there. But it is not prose about code, it is checked against code:

Direction Count
scope: lines naming C# symbols ~185 (of 191 rules)
[VerifiesRule] attributes in test/ 70
Source/test files citing a rule id in comments 75
coverage/rule-coverage-baseline.json, counting all of it already in this repo
Markdown links from rules/ → rest of claude/ 4

Roughly 330 references to code, four to the rest of the knowledge base. A directory's home is wherever its verifier lives.

What the boundary was costing

  1. A PAT in a public repo's CI. Two jobs checked out the private repo with secrets.TYPHON_CLAUDE_TOKEN. merge-gate.yml's own comment: "a capability, not a fence: anyone with push access here could print the private knowledge base from a workflow step."
  2. 19 forks got no audit. Secrets are withheld from fork PRs, so the checkout produced nothing and --skip-if-no-rules skipped.
  3. The path filter could not see rule edits — with the admission in-file that "the rule database lives in the private repo, so its own edits cannot trigger this". Editing a rule ran no audit at all.
  4. Two ~15-line steps guessed the companion docs branch by matching its NAME, continue-on-error, announcing the fallback so a green run could be told from the wrong green run.
  5. A merge deadlock. Docs PR red until the code merged (scope: cites an unlanded symbol); code PR red until the docs merged (unknown rule id + ratchet regression). Test suite as a defect detector #702, Bug bash: eight defects fixed, two filed with measurements #717, #631 #662 #582 #710 #569 #672 #688 Bug bash round two: seven fixes, and the view bug underneath one of them #719 — main red for twelve hours, two runs never re-run.
  6. Plus the two workarounds built to survive it: a docs-first human protocol, and a --baseline-rules mode that materialised a git worktree in CI to tell "drifted" from "hasn't landed yet".

All deleted, not tuned. A rule, its verifier and the code it scopes land in one commit now, so there is nothing left to sequence.

Decisions worth reviewing

rules/ at the repo root, not doc/rules/. It is a contract, not documentation output.

The scope check runs in invariants, unconditionally — not in the rules/**-gated job. An unresolved scope: symbol is a source-side defect: someone renames a type in src/ and a correct rule quietly becomes false, with no rule file in the diff. Gating it on rule paths would miss the entire failure mode it exists to catch. This is precisely the direction that previously could only be caught by a nightly sweep in the other repo, a day late.

--rules-dir survives; --skip-if-no-rules does not. The first is the fixture hook the self-tests use, alongside --tests-dir / --baseline / --matrix. The second is the one that could manufacture a false green — a gate that can decline to run is one a reader must check the logs to trust.

The TLA job inherits the docs-repo version's *.cfg glob and jar cache, replacing a hardcoded three-spec list. When the two copies disagreed, the hardcoded one silently checked less.

Found while doing it

A guard that would have been silently dropped. check-doc-drift.py had ENFORCED_DIRS = {"overview", "rules"} — it validated the src/… paths and links inside rule files. check-rule-scopes.py does not do that job; it resolves scope: symbols, which is a different check. Moving the database out without noticing would have left those unguarded. scripts/check-doc-links.py already does exactly this for doc/ and now covers rules/, with build-docs.yml gated on rules/**.

A latent bug in check-doc-drift.py (fixed in the companion PR): its link checker never skipped absolute URLs while its regex matches any .md target, so every https://…/rules/durability.md read as a missing file. Harmless only because no enforced-tier doc had an https link ending in .md — until these citations became absolute.

Verification

Check Result
check-rule-scopes.py 185 scope lines, all resolve
audit-rule-coverage.py 22 findings, 0 blocking, against the untouched baseline (191 / 26 / 21 / 4)
check-doc-links.py 335 files, 1865 links, PASS
check-doc-drift.py no drift in enforced docs
Script self-tests 100 passed
Build 0 warnings, 0 errors
Engine suite 5072 passed, 3 failed

The 3 failures are pre-existing and unrelated. PayloadAxes_SurviveACrash, DirtyCounter_IsConservedAtQuiesce and ParallelOperations_AreLinearizable fail deterministically on unmodified 3958c154 (this branch's base) and on current main head a464cf75 — baselined in a throwaway worktree. The C# diff here is thirteen comment lines across twelve files; a comment cannot change runtime behaviour.

The coverage baseline is deliberately untouched: changing it during a move would hide whether the move was faithful.

Follow-up, not in this PR

TYPHON_CLAUDE_TOKEN should be revoked at the org once this merges. Nothing references it any more, so it becomes a standing capability with no consumer.

🤖 Generated with Claude Code

https://claude.ai/code/session_01WdANiVsrwEwuZd3Zdygu9J

The rule database was in the private Typhon-Claude repo because it is markdown, and everything markdown lived there. But it is not prose about code, it is checked against code: ~185 `scope:` lines name C# symbols, 70 `[VerifiesRule]` attributes name rule ids, 75 source files cite rule ids in comments, and the ratchet baseline counting all of it already lived here. It pointed at code roughly 330 times and at the rest of the knowledge base four times.

Living across the boundary cost a PAT in a public repo's CI (the workflow's own comment called it "a capability, not a fence"), an audit that fork PRs silently skipped, a path filter that could not see rule edits at all, two ~15-line steps that guessed the companion docs branch by matching its NAME, and a merge deadlock where each repo's gate demanded the other merge first — three consecutive merges left main red for twelve hours. All of that is deleted rather than tuned, because a rule, its verifying test and the code it scopes now land in one commit.

`rules/` sits at the repo root: it is a contract, not documentation output. `check-rule-scopes.py` comes with it, minus `--repo-root` and minus the whole `--baseline-rules` regression-only mode, which existed only to tell "drifted" from "hasn't landed yet" — a distinction with no meaning once both halves travel together. The audit keeps `--rules-dir` as the fixture hook its self-tests use, alongside `--tests-dir` and `--baseline`, but loses `--skip-if-no-rules`: a gate that can decline to run is one a reader must check the logs to trust.

The scope check runs in `invariants`, unconditionally, not in the `rules/**`-gated job. An unresolved `scope:` symbol is a source-side defect — someone renames a type in src/ and a correct rule quietly becomes false, with no rule file in the diff — so gating it on rule paths would miss the failure mode it exists to catch. This is the direction that previously could only be caught by a nightly sweep in the other repository, a day late.

Moving the database out of `claude/` would have silently dropped a guard: check-doc-drift.py had rules/ in its ENFORCED_DIRS, validating the src/ paths and links inside rule files, which is a different check from scope-symbol resolution. check-doc-links.py already does exactly that job for doc/ and now covers rules/ too, with build-docs.yml gated accordingly. That work also surfaced a latent bug in check-doc-drift.py: its link checker never skipped absolute URLs while its regex matches any .md target, so every https link to a rules file read as a missing file.

Verified against the untouched baseline: 185 scope lines all resolve, the coverage audit is clean at 191/26/21/4 with 22 non-blocking mutant advisories, doc-links passes over 335 files and 1865 links, and 100 script self-tests are green. The three engine tests failing here (PayloadAxes_SurviveACrash, DirtyCounter_IsConservedAtQuiesce, ParallelOperations_AreLinearizable) fail identically on unmodified 3958c15 and on current main; the C# diff in this change is thirteen comment lines.
…ommit

Rebasing onto main hit the one conflict this move can produce: `rules/indexing.md` was deleted on this branch and modified on the docs repo's main, where #740 added IXW-03 (a leaf's lower bound is the previous leaf's HighKey). Resolving it the obvious way — deletion wins, the file is going away — would have dropped a `[fatal]` rule added a few hours earlier. So the resolution is main's version of the file, with this branch's link change re-applied on top, not the version this branch started from.

That IXW-03 exists at all is worth noting here, because it is the same failure mode from a different angle: the guard shipped in PR #737 was strictly stronger than the invariant it protected, and nothing could see the contradiction because the guard and the consistency check that disagreed with it never met. A rule deleted by a clean merge resolution would be invisible in exactly the same way.

Its `scope:` resolves — `KeyBelowLeafLowerBound` and `InsertIterative` in `BTree.Insert.cs` — because the fix landed in PR #745 meanwhile. Worth stating plainly, since this branch deletes the `--baseline-rules` mode that used to demote a not-yet-landed citation to a warning: had the rule arrived before its fix, the scope check would now fail, and that is the intended behaviour rather than an oversight. The window in which a rule can outrun its code is the width of one commit.

`rules_total` goes 191 to 192. The three coverage figures are untouched — IXW-03 is covered by its `verified:` line but carries no `[VerifiesRule]` attribute, so nothing the ratchet protects moves. That the count and the rule it counts can be corrected together is the whole point: PR #745 could not touch the rule, PR #73 could not touch the counter, and neither was wrong to leave it.
@nockawa
nockawa force-pushed the feature/move-rules branch from 67984e3 to 5c9509a Compare August 10, 2026 09:47
@nockawa
nockawa merged commit c011a7f into main Aug 10, 2026
10 checks passed
@nockawa
nockawa deleted the feature/move-rules branch August 10, 2026 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant