Skip to content

feat(concurrency-policy): admit the branched contract-only group and both fallback terms - #532

Merged
kyle-sexton merged 1 commit into
mainfrom
ci-perf/phase-6b-i-concurrency-policy
Sep 5, 2026
Merged

kyle-sexton merged 1 commit into
mainfrom
ci-perf/phase-6b-i-concurrency-policy

Conversation

@kyle-sexton

Copy link
Copy Markdown
Member

No related issue: melodic-software/github-iac#378 tracks Phase 6b of the ci-perf program

Summary

Phase 6b of the ci-perf program branches the top-level concurrency group on the
contract-only predicate. Two runs of one required workflow on one head SHA share
a single concurrency group today, and GitHub cancels a pending run in that group
unconditionally when a newer run arrives, whatever cancel-in-progress says. A
contract-only run evicted while pending starts no job at all, so its check suite
never receives the required ci-status check run and the pull request stops
reporting until someone re-runs that specific run. That was observed on
dotfiles#647 and cost 2 hours 14 minutes of a silently blocked pull request.

components/concurrency-policy is the gate that shape has to pass. It matches
concurrency.group against one exact-token expression today, so every consumer
pull request carrying the branched group would fail concurrency-group-drift.
The design records this grammar change as the first Phase 6b-i pull request and
as unconditional: nothing else in the phase can merge past it.

This is a producer-internal lint. distribution/sync-manifest.yml carries no
concurrency-policy entry (grep -c -i concurrency distribution/sync-manifest.yml
returns 0), so no sync follows this merge and no consumer receives a payload.

Fix

components/concurrency-policy/concurrency-policy.mjs

  • The contract-only predicate is lifted into its own constant,
    CONTRACT_ONLY_PREDICATE_TEXT, and CONTRACT_ONLY_CANCEL_TEXT is derived
    from it as ${{ !(<predicate>) }}. The existing test's inline literal still
    guards that derivation byte for byte, so the two places the predicate can now
    appear cannot drift apart.

  • concurrency.group admits a second form, the branched expression from the
    design:

    group: >-
      ${{ (<contract-only predicate>)
          && format('ci-contract-{0}-{1}', github.event.pull_request.number, github.run_id)
          || format('{0}-{1}', github.workflow, github.event.pull_request.number || <fallback>) }}

    One compiled pattern per admitted fallback term, built by escaping the
    predicate and both format(...) calls as literals. Whitespace is tolerated
    only at the two operator joins and inside the ${{ }} delimiters. That is
    exactly and only where the folded spelling differs from the single-line one:
    written as group: >- with the continuation lines more-indented, the pinned
    YAML parser preserves a newline plus the continuation indent at each join and
    folds nothing else. That was verified with a probe against yaml 2.9.0 rather
    than inferred, and both spellings appear as fixtures in the tests. The
    predicate, the contract branch and the fallback term are exact; there is no
    other loosening.

  • FALLBACK_TERMS is exactly github.ref and github.run_id. The canonical
    form is unchanged and still carries github.run_id by construction.

  • New informational rule concurrency-group-fallback. The fallback term is a
    per-repository decision rather than drift (github.ref keeps push-side burst
    collapse, github.run_id gives none, and the design's table assigns one per
    repository), so the analyzer reports the term it found instead of picking a
    side, and a later fleet check can list which repositories keep push collapse.
    Decision worth reversing cheaply if the coordinator disagrees: it is
    emitted on BOTH accepted forms, not only the branched one, so a fleet check
    can tell github.run_id apart from a repository with no block at all.

  • Every finding now carries an explicit level, "error" by default and
    "info" for that one rule. The process exit status and the --json ok
    field are computed from the presence of any non-info finding, so an
    informational rule cannot mask a blocking one, and a new info rule cannot
    silently turn a red gate green. Info findings print on stdout; blocking
    findings keep stderr and the non-zero exit.

  • The concurrency-group-drift message now names both accepted forms.

Nothing else in the accepted set moves. cancel-in-progress still admits
exactly the literal true and the byte-identical contract-only text, which
repositories not yet reshaped still carry; ${{ github.workflow }}-${{ github.ref }},
the head_ref variant, the group-only shorthand, the extra-key and malformed
shapes, and the whole exception surface are untouched.

