Repository navigation
skills(running-tend): skip notifications run when a dedicated tend run is in-flight - #2386
worktrunk-bot wants to merge 1 commit into
Conversation
…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
left a comment
There was a problem hiding this comment.
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.
| # $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" \ |
There was a problem hiding this comment.
| # $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.
|
should this be in worktrunk or tend? |
|
Tend, I think. Nothing in the fix is worktrunk-specific — the race is between the bundled I'd suggest: close this PR, move the section into the bundled One nit the review already surfaced — reuse |
## 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]>
|
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 Closing as superseded.
|
|
Just a small clarification — this PR was closed without being merged (commit |
Summary
Review-runs analysis over the last 24 hours surfaced one finding that passes both confidence and magnitude gates: a structural race between
tend-notificationsand in-flighttend-mentionruns on the same issue/PR, repeating across multiple weeks and producing large duplicate sessions. This PR adds a repo-local overlay to therunning-tendskill 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-mentionrun 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.post-create→ fatal-error change (edits tosrc/config/deprecation.rs, snapshots, integration tests, pre-merge hook). At the very last step beforegh pr createit re-checked and found PR fix(config): reject post-create hook instead of silently migrating #2361 already open, then cleaned up its branch.Gate assessment
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: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_titlebecause the workflow_run endpoint doesn't expose the triggering issue number forissue_commentevents 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 --jqdoesn't accept--arg, and!=in a jq filter authored via the Bash tool gets rewritten to\!=.Below-threshold observations (not acted on)
Test plan
jqquery verified againstrepos/max-sixty/worktrunk/actions/runs?status=in_progress(returns0when no concurrent tend run matches, which is the current state).cargo testrequired.IN_PROGRESS > 0and exits cleanly.