Skip to content

fix(gate): fail loudly on a gate key the reader cannot read - #1279

Merged
tieubao merged 3 commits into
masterfrom
fix/gate-key-shape
Dec 6, 2026
Merged

tieubao merged 3 commits into
masterfrom
fix/gate-key-shape

Conversation

@tieubao

@tieubao tieubao commented Dec 6, 2026

Copy link
Copy Markdown
Collaborator

What

A gate key written in a valid TOML form the line reader cannot read was skipped without a word. [dev] + gate.proof_of_done = true reads to anyone as "turn proof_of_done on", but gate-policy.sh saw it as unset and the gate stayed off. This is the adjacent gap found while fixing #1278.

gate-policy.sh enabled now checks every layer the key can come from: project kit.toml [dev.gate], .kit.toml [gate] (or their --at base copies), the operator file and the kit root. A layer that writes the key in an unreadable form turns the gate ON, with a stderr line naming the file and the offending line. An odd true gets what it meant; an odd false cannot switch a gate off.

before:  [dev] / gate.proof_of_done = true      -> off, silent
after:   gate-policy: <repo>/kit.toml line 2 cannot be read the way TOML reads it, and it may
         set [dev.gate] proof_of_done; treating the gate as on (write a plain [dev.gate] table
         with proof_of_done = true or false)

How. The left-to-right TOML scanner from #1278 moves into lib/config/kit-config.sh as _kit_toml_shape <file> <section> <key> <str|bool> <table|key>, and _kit_mc_shape becomes a one-line wrapper. Key scope guards only <section>.<key>, so [[gate.hard_path_exempt]] stays fine.

Review led to two scanner changes that the merge check shares. It now counts { and }, so a TOML 1.1 inline table spanning lines refuses. It also accepts a quoted header or an escaped key in an unrelated table ([repo.labels."good first issue"]).

Demo

Command: bash tests/run-all.sh --only test-gate-key-shape   (new test on origin/master)
FAILS: 21          (the 10 negative-control rows pass)

Command: bash tests/run-all.sh --only test-gate-key-shape   (this branch)
run-all: all 1 suites passed, 0 skipped for missing tooling

Command: bash tests/run-all.sh --time   (diff-scoped)
run-all: all 64 suites passed, 0 skipped for missing tooling

Proof

docs/verification/gate-key-shape.md: the differential, the red run, the green runs, the fuzz, the independent review, the negative controls, the cost and the rollback.

  • Fuzz against tomllib. The 9,231-file merge corpus was rewritten into gate keys. With the check: 0 disagreements in gate and in dev.gate. The reader alone: 833 and 1,078. The merge corpora, including the 59,547-file key-form corpus, also show 0 disagreements after the scanner change.
  • Independent review. A fresh-context security reviewer ran two rounds with targeted fuzzers under tomllib 3.12 and 3.15, on macOS awk, gawk and mawk. Round one found the TOML 1.1 gap, an over-refusal and a vague message, all fixed with test rows. Round two found nothing.
  • Negative controls. 40 real kit.toml / .kit.toml files from the local workspace, the operator file and this repo pass the check for all 7 gate keys. They also give the same merge result as master.
  • Cost. About 10 to 15 ms per enabled call in an adopted repo, and 25 to 35 ms in this repo, which has two long files. Well inside the 500 ms hook budget.

Bookkeeping

no-board-row: follow-up fix from a security review, one function plus its tests

This changes lib/gate/gate-policy.sh, a Core gates one-way-door path, so scripts/pr-merge.sh needs a second maintainer's recorded approval before it will merge.

A gate key written in valid TOML the line reader cannot read ([dev] + gate.proof_of_done = true, a quoted header, an inline table) read as unset, so a gate meant to be on stayed off with no message. The merge-command scanner moves into kit-config.sh as a shared key-scoped check; gate-policy.sh runs it on every layer and treats an unreadable form as ON with a stderr line naming the file and key. Proof: docs/verification/gate-key-shape.md.
Review of the gate key check: a TOML 1.1 inline table spanning lines could hide a key line, and a quoted header or escaped key in any unrelated table turned every gate on. The scanner now counts braces, accepts quoted headers and escaped keys whose path cannot reach the guarded table, and the gate message names the file line.
@tieubao
tieubao merged commit 4c080be into master Dec 6, 2026
9 checks passed
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