Skip to content

feat(gate): the orchestrator's OK at the round cap - #340

Open
bfcarrasco wants to merge 1 commit into
mainfrom
feat/merge-gate-round-cap
Open

bfcarrasco wants to merge 1 commit into
mainfrom
feat/merge-gate-round-cap

Conversation

@bfcarrasco

Copy link
Copy Markdown
Owner

Request

#327 (behaviours 9 and 10 of #318). Acceptance criteria:

  • At the cap a lane returns the state capped with its open findings, and does not ask the owner.
  • A script gives the orchestrator's OK for a head only when all of this holds: the rounds reached the cap; the checks are green on that head; the PR changes no policy file; the tier is below 2, or the repo's exposure is internal and the diff holds no schema change and no deletion of data; every open blocking finding has a follow-up issue; and the script is not running in a checkout of the PR's branch. Each refusal names the condition that failed.
  • The merge gate lets that head through on the orchestrator's OK and posts a status that names it and the judge's comment, as it does for the owner's OK. Every other head is gated as today, and the owner's line works as today.
  • The guard refuses the orchestrator's OK line when written by hand or through an MCP tool.
  • The skill names the three choices at the cap (a fresh builder with another approach, merge with follow-up issues, close the PR). It never merges over an open finding about data loss, security or access; that goes to the owner. A ticket whose acceptance criterion still fails stays open.
  • UNPROVEN: the gate is unchanged. The skill first starts a fresh judge on a machine that has the missing proof, and asks the owner only when none has.

Closes #327

Why

At three blocking rounds every stuck ticket went to the owner. With the orchestrator, it decides at the cap and the owner is asked only when a revert could not undo the merge.