components/concurrency-policy/README.md gains a section on the branched form
with the per-repository fallback table, the folded-versus-single-line rule, the
informational finding, and a pointer to melodic-software/github-iac#378. The
opening paragraph no longer claims a default-branch run is never cancelled,
because with || github.ref that is the repository's decision.

components/concurrency-policy/THREAT-MODEL.md restates the never-cancelled
objective as the two-valued fallback decision, adds the contract-only eviction
objective, rewrites the github.ref row (that term is admitted only as a
fallback, never as the whole key), and adds two rows: the contract branch
without github.run_id, and the level field as the control that keeps an
informational rule from masking a blocking one.

Verification

  • node --test components/concurrency-policy/concurrency-policy.test.mjs:
    31 pass, 0 fail, up from 25 on origin/main. Six new tests.
    • Accept: the branched group single-line and folded, each with each fallback
      term, asserting both no blocking finding and the reported term; the branched
      group paired with cancel-in-progress: true and with the contract-only
      text (the grammar leaves the two fields independent).
    • Reject: a predicate with one space added inside the fromJSON array
      literal; a predicate with the base-edit clause dropped; the predicate
      stripped of its surrounding parentheses; fallback github.head_ref,
      github.sha, github.ref_name, github.run_number; and a contract branch
      of format('ci-contract-{0}', …), or one carrying github.sha or
      github.run_attempt in place of github.run_id. Each is exactly one
      concurrency-group-drift and no reported fallback term.
    • A child-process test runs the command line itself: --json on an
      info-only repository exits 0 with "ok": true and the full expected
      finding object, and on a drifted one exits 1 with "ok": false.
    • Every pre-existing test is still present. The accept-case helpers now read
      blocking findings and informational findings through separate accessors;
      no assertion was weakened to accommodate the new rule.
  • npm run lint:concurrency-policy against this repository exits 0,
    printing two info lines (ci.yml and claude-review.yml, both the canonical
    form with github.run_id) and Concurrency policy passed. Standards' own
    ci.yml, which carries the canonical group and the contract-only
    cancel-in-progress text from ci: fold the pull-request contract into ci-status and carry it forward on contract-only events #526, is unaffected.
  • npx @biomejs/biome check components/concurrency-policy clean;
    npm run lint:md clean over 122 files; lefthook pre-commit ran on the commit
    and was never bypassed.
  • No workflow file is edited in this pull request, so no actionlint or
    zizmor surface changes.

Related

  • Refs melodic-software/github-iac#378
  • The design is .work/ci-perf/wave-d/phase-6b-design.md in github-iac, section
    "Race analysis and fix". This pull request implements only the grammar half of
    its Decision block. The ci-status carry-forward wait, the
    carry-forward-wait-seconds input, the contract-predicate composite and the
    v0.22.0 tag are ci-workflows changes and are not in this repository.
  • Nothing here is distributed: distribution/sync-manifest.yml has no
    concurrency-policy component definition and no target rows for it, so this
    merge triggers no sync pull request. The manifest is not edited.
  • Sequencing: the design makes this the first Phase 6b-i pull request and
    unconditional. No consumer repository can adopt the branched group until it
    merges, and no consumer in this repository's sync roster is affected by it.
  • The predicate this grammar pins is the same one ci: fold the pull-request contract into ci-status and carry it forward on contract-only events #526 introduced in
    cancel-in-progress; the two are now derived from one constant rather than
    written twice.

🤖 Generated with Claude Code

https://claude.ai/code/session_019APkoJh8NVN773d82fBBSG

…both fallback terms

Two runs of one required workflow on one head SHA share a single concurrency
group, and GitHub evicts a pending run in that group unconditionally, whatever
cancel-in-progress says. A contract-only run evicted while pending starts no
job, so its check suite never receives the required check run and the pull
request stops reporting until someone re-runs that specific run. Phase 6b of the
ci-perf program branches the group on the contract-only predicate, keying every
contract-only run on github.run_id so it can neither be evicted nor evict
anything. This component was the gate blocking that shape.

The group grammar now admits two forms: the existing canonical expression, and
the branched form whose predicate is byte-identical to the contract-only
predicate the component already knew, whose contract branch carries
github.run_id, and whose full branch falls back to exactly github.ref or
github.run_id. Whitespace is tolerated only at the two operator joins and inside
the expression delimiters, which is where the folded scalar the design writes
differs from the same expression on one line; a probe against the pinned YAML
parser confirmed the parser preserves a newline and the continuation indent at
each join and nowhere else. The predicate, the contract branch and the fallback
term are exact.

