Skip to content

fix(sync): wait for a queued sync PR to leave the merge queue - #695

Merged
kyle-sexton merged 4 commits into
mainfrom
fix/sync-merge-queue
Oct 5, 2026
Merged

kyle-sexton merged 4 commits into
mainfrom
fix/sync-merge-queue

Conversation

@kyle-sexton

@kyle-sexton kyle-sexton commented Oct 5, 2026 •

Copy link
Copy Markdown
Member

Summary

Standards-sync runs failed red with "A pull request for this branch has been added to a merge queue … cannot be updated" whenever the target's previous sync PR was queued (standards runs 37241627436 and 37242006896, claude-code-plugins#6383). Fixes melodic-software/standards#703 once standards repins to a release containing this.

Fix

A new step in the sync job, placed before Check out target, polls the open PR on chore/standards-sync (GraphQL isInMergeQueue) every 30 s, up to 60 polls (30 min):

  • no open PR, or a PR outside any queue (targets without a merge queue): proceeds after one query;
  • queued PR merges: the job then checks out the target with that merge as its base and create-pull-request opens a fresh sync PR carrying the newer state;
  • queued PR is dequeued back to open: the job updates it in place, as before;
  • still queued after 30 min: the target fails red, naming the PR and telling the reader to re-run the job; otherwise the next push to standards main or the weekly reconciliation carries the change, so nothing is dropped;
  • a queued fork PR that reuses the branch name is ignored; a non-positive or non-numeric budget fails before any query;
  • the queue state cannot be read: warns and proceeds, which is the behavior before this change.

The sync job timeout rises from 15 to 45 minutes to cover the wait. Job names, the matrix, and the plan/attest/sync structure are unchanged. Observed queue time on claude-code-plugins sync PRs is 7–11 min (#6383: queued 22:56:05, merged 23:02:48).

Verification

  • node --test .github/scripts/*.test.cjs: 240 pass, including the new standards-sync-merge-queue-wait.test.cjs (runs the extracted inline script against mocked GraphQL for each case above, and checks step order, branch agreement with the PR step, and timeout headroom).
  • actionlint clean.

Related

🤖 Generated with Claude Code

kyle-sexton and others added 2 commits October 4, 2026 21:36
A target with a merge queue refuses pushes to a queued PR's branch, so a
sync that ran while the previous sync PR was queued failed red
(melodic-software/standards#703). Before checking the target out, the sync
job now polls the open PR on chore/standards-sync and waits, up to 30
minutes, until it merges or drops out of the queue. A merged predecessor
becomes the base of a fresh sync PR; a dequeued one is updated in place.
Past the budget the target fails and the next sync run reconciles it.
Targets without a merge queue proceed after one query.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Validate MAX_POLLS and POLL_SECONDS so a bad value fails instead of
removing the bound or hot-spinning, wait only on PRs whose head lives in
the target repository, and name the re-run remedy in the timeout
message. Tests now assert each 30-second sleep, the fork case, and the
budget validation, and the test file is Biome-formatted.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@kyle-sexton
kyle-sexton marked this pull request as ready for review October 5, 2026 01:46
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 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-10-05T01:49:26.587418Z b45070f Draft marked ready
ℹ️ 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b45070f611

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@claude

claude Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

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


Security review — no issues found

  • Gather context (PR diff, changed files)
  • Review maintenance-sync-standards.yml workflow changes for security issues
  • Review new test file for issues
  • Check README changes
  • Post findings

I reviewed the three changed files for logic flaws, authorization/trust-boundary gaps, injection surfaces, and unsafe credential handling (GitHub Actions hardening — unpinned actions, trigger/permission widening — is zizmor's advisory lane, so I didn't re-report on that axis):

  • New step, maintenance-sync-standards.yml#L449-L482 — the GraphQL query is fully parameterized ($owner, $repo, $headRefName), so there's no injection surface despite building a query string. The values interpolated into core.setFailed/core.info messages (owner, repo, pull.number) come from the workflow's own matrix and from numeric GraphQL fields, not from attacker-controlled input, so there's no log/message injection path either.
  • Credential scope — the step reuses steps.token.outputs.token, the App token already minted scoped to just the target repo (matrix.repo_owner/matrix.repo_name) for this job. No broader or additional token is introduced, and the token is never logged or echoed.
  • Fork handling — .filter((pull) => pull.isInMergeQueue && pull.headRepositoryOwner?.login === owner) correctly excludes PRs from forks that happen to reuse the chore/standards-sync branch name, so an external contributor can't queue a same-named fork PR and have this wait key off it. This is a genuine (if minor) hardening over a naive "any open PR on this branch name" check.
  • Failure-open behavior — an unreadable queue state (e.g. a permissions/GraphQL error) warns and proceeds rather than blocking, matching pre-existing behavior; this is a deliberate availability choice (documented in the PR description), not a new access-control gap.

I did not re-report the installation-token scope concern Codex already raised inline (whether the mint needs merge_queues: read for isInMergeQueue to resolve) — that's a functional/correctness question about whether the fix works as intended, not an exploitable security gap, so it's out of scope for this lane.

No CLAUDE.md/AGENTS.md/rules-file changes are present in this diff, so the instruction-surface-deletion check doesn't apply.

Result: no security findings.

@claude

claude Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Claude is reviewing this PR

  • Gather context (PR body, diff, Codex review comment)
  • Read CLAUDE.md / REVIEW.md criteria
  • Review .github/workflows/maintenance-sync-standards.yml changes
  • Review .github/scripts/standards-sync-merge-queue-wait.test.cjs
  • Review README.md changes
  • Post findings

@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

claude-security-review has reviewed this pull request through 3400ca5; a later push is reviewed from there.

The sync App token holds no merge-queues permission. A probe run with a
pull-requests:read token of that App read isInMergeQueue and the PR's
ADDED/REMOVED_FROM_MERGE_QUEUE timeline events without error, but whether
isInMergeQueue reports true without that permission is unproven, so a PR
whose latest queue event is AddedToMergeQueueEvent also counts as queued.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@claude

claude Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

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


Claude is running /review:code-review

  • Gather context (PR body, diff, prior Codex/security review comments)
  • Read AGENTS.md / REVIEW.md criteria (security lane exists → security findings out of scope here)
  • Review maintenance-sync-standards.yml changes
  • Review standards-sync-merge-queue-wait.test.cjs
  • Review README.md changes
  • Adversarial verification of candidate findings
  • Post findings

@claude

claude Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

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


Claude security review (incremental)

  • Read review scope (.claude-lane/incremental.diff, reviewed since 0ba0ab3)
  • Review .github/workflows/maintenance-sync-standards.yml changes
  • Review .github/scripts/standards-sync-merge-queue-wait.test.cjs changes
  • Check for instruction-surface deletions (none present in this diff)
  • Post findings

This pass covers only what changed since 0ba0ab3: the two files above. The rest of the PR (including README.md) was reviewed at that commit and is unchanged.

What changed: maintenance-sync-standards.yml#L458-L480 adds a timelineItems(last: 1, itemTypes: [ADDED_TO_MERGE_QUEUE_EVENT, REMOVED_FROM_MERGE_QUEUE_EVENT]) selection to the pull-request query, and the queued() predicate now treats a PR as queued when either isInMergeQueue is true or the most recent queue timeline event is AddedToMergeQueueEvent — working around the installation token lacking merge_queues: read (per Codex's earlier P1 comment) by falling back to data pull-requests: read already covers.

Security read:

  • The GraphQL query stays fully parameterized ($owner, $repo, $headRefName); the new timelineItems field adds no injection surface.
  • AddedToMergeQueueEvent / RemovedFromMergeQueueEvent timeline entries are generated by GitHub itself when a merge queue's state changes — a PR author (including from a fork) cannot forge these through comments or other user-controlled actions, so this doesn't give an attacker a way to manipulate the wait logic.
  • The fork exclusion is preserved: queued(pull) && pull.headRepositoryOwner?.login === owner still ANDs the new predicate with the existing owner check, so a same-named fork PR still can't be mistaken for the target's own sync PR.
  • No permission widening accompanies this change — permission-contents, permission-pull-requests, permission-workflows at the token mint (L386-L396) are unchanged; merge_queues: read was not added, consistent with this diff's intent to avoid needing it.
  • Fail-open behavior on a query/permission error (warn and proceed) is pre-existing and was already assessed as a deliberate availability choice, not an access-control gap, in the prior review at 0ba0ab3.

Whether isInMergeQueue still being present in the same query can itself trigger a permission error (and thus whether this workaround fully closes Codex's P1) is a correctness/functional question, not a security one, so it's out of scope for this lane — Codex's thread is the right place for that follow-up.

No new test-file (standards-sync-merge-queue-wait.test.cjs) findings: the added tests exercise the new event-fallback logic against mocked GraphQL responses only, no security-relevant surface.

Result: no security findings in this incremental diff.

@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown

claude-review has reviewed this pull request through 3400ca5; a later push is reviewed from there.

@kyle-sexton
kyle-sexton merged commit 2531d56 into main Oct 5, 2026
28 checks passed
@kyle-sexton
kyle-sexton deleted the fix/sync-merge-queue branch October 5, 2026 02:18
kyle-sexton added a commit to melodic-software/standards that referenced this pull request Oct 5, 2026
## Summary

Registers the nine ci-workflows reusables at the v0.38.1 tag
`2531d56a21e79b7b5222643fadbee95c23a4525b` in
`components/runner-policy/policy.json`. Without them the automated repin
#711 fails `check-policies` (the sync job's routing reads `needs`, so
its new SHA cannot be auto-approved). #711 carries the merge-queue wait
from ci-workflows#695 into this repo's sync, which fixes #703.

## Fix

- `policy.json`: nine new keys, each body a verbatim copy of its
`95732fd` (v0.38.0) entry, text-spliced (121 insertions, 0 deletions; a
JSON comparison confirms each copy equals its source).
- `README.md`: review note for v0.38.1.

v0.38.1 adds only ci-workflows#695 on top of v0.38.0: eight workflow
blobs are byte-identical. `maintenance-sync-standards.yml` adds one
`actions/github-script` step that uses the target-scoped App token it
already mints, and raises the `sync` job timeout from 15 to 45 minutes.
No input, secret, caller permission or `runs-on` routing moved. The
`95732fd` and `fb56986` entries stay until every consumer repins.

## Verification

- `git diff 95732fd..2531d56` in ci-workflows: only #695's three files.
- `npm run test:runner-policy` 297/297, `npm run lint:runner-policy`
pass, markdownlint and biome clean.
- With #711's patch applied on top locally, `runner-policy.mjs --root .`
passes and the 297 tests pass.

## Related

- #703
- #711 (automated repin to v0.38.1)
- melodic-software/ci-workflows#695

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 (1M context) <[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.

fix(sync): standards-sync fails when the target's previous sync PR is in a merge queue

1 participant