Skip to content

skills(running-tend): skip notifications run when a dedicated tend run is in-flight - #2386

Closed
worktrunk-bot wants to merge 1 commit into
mainfrom
daily/review-runs-24767971676
Closed

worktrunk-bot wants to merge 1 commit into
mainfrom
daily/review-runs-24767971676

Conversation

@worktrunk-bot

Copy link
Copy Markdown
Collaborator

Summary

Review-runs analysis over the last 24 hours surfaced one finding that passes both confidence and magnitude gates: a structural race between tend-notifications and in-flight tend-mention runs on the same issue/PR, repeating across multiple weeks and producing large duplicate sessions. This PR adds a repo-local overlay to the running-tend skill so the notifications bot detects an in-flight dedicated run and skips without doing redundant implementation work.

Finding (passes gates)

tend-notifications duplicates in-flight tend-mention work on the same subject. The bundled notifications skill's step 4a dedup check looks for completed bot activity (comments, reviews, bot-PR cross-references in the issue timeline). It does not look for workflow runs that are still executing. When a tend-mention run takes longer than the bundled 10-minute freshness gate — common for any mention that implies real implementation — the notifications bot can pick the notification up as "stale", pass dedup with 0 hits, and re-do the same work.

  • Classification: Structural — same inputs (slow-to-push mention + scheduled notifications poll landing past the freshness gate) produce the same failure every time. One decision point, no stochastic component.
  • Change type: Targeted fix (a repo-local overlay to step 4a).
  • Occurrences (current + historical): 2

Gate assessment

Gate Threshold This finding
1 — confidence High evidence, 2–3 occurrences (structural needs only 1) 2 occurrences, structural — passes
2 — magnitude Targeted fix: normal (use Gate 1 thresholds) Passes — no broader refactor, single new section

The fix

Adds a "Notifications: Skip When a Dedicated Run is Still In Progress" section to .claude/skills/running-tend/SKILL.md. Extends step 4a of the bundled notifications skill with:

SUBJECT_TITLE=$(gh api "$NOTIF_SUBJECT_URL" --jq '.title')
IN_PROGRESS=$(gh api \
  "repos/$GITHUB_REPOSITORY/actions/runs?status=in_progress&per_page=50" \
  | jq --arg title "$SUBJECT_TITLE" --argjson own "$GITHUB_RUN_ID" \
      '[.workflow_runs[]
        | select(.name | startswith("tend-"))
        | select((.id == $own) | not)
        | select(.display_title == $title)
       ] | length')

When IN_PROGRESS > 0, skip without marking read — mirrors the bundled freshness-gate behavior so the next scheduled poll picks it up once the dedicated run either succeeds (existing dedup then finds its response) or fails (stale-items path).

Match is on display_title because the workflow_run endpoint doesn't expose the triggering issue number for issue_comment events without a second API call per run; display_title equals the issue/PR title for those events. Title collisions across unrelated subjects are rare enough that skipping one unrelated notification is cheaper than one duplicate implementation session.

Also documents the two bash-tool gotchas that blocked the first iteration: gh api --jq doesn't accept --arg, and != in a jq filter authored via the Bash tool gets rewritten to \!=.

Below-threshold observations (not acted on)

Test plan

  • jq query verified against repos/max-sixty/worktrunk/actions/runs?status=in_progress (returns 0 when no concurrent tend run matches, which is the current state).
  • No source files touched — skill-text change only, no cargo test required.
  • Next time a mention triggers a long implementation run, verify a concurrent notifications run sees IN_PROGRESS > 0 and exits cleanly.

…n is in-flight

