Skip to content

feat(dispatcher): approve a contract sync that matches its source - #279

Closed
Ardnived wants to merge 1 commit into
mainfrom
claude/verify-contract-sync
Closed

Ardnived wants to merge 1 commit into
mainfrom
claude/verify-contract-sync

Conversation

@Ardnived

Copy link
Copy Markdown
Contributor

Summary

  • Adds .github/workflows/contract-verify.yml, a reusable workflow that each contract consumer (WeMeditateWeb, SahajAtlasWeb, SahajAtlasWordpress) calls from workflow-state.yml on PRs on contractSync.branch.
  • It re-runs the consumer's contractSync command on the consumer's own main and compares the output with the PR head, byte for byte. If they match, and the PR is a ready bot PR from the same repo that changes nothing but the copy (isContractSyncOnly), it approves as github-actions[bot], pinned to that head SHA. The dispatcher already arms auto-merge at mark-ready, so the merge queue runs CI and merges.
  • If the copy differs (a hand edit, or a source that moved) or the check doesn't finish, it requests assignment.reviewer and leaves one comment per head saying why.
  • The dispatcher no longer requests the reviewer at a contract-only sync's mark-ready or ready_for_review. The check asks instead, and only when it can't vouch.

Failure this prevents

Every contract-sync PR (17 of the 32 small bot merges in the eight weeks to 2026-10-20) waited on the owner's approval. The ruleset needs one, and sydevs-bot can't approve its own PR. Yet the PR has exactly one correct content, and a person checks nothing a machine can't. Example: sydevs/WeMeditateWeb#292 sat BLOCKED with green CI and auto-merge armed.

Safety

  • Runs no PR code. The caller is on pull_request_target, and the PR head is only git fetched and diffed. The command comes from loop-config.json on this repo's main, and the script it runs comes from the consumer's main.
  • Approves only an exact match. The PR must touch only the copy's paths, so it can't edit package.json or the strip script to game the comparison.
  • The approval is tied to one commit. It is pinned to the compared SHA, and dismiss_stale_reviews_on_push drops it on any later push, which re-runs the check.
  • Rulesets unchanged. No bypass actor. Every other PR keeps the owner-approval flow.
  • Approval rights confirmed. All three consumers report can_approve_pull_request_reviews: true.

Rollout order

  1. Merge this first. The consumer callers reference contract-verify.yml@main, and a caller referencing a missing file would break workflow-state.yml (and so the dispatcher) in that repo.
  2. Then merge the three caller PRs, which add a verify-contract-sync job with contents: read and pull-requests: write.

Between steps 1 and 2, a sync PR that reaches mark-ready gets no reviewer request. It still gets the dispatcher's "critic skipped" comment.

sydevs/WeMeditateWeb#292 will not be auto-approved. It carries a hand edit that restores blocks.general.wisdom_sidetext, which the generator drops until sydevs/SahajCloud#1218 merges. The check will ask for review on it. That is correct behaviour.