What changed

  • scripts/cap-ok.mjs <pr> -R owner/repo --follow-up F2=341 ... checks the six conditions (plus: the PR is open, the findings can be read) and posts a tagged comment with the OK line for the head; else exit 1 with one refused: <condition>: <found> line per failure. A follow-up is an open issue in the PR's repo whose body names the PR URL and the finding id.
  • Merge gate: at the cap the orchestrator's OK opens the head like the owner's line, after re-checking the diff conditions (policy file, tier/exposure); it posts orchestrator-ok judge=<result> on bstack/judge with the judge's comment as target. Not at the cap, or on UNPROVEN, it counts for nothing.
  • Guard: the line is refused in gh posting commands and body files (as the owner's line), and in any MCP tool input. The cap messages tell a lane to stop with state capped and its open findings and ask no one.
  • lane.mjs result: capped needs the PR, the head and at least one open finding.
  • Orchestrator skill: an "At the cap" section with the three choices, the owner-only cases, and the UNPROVEN route to a judge on another machine.

Scope

Not changed: the number of rounds; no way for a builder to clear its own PR beyond the checkout check the ticket names.

Blast radius

Every repo's merge gate (guard + lib). Owner-OK statuses read as before (owner-ok and orchestrator-ok share one parser).

Verification

node --test "tests/*.test.mjs": 928 tests, 902 pass, 0 fail (rest skipped as before). New tests/cap-ok.test.mjs (10 tests): each refusal, success, gate pass/refusals, status text and target, guard refusals by hand and MCP, lane result, skill text. Mutations (gate re-check removed; MCP rule removed) each fail a test.
node tools/check-plugin.mjs: ok.

The cap-ok script posts the orchestrator's OK for a PR head only when the
rounds reached the cap, the checks are green, no policy file changes, a
revert undoes the change and every open finding has a follow-up issue,
and refuses to run in a checkout of the PR's branch. The merge gate lets
that head through at the cap and posts an orchestrator-ok status; the
guard refuses the line by hand or through an MCP tool.
@bfcarrasco

Copy link
Copy Markdown
Owner Author

bstack-judge: PASS+NOTES tier=2 sha=9f78995f17d77ece433d4fe6dff4ecd737067612

PR 340 (bfcarrasco/bstack), head 9f78995, checked out detached and confirmed. Contract: issue #327. GitHub Actions checks (ubuntu, windows, validate) are green on the head. No bstack/checks status is posted on it, so I ran only the tests my proofs needed. risk-tier.mjs --pr 340 gives tier 2 with no weakened check.

Criteria, each proved with the real decide() / runCapOk() / lane.mjs result code against faked gh responses (fixtures):

  1. Capped lane does not ask the owner. Proved. lane.mjs result refuses capped without pr, head or open findings, and refuses it when open_findings is missing. A judge started at the cap (Agent and Task) is refused with "a lane stops with state capped and its open findings, and asks no one". The merge-gate cap message says the same.
  2. cap-ok conditions. Proved. tests/cap-ok.test.mjs covers 13 refusal cases: open, cap, CI, policy file, tier with external or internal exposure, follow-up missing/closed/wrong body/unreadable, checkout by branch and by head. Each refusal names its condition. 5 failing conditions give 5 lines, and nothing is posted on a refusal.
  3. Gate. Proved. The gate posts orchestrator-ok judge=FAIL tier=1 blocking=2 pr=5 with the judge comment #issuecomment-77 as target. It refuses: no OK, an OK for another sha, a quoted or untagged line, before the cap, UNPROVEN, red CI, a policy file, deletion in an internal repo. My extra probe: os.remove in an internal repo is refused at the gate. The owner line still passes a policy diff with owner-ok. With both OKs present, owner wins. Line endings CRLF parse.
  4. Guard. Proved. The line is refused in gh pr comment --body, --body-file, gh api -f body=, piped -F -, gh api --input body.json (my probe) and gh issue create, and in MCP inputs.
    5 and 6. Skill text. Proved by reading the "At the cap" section and the UNPROVEN route in plugins/bstack/skills/orchestrator/SKILL.md; the skill-text test asserts both. The gate on UNPROVEN is unchanged (merge-gate line 127 still asks for the owner's line).
    New tests fail on base: with base plugins/ restored, node --test tests/cap-ok.test.mjs gives pass 0, fail 1 (module missing). Head gives 10/10.
    Not done: the ticket's "one real PR driven to the cap in a throwaway repo". I do not create repos or post to GitHub, and the fixtures run the same code paths.

Findings (none blocking):

  • F1: a follow-up check matches by substring. body.includes(pr.url) takes an issue naming https://github.com/o/r/pull/55 as a follow-up for PR 5, and cap-ok exits 0. Low impact, since the orchestrator passes the issue numbers itself.
  • F2: if the head is pushed after the cap and never judged, the orchestrator's OK merges it. The status is orchestrator-ok pr=5 with the PR URL as target, not a judge comment. Same as the owner-OK path on base.
  • F3: the checkout check misses a worktree detached at an older PR commit (cap-ok exits 0), and a builder can run cap-ok from any other folder anyway. The PR's Scope states this trade-off.

Dropped hypotheses:

  • MCP inputs that only mention the marker, such as a read-only search, are now refused. Dropped because the PR body says the line is refused "in any MCP tool input".
  • Running cap-ok twice, or two OK comments: one status post.
  • Duplicate --follow-up for one id: the last one wins, and an unreadable one is refused.
  • A consumer of the old names (ownerOk, postOwnerOk, USER_OK_MARKER): none left in plugins; old owner-ok statuses still parse.
  • The gate trusting the OK without re-checking the diff: the re-check holds.
  • An OK for a stale sha: refused.
  • A Write tool containing the marker is allowed, but posting that file through gh is refused.
[{"id":"F1","title":"Follow-up check accepts an issue naming another PR whose URL starts with this PR's URL (pull/55 for pull/5)","reproduction":"tests/cap-ok.test.mjs harness: capOk({issues:{12:issue(12,'Follow-up of https://github.com/o/r/pull/55 F1'),13:issue(13,'Follow-up of https://github.com/o/r/pull/55 F2')}}) exits 0","base":"not run","head":"fail","blocks":"no","files":["plugins/bstack/scripts/lib/cap-ok.mjs"]},{"id":"F2","title":"Orchestrator OK lets a post-cap unjudged head merge; status names no judge comment (same as owner OK on base)","reproduction":"tests/cap-ok.test.mjs harness: merge({judgements:[ROUND1,ROUND2,judged(77,'3'.repeat(40),'2026-12-03T10:00:00Z',[F1])],comments:[okComment()]}) returns null, status 'orchestrator-ok pr=5'","base":"not run","head":"fail","blocks":"no","files":["plugins/bstack/scripts/lib/merge-gate.mjs"]},{"id":"F3","title":"Checkout check misses a worktree detached at an older PR commit","reproduction":"tests/cap-ok.test.mjs harness: capOk({checkout:{branch:'HEAD',head:'2'.repeat(40)}}) exits 0","base":"not run","head":"fail","blocks":"no","files":["plugins/bstack/scripts/lib/cap-ok.mjs"]}]

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.

Merge gate: the orchestrator's OK at the round cap

1 participant