The bundled notifications skill's step 4a dedup check looks for completed
bot activity (comments, reviews, timeline cross-references) but misses the
case where a dedicated workflow is still running and hasn't pushed yet.
Over the last week that race cost ~$9/16min (run 24519963858 duplicating
PR #2263) and ~$25/79min (run 24742688091 duplicating PR #2361) of
in-flight implementation work.

Add a repo-local overlay that runs a targeted in-progress check against
the Actions API before any implementation work on a same-repo stale
notification. On match, skip without marking read so the next scheduled
poll can re-evaluate once the dedicated run has a chance to complete.

@worktrunk-bot worktrunk-bot 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.

One observation inline — the snippet re-fetches a title that step 1 of the bundled skill already extracts, which adds a round-trip per notification and also introduces a rename-race: a workflow run's display_title is captured at dispatch time, so if the subject was renamed between the triggering event and this poll, fetching the current title via $NOTIF_SUBJECT_URL will fail to match the in-flight run. Reusing .subject.title from the notification record (same moment as the event that created the run) keeps those in sync.

Comment on lines +74 to +78
# $NOTIF_SUBJECT_URL is .subject.url from the notification record
SUBJECT_TITLE=$(gh api "$NOTIF_SUBJECT_URL" --jq '.title')
IN_PROGRESS=$(gh api \
"repos/$GITHUB_REPOSITORY/actions/runs?status=in_progress&per_page=50" \
| jq --arg title "$SUBJECT_TITLE" --argjson own "$GITHUB_RUN_ID" \

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.

Suggested change
# $NOTIF_SUBJECT_URL is .subject.url from the notification record
SUBJECT_TITLE=$(gh api "$NOTIF_SUBJECT_URL" --jq '.title')
IN_PROGRESS=$(gh api \
"repos/$GITHUB_REPOSITORY/actions/runs?status=in_progress&per_page=50" \
| jq --arg title "$SUBJECT_TITLE" --argjson own "$GITHUB_RUN_ID" \
# $NOTIF_SUBJECT_TITLE is .subject.title from the notification record (step 1)
IN_PROGRESS=$(gh api \
"repos/$GITHUB_REPOSITORY/actions/runs?status=in_progress&per_page=50" \
| jq --arg title "$NOTIF_SUBJECT_TITLE" --argjson own "$GITHUB_RUN_ID" \

Step 1 already extracts subject_title: .subject.title, so the extra gh api call is redundant. More importantly, display_title on the in-flight workflow run is frozen at dispatch time — re-fetching the title here will miss the in-flight run if the issue/PR was renamed between the triggering event and this poll. Using the notification's cached .subject.title keeps both sides anchored to the same moment.

@max-sixty

Copy link
Copy Markdown
Owner

should this be in worktrunk or tend?

@worktrunk-bot

Copy link
Copy Markdown
Collaborator Author

Tend, I think. Nothing in the fix is worktrunk-specific — the race is between the bundled tend-notifications dedup window and any dedicated tend-* workflow that takes longer than 10 min to push. Any repo running notifications alongside tend-mention/tend-triage/etc. hits the same structural bug, and the in-progress check (actions/runs?status=in_progress filtered to tend-*, own-run excluded, matched on subject) has no repo-local state.

I'd suggest: close this PR, move the section into the bundled notifications skill in tend, and drop the overlay entirely. The two bash-tool gotchas I noted (no --arg with gh api --jq, \!= rewrite) belong with the generic snippet too.

One nit the review already surfaced — reuse .subject.title from the notification record instead of refetching via $NOTIF_SUBJECT_URL, which also sidesteps a rename-race against display_title. Worth folding in before upstreaming.

max-sixty added a commit to max-sixty/tend that referenced this pull request Apr 22, 2026
## Summary

Upstreams the fix from worktrunk PR
[max-sixty/worktrunk#2386](max-sixty/worktrunk#2386)
into the bundled notifications skill.

Step 4a of the dedup check currently finds *completed* bot activity
(comments, reviews, timeline cross-references). It does not see a
dedicated workflow that is still running. `tend-mention` sessions that
involve real implementation routinely run past the 10-minute freshness
gate — when the notifications bot proceeds, it re-implements in-progress
work.

Evidence (from worktrunk, finding in #2386):

- Run
[24742688091](https://github.com/max-sixty/worktrunk/actions/runs/24742688091)
— ~79 min, ~$25, 279 turns. Re-implemented [PR
#2361](max-sixty/worktrunk#2361) while
tend-mention was still pushing; last-step dedup caught the collision and
cleaned up, but the session cost had already been incurred.
- Run
[24519963858](https://github.com/max-sixty/worktrunk/actions/runs/24519963858)
— ~16 min, ~$9, 168 turns. Same pattern on PR #2263 / issue #2261.

## Change

Adds an **In-flight check** sub-step to step 4a of
`plugins/tend-ci-runner/skills/notifications/SKILL.md`, sitting between
the freshness gate and the dedup check. It queries
`actions/runs?status=in_progress`, filters to `tend-*` runs, excludes
`$GITHUB_RUN_ID`, and matches on `display_title` (the workflow_run
payload does not expose the triggering issue number for `issue_comment`
/ `pull_request_review` events without an extra API call per run). On
hit, skip without marking read — same disposition as the freshness gate.

The two bash-tool caveats from the overlay are preserved inline: `gh api
--jq` does not accept `--arg`/`--argjson`, and the Bash tool's bang
rewriting can still bite outside heredocs, so the jq uses `(X) | not`
rather than the not-equal operator.

## Why this lives in tend, not as a per-repo overlay

The precedence rule codified in CLAUDE.md ("Skill precedence: repo >
bundled") and in `running-in-ci/SKILL.md`
([#306](#306)) says overlays are
for repo-specific policy/convention/taste. This fix is generic: any tend
consumer whose `tend-mention` runs can exceed 10 minutes will hit the
same race. That makes it a bundled-skill defect, not an overlay.

## Follow-up on worktrunk

Once this lands,
[worktrunk#2386](max-sixty/worktrunk#2386) is
redundant — the bundled skill now covers what its overlay added. A human
should close #2386 and revert the overlay section it added to
`.claude/skills/running-tend/SKILL.md`. I have not touched worktrunk.

## Test plan

- [x] `pre-commit run --all-files` passes
- [x] jq query verified against worktrunk's
`actions/runs?status=in_progress` (returns 0 when no concurrent tend run
matches the subject title, which is the current state)
- [ ] Next time a same-repo mention triggers a long `tend-mention` run,
verify a concurrent notifications run sees `IN_PROGRESS > 0` and exits
cleanly

> _This was written by Claude Code on behalf of @max-sixty_

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
@max-sixty

Copy link
Copy Markdown
Owner

Superseded by max-sixty/tend#322, which integrates the in-flight-run check directly into step 4a of the bundled notifications skill. With the fix in tend, this overlay is redundant — the section it adds to .claude/skills/running-tend/SKILL.md should be reverted in a follow-up PR.

Closing as superseded.

This was written by Claude Code on behalf of @max-sixty

@max-sixty max-sixty closed this Apr 22, 2026
@worktrunk-bot

Copy link
Copy Markdown
Collaborator Author

Just a small clarification — this PR was closed without being merged (commit 61fd5a25 only exists on the daily/review-runs-24767971676 branch, not main), so there's nothing in .claude/skills/running-tend/SKILL.md to revert. No follow-up PR needed; the tend-side fix in tend#322 covers it on its own.

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.

2 participants