The fallback term is a per-repository decision rather than drift: github.ref
keeps push-side burst collapse and github.run_id gives none. The analyzer now
reports it as an informational finding, concurrency-group-fallback, on both
accepted forms, so a later fleet check can list which repositories keep push
collapse without this component picking a side. Findings carry an explicit
level, and the exit status and the JSON ok field are computed from the presence
of any non-info finding, so an informational rule cannot mask a blocking one.

Every previously accepted form stays accepted, including the contract-only
cancel-in-progress text, which repositories not yet reshaped still carry.
Rejected: a branched group whose predicate differs by one byte, a fallback term
outside the two, and a contract branch without github.run_id.

Tests: 31 pass, up from 25. The README documents both forms, what each fallback
term means, and the ci-perf plan; the threat model records the widened objective
and the two new controls.

Refs melodic-software/github-iac#378

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019APkoJh8NVN773d82fBBSG
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 5, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-05T19:28:05.904021Z b7d3a08 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@claude

claude Bot commented Sep 5, 2026 •

Copy link
Copy Markdown

Claude finished @kyle-sexton's task in 4m 4s —— View job


Code review complete

  • Gather context (PR body, changed files)
  • Read changed files and diff against origin/main
  • Review concurrency-policy.mjs logic and regex construction
  • Review test coverage in concurrency-policy.test.mjs
  • Review README/THREAT-MODEL doc changes
  • Post inline findings and summary

No blocking findings.

What I checked

  • Regex correctness. literalPattern (concurrency-policy.mjs#L152) escapes . * + ? ^ $ { } ( ) | [ ] \, which correctly covers the [/] characters embedded in CONTRACT_ONLY_PREDICATE_TEXT's fromJSON('["labeled","unlabeled"]') literal — I traced this by hand since I couldn't execute node in this sandbox (see note below), and it escapes cleanly.
  • Paren counting. The branched-group regex (concurrency-policy.mjs#L107-L119) wraps the predicate in exactly one additional (...) pair beyond the predicate's own balanced parens, matching the README's fixture (...!github.event.changes.base))) — three closes: the predicate's inner clause, the predicate's own outer paren, and the branch-wrapping paren) and the "stripped of surrounding parentheses" reject-case in the tests.
  • Whitespace tolerance. \s+ at the two operator joins correctly admits the folded scalar's newline + continuation indent (JS \s matches newlines), consistent with the YAML spec's more-indented-lines-preserve-linebreaks rule the PR body cites, and consistent with the single-line and folded test fixtures.
  • Exit-status/level plumbing. hasBlockingFindings and the finding() helper guarantee every finding carries an explicit level, so ok/exit code can't be masked by the new informational rule. The plain-text output format gained a level segment (file: level: rule: message); I checked .github/workflows/ci.yml and nothing else in this repo parses that stdout/stderr text — the CI step only relies on the exit code — so this isn't a breaking change.
  • Docs/threat-model consistency. README's branched-group example, the fallback-term table, and THREAT-MODEL's new/updated rows all match the implementation and the test fixtures (branchedSingleLine/branchedFolded helpers).
  • Confirmed via git show b7d3a08 that the diff is scoped to exactly the 4 files listed on the PR (README, THREAT-MODEL, concurrency-policy.mjs, concurrency-policy.test.mjs) — no drift from the stated scope.

Note on verification: this sandbox's Bash tool required approval for node/npm invocations that wasn't available, so I could not independently re-run node --test components/concurrency-policy/concurrency-policy.test.mjs or npm run lint:concurrency-policy to confirm the PR's claimed 31/31 pass. I instead verified the regex/escaping/paren-balance logic by static hand-tracing against the test fixtures, which line up. If independent execution matters here, that would need to happen in a lane with broader tool permissions.

@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown

Claude has reviewed this PR 1 time. The lane skips further automatic reviews after 5; deleting this comment resets the count.

@kyle-sexton
kyle-sexton merged commit c346175 into main Sep 5, 2026
2 checks passed
@kyle-sexton
kyle-sexton deleted the ci-perf/phase-6b-i-concurrency-policy branch September 5, 2026 19:32
kyle-sexton added a commit that referenced this pull request Sep 5, 2026
…checks.yml at the tag (#534)

No related issue: melodic-software/github-iac#378 tracks the ci-perf
program (Phase 6b-i, standards leg)

## Summary

Phase 6b-i of the ci-perf program converges every consumer of
`melodic-software/ci-workflows` onto one tag, v0.22.0
(`906ae7ef379ea4d2b8497f64475dce1d3d8715c4`). The Phase 6b design names
standards-distributed components as one of the two structural
obstructions to
that convergence: three caller templates this repository distributes
carry a
ci-workflows pin, `managed-files-guard` reverts a consumer that edits
one of
them, and the synced `runner-policy` component approves ci-workflows
reusables
by exact `path@SHA`. So the pins have to move here, with their policy
approvals, before any consumer's own pull request can claim it
converged.

This is the standards leg. It moves the three distributed pins and adds
the
three `runner-policy` contracts the converged callers need. It
deliberately
does not touch this repository's own workflows, which are a separate
consumer
pull request after this one merges.

## Fix

**Three caller templates re-pinned to v0.22.0.**

| Template | From | To |
| --- | --- | --- |
| `components/claude-lanes/claude-review.yml` |
`0f8176e87e0be518f382664779655011bf95784a` (v0.17.2) |
`906ae7ef379ea4d2b8497f64475dce1d3d8715c4` (v0.22.0) |
| `components/claude-lanes/claude-security-review.yml` |
`0f8176e87e0be518f382664779655011bf95784a` (v0.17.2) |
`906ae7ef379ea4d2b8497f64475dce1d3d8715c4` (v0.22.0) |
| `components/managed-files-guard/managed-files-guard.yml` |
`3b2f4eab5b4bb58a150e400613350ede37742ee8` |
`906ae7ef379ea4d2b8497f64475dce1d3d8715c4` (v0.22.0) |

The guard's old pin was an unreleased `main` commit (ci-workflows#530,
the
close of the guard's fail-open on an unreadable diff), so its pin
comment took
the `pin-comment-convention` short-SHA fallback form and the re-pin
cascade's
ancestry fence held the file back from every release that did not
contain it.
v0.22.0 is the first release that does, so the comment takes the
release-tag
form now and `components/managed-files-guard/README.md` records the
change.

**Input contract findings, read at the tag through the contents API.**
Nothing
required a template change.

- `checks.yml` is **byte-identical** between
  `b260ba091ca89bb3292eb53abea07ca8f0a51bf1` (v0.21.0) and the tag.
- `.github/actions/managed-files-guard/action.yml` is **byte-identical**
  between `3b2f4eab5b4bb58a150e400613350ede37742ee8` and the tag.
- `claude-review.yml` and `claude-security-review.yml` each differ from
  v0.17.2 by exactly **three `uses:` lines and nothing else**: two
  `anthropics/claude-code-action` pins (v1.0.198 to v1.0.215) and one
`claude-lane-outcome` composite pin. Every `on.workflow_call` input and
secret, every job permission, and every `runs-on` expression is
unchanged in
  both.

**Three `runner-policy` contracts added at the tag**, each a verbatim
copy-forward of the terms already reviewed for that workflow path:

- `claude-review.yml@906ae7ef379ea4d2b8497f64475dce1d3d8715c4`, from
v0.17.2.
- `claude-security-review.yml@906ae7ef379ea4d2b8497f64475dce1d3d8715c4`,
from
  v0.17.2.
- `checks.yml@906ae7ef379ea4d2b8497f64475dce1d3d8715c4`, from v0.21.0,
the
  second SHA #531 shaped its trailing entry to make cheap.

Nothing widens. No entry gains an input, a secret, a routing surface, or
a
caller permission, and the tests below assert that as equality against
the
predecessor rather than by restating the terms a second time. No
selector
allowlist entry is added: the lane caller components stopped pinning
`select-runner.yml` in Phase 3b, so there is no selector reference to
approve.
No entry at all is added for `managed-files-guard`, which calls a
composite
action rather than a reusable workflow, and composite actions are not
SHA-allowlisted.

**The repin lane was used as the oracle, not as the pen.**
`components/claude-lanes/repin-callers.sh apply v0.22.0 <sha>
2026-09-05`
produced the rewrite form, which is what the committed pins carry.
`repin-policy-lockstep.mjs` then **declined** the automatic
copy-forward:

```text
::warning::claude-review.yml credentialReferences changed between revisions (from 0f8176e);
claude-security-review.yml credentialReferences changed between revisions (from 0f8176e)
```

That is the documented human path, and the reason is the familiar one
this
repository has recorded twice before: both `claude-code-action` pins sit
inside
the steps that pass `claude_code_oauth_token`, and the
credential-references
surface records such a step in full, so an action pin bump on a
credential-consuming step reads as a `credentialReferences` diff. Human
review
confirms the secret mapping itself is unchanged and still only
`claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}`. The
contract
entries are therefore written by hand and
`components/runner-policy/README.md` carries the rollout record.

**Scope.** The lane's `EXTRA_CALLER_FILES` also enumerate this
repository's own
`.github/workflows/claude-review.yml`, `sync.yml` and
`standards-sync-stuck-automerge-alert.yml`, and the lockstep's
`REPIN_TARGETS`
would copy the two sync-family contracts forward with them. Those are
reverted here and left to the standards consumer pull request that
follows
this one, for two reasons: the Phase 6b design's order of work separates
the
distributed-component bump and its sync from the per-repository re-pin,
and
bumping the `standards-sync.yml` reusable inside the very change whose
merge
triggers the sync would put an untested revision on the critical path of
the
fan-out this pull request has to land.

## Verification

- `node --test components/runner-policy/runner-policy.test.mjs`: **294
pass / 0
  fail before, 298 pass / 0 fail after.**
- **Red first, verified.** With the whole change stashed, the four new
tests
fail and the rest pass. With only the pin bump applied and the policy
change stashed, three tests that already existed fail as well: `every
managed target of a claude lane caller admits that caller`, `claude lane
caller components pass runner policy for a private self-hosted
consumer`,
and `a fleet-routed claude lane caller is rejected outright on a public
consumer`. Those three audit the shipped component bytes against the
real
`policy.json`, so they are the load-bearing proof that the pin and the
    approval move together.
- New: the `checks.yml` contract at the tag equals the v0.21.0 contract;
a
private fleet caller of `checks.yml` at the tag is admitted; both claude
lane contracts at the tag equal their v0.17.2 predecessors; and the lane
    caller components all pin one ci-workflows revision.
- That last test asserts convergence as a **property, with no SHA in the
assertion**, on purpose. The daily `claude-lanes-repin` lane rewrites
these
components on every ci-workflows release and the lockstep maintains only
the selector constants, so a test naming one revision would go red by
construction on each of the lane's pull requests, which is the exact
shape
6b is removing from ci-runner's pin metadata test. It is non-vacuous:
pointing one lane caller back at the v0.17.2 SHA fails it and nothing
else,
    that revision still being approved.
- `node --test components/claude-lanes/repin-policy-lockstep.test.mjs`:
7 pass.
- `bash harness/shell/run-tests.sh
components/claude-lanes/repin-callers.test.sh`:
  pass.
- `bash harness/shell/run-tests.sh
components/pin-comment-convention/pin-comment-convention.test.sh`:
  pass, and
`bash components/pin-comment-convention/scan-workflow-files.sh
components/claude-lanes/*.yml components/managed-files-guard/*.yml`
exits 0, which is what proves the guard's new comment form is
convention-legal.
- `actionlint` clean on both changed component workflows; `typos` clean
on
every changed file; `markdownlint-cli2` 0 issues on both changed
READMEs;
lefthook pre-commit green (editorconfig, typos, gitleaks, markdownlint,
  biome).
- Three suites were run against a clean `origin/main` tree first to
separate
  host noise from regressions, and each fails identically there:
`claude-lanes.test.sh` case 32 and `managed-files-guard.test.sh` case 86
  (both `actionlint` on a scratch tree outside a Git repository), and
`distribution/sync-manifest.test.sh` with 7 failures both before and
after.
  CI covers all three on Linux.

## Related

- melodic-software/github-iac#378, the ci-perf program tracking issue.
- #531 added the `checks.yml` contract at
v0.21.0 and
shaped its trailing entry so a second SHA is a copy of one
self-contained
object; this pull request answers its open question, and the answer is
that
  the surface is byte-identical.
- #532 taught `concurrency-policy` the
branched
  contract-only group shape, the unconditional first gate of 6b-i.
- melodic-software/ci-workflows#557 is the change v0.22.0 cuts: the
bounded
  carry-forward wait and the branched concurrency group.

---------

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
@claude claude Bot mentioned this pull request Sep 6, 2026
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