Repository navigation
feat(ci): a pull request contract — a ticket, and a post-merge ledger - #809
Merged
Merged
Conversation
4 tasks
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.
athvin
force-pushed
the
ci/pr-contract
branch
from
November 7, 2026 20:55
edc9a11 to
fa0bfc8
Compare
…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.
This was referenced Nov 7, 2026
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).
9 tasks done
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #807
What
A pull-request template designed to be worked by an agent, and a
pull request contractcheck behind it: every PR closes a board ticket, andevery PR carries a post-merge ledger that
/land-prticks 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 realbug in the classifier:
invertedwas unreachable).scripts-home-check,workflow-shell-checkandskills-checkall green. The wrapper was run againstlive 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-274d64ddb944onbrians-MacBook-Pro· 2026-11-07T21:20:12Zmainis green with this change on it — merge0110c102,rustrun42414029844: success, 23 jobs, no failed jobs, having gonepending → in_progress → completed, so not the cancelled-with-zero-jobscase.
devcontainer,infraandfrontendon the same SHA are alsosuccess, and
origin/mainnow is0110c102with no failures on itshead. 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 on0110c102.Nothing that goes into an image changed (
.claude/,.github/,scripts/ci/,Makefile,CLAUDE.md).deploy—n/a: 0 runs on0110c102. Noimagessuccess meansno
workflow_run, and the diff touches noinfra/k8s/**, so deploy's ownpush door did not open either. Nothing is deployed, and nothing should be.
deployn/aasabove;
driftgreen 2026-11-07T06:01;kind's scheduled leg green2026-11-07T06:44, which is its first green on
mainand the stale"has never passed" claim this PR corrected in
post-merge.md. Neitherreads anything this diff touches.
Done, moved by the automation, confirmed from theissue'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 / COMPLETEDat 21:03:44Z withcloser.__typename = PullRequest,#809. Never touched by hand, so theStatus → Donepath that closes an issue was not raced.pull request contractto a requiredcontext. 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.
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 owncomment, and
post-merge.md);statusCheckRollupreturns everycheck-run for a name rather than the latest, so a healed red shows in
gh pr checksforever (ci-and-supply-chain); andCLAUDE_CODE_SESSION_IDis the authoritative session id because ascratchpad path may carry the parent's id under
CLAUDE_CODE_CHILD_SESSION=1(land-prPhase 4).Specific to this change
pull request contractFAILING on a real pull request —done pre-merge, on this one.
Closes #807removed from this body at20:50:41Z; run
42412994598was created 3 seconds later and went redwith
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 forthe clause under test, not at the checkout. Body restored 20:53:04Z, green
again at 20:53:09Z. That cycle also proves the
editedtrigger fires,which is the whole reason this is a separate workflow.
n/afor a body edit: refactor(dispatcher): delete the legacy in-process dispatch arm (#645) #756 was the only one, and it was commentedrather 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.
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.
no-ticketlabel —gh label create no-ticketwithcolour
ededed(the override was unreachable without it, since the checkmatches the label by whole name). Read back present in
gh label list.n/afor any further work: nothing uses it yet, which is correct.as written, with one gap it exposed by being used: the vocabulary offers
n/aandblocked, 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
.github/pull_request_template.md— brief everywhere except the ledger; theagent-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.scripts/ci/pr-contract.sh— the decision logic, pure: facts in through theenvironment, body on stdin, verdict on stdout, no network.
scripts/ci/pr-contract-check.sh— the only part that talks to GitHub: oneGraphQL query, then annotations.
scripts/ci/pr-contract-test.sh— fixtures, including "the committedtemplate passes its own gate".
.github/workflows/pr-contract.yml— its own workflow, because it needstypes: [… edited …]andrust.ymlmust not have that.scripts/ci/pr-ledger-audit.sh— the reader: merged PRs whose ledger stillhas open boxes.
land-prgains Phase 4;claim-ticketbuilds its draft body from thetemplate;
ci-and-supply-chainandCLAUDE.mdrecord the rules.Discoveries
PATCHto/repos/.../pulls/806whilemerged: true→ HTTP 200. The whole design restson this; without it the ledger would have to be a comment.
gh pr view --json closingIssuesReferencesomits each reference'srepository — it reads back
null, so a cross-repo closing reference wouldlook local. That is why the wrapper asks GraphQL directly.
closes, measured rather than assumed.
kindprobe's first green scheduled run onmainwas 2026-11-07.post-merge.mdstill said it had never passed, so that line is corrected here(it steers post-merge attribution).
pr_ledger_scanonly recorded the ENDmarker after a BEGIN, so scrambled markers reported as "no ledger" and the
invertedstate was unreachable.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/checkoutdefaults to themerge ref on a
pull_requestevent, so closing a ledger (which edits a mergedbody) would have failed at checkout and painted a red check on every properly
recorded pull request. The workflow pins
ref: head.shafor that reason.CLAUDE_CODE_SESSION_IDis in the environment, and it is the only safesource: a scratchpad path may carry the parent session's id when
CLAUDE_CODE_CHILD_SESSION=1, which is what a/clearleaves behind — bothids had transcripts in this very session.
claude --from-pr <n>alreadyresumes a PR-linked session, but a transcript is a local file, so the ledger
records the host too.
statusCheckRollupreturns every check-run for a name, not the latest.Three body edits here left four
pull request contractrows on one SHA,including the healed
FAILURE. Branch protection reads the latest so mergingis unaffected, and
polling.mdalready doesmax_by(.started_at)— butgh pr checkswill show a red that no longer exists. Noted inci-and-supply-chain.Measurements
scripts/ci/pr-contract-test.sh→ 22 assertions, ~0.3s, no network.detect_classifyon this change set →code=true erd=true drift=true, so CIruns the full backend gate: a new
.github/workflows/*.ymlfile is not inthe exempt denylist, by design.
workflow-shell-check→ 12 hand-written workflows, 6 inline blocks, allwithin budget (the new workflow's three
run:lines are one command each).Files
.github/pull_request_template.md.github/workflows/pr-contract.ymlpull request contract, not requiredscripts/ci/pr-contract.shscripts/ci/pr-contract-check.shscripts/ci/pr-contract-test.shscripts/ci/pr-ledger-audit.sh.claude/skills/land-pr/SKILL.md.claude/skills/land-pr/references/post-merge.mdkindcorrection.claude/skills/claim-ticket/SKILL.md.claude/skills/ci-and-supply-chain/SKILL.mdMakefilepr-contract-check, wired intomake checkCLAUDE.mdmake checkline.claude/skills/*/references/*.mdskills-check regen)