Skip to content

feat(state): assign the bot to its own PR, once, at open - #53

Merged
Ardnived merged 1 commit into
mainfrom
claude/state-assign-bot-on-pr-open
Sep 5, 2026
Merged

Ardnived merged 1 commit into
mainfrom
claude/state-assign-bot-on-pr-open

Conversation

@Ardnived

@Ardnived Ardnived commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Rungs find the loop's PRs with author:<bot>, so nothing reads a PR's assignee when the bot wrote
it — and nothing wrote it either. That was defensible and it read as broken: a queue of PRs with no
owner, in a UI where every other row has one.

state-machine.yml now calls a new assignBot on pull_request: opened, for the bot's own PRs:

if (action === 'opened' && ours) await assignBot(n)

assignBot mirrors the existing unassignBot — it reads current assignees and returns early when
the bot is already there, so it is idempotent like every other writer in this file. Assigning a PR
fires pull_request: assigned, which no caller subscribes to, so it cannot recurse.

The failure this prevents — and why opened alone

On a PR the bot did not write, the assignee means the opposite thing: a human handing the loop
that work, with removal as the kill switch (preflight, triage-issue). Re-asserting the
assignment on reopened or synchronize would undo a deliberate removal on the author's next push
— and a kill switch that holds only until the next push is not a kill switch.

opened fires exactly once in a PR's life. That is the only safe place for this write, and the
guard says so in the code, in the helper's comment, and in docs/why.md.

preflight's delegated-PR query is is:pr is:open assignee:<bot> -author:<bot>, so the bot's own
PRs stay out of it — verified in the checklist below.

The doctrine change

Three skills stated the old rule as an absolute, one in Hard rules. Each is narrowed, not
deleted
— the loop still writes no PR assignee in either direction, and no rung may start reading
the new one, or authorship and assignment become two answers to one question:

File Was Now
triage-issue baton + hard rule "Never set or change a PR's assignee at all" "Never set or change a PR's assignee. The state machine does it at opened." Surface table splits PR, ours from PR, someone else's
preflight never-write table "The reviewer adds the bot. The workflow removes it at Implemented" "…and adds it to our own PR at open"
finalize-pr step 7 + hard rule "Set no assignee at all" unchanged for the loop, plus who does write it

docs/why.md gains A PR's assignee is a record, never a signal, cited from triage-issue.

rule-delta.mjs --base main: 57 → 57 directives, 1 reworded, none dropped.
Version bumped 0.2.2 → 0.2.3 — the cache key, per cb46fca.

Verification

Not testable before merge: for pull_request_target GitHub always runs the workflow from the
default branch. After merging, from a PR authored by sydevs-bot (one authored by a human
correctly gets nothing):

gh pr view <n> --json assignees --jq '.assignees[].login'      # sydevs-bot
# then the kill switch must hold:
gh pr edit <n> --remove-assignee sydevs-bot
git commit --allow-empty -m "test: fire synchronize" && git push
gh pr view <n> --json assignees --jq '.assignees[].login'      # still empty
# and the delegated-PR query must stay clean:
gh search prs --owner sydevs --state open 'assignee:sydevs-bot -author:sydevs-bot'

Stacked behind #52, which touches the same file in a different region.

🤖 Generated with Claude Code

Rungs find the loop's PRs with `author:<bot>`, so nothing reads a PR's
assignee when the bot wrote it, and nothing wrote it either. That was
defensible and it read as broken: a queue of PRs with no owner, in a UI
where every other row has one.

The state machine now calls `assignBot` on `pull_request: opened`, for the
bot's own PRs only. `assignBot` mirrors `unassignBot` — it reads the current
assignees and returns early when the bot is already there, so it is
idempotent like every other writer here. Assigning a PR fires
`pull_request: assigned`, which no caller subscribes to, so it cannot
recurse.

The failure this prevents, and the reason for `opened` alone: on a PR the
bot did NOT write, the assignee means the opposite thing — a human handing
the loop that work — and removing it is the kill switch. Re-asserting the
assignment on `reopened` or `synchronize` would undo a deliberate removal on
the author's next push, and a kill switch that holds only until the next
push is not a kill switch. `opened` fires once in a PR's life, which is the
only safe place for this write.

`preflight`'s delegated-PR query is `is:pr is:open assignee:<bot>
-author:<bot>`, so the bot's own PRs stay out of it.

Three skills stated the old rule as an absolute, one of them in Hard rules.
Each is narrowed rather than deleted: the loop still writes no PR assignee
in either direction, and no rung may start reading the new one, or
authorship and assignment become two answers to one question.

rule-delta: 57 -> 57 directives, 1 reworded, none dropped.

Co-authored-by: Claude Opus 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

Development

Successfully merging this pull request may close these issues.

1 participant