Gate the three doc constants that had drifted from their sources

Merged
JE
4mo ago
+1802-30

Three constants are restated in prose. Nothing checked them, and all three had drifted — one of them for four repins.

ClaimProse saidSource says
API_VERSION (SPEC.md ×2)2026-03-23openapi.json .info.version = 2026-08-02
bc3 pin (COORDINATION.md)338b7a11 (2026-07-23)spec/api-provenance.json .bc3.revision = 2c0dafba13 (2026-08-02)
bc3 pin (spec/api-gaps/README.md)e83b2733 (2026-07-30)same
Assertion types (SPEC §19)17 rowsconformance/schema.json defines 21

headerAbsent, requestMethod, requestBody and requestBodyAbsent have been in the schema and in use by the conformance fixtures the whole time, undocumented.

The pin column moved during review: this branch was rebased onto main's repin to 2c0dafba13, which is also the best evidence in the PR — see What the repin proved below.

Red proof

The first commit adds the gate and the markers but leaves the scalar values wrong, so the red is reproducible from history — git checkout f0ae5eb1b && ruby scripts/sync-doc-constants.rb --check:

ERROR: documentation constants have drifted from their sources.
  SPEC.md:1061: @api-version says 2026-03-23, openapi.json .info.version is 2026-08-02
  SPEC.md:1719-1739: conformance/schema.json defines 21 assertion types, the table documents 17; missing: `headerAbsent`, `requestMethod`, `requestBody`, `requestBodyAbsent`
  SPEC.md:1917: @api-version says 2026-03-23, openapi.json .info.version is 2026-08-02

  Scalar constants: run `make sync-api-version` to rewrite marked spans.
  Assertion types:  edit SPEC.md §19's marked table by hand — a new row needs a description only a human can write.
REAL_EXIT=1

(That is the bare runner, hence exit 1; make doc-constants-check wraps it and exits 2. The two @bc3-pin errors that this block showed before the rebase are gone from it because the rebase carried main's already-correct pin into that commit — the remaining three are the original drift.)

Green at the tip:

==> Checking documentation constants...
Doc constants match their sources (5 marked spans across 3 files).
  api-version      2026-08-02
  bc3-pin          2c0dafba (2026-08-02)
  assertion-types  21
sync-doc-constants self-test: all cases passed.
REAL_EXIT=0

Why markers, not a blanket scan

spec/api-gaps/ cites ~30 historical bc3 SHAs on purpose — "the pin has since advanced to X", "the A..B range contains exactly two contract changes". A "every SHA must equal the current pin" gate would false-positive on all of them, and worse, its writer would rewrite settled triage into a range claim nobody verified. That hazard was live: spec/api-gaps/README.md had the current-pin sentence and the dffa7e11..e83b2733 range analysis on the same line, so a line-scoped rewrite would have produced "the dffa7e11..2c0dafba13 range contains exactly two API-contract changes" — untrue and unverified.

So a claim about the current value carries an HTML comment and only marked spans are read or written:

  • <!-- @api-version --> — trailing marker; every YYYY-MM-DD on that line must equal openapi.json .info.version
  • <!-- @bc3-pin --> — trailing marker; every backticked 7–40-char hex token on that line must be a prefix of .bc3.revision, and every date must equal .bc3.date
  • <!-- @assertion-types:begin --> / :end — block; the table's first-column identifiers must equal the schema enum, both directions

A marker inside an inline code span or a fenced block is a mention of the convention (AGENTS.md documents the syntax), not a use of it — the scanner masks both. That bit found itself: writing the AGENTS.md section turned the gate red until the masking landed. It happened a second time later, when the paragraph documenting the range trap quoted the live range and the gate failed on it.

The writer must not touch the narrative

make generate → smithy-build → sync-api-version reaches this script's --write mode, so the gate ships a generator that edits prose. For spec/api-gaps/README.md that is exactly the unreviewed-rewrite hazard the marker convention exists to prevent: its pin sentence is the heading of the range triage below it, and advancing the SHA without adding the new range's triage would make the one document whose job is recording that triage assert a range nobody triaged.

So it is listed in spec/doc-constants.json .writerExcludes, with the reason committed next to the exclusion. The writer diffs it, refuses to write it, says so loudly, and exits 0 so make generate is never held hostage; --check then stays red until a human answers.

What the repin proved

Main repinned to 2c0dafba13 mid-review, and the rebase became the first run of this gate against a real sync. It earned its keep three times over:

  1. It caught SPEC.md's two @api-version spans two versions stale and fixed them from openapi.json.
  2. Main's own repin commit advanced the README pin sentence together with ~15 lines of new range triage — precisely the coupling the exclusion exists to protect. A writer that silently advanced only the SHA would have produced a false document.
  3. It reported a now-dead .unmarkedPinCitations grant (my-assignments-priorities.md, which had described the previous pin) and demanded it be dropped.

Simulating a further repin shows the decline path end to end — the writer advances COORDINATION.md, refuses the README, and make doc-constants-check goes red at exit 2:

NOTE: spec/api-gaps/README.md has stale marked doc constants and was NOT rewritten.
      Reason it is in spec/doc-constants.json .writerExcludes:
        the pin sentence heads a triage narrative — advancing the SHA without adding the new range's triage would make the one document whose job is recording that triage assert a range nobody triaged
      Update it by hand, along with the prose that depends on it.
      `make doc-constants-check` stays red until you do.
Rewrote marked doc constants in COORDINATION.md

The README was byte-identical afterwards (md5 b93ac2ec207d9c331b0eb2b21045d0fd before and after).

Deleting a marker doesn't work

spec/doc-constants.json commits the exact per-file marker count. Every deviation fails: too few (a claim was deleted or unmarked), too many (a claim was added without being recorded, and so would not be missed if it later went), or a marked file the inventory never mentions.

This started as a floor. Review pointed out that a minimum only protects the first N claims in a file — add a third @api-version to SPEC.md against a floor of 2, delete it a month later, and two markers remain, so the gate stays green while the value it guarded drifts. An exact count costs one line in the commit that adds the marker and buys an inventory that is true.

.unmarkedPinCitations is bounded the same way, for the same reason. Some files legitimately name today's pin unmarked — a range's endpoint is the pin that repin set, so spec/api-gaps/README.md does it at every sync — but an unbounded file grant would wave through whatever that file grows next, in exactly the file likeliest to grow a real "the provenance pin is X". Each grant carries an exact count and a reason, and the shape is validated so the pre-count bare-string spelling cannot read as "grant everything".

Self-test

make doc-constants-check runs the live check and scripts/test-doc-constants.rb, same shape and same stated reason as scripts/test-check-fixture-coverage.rb: the live run only ever proves the gate can say yes.

It drives the gate against a crafted throwaway git repo via a DOC_CONSTANTS_ROOT override and asserts a non-zero exit plus an expected message fragment for every failure mode claimed — each constant drifting, missing SHA/date in a pin span, bare SHA, unmarked restatement (backticked, bare, inside a compound span, more than one per line), every marker-structure error, every marker-inventory case including the count, grant shape and bounds, fenced-code edge cases, the four source-of-truth failures, and the writer's own contracts. Positive controls too, including LC_ALL=C. 70 assertions.

It has already paid for itself twice: it caught a crash in the grant-shape validation (malformed grants reached a count comparison and died on Integer > nil instead of printing the message that says what to fix), and every review fix below was demonstrated to fail against the un-fixed code before being accepted.

Review rounds

Ten findings from Codex across six rounds. Nine are fixed; one is argued and recorded. Every one of them is the same bug wearing different clothes — something the scanner could not see was something it silently vouched for:

FindingHoleOutcome
Bare restatementsthe pin is d0edc128 unbackticked slipped pastfixed
Marker flooronly the first N claims in a file protectedfixed (exact counts)
Compound code spans`A..B` invisible to both scan passesfixed
Occurrences vs linestwo claims on one line counted oncefixed
Fence delimitersodd nested fence left the rest of the file "code"fixed
Fence indentationa 4-space ``` opened a fence that never closedfixed
Backtick fence info```code``` is inline opened a fence that never closedfixed
Uppercase hex2C0DAFBA not recognised as the pinfixed
Grant covers a class-A claimswap one granted citation for "the pin is X", count holdsfixed (grammar floor) + residual argued
Count is per file, not per claimunmark one @api-version, mark another, total holdsargued, recorded in-file

Each fix has a self-test case shown to fail against its own un-fixed version, and in each round only that round's cases fail — so none rides on another's fix. The fence-delimiter round failed in both directions against the old toggle, which also showed the toggle inventing findings inside code samples.

The one not fixed

A marker count is per file, so unmarking one @api-version sentence in SPEC.md while marking a different one in the same change keeps the total at 2 and passes, leaving the first unprotected. True, and closing it needs per-claim identity — named markers, <!-- @api-version#headers -->, with the inventory listing names.

Not done here, for two reasons recorded next to the mechanism rather than only in a review thread. It changes the marker grammar that AGENTS.md and SPEC.md document and collides with the :begin/:end suffix, so it is a design change to the convention rather than a bug fix. And unlike every other finding — all of which triggered on ordinary authoring — this one requires a deliberate within-file relocation of a marker, which is by definition a reviewed edit to marked spans; cross-file relocation is already caught.

The symmetric fix is unavailable, which is worth knowing: @bc3-pin gets an unmarked-restatement scan, but API_VERSION cannot have one. It is a date, and the same date as .bc3.date, so the scan would fire on every legitimate mention — starting with COORDINATION.md's own "as of the 2026-08-02 sync". A 40-hex SHA appears nowhere by accident; a date appears everywhere by accident.

The in-file note names the condition under which the argument stops holding, so it is falsifiable rather than a standing excuse: a third @api-version claim.

Because they kept arriving in the same shape, the file now states which way this gate should be wrong: resolve any prose-vs-code ambiguity toward treating a line as prose. Over-scanning costs a false alarm — loud, in front of the author, disproved in a minute. Under-scanning costs a claim nobody looked at, reported as success, carrying the gate's own green tick.

SPEC Appendix A

Only API_VERSION is gated. The other 13 rows were read against their cited sources on 2026-08-03 — all 13 matched, recorded in SPEC.md with the date. They stay ungated because each is asserted of several SDKs at once in a different spelling per language, so a checker would need a per-row, per-language extraction rule rather than the one-value-one-source substitution the marker convention is built on. Also recorded: the two spellings that defeat a naive grep, since I hit both — MAX_ERROR_MESSAGE_LENGTH is MaxErrorMessageBytes in Go and MAX_ERROR_MESSAGE_BYTES in Ruby, and TOKEN_REFRESH_BUFFER is not a named constant anywhere, it is the literal 300 in creds.ExpiresAt-300 (go/pkg/basecamp/auth.go:287).

Residual pin restatements

Every present-tense restatement carrying a literal SHA is rewritten as an as-of fact bound to what makes it permanently true, across calendar.md, my-bookmarks.md, my-drafts.md, my-assignments-priorities.md, everything-tasks-aggregate.md and upload-new-version.md.

The sweep surfaced a third form that had never been written down and is usually the right answer: name the pin by reference, not by value — "the revision spec/api-provenance.json currently pins". It means today's pin, survives every repin, and restates no constant, so nothing can drift and nothing needs marking. That is now in AGENTS.md alongside the A/B rule.

Verification

CommandExit
make doc-constants-check0
make sync-api-version-check0
make validate-api-gaps0 (31 entries)
make lint-actions0 (actionlint + zizmor, no findings)
ruby -w -c scripts/sync-doc-constants.rb0
shellcheck scripts/check-doc-constants.sh scripts/sync-api-version.sh0

No SDK source, openapi.json, or spec/basecamp.smithy touched. SPEC §7 untouched.


Summary by cubic

Adds a gate and writer to keep three documentation constants in sync with their sources, with strict fence parsing, exact per‑file marker counts, and a rule that “the pin is X” sentences must be marked — grants only cover as‑of facts.

  • New Features

    • Check: make doc-constants-check validates @api-version (vs openapi.json .info.version), @bc3-pin (SHA+date, vs spec/api-provenance.json), and @assertion-types:begin/end (vs conformance/schema.json). Runs a negative self‑test (scripts/test-doc-constants.rb). Supports --openapi; all I/O forced to UTF‑8.
    • Writer: scripts/sync-doc-constants.rb (--check/--write) is called from scripts/sync-api-version.sh and forwards --openapi. Preserves SHA abbreviation length; never edits files in spec/doc-constants.json .writerExcludes (e.g., spec/api-gaps/README.md). The assertion‑types table is check‑only.
    • Safety: scans raw prose lines (including ranges), counts every occurrence, is case‑insensitive for SHA matches, and rejects bare SHAs inside @bc3-pin. Fenced code is skipped with delimiter matching and ≤3‑space indentation; backtick fences with a backtick in the info string do not open; tilde fences allow any info. Ambiguities over‑scan as prose.
    • Inventory and grants: spec/doc-constants.json records exact per‑file marker counts (markers in undeclared files fail). .unmarkedPinCitations entries are shape‑validated and bounded by an exact count+reason; grants do not cover class‑A grammar (“the pin is X”, “at the pinned X”) — those lines must be marked. A per‑file count residual is documented in code comments.
    • CI/docs: wired into check and Actions. SPEC/AGENTS updated (A/B rule, request assertion index); API version, bc3 pin, and assertion‑types table corrected.
  • Migration

    • After a repin, run make sync-api-version to update SDK constants and marked prose; update the triage narrative in spec/api-gaps/README.md by hand.
    • When adding or moving a marked claim, keep it marked and update the count in spec/doc-constants.json. For an as‑of reference that happens to name today’s pin, either mark it (and include the date) or add a bounded .unmarkedPinCitations grant with a reason.