Skip to content

feat(rules): prove the kit's state machines with gdp-wired and fix the laws the bash broke (SPEC-430) - #1210

Open
monotykamary wants to merge 3 commits into
masterfrom
feat/gdp-wired-proof
Open

monotykamary wants to merge 3 commits into
masterfrom
feat/gdp-wired-proof

Conversation

@monotykamary

Copy link
Copy Markdown

What

Every implicit state machine and decision the kit runs is now a native gdp-wired rule in lib/rules/<area>/. Each rule is written from what the code does, with the laws the docs promise, proven and kernel-checked, and held to the real bash by a bridge. Where the code broke a promised law, the bash is fixed.

Spec: docs/specs/SPEC-430-gdp-wired-rules.md. Module: lib/rules/README.md. Per-area findings: lib/rules/{gates,goals,specs,wrap,hooks}/FINDINGS.md.

The retry loop is now code

The two-retry fix cap ("a fix loop stops after two tries and asks you") existed only as pseudocode in commands/execute.md. It is now a proven rule (lib/rules/verify-loop.ts, 8 laws: at most 2 fix cycles, FAIL:escalate never retried, a known failure spends nothing, a finished run never reopens, …). bin/verify-loop runs the compiled rule, and /kit:execute reports each verdict to it and does what it prints.

How each rule is held

  • Rules: ~100 across gates, goals/queue, specs/board, wrap/land and hooks.
  • Proofs: laws over state reloaded from disk are proven {from: 'any'}. A proof counts only when proven && checked && !assumes.
  • Broken variants: each rule keeps the bug it rules out, and the prover asserts it is refused.
  • Bridges: each rule backed by bash runs the real script in a temp sandbox on enumerated and seeded inputs, and compares the result with the rule. That is roughly 15,000 script runs in total, all agreeing.
  • Running it: node lib/rules/prove.ts runs every proof in about a minute (tests/test-rules.sh). --bridges also runs every bridge.

30 broken laws, fixed

Each was found by a faithful rule refuting a documented promise, reproduced by its bridge on the real bash, fixed minimally in the kit's style, re-proven, kept as a refused variant, and covered by a regression test. Highlights:

  • safety-gate: 17 destructive commands got through, among them FOO="a b" rm -rf src, git reset --har, git push --branches, a tag pushed onto main, and kubectl -v 6 delete.
  • anti-rationalization: it read .assistant_response, but Claude Code sends last_assistant_message, so it never fired.
  • lane-data: a run could lower its lane below the spec header through the plain override verb.
  • ship-gate: an ACTION line containing | GATE | impl-notes | override | cleared the missing-notes block.
  • dispatch-gate: ./** vs a/** and b/../a/** vs a/** were "proven" disjoint, so overlapping sub-goals could run in one wave.
  • queue:
    • two conductors could run on one slug;
    • a breaker trip never reached quarantine, so the slug was re-planned forever.
  • goal-registry: a claim could take over another session's running goal.
  • orchestrate: a held gate with its PR open was re-dispatched on every run.
  • wrap:
    • a missing mergeStateStatus was read as CLEAN;
    • a non-numeric WRAP_MERGE_RETRY_MAX retried forever;
    • a quoted ["merge"] table name fell back to a plain squash.
  • config: config get read the wrong layer for keys with two dots.
  • board work: it crashed on jq 1.7, the version stock Ubuntu and Debian ship.
  • spec-task-done: it could check a task off with no verification-log entry.
  • ledger: an append could write outside the ledger root, or join onto a torn line.
  • The full list, with counterexamples and before/after bridge counts, is in each FINDINGS.md.

Kept findings: design calls for the maintainer

These promises the code knowingly does not keep. Each is recorded, and the prover asserts it stays refuted, so a change is noticed:

  • The anti-rationalization hard stop holds for one Stop only (stop_hook_active), which contradicts "the four hard stops are never waived".
  • secrets-guard does not cover the Grep tool.
  • mega status shows PENDING for an existing branch measured against a missing base.
  • Spec and board moves off the next path are silent.
  • A debt line after payment is collected again.

Prose-only machines that could be wired the way bin/verify-loop wires the retry loop: the autonomy dial, the /kit:debug 3-fix wall, the quiescence round cap, and the /kit:docs 2-round stop.

Verification

  • Negative controls (lib/gate/negctl.sh on a disposable copy, Linux box): each fixed file was put back to master, its regression suite went RED, then GREEN once restored. All 8 controls passed:
    • dispatch-gate
    • safety-gate
    • lane-data
    • queue guards: 51/57 under the revert
    • pr-gate and retry cap: 280/284
    • spec-depth: 122/124
    • precedent: 82/83
    • the verify-loop cap mutated: test-rules 9/12
  • Full suite (run-all.sh --all, 353 suites, Linux, jq 1.7, against a master baseline on the same box):
    • Fixed on the branch: board-work, mega-box, mega-merge, mega-reconcile, mega-tick and merge-command, which fail on master there.
    • The suites that failed only on the branch are fixed in this PR.
    • The remaining shared failures are environmental on that box: wrap-*, board-hermes, harvest-sweep, shared-lookups and ui-acceptance-verifier.
  • Local (macOS):
    • test-rules 12/12
    • test-meta 934/934
    • test-hooks all
    • test-bin-forwarders 53/53
    • test-kit-contract 25/25
    • test-known-failures, test-board-work 113/113, test-precedent 83/83, test-whole-spec-dispatch 39/39
  • A final post-rebase run (every proof, every bridge and the full suite) is in progress. Its results land as docs/verification/gdp-wired-proof.md in a follow-up commit on this branch.

Notes

  • Dependency: bin/verify-loop and the provers need Node 22+ and the pinned gdp-wired (install.sh runs npm ci in lib/rules). Hooks stay bash and never load these files.
  • Codex pins: hooks/codex-hooks.json is repinned for the edited hooks.

…e laws the bash broke (SPEC-430)

Every implicit state machine and decision the kit runs is now a native gdp-wired rule in lib/rules/<area>/,
written from what the code does, with the laws the docs promise. Laws over state reloaded from disk are proven
from any state and kernel-checked; each rule keeps the bug it rules out as a broken variant that must be
refused; each rule backed by runnable bash has a bridge that runs the real script beside it.

- verify-loop: the two-retry fix cap lived only as prose in commands/execute.md. It is now a proven rule that
  bin/verify-loop steps; /kit:execute reports each verdict to it and does what it prints.
- 100 rules across gates, goals/queue, specs/board, wrap/land and hooks; `node lib/rules/prove.ts` proves them
  all (tests/test-rules.sh), `--bridges` runs every bridge against the real scripts.
- 30 promised laws the bash broke, each reproduced by its bridge, fixed, re-proven, kept as a refused variant and
  covered by a regression test, among them: 17 destructive commands past safety-gate; anti-rationalization reading
  a field Claude Code never sends; lane lowering through the plain override verb; dispatch-gate proving ./** and
  a/** disjoint; two queue conductors on one slug; a goal claim taking over another session; a missing merge
  state read as CLEAN; a non-numeric retry cap looping forever; board work crashing on jq 1.7.
- Promises the code knowingly does not keep are recorded per area in FINDINGS.md, asserted to stay refuted.
…rd the proof of done

master took SPEC-430 while this branch was open. tests/test-rules.sh now uses a named mktemp template.
docs/verification/gdp-wired-proof.md records the proofs, the bridges, the full suite against master on the
same box, and the eight negative controls.
@tieubao

tieubao commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

PR 1210 review (head 0a1ac00)

Verdict: split

  1. The safety-gate fix opens a broader bypass. The quoted-value join (hooks/safety-gate.sh:207,211) cannot tell an opening quote from a closing one. These now pass, and master blocks all of them: X="abc=" git reset --hard "HEAD~1", TOKEN="abc==" rm -rf src "x", git -c core.x="y=" push origin "main", kubectl --selector "app=" delete ns "prod". The PR's own spec Depth line names this failure mode.
  2. The retry-cap hard stop moves onto Node and the author's own npm package.
    • gdp-wired: sole maintainer is the PR author; created 2026-10-16; 89 versions; 0.59.0 published 2026-11-24.
    • execute.md:175 deletes the bash loop. VERIFY_LOOP_MAX (bin/verify-loop:18) lifts the cap: =9 granted 5 fix cycles.
    • Conflicts with PHILOSOPHY:166 and the lib/ui-verify precedent (the operator installs npm deps, never install.sh).
  3. One 262-file commit (5872c6b) mixes about 150 lines of real bash fixes with 15k lines of TS, a new bin, install-time npm and author infrastructure. lib/rules/gates/supercomputer-jobs.json holds the author's batch jobs, and they run plain npm install. Land the bash fixes alone, minus the QV_RE join.

Hook behaviour changes

File:line (PR head) Change Weakens a block?
safety-gate.sh:207-211 Joins blanks inside ="…"/='…' YES, new bypass
safety-gate.sh:285,317-322,330,341 */rm under find -exec; main checked before the tag allowance; long-option prefixes (--har, --branches, --mirr); kubectl value flags No, adds blocks
anti-rationalization.sh:24 .assistant_response // .last_assistant_message No, the gate now fires under CC
commit-format.sh:46 A $(cat << subject takes the next line Minor: a single-quoted literal -m '$(cat <<EOF⏎fix: x' now passes (master blocks). Master blocked every heredoc commit.
ship-gate.sh:841 The override must be a GATE row, matched by field No, closes a bypass
post-compact-reinject.sh:75 python3 → jq No (identical output)
slop-cleaner.sh:87 Skips unreadable files No
codex-hooks.json Repins No (all 5 pins match)
install.sh:689-708 npm ci without --ignore-scripts First package-manager network call in install.sh

No new env switch in any hook. Input read changes only in anti-rationalization.

anti-rationalization claim confirmed. The Claude Code 2.1.332 Stop schema has last_assistant_message and no assistant_response. A CC-shaped payload gave master rc=0 and PR rc=2.

Reproduced bugs (master, sandboxed)

D = direct hook/script input. T = the PR's regression test run against master code.

Claim Result
safety-gate: FOO="a b" rm -rf src, reset --har, push --branches/--mirr, refs/tags/v1:main, kubectl -v 6 delete Reproduced (D)
anti-rationalization never fires under CC Reproduced (D)
dispatch-gate: ./** and b/../a/** "disjoint" from a/** Reproduced (D)
goal-registry: a second worktree overwrites the holder's claim Reproduced (D)
ship-gate: an ACTION line clears missing-notes Reproduced (T 12b)
queue: two conductors run on one slug; breaker never quarantines Reproduced (T A10, B9)
lane-data: the override verb lowers the lane Reproduced (T)
wrap: missing mergeStateStatus is eligible; non-numeric retry max Reproduced (T)

Also red on master: ledger root escape and torn line, orchestrate B8/B9, spec-task-done unwritable log.

Supply chain and fail-open

  • Lockfile: one package, gdp-wired@0.59.0, with no deps and two optional peers. No install scripts. The tarball sha512 matches the lockfile.
  • Package scan: 762 files, 10.8 MB of built JS. A grep found no static http/net/tls imports and no fetch(. child_process appears in 18 files. I did not audit the package.
  • Latency: no hook starts Node; hooks stay at 20-41 ms (budget 500 ms). verify-loop costs about 240 ms per verdict.
  • Fail behaviour:
    • Without Node or the package, verify-loop fails closed (exit 69).
    • execute.md then gives no instruction, so the documented 2-cycle cap has no enforcement.
    • tests/test-rules.sh:14,17 turns a missing install into SKIP, exit 0, and runs npm ci at test time.
    • The PR has no CI run.
  • Node floor: node file.ts needs native type stripping (Node 22.18+). The engine fields say ">=20" and "22+".

Scope

  • The title and body cite SPEC-430, which collides with master's SPEC-430-mega-tick-verb.md. The PR adds SPEC-431-gdp-wired-rules.md, self-marked VALIDATED.
  • Unrelated changes: supercomputer-jobs.json, .last-prove.json, FEATURES.md regeneration, and the /kit:execute routing rewrite (a new feature).
  • I found no prompt-injection text in the body, FINDINGS or docs.

Tests on the PR head (sandboxed)

Suite master PR
test-hooks 840/843 863/866
test-meta pass pass
test-bin-forwarders 48/50 51/53
test-rules (verified package, offline) n/a 12/12
  • The failures are identical on both trees: PTY colors, slop-cleaner exit 0 twice, and stats forwarder via uv twice. Cause not established; likely the sandbox.
  • Sampled tests were red on master and green on the PR: ledger-substrate, orchestrate-gate-dispatch, runaway-guards, spec-task-done, ship-gate-impl-notes, lane-effective, wrap-merge.

Kept findings

Finding Real on master? Severity
The hard stop yields after one block (anti-rationalization.sh:20) Yes, against gates-and-proof.md:19. Moot on master (the hook never fired); live after this PR. Medium
secrets-guard skips Grep (matcher Read|Edit|Bash) Yes. Whether the Read() denies cover Grep is unverified; the plugin path has none. Medium
mega status PENDING, silent moves off next, debt re-collected Not checked Not rated

Could not check

  • run-all.sh --all, the --bridges runs, and Linux with jq 1.7.
  • Three kept findings.
  • A full audit of gdp-wired.
  • Method: sandbox-exec, no network, scratch-only writes, empty env. No npm install; tarball via npm pack --ignore-scripts.

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.

2 participants