Skip to content

fix(mention): don't cancel verify job on rapid comments - #95

Merged
max-sixty merged 11 commits into
mainfrom
fix/issue-93
Mar 29, 2026
Merged

max-sixty merged 11 commits into
mainfrom
fix/issue-93

Conversation

@tend-agent

Copy link
Copy Markdown
Collaborator

Problem

The tend-mention workflow's verify job has a concurrency group keyed by PR number with cancel-in-progress: true. When two comments arrive on the same PR within seconds, the second run cancels the first — even if the first was an explicit @bot mention.

This is exactly what happened at PRQL/prql#5750:

  1. 19:44:09 — @prql-bot can you do a follow-up... → triggered run 23664429862
  2. 19:44:14 — thanks @snth ! (5 seconds later) → triggered run 23664431397
  3. Run 2 cancelled run 1 via the concurrency group
  4. Run 2 processed "thanks @snth" (no bot mention) → bot exited silently. The explicit @prql-bot request was lost.

Solution

  • Remove concurrency from the verify job — it's lightweight and fast; parallel verify jobs for the same PR are harmless.
  • Change handle's cancel-in-progress to false — jobs queue instead of cancelling. The first handle completes (processes the mention), then the second runs (exits silently for non-mention). No mention gets dropped.

Testing

  • Added test_mention_verify_no_concurrency — verifies the verify job has no concurrency group
  • Added test_mention_handle_job_queues_not_cancels — verifies handle uses cancel-in-progress: false
  • Both tests fail before the fix, pass after
  • Full suite: 110 tests pass, all pre-commit lints pass

Closes #93 — automated triage

The verify job's concurrency group (keyed by PR number with
cancel-in-progress: true) caused explicit @bot mentions to be
dropped when a second comment arrived on the same PR within seconds.

Remove concurrency from verify (it's lightweight) and change handle's
cancel-in-progress to false so jobs queue instead of cancelling.

Closes #93

Co-Authored-By: Claude <[email protected]>
@tend-agent tend-agent mentioned this pull request Mar 28, 2026
@max-sixty

Copy link
Copy Markdown
Owner

do we have a spec of how we handle concurrency? let's write one out if not


in this case: does it fully solve the issue? if a handle job which has should_run: false kicks a job which has should_run: true from the queue (even if not canceling, after this change), does that risk losing a comment?

are we left needing to look through the whole history of the issue, including downloading its content, to evaluate whether we need to respond?

@max-sixty

Copy link
Copy Markdown
Owner

@tend-agent looks like there was a 500 error in https://github.com/max-sixty/tend/actions/runs/23694484189

So open a new issue with:

  • Consider how we can deal with these — maybe a retry? maybe some way of reporting the error, so then at least people aren't left hanging?
    • with form text / an emoji?
    • or one approach could be a repo-level issue which references the comment — then there's a cross-issue reference but it's not like if Anthropic is down, then every issue gets dozens of comments

Then:

  • Answer the point above

@tend-agent

Copy link
Copy Markdown
Collaborator Author

Created #97 for the 500 error handling.

On the concurrency question — no, a should_run: false handle can't displace a should_run: true handle, even with queuing. The handle job has if: needs.verify.outputs.should_run == 'true' — GitHub Actions evaluates that condition before the job enters the concurrency group. If the condition is false, the job is skipped entirely and never enters the queue.

So the flow for rapid comments is:

  1. Comment A (@bot do X): verify → should_run: true → handle starts, enters concurrency group
  2. Comment B (thanks!): verify → should_run: false → handle is skipped (never queues)

Comment B's handle never touches the concurrency group, so Comment A's handle runs uninterrupted.

The only scenario where queuing matters is two genuine @bot mentions on the same PR arriving close together — both get should_run: true, both enter the queue, and the second waits for the first to finish. That's the correct behavior (no mention dropped).

We don't have a written concurrency spec yet — happy to draft one if you'd like.

@max-sixty

Copy link
Copy Markdown
Owner

yes, please draft one

please ensure it contains where jobs drop out: it seems that some get cut by GHA conditions but some get cut by our own, more custom, conditions?

Document the three filtering layers (GHA conditions, custom should_run
logic, concurrency groups) and where each workflow drops events. Replaces
the previous concurrency section which was outdated after #93.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@tend-agent

Copy link
Copy Markdown
Collaborator Author

Done — pushed a concurrency spec in DESIGN.md (edb9dc2). It documents three filtering layers:

  1. GHA job if: conditions — draft PRs, bot self-comments, bare approvals, etc. Jobs are skipped entirely and never enter concurrency groups.
  2. Custom should_run logic (mention only) — the verify job's shell script checks bot engagement (direct mention, bot authored PR/issue, bot previously commented). The handle job's if: needs.verify.outputs.should_run == 'true' is technically a GHA condition, but the decision is made by our script.
  3. Concurrency groups — which jobs cancel vs queue, and why.

The key distinction you flagged: GHA conditions (Layer 1) drop jobs before they touch concurrency, while our custom verify script (Layer 2) feeds into a GHA condition on the handle job. Both result in the handle job being skipped, but the logic lives in different places.

@tend-agent tend-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

DESIGN.md spec contradicts the code change: the Layer 3 table and rationale still document verify as having a concurrency group, but the code (correctly) removes it. See inline suggestion.

Comment thread DESIGN.md Resolved
The spec table and rationale incorrectly documented verify as having a
concurrency group — the code correctly removes it.

Co-Authored-By: Claude <[email protected]>
Comment thread DESIGN.md Outdated
| Workflow | Condition | Filters out |
|----------|-----------|-------------|
| **review** | `event == pull_request_target && !draft` | Draft PRs |
| **review** | `event == pull_request_review && pr.user == bot && reviewer != bot && (state != approved \|\| body)` | Reviews on non-bot PRs; bot self-reviews; bare approvals with no body |

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

why does the review workflow respond to pull_request_review at all? should that just be the mention / react workflow?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good question — there's a meaningful distinction between the two event types:

  • pull_request_review (submitted) — a top-level review on a PR (approve / request changes / comment, with an optional body). The review workflow handles this, but only for bot-authored PRs (pr.user == bot). The idea is that when a human reviews a PR the bot created, the bot should re-run its full review skill to address the feedback — it needs the same checkout/context setup as a regular review run, just triggered by the review event instead of a push.

  • pull_request_review_comment (inline code comments) — these go to the mention workflow, which handles them like any other comment where the bot may need to respond.

That said, you could argue the review workflow's pull_request_review handler is really "respond to review feedback on my PR" — which is conceptually closer to mention/react territory than to "review this PR." The current split means the review workflow serves two purposes: (1) review other people's PRs on push, and (2) respond to reviews on its own PRs. Those could be separated.

Want me to open an issue to track whether this should move to the mention workflow (or a dedicated workflow)?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

(1) review other people's PRs on push, and (2) respond to reviews on its own PRs. Those could be separated.

change our workflow types to only do (1)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done in 4a151f3 — removed pull_request_review from the review workflow entirely. It now only triggers on pull_request_target (PR open/push/ready). Simplified the checkout, concurrency group, and prompt accordingly. Updated DESIGN.md and regenerated all workflows.

Note: top-level reviews on bot-authored PRs won't trigger anything now. Inline review comments (pull_request_review_comment) still go through the mention workflow. If we want top-level review responses routed somewhere, that'd be a separate addition to the mention workflow.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done — removed pull_request_review from the review workflow (0c8d21b). It now only triggers on pull_request_target (reviewing other people's PRs on push). Also updated the DESIGN.md example workflow and Layer 1 table to match.

Comment thread DESIGN.md Resolved
Remove the `issue.user.type != 'Bot'` filter from the triage workflow
so the bot triages issues opened by other bots. The self-login filter
is kept to prevent the bot from triaging its own issues.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Comment thread DESIGN.md Outdated
|----------|-----------|-------------|
| **review** | `event == pull_request_target && !draft` | Draft PRs |
| **review** | `event == pull_request_review && pr.user == bot && reviewer != bot && (state != approved \|\| body)` | Reviews on non-bot PRs; bot self-reviews; bare approvals with no body |
| **mention (verify)** | `event == issues && body contains @bot && author != bot` | Issue edits by the bot itself, edits without a mention |

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

what does each of these conditions precisely mean?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The table uses pseudo-code shorthand — here's what each maps to in GHA expression context:

Review (line 357):

  • event == pull_request_target — the pull_request_target event (PR opened/pushed/reopened)
  • !draft — github.event.pull_request.draft == false

Review (line 358):

  • event == pull_request_review — the pull_request_review event (someone submits a review)
  • pr.user == bot — the PR was authored by the bot (github.event.pull_request.user.login == 'tend-agent')
  • reviewer != bot — the reviewer isn't the bot itself (github.event.review.user.login != 'tend-agent')
  • state != approved || body — either it's not an approval, or it's an approval that has a body. This filters out bare "approve clicks" with no text (nothing actionable for the bot to respond to)

Mention verify (line 359, issues event):

  • event == issues — fires on issue opened/edited
  • body contains @bot — contains(github.event.issue.body, '@tend-agent') — the issue body mentions the bot
  • author != bot — the issue wasn't authored by the bot (avoids self-triage loops)

Mention verify (line 360, issue_comment):

  • comment.author != bot — the comment wasn't posted by the bot itself

Mention verify (line 361, pull_request_review_comment):

  • Same as above but for inline review comments

These are all direct translations of the actual GHA if: expressions. Want me to expand the table to be more self-explanatory (e.g., replace the pseudo-code with plain-English descriptions)?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Each row maps to one branch of the verify job's if: expression (workflows.py:212-219):

if: |
  (github.event_name == 'issues' &&
    contains(github.event.issue.body, '@bot') &&
    github.event.issue.user.login != 'bot') ||
  (github.event_name == 'issue_comment' &&
    github.event.comment.user.login != 'bot') ||
  (github.event_name == 'pull_request_review_comment' &&
    github.event.comment.user.login != 'bot')

Breaking it down:

  1. issues event (on: issues: types: [edited]): fires when someone edits an issue body. The condition requires @bot is in the body AND the editor isn't the bot itself. Purpose: catch someone editing @bot into an existing issue, while ignoring the bot's own edits (which would cause a loop).

  2. issue_comment event (on: issue_comment: types: [created, edited]): fires on any new or edited comment on issues or PRs (GitHub treats PR comments as issue comments). Only condition: comment author isn't the bot. Purpose: let verify check whether the bot should engage (direct mention or prior engagement), while filtering out the bot's own comments to prevent loops.

  3. pull_request_review_comment event (on: pull_request_review_comment: types: [created, edited]): fires on inline code review comments. Same filter: comment author isn't the bot. Purpose: same as above, but for inline review threads specifically (these use a different GitHub event than regular PR comments).

The issues branch is the strictest — it requires @bot in the body at the GHA level. The other two are permissive at the GHA level (just "not the bot's own comment") and delegate the engagement check to the Layer 2 should_run script.

I can make the spec table clearer if you think the pseudocode notation is too compressed — e.g. expanding each row to say "fires when X; skips when Y."

Comment thread DESIGN.md Resolved
tend-agent and others added 3 commits March 29, 2026 19:37
The pseudocode shorthand (e.g. `event == issues && body contains @bot
&& author != bot`) was hard to parse. Replace with plain-English
descriptions split by event type, so each row is self-explanatory.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
The review workflow now only reviews other people's PRs on push/open
(purpose 1). Responding to reviews on bot-authored PRs (purpose 2) is
removed per feedback — it's conceptually closer to the mention workflow.

- Remove pull_request_review trigger and conditional logic
- Simplify checkout (single path, no event branching)
- Simplify concurrency group key (no event_name split needed)
- Set use_sticky_comment: true unconditionally
- Update DESIGN.md Layer 1 and Layer 3 tables
- Regenerate all workflow files

Co-Authored-By: Claude Opus 4.6 <[email protected]>
The review workflow now only reviews other people's PRs on push
(pull_request_target), and no longer responds to reviews on bot-authored
PRs. This separates the two concerns as requested.

- Remove pull_request_review trigger and all review-response checkout/prompt logic
- Simplify if: condition to just draft check
- Simplify concurrency group key (no longer needs event_name)
- Update DESIGN.md spec and example workflow
- Regenerate all workflow files

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Comment thread DESIGN.md Outdated

1. **Issue edits** (`issues` event): always `true` (the GHA condition already
confirmed `@bot` is in the body).
2. **Direct mention**: comment body contains `@bot` → `true`.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

to confirm, is this literally looking for @bot? or $bot-name?

if the latter, can we adjust this?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It's the configured bot_name from .config/tend.toml — the generated workflows use @{bot_name} (e.g. @tend-agent, @prql-bot). Updated the spec to say @$bot_name to make that clear (ef414f2).

The generated workflows use the configured bot_name from
.config/tend.toml, not a literal "@bot". Clarify this in the
concurrency spec.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@max-sixty

Copy link
Copy Markdown
Owner

@tend-agent can we do another review of this concern?

in this case: does it fully solve the issue? if a handle job which has should_run: false kicks a job which has should_run: true from the queue (even if not canceling, after this change), does that risk losing a comment?

are we left needing to look through the whole history of the issue, including downloading its content, to evaluate whether we need to respond?

Given that jobs can make it through to Layer 2, doesn't that displace the queued job? and if the queued job would have should_run: true but the new job is should_run: false, doesn't that threaten to remove a job that would have run?

@tend-agent

Copy link
Copy Markdown
Collaborator Author

Good question — let me trace through this carefully.

Can a should_run: false handle displace a queued should_run: true handle?

No. When the handle job's if: needs.verify.outputs.should_run == 'true' evaluates to false, GitHub Actions skips the job entirely. A skipped job never enters the concurrency group — it doesn't run, doesn't queue, and can't displace anything. So a non-mention comment's handle job is invisible to the concurrency system.

Where displacement can happen:

GitHub Actions concurrency queues have a depth of exactly 1. With cancel-in-progress: false, only one job can be pending while another runs. If a third job arrives, it replaces the pending job (the pending one is cancelled, the new one takes its place).

This means: if three or more genuine @bot mentions arrive on the same PR in rapid succession, the middle ones can be lost. Mention A starts running, mention B queues, mention C arrives and displaces B. This is a real limitation, but it requires three should_run: true events within the ~60-second window of the handle job startup — quite unlikely in practice.

Summary: The should_run: false path is safe — those jobs are skipped before they touch the concurrency group. The only risk is three+ genuine mentions racing, which is a GHA queue-depth-of-1 limitation that would require a fundamentally different approach (e.g., a single job that reads all unprocessed mentions) to solve.

@max-sixty

Copy link
Copy Markdown
Owner

This means: if three or more genuine @bot mentions arrive on the same PR in rapid succession, the middle ones can be lost. Mention A starts running, mention B queues, mention C arrives and displaces B. This is a real limitation, but it requires three should_run: true events within the ~60-second window of the handle job startup — quite unlikely in practice.

but this actually seems quite likely in lots of people are adding comments

the important question is: can job A be displaced by a job B that won't review job A's content

Can you:

  • Evaluate the answer to that question
    • For example, if job B always reviews the whole PR, then we're OK. but if job B might evaluate to running nothing, then we're not
  • Add this as guidance (improve wording) to our spec

Each handle job only processes its own triggering comment, so if
three genuine mentions race, the middle one can be displaced from
the GHA pending queue and lost. Document this as a known limitation
with mitigation paths.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@tend-agent

Copy link
Copy Markdown
Collaborator Author

You're right to push on this — the answer is yes, a displaced job's mention can be lost.

Each handle job receives only its own triggering comment's URL in the prompt. It does not scan the conversation for unprocessed mentions. So if job B is displaced from the GHA pending queue by job C, job C only processes its own comment — job B's @bot request is dropped.

GHA concurrency queues have a depth of exactly 1. With cancel-in-progress: false:

  1. Mention A → handle running
  2. Mention B → handle queued (pending slot)
  3. Mention C → handle arrives, displaces B from pending slot
  4. Result: A ✓, B dropped ✗, C ✓

The most natural mitigation: have the handle job scan recent conversation for any unprocessed @bot mentions before responding. That way even if job B is displaced, job C picks up B's mention when it reads the thread. This makes the system self-healing — the last job in the queue always catches everything.

Pushed 668cfab with this documented as a known limitation + mitigation paths in the spec.

@max-sixty

Copy link
Copy Markdown
Owner

@tend-agent merge in main

# Conflicts:
#	.github/workflows/tend-review.yaml
@tend-agent

Copy link
Copy Markdown
Collaborator Author

Merged main in, resolved a conflict in tend-review.yaml (the new setup-uv step from #96), and regenerated workflows. All 110 tests pass.

Comment thread DESIGN.md Outdated
Comment on lines +439 to +442
- Have the handle job scan recent conversation for any unprocessed `@$bot_name`
mentions (not just its own triggering comment) before responding. This would
make the bot self-healing: even if job B is displaced, job C would pick up
B's mention when it scans the conversation.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

right, this is what we should do — the skill should review the state when it loads, not just the comment it was asked to mention

it should be aware of both:

  • other jobs might have responded to its comment, prior to it running
  • other comments might need responding

we could inject the time difference between the job being queued and running, as some indication of this likelihood

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Agreed — updated the mitigation spec (ae922a1). It now describes two things the skill should check on load:

  1. Whether another job already responded to its triggering comment (avoid duplicating work)
  2. Whether other @bot mentions in the conversation are unprocessed (pick up displaced jobs' work)

Also added the queue-to-run time delta idea — the workflow can inject the delay as an env var so the skill knows how stale its triggering context might be.

Update the queue-depth-of-1 mitigation spec per review feedback: the skill
should review conversation state on load (check for prior responses and
unprocessed mentions), not just its triggering comment. Add queue-to-run
time delta as a proposed signal.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@max-sixty
max-sixty merged commit 6c9340a into main Mar 29, 2026
5 checks passed
@max-sixty
max-sixty deleted the fix/issue-93 branch March 29, 2026 21:49
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.

bot miss at PRQL

2 participants