Skip to content

feat(ci): a pull request contract — a ticket, and a post-merge ledger - #809

Merged
athvin merged 2 commits into
mainfrom
ci/pr-contract
Nov 7, 2026
Merged

athvin merged 2 commits into
mainfrom
ci/pr-contract

Conversation

@athvin

@athvin athvin commented Nov 7, 2026 •

Copy link
Copy Markdown
Owner

Closes #807

Post-merge is part of this pull request. The ledger below records whether
the follow-up work actually happened. /land-pr closes it.

What

A pull-request template designed to be worked by an agent, and a
pull request contract check behind it: every PR closes a board ticket, and
every PR carries a post-merge ledger that /land-pr ticks after the merge.

Why

Post-merge observations lived only in session transcripts, so a merged PR and an
abandoned post-merge watch looked identical from GitHub. And a PR that closes no
issue moves no board card — work landed without the board showing it.

Proof

bash scripts/ci/pr-contract-test.sh → 22 passed, 0 failed (it caught one real
bug in the classifier: inverted was unreachable). scripts-home-check,
workflow-shell-check and skills-check all green. The wrapper was run against
live PRs: #806 fails both clauses, #756 fails only the ledger, this body passes.

Risk & rollback

Risk: the check is new and not required, so a false failure is advisory, not
a block — except on a merge-bus/* PR, whose verdict step reads the rollup;
that path is exempt and the exemption is unit-tested.
Rollback: revert, or delete .github/workflows/pr-contract.yml.

Post-merge ledger

Closed by: agent · session 4bc5a8d3-968f-421f-97af-274d64ddb944 on brians-MacBook-Pro · 2026-11-07T21:20:12Z

  • main is green with this change on it — merge 0110c102, rust run
    42414029844: success, 23 jobs, no failed jobs, having gone
    pending → in_progress → completed, so not the cancelled-with-zero-jobs
    case. devcontainer, infra and frontend on the same SHA are also
    success, and origin/main now is 0110c102 with no failures on its
    head. This box carries unusual weight here: the PR was admin-merged with
    11 required Rust jobs still pending (against a diff containing zero
    Rust), so this run is where the backend gate actually concluded.
  • images — n/a, correctly never ran: 0 runs on 0110c102.
    Nothing that goes into an image changed (.claude/, .github/,
    scripts/ci/, Makefile, CLAUDE.md).
  • deploy — n/a: 0 runs on 0110c102. No images success means
    no workflow_run, and the diff touches no infra/k8s/**, so deploy's own
    push door did not open either. Nothing is deployed, and nothing should be.
  • the push-only surface no pull request can pre-test — deploy n/a as
    above; drift green 2026-11-07T06:01; kind's scheduled leg green
    2026-11-07T06:44, which is its first green on main and the stale
    "has never passed" claim this PR corrected in post-merge.md. Neither
    reads anything this diff touches.
  • the board card — Done, moved by the automation, confirmed from the
    issue's own timeline rather than from the card: PR contract: every pull request closes a board ticket and carries a post-merge ledger #807 is
    CLOSED / COMPLETED at 21:03:44Z with
    closer.__typename = PullRequest, #809. Never touched by hand, so the
    Status → Done path that closes an issue was not raced.
  • follow-ups — Promote 'pull request contract' to a required status check (sweep #756 first) #810: promote pull request contract to a required
    context. It carries the two preconditions already met (observed failing,
    with the run id; reported green repeatedly), the refactor(dispatcher): delete the legacy in-process dispatch arm (#645) #756 sweep that is not,
    and the trap that the protection endpoint replaces the context list
    rather than appending to it.
  • what was learned is written down — three facts, each placed where the
    next session will hit it rather than in a transcript: a merged pull
    request has no refs/pull/<n>/merge, only /head (the workflow's own
    comment, and post-merge.md); statusCheckRollup returns every
    check-run for a name rather than the latest, so a healed red shows in
    gh pr checks forever (ci-and-supply-chain); and
    CLAUDE_CODE_SESSION_ID is the authoritative session id because a
    scratchpad path may carry the parent's id under
    CLAUDE_CODE_CHILD_SESSION=1 (land-pr Phase 4).

Specific to this change

  • observed pull request contract FAILING on a real pull request —
    done pre-merge, on this one. Closes #807 removed from this body at
    20:50:41Z; run 42412994598 was created 3 seconds later and went red
    with no ticket — this pull request closes no issue in athvin/entity-resolution-engine. Per-step: checkout success,
    self-test success, check this pull request FAILURE — so it failed for
    the clause under test, not at the checkout. Body restored 20:53:04Z, green
    again at 20:53:09Z. That cycle also proves the edited trigger fires,
    which is the whole reason this is a separate workflow.
  • swept the open pull requests whose bodies predate the template —
    n/a for a body edit: refactor(dispatcher): delete the legacy in-process dispatch arm (#645) #756 was the only one, and it was commented
    rather than rewritten, because a concurrent rewrite of another session's
    in-flight body is the shared-checkout hazard this repo keeps paying for.
    It cannot be blocked today — the check is not required. The
    pre-promotion sweep belongs to Promote 'pull request contract' to a required status check (sweep #756 first) #810.
  • decided whether to promote it to a required context — not now, and
    tracked as Promote 'pull request contract' to a required status check (sweep #756 first) #810. Branch protection is not a file in this tree, so it is a
    deliberate separate act; two of its three preconditions are met and
    recorded, and the third (the sweep) is not.
  • created the no-ticket label — gh label create no-ticket with
    colour ededed (the override was unreachable without it, since the check
    matches the label by whole name). Read back present in gh label list.
    n/a for any further work: nothing uses it yet, which is correct.
  • this PR's own ledger is the first one ever closed — and Phase 4 worked
    as written, with one gap it exposed by being used: the vocabulary offers
    n/a and blocked, but has no word for deferred to a tracked ticket,
    which is what the sweep above actually is. Recorded as an item on Promote 'pull request contract' to a required status check (sweep #756 first) #810
    rather than spent on a one-line pull request.
Context — plan, discoveries, measurements, files

Plan

  1. .github/pull_request_template.md — brief everywhere except the ledger; the
    agent-facing notes in an HTML comment (invisible when rendered, present in
    the body an agent reads through the API); descriptive material in a collapsed
    <details> block.
  2. scripts/ci/pr-contract.sh — the decision logic, pure: facts in through the
    environment, body on stdin, verdict on stdout, no network.
  3. scripts/ci/pr-contract-check.sh — the only part that talks to GitHub: one
    GraphQL query, then annotations.
  4. scripts/ci/pr-contract-test.sh — fixtures, including "the committed
    template passes its own gate".
  5. .github/workflows/pr-contract.yml — its own workflow, because it needs
    types: [… edited …] and rust.yml must not have that.
  6. scripts/ci/pr-ledger-audit.sh — the reader: merged PRs whose ledger still
    has open boxes.
  7. land-pr gains Phase 4; claim-ticket builds its draft body from the
    template; ci-and-supply-chain and CLAUDE.md record the rules.

Discoveries

  • A merged pull request's body is writable. Probed with a no-op PATCH to
    /repos/.../pulls/806 while merged: true → HTTP 200. The whole design rests
    on this; without it the ledger would have to be a comment.
  • gh pr view --json closingIssuesReferences omits each reference's
    repository
    — it reads back null, so a cross-repo closing reference would
    look local. That is why the wrapper asks GraphQL directly.
  • docs(claim-ticket): the empty draft now goes red by design, not green #806 — merged the same day — closes no issue at all, which is the gap this
    closes, measured rather than assumed.
  • The kind probe's first green scheduled run on main was 2026-11-07.
    post-merge.md still said it had never passed, so that line is corrected here
    (it steers post-merge attribution).
  • The self-test caught a real bug: pr_ledger_scan only recorded the END
    marker after a BEGIN, so scrambled markers reported as "no ledger" and the
    inverted state was unreachable.
  • A merged pull request has no refs/pull/<n>/merge — only /head. Probed:
    merged docs(claim-ticket): the empty draft now goes red by design, not green #806 exposes one ref, open refactor(dispatcher): delete the legacy in-process dispatch arm (#645) #756 two. actions/checkout defaults to the
    merge ref on a pull_request event, so closing a ledger (which edits a merged
    body) would have failed at checkout and painted a red check on every properly
    recorded pull request. The workflow pins ref: head.sha for that reason.
  • CLAUDE_CODE_SESSION_ID is in the environment, and it is the only safe
    source: a scratchpad path may carry the parent session's id when
    CLAUDE_CODE_CHILD_SESSION=1, which is what a /clear leaves behind — both
    ids had transcripts in this very session. claude --from-pr <n> already
    resumes a PR-linked session, but a transcript is a local file, so the ledger
    records the host too.
  • statusCheckRollup returns every check-run for a name, not the latest.
    Three body edits here left four pull request contract rows on one SHA,
    including the healed FAILURE. Branch protection reads the latest so merging
    is unaffected, and polling.md already does max_by(.started_at) — but
    gh pr checks will show a red that no longer exists. Noted in
    ci-and-supply-chain.

Measurements

  • scripts/ci/pr-contract-test.sh → 22 assertions, ~0.3s, no network.
  • detect_classify on this change set → code=true erd=true drift=true, so CI
    runs the full backend gate: a new .github/workflows/*.yml file is not in
    the exempt denylist, by design.
  • workflow-shell-check → 12 hand-written workflows, 6 inline blocks, all
    within budget (the new workflow's three run: lines are one command each).

Files

File Role
.github/pull_request_template.md new — the template, and the ledger markers
.github/workflows/pr-contract.yml new — pull request contract, not required
scripts/ci/pr-contract.sh new — pure classifier, sourced
scripts/ci/pr-contract-check.sh new — the GitHub-facing wrapper
scripts/ci/pr-contract-test.sh new — the self-test the job runs first
scripts/ci/pr-ledger-audit.sh new — hand-run sweep of merged ledgers
.claude/skills/land-pr/SKILL.md Phase 4, the diagnosis row, the report
.claude/skills/land-pr/references/post-merge.md closing the ledger; the kind correction
.claude/skills/claim-ticket/SKILL.md draft body built from the template
.claude/skills/ci-and-supply-chain/SKILL.md the check, its exemptions, promotion order
Makefile pr-contract-check, wired into make check
CLAUDE.md the convention, and the corrected make check line
.claude/skills/*/references/*.md regenerated blocks (skills-check regen)

Two things a pull request here did not carry, both invisible rather than
wrong.

Post-merge work had no record. `/land-pr` already knew the merge was not the
finish line, but every observation it made lived in a session transcript — so a
merged pull request and an abandoned post-merge watch looked identical from
GitHub. The template now carries a ledger between stable
`<!-- BEGIN POST-MERGE -->` markers, and land-pr gains Phase 4: tick it in the
MERGED body, evidence inline, `n/a — <why>` where it does not apply, and leave
a box empty rather than tick something unverified. A merged pull request's body
is writable — probed, a PATCH on #806 while `merged: true` returned 200 — which
is what makes the body the right home for the record.

And a pull request need not have been tied to a ticket. The board's `Pull
request merged` automation acts on the linked issue, so a pull request closing
nothing moves no card; #806 merged the same day closing no issue at all. The
`pull request contract` check asserts both clauses from the body, reading
GitHub's own parsed `closingIssuesReferences` rather than regexing text that
may not actually close anything.

It is its own workflow because it needs `types: [… edited …]` — filling in the
ticket line must turn it green with no push, and putting `edited` on rust.yml
would re-run the backend gate on every typo fix. No `paths:` filter, so it
stays promotable. Exempt: `merge-bus/*` (a bus pull request closes nothing by
design, and merge-bus-verdict.sh reads its rollup, so a failure there would
stop every batch), Dependabot, reverts, and a `no-ticket` label.

The decision logic is pure and sourced, so pr-contract-test.sh exercises it
with no network — 22 assertions, including that the committed template passes
its own gate. It caught one real bug while being written: the END marker was
only recorded after a BEGIN, making the `inverted` verdict unreachable.

Not a required check: promoting it is a branch-protection change, and it must
come after the check has been observed failing and the open pull requests
predating the template have been swept.

Also corrects post-merge.md, which still said the `kind` probe had never
passed; its first green scheduled run on `main` was 2026-11-07.
…he template

The ledger says WHAT was done; it did not say who, or where to go to read the
reasoning behind a tick. `**Closed by:**` now carries the Claude Code session id
and the machine, not just a timestamp:

  agent · session `<CLAUDE_CODE_SESSION_ID>` on `<hostname -s>` · <UTC>

The host is the part that is easy to leave out and the part that makes the id
resolvable. A transcript is a local file — `~/.claude/projects/<slug>/<id>.jsonl`
on the machine that ran it — so an id alone goes nowhere once more than one
machine is in play. With both, `claude --resume <id>` reopens months later;
`claude --from-pr <n>` is the shortcut while that link survives, and the line in
the body is what remains when it does not.

`CLAUDE_CODE_SESSION_ID` is named as the authoritative source because the
obvious alternative is wrong: a scratchpad path may carry the PARENT session's
id when `CLAUDE_CODE_CHILD_SESSION=1`, which is the state a `/clear` leaves
behind. claim-ticket stamps the same pair into its claim banner, which also
gives the worktree audit a durable answer to "which session owns this tree" —
the question `lsof` cannot answer when a session drives its worktree with
`git -C` from the primary checkout.

And `pr-contract-test.sh` joins `make check` as `pr-contract-check`. The
committed template is one of its fixtures, so without it a template edit that
drops a ledger marker would surface only as a red check on every pull request
opened afterwards, with nothing in the diff that mentions CI. The generated
gates reference picked the new step up by itself; CLAUDE.md's hand-written
`make check` line is corrected to match, including the
`tf-static-credentials-check` step it was already missing.
@athvin
athvin merged commit 0110c10 into main Nov 7, 2026
41 checks passed
athvin pushed a commit that referenced this pull request Nov 7, 2026
…e work

Found by USING the ledger rather than reading it: #809's was the first one ever
closed, and the #756 sweep it recorded fitted neither annotation. `n/a` was
false (the work was real) and `blocked` was false (nothing blocked it — another
ticket owned it). It got `n/a` with the reason spelled out, which blurred the
distinction the whole mechanism rests on: an empty box means exactly one thing,
and that is only true while every other outcome has somewhere else to go.

So there are three annotations now, and the asymmetry is the design:

  n/a — <why>            ticks   the item does not apply
  deferred — #<ticket>   ticks   real work, owned by a filed ticket
  blocked — <why>        EMPTY   could not be established; goes in the report

`deferred` is the only one with a syntactic requirement, and it needs one: it
TICKS the box, so a deferral naming no ticket would be the way to retire an
item into nothing — strictly worse than the unticked box it replaces.
`pr_ledger_scan` therefore counts them, and `pr-ledger-audit.sh` reports
`LOOSE-DEFER (k)` separately from `OPEN (k)` because the remedy differs: file
the ticket, do not do the work.

Making that checkable needed the scan to group each box with its CONTINUATION
LINES, since the annotation usually lands on a wrapped line — a per-line test
would see the tick and the ticket separately and could not relate them. The
regrouped scan reproduces #809's real ledger exactly (12 boxes, 0 unticked, 0
loose, and its one ticked box containing the word "deferred" passes because it
names #810).

The self-test earned its place twice here. It caught that adding a fifth field
to the scan broke an assertion through a short `read` folding the trailing
fields into one variable — so every caller now reads all five, and the function
doc says why.

Also corrects what is now false everywhere it was stated: `pull request
contract` IS a required context as of today. The order that made it safe —
report on real PRs, observe it failing, confirm no open PR would be blocked,
then append — is recorded in ci-and-supply-chain as the reusable part, with the
two mechanics that cost care: the endpoint REPLACES the context list, and
`mergeStateStatus` cannot tell you what blocks a PR (both open ones read
BLOCKED straight after the PATCH, neither by the new context).
athvin added a commit that referenced this pull request Nov 7, 2026
…e work

* wip: claim #810 — a deferred annotation for the ledger

* feat(ci): a `deferred` ledger annotation, enforced so it cannot retire work

Found by USING the ledger rather than reading it: #809's was the first one ever
closed, and the #756 sweep it recorded fitted neither annotation. `n/a` was
false (the work was real) and `blocked` was false (nothing blocked it — another
ticket owned it). It got `n/a` with the reason spelled out, which blurred the
distinction the whole mechanism rests on: an empty box means exactly one thing,
and that is only true while every other outcome has somewhere else to go.

So there are three annotations now, and the asymmetry is the design:

  n/a — <why>            ticks   the item does not apply
  deferred — #<ticket>   ticks   real work, owned by a filed ticket
  blocked — <why>        EMPTY   could not be established; goes in the report

`deferred` is the only one with a syntactic requirement, and it needs one: it
TICKS the box, so a deferral naming no ticket would be the way to retire an
item into nothing — strictly worse than the unticked box it replaces.
`pr_ledger_scan` therefore counts them, and `pr-ledger-audit.sh` reports
`LOOSE-DEFER (k)` separately from `OPEN (k)` because the remedy differs: file
the ticket, do not do the work.

Making that checkable needed the scan to group each box with its CONTINUATION
LINES, since the annotation usually lands on a wrapped line — a per-line test
would see the tick and the ticket separately and could not relate them. The
regrouped scan reproduces #809's real ledger exactly (12 boxes, 0 unticked, 0
loose, and its one ticked box containing the word "deferred" passes because it
names #810).

The self-test earned its place twice here. It caught that adding a fifth field
to the scan broke an assertion through a short `read` folding the trailing
fields into one variable — so every caller now reads all five, and the function
doc says why.

Also corrects what is now false everywhere it was stated: `pull request
contract` IS a required context as of today. The order that made it safe —
report on real PRs, observe it failing, confirm no open PR would be blocked,
then append — is recorded in ci-and-supply-chain as the reusable part, with the
two mechanics that cost care: the endpoint REPLACES the context list, and
`mergeStateStatus` cannot tell you what blocks a PR (both open ones read
BLOCKED straight after the PATCH, neither by the new context).

* fix(skills): move the contract detail into a reference, under the 500-line cap

`agent skills (lint + drift)` went red on this PR with
`ci-and-supply-chain: SKILL.md body is 508 lines (max 500)` — my section had
pushed it past the authoring cap. The cap is the economy rule: a SKILL.md is the
routing layer, and detail belongs in `references/`.

So the detail moves to `references/pr-contract.md` — what the check asserts and
what it deliberately does not, the exemption table, the promotion order, and the
rollup finding — and SKILL.md keeps a 23-line summary pointing at it. Body is
460 lines now. Every `references/*.md` must be linked from SKILL.md in the exact
`](references/x.md)` form or the same gate errors on an unreachable reference,
so the pointer is load-bearing rather than courtesy.

Worth recording why this reached CI at all: I ran `scripts/skills-check.sh
regen`, saw "generated references are current", and took it as the gate. Regen
is one stage — it does not lint. The gate is `make skills-check`, which runs the
regression test and then `all`.

---------

Co-authored-by: bmoore813 <[email protected]>
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.

PR contract: every pull request closes a board ticket and carries a post-merge ledger

2 participants