baseline icon indicating copy to clipboard operation
baseline copied to clipboard

Extend §2.5 to all external contracts, and verify them before the commit gate

Open tusharsrivastava opened this issue 3 months ago • 0 comments

What happened

A twelve-phase power workflow shipped code that could not execute a single one of its three new database queries. It carried 629 passing tests, a per-ticket security review, a CLEAN code-review fan-out, a passing spec-lint and a drift check. A five-minute rehearsal against the real system, run immediately after the commit, found that defect and three more.

The specific defect was a table's primary key being named by convention rather than read from the schema. The general shape is what matters:

The change encoded an assumption about a system the project does not own, and every check in the pipeline was derived from that same assumption.

The spec asserted it. The implementation encoded it. The test fixture reproduced it. 629 tests then confirmed that the fixture and the query agreed with each other. Nothing in twelve phases read the system itself.

Why this is a baseline gap and not a project mistake

That shape is available wherever a project depends on a contract it cannot change:

Contract How the assumption enters What "reading the system" means
Third-party HTTP API a remembered field name current docs, llms.txt (already covered by §2.5)
Database schema a naming convention information_schema
Message broker topic an assumed payload shape the schema registry, or a live sample
Upstream file format a parser written to a guess a real file the producer emitted
Another team's service an interface from a conversation their contract test, or a live call
Deploy-target environment an assumed variable or path the target itself

The baseline already handles exactly one row of that table, and handles it well. §2.5 / Article VI.5 forbids recalling a third-party library API from training data and mandates verification against current documentation. It worked on this same epic: research checked the vendor's API and established that a route the intake assumed did not exist, so a criterion was dropped rather than built.

The rule is right. Its subject is too narrow.

Two other rules were honoured and did not help:

  • §2.3 / VI.3 forbids mocking the database and mandates a real test DB. The suite honoured it, using a real Postgres container with no mocks, and then built that container from a schema somebody invented. VI.3 governs the mechanism of a test double. Nothing governs its shape. A real dependency configured from an assumed shape is a mock wearing the dependency's clothes.
  • The drift check worked. It reported the unrun rehearsal criterion and exited 1 before any commit. What followed was a written justification for deferring it. The information was present, correct, and talked out of.

Why widening the rule is not enough

The baseline already argues this against itself. document/SKILL.md justifies document-gate.mjs like so:

This exists because the prose rule below was correct and got skipped anyway: a sentence in a SKILL.md cannot fail a build.

Same here. Widening §2.5 is worth doing and will be forgotten under deadline. The fix has to be structural.

Proposed mechanism

Projects declare their external contracts and how to check them. The workflow runs the check when the diff touches one, and the consent gate states plainly whether it ran.

1. Declaration — a new project.json key

"contracts": [
  {
    "name": "source-schema",
    "cmd": "./scripts/verify_contracts.sh",
    "when": ["src/<pkg>/source/**", "src/<pkg>/mappers/**"],
    "requires_env": ["SOURCE_DSN"],
    "timeout_seconds": 120
  }
]
  • when sets the diff globs, so an unrelated workflow pays nothing.
  • requires_env names what the check needs to reach the real system. Without it the check is not run, which is a recorded state of its own and never counts as a pass.
  • cmd is the project's own command. The baseline supplies the obligation, the diff matching and the visibility, and never learns what a contract is or how to read one. That ignorance is what keeps it general across stacks.

Absent contracts, all of this is a no-op and behaviour is byte-unchanged, so an existing project updates and notices nothing until it opts in.

2. Execution — inside /integrate

After the binding test verdict, before the code-review fan-out. /integrate already owns "the change is real and the tree is final", already runs a project-supplied command, and is the last phase before the commit gate. Making this its own phase would touch Article IV ordering, the track DAGs and the materializer, and buy nothing.

Outcome Meaning Effect
passed ran, exited 0 continue
failed ran, exited non-zero yield, exactly as an integrate failure does
not-run requires_env unsatisfied continue, and record it

3. Visibility — the gate says what it does not know

not-run goes to workflow.json → contracts_unverified[], and the gate-C yield names it:

<slug> needs your attention: /grant-commit

  Contract checks NOT RUN: source-schema (SOURCE_DSN unset)
  This diff touches src/<pkg>/source/** and src/<pkg>/mappers/**.

This is the whole point. A pipeline cannot force a developer to have a tunnel open. It can refuse to let the absence be silent. On the day this went wrong the operator had the connection available and would have opened it had the gate said this.

Proposed rule changes

  • §2.5 / VI.5 — read "external contracts" where it now reads "third-party library APIs". Any interface owned outside the project SHALL be verified against the system itself before code encodes it, whether that is a library API, a database schema, a broker topic, an upstream file format, another team's service or the deploy target. Keep VI.5's existing shape exactly: it is already an outcome mandate rather than a tool mandate, which is what lets one rule cover information_schema, a schema registry and a sample file without naming any of them.
  • §2.3 / VI.3 — add provenance to the mock rule: a test double standing in for an external system SHALL derive its shape from that system, and SHALL record when and from what it was derived.
  • §5 / Article IV — name the contract step in the integrate phase, and note that not-run is carried to the consent gate rather than swallowed.
  • §16 — document project.json → contracts[] alongside test and lint.
  • §14 Known follow-ups — one entry until the above lands.

What it would have caught

All four defects from the incident fall out of one check that executes the change against the real system and reports counts:

  1. A join on a column that does not exist — three queries raise immediately.
  2. A population query covering two of eight source tables — the reported row count disagrees with the spec's figure.
  3. An egress filter refusing 64% of real records whole, so the record count was wrong rather than the content — visible in per-route accepted/rejected counts.
  4. A source sized at ~900 records that actually holds 13.6M — the same count report.

That is not luck. It is what the failure class predicts: assumptions about an unowned system fail on contact with it, and only on contact with it.

Cost and risk

  • Zero adoption cost for a project declaring no contracts.
  • Runtime is bounded by the project's own timeout_seconds and when globs. In the originating project it is about five seconds.
  • CI is unchanged — no credentials, so requires_env is unsatisfied, the check records not-run, and CI never sees a gate.
  • Main risk: not-run becoming wallpaper. If every workflow yields with a check unrun, the line stops being read, which is exactly how the deferral note in this incident came to work. Mitigation: when globs narrow enough that the line is rare, and a gate message naming the diff paths that triggered it.

Reported from an installed baseline at 0.26.5.

tusharsrivastava avatar Sep 05 '26 14:09 tusharsrivastava