Test results

  • node --test dispatcher/test/*.test.mjs: 383 pass, 0 fail. The new tests cover the gate (draft, closed, non-bot, fork, other branch, extra file, empty list, producer), approval pinned to the SHA and given once, a moved head left alone, a mismatch or unfinished check asking once per head, dry run, and no reviewer request on a contract-only sync draft.
  • The workflow YAML parses. Not yet run end to end: the first sync PR after rollout is the supervised check. Watch whether the ruleset counts the github-actions[bot] approval.

🤖 Generated with Claude Code

A contract-sync PR has one correct content, yet each waited on the owner's
approval: the ruleset needs one, and sydevs-bot cannot approve its own PR.

contract-verify.yml, called from each consumer's workflow-state.yml, re-runs
the consumer's contractSync command on its own main and compares the result
with the PR head. A byte-for-byte match on a ready bot PR that changes
nothing but the copy is approved as github-actions[bot], pinned to that head.
A mismatch, or a check that never finishes, asks assignment.reviewer and
says why. Nothing from the PR executes: the head is only fetched and diffed.

The dispatcher stops asking the reviewer at a contract-only sync's
mark-ready, since the check asks on a mismatch.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sydevs-bot

sydevs-bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

🤖 no session running

recent dispatches
  • 22:56Z address-review · attempt 1 · session · done
  • 22:56Z address-review · attempt 1 · session
  • 22:49Z review-pr · attempt 1 · session · done
  • 22:49Z review-pr · attempt 1 · session

Written by the sydevs dispatcher. Sessions never edit this comment.

@sydevs-bot sydevs-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧐 Adversarial review

The shape is right, and the design is forced in a way the PR never says: only a workflow running in the consumer can approve there, because the sync job holds the producer's GITHUB_TOKEN and a PAT that is the PR's own author. The diff is the size of that problem — one reusable workflow, one gate, one finisher, tests for each. Safety holds: nothing from the head runs, the approval is pinned and dismissed on push, the queue still runs CI. My two real objections are about the check this adds rather than what it decides: it is not declared as the dispatcher's own check run, and it does not decide where it runs.

Findings

  • should-fix — the new check is absent from ci.ignoreCheckNames and cancels in progress; a cancelled run reads as failing CI. .github/workflows/contract-verify.yml:42
  • should-fix — the verify job carries no event guard, unlike its sibling contracts-plan. .github/workflows/contract-verify.yml:33
  • should-fix — why.md omits the fact that makes this design the only one available. docs/why.md:1395
  • consider — the approval dedupe hardcodes github-actions[bot]. dispatcher/contracts.mjs:155

What was checked. contract-verify.yml and contracts.mjs whole; dispatcher.yml's contracts-plan and contracts-sync beside them (the new job mirrors the sync job's step set, install step included, so the toolchain is proven); gather.mjs:286 and requiredOnly for how the new check reaches the CI verdict; workflow-state.yml here as the caller template — it does fire ready_for_review, so the gate's draft skip is reachable; docs/why.md#our-own-check-runs-are-not-ci and #only-required-checks-are-ci. Ladder: contractVerifyGate reuses isContractSyncOnly and changedPaths and adds no helper of its own. No linked ticket, so judged against the body. Not run.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

# A newer head supersedes an older one's check.
concurrency:
group: contract-verify-${{ github.repository }}-${{ github.event.pull_request.number }}
cancel-in-progress: true

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This job's check run is not in ci.ignoreCheckNames, and cancel-in-progress cancels it on every push. Where the ruleset cannot be read, every check counts and a cancelled run reads as failing — the shape that fired fix-ci five times on SahajCloud#742 (docs/why.md#our-own-check-runs-are-not-ci). Every sibling job is listed there. Add this one's <caller job> / verify name.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

permissions: {}

jobs:
verify:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The verify job carries no if:. Its sibling contracts-plan in dispatcher.yml guards itself with if: github.event_name == 'pull_request_target' && …, so the called workflow decides when it runs. Here that condition lives in three consumer callers, on an on: block that also fires for issues, comments, statuses and a */30 cron — a runner and a checkout per event unless each caller's if: is right, and three places to drift. Guard the job here.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

Comment thread docs/why.md
sync's mark-ready; the check asks instead, and says why, when the copy differs (a hand edit, or a
source that moved) or the check does not finish. Once `fix-ci` touches a file beside the copy,
`isContractSyncOnly` is false and the PR is reviewed like any other. The rulesets are unchanged: a
bypass actor could not be scoped to these paths, and would skip the queue for every bot PR.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This says why not a bypass actor, but not why the check re-derives bytes contracts-sync already wrote. That answer looks load-bearing: the sync job runs in the producer's event, so its GITHUB_TOKEN cannot approve in the consumer, and its PAT is sydevs-bot, who cannot approve its own PR. Only a workflow running in the consumer can approve. Without that line, "approve what you just pushed and let dismiss-on-push catch a hand edit" has no answer here.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

Comment thread dispatcher/contracts.mjs
if (pr.head.sha !== sha) return core.info(`#${number}: the head moved past ${sha.slice(0, 7)}; its own run decides`)
if (matched) {
const reviews = await github.paginate(github.rest.pulls.listReviews, { owner, repo, pull_number: number, per_page: 100 })
if (reviews.some((r) => r.state === 'APPROVED' && r.commit_id === sha && r.user?.login === 'github-actions[bot]')) return core.info(`#${number}: ${sha.slice(0, 7)} is already approved`)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

'github-actions[bot]' pins the dedupe to the token identity, while every other login here comes from config. An APPROVED review whose commit_id is sha is already this check's own — nothing else approves a head it did not compare. Dropping the login test is shorter and survives a token change.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Nov 19, 2026
@Ardnived

Copy link
Copy Markdown
Contributor Author

Superseded by #280: the check moves into dispatcher.yml as a contracts-verify job, and decide asks the reviewer from a commit-status verdict. #280 takes this PR's review findings.

@Ardnived Ardnived closed this Nov 19, 2026
@Ardnived
Ardnived deleted the claude/verify-contract-sync branch November 19, 2026 23:06
@sydevs-bot sydevs-bot moved this from Working to Done in SYDevelopers Technical Roadmap Nov 19, 2026
@sydevs-bot

Copy link
Copy Markdown
Contributor

Superseded mid-run. All four critic findings were built and pushed before this closed — they are on claude/verify-contract-sync at 07d4b6d if any detail is useful, though #280 says it takes them.

One thing #280 does not take. The branch security review found that the check never dismisses its own approval. It approves head X; a later head the gate refuses leaves that approval standing, with auto-merge armed and nobody asked, so a commit nothing compared can merge. dismiss_stale_reviews_on_push is the stated defence, and docs/why.md:2152 and dispatcher/decide.mjs:659 both say the ruleset keeps an approval through later pushes. #280's contracts.mjs has no dismissReview.

Filed as #282 (Critical), with the fix and its tests on that branch.

Threads here are left as they are: this PR is closed and #280 carries them.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

2 participants