Repository navigation
fix(notifications): recover missed work from unread queue - #1074
Conversation
tend-agent
left a comment
There was a problem hiding this comment.
The tests are unusually thorough for a skill rewrite and the pre-check itself is clean — I ran it under bash -e with a gh stand-in that fails the subscription PUT and it warns and continues to a correct count, and shellcheck is clean. My concerns are all on the acknowledgement path: what happens when the queue doesn't drain in one session. Five inline, plus one that has nowhere to anchor:
Nothing serializes tend-notifications any more. The workflow has no concurrency: block (unlike review/mention/triage), and what kept two overlapping runs off each other's work was old step 4c marking each thread read as it was processed — a second run's gh api notifications simply didn't return them. All acknowledgement now happens in one write at the very end, so an overlapping run reads the byte-identical snapshot and re-walks it from the same end. Current-state dedup catches threads the first run already posted on, but two runs walking one oldest-first list at similar pace sit on the same thread, which is the one dedup can't see yet — and it doesn't see outcomes that aren't comments (a pushed commit, an opened PR) at all. Recent tend-notifications runs on this repo already reach 8 and 11½ minutes against a 15-minute cron, before whole-repo watching and before the agent started invoking triage/review per thread. This is a duplicate-outward-action path rather than wasted compute, and the remedy is one knob in one place — concurrency: { group: tend-notifications } in notifications.yaml.j2, at job level and so outside this diff's hunk. Say the word and I'll push it.
Two of the inline points reach files this PR doesn't touch (shared/steps/report_failure.py, plugins/tend-ci-runner/skills/nightly/SKILL.md). Happy to carry those in one commit once you've decided where the outage-issue close should live.
Checked, not raising
- The
add // []page validation is right across everygh api --paginate --slurpshape I could construct: zero pages, one empty page, several pages, an HTML body, and a JSON error object all land where intended — the last two exit 5, so theelsebranch fires.-edoesn't misfire on[]. beforevslast_read_atboundary: GitHub documents neither as explicitly inclusive or exclusive, and the two readings are mutually consistent, so I'm not treating an item stamped exactly at the cutoff as a hole.- Subscription scope and placement: the install skill requests
repofor every adopter, notpublic_repo, so the PUT has what it needs, and it runs as the bot after the invitation is accepted. - Dropping the 3-attempt retry loop and the
gh api -idiagnostic is aligned with CLAUDE.md — a lost cycle is one tick, and the::warning::still leaves a trace. - Cross-repo notifications inside the cutoff now wait a cycle where the old freshness gate exempted them: ~25 min instead of ~15 for a cross-repo mention. Not worth machinery.
- Unverified, so not a finding:
shared/steps/mark_notification_read.pyfetchesgh api notificationsunpaginated, andthreads_to_markwants a thread older thanrun_started_at. That only misses when more than a page of notifications arrives during one run — whole-repo watching raises that traffic, but I couldn't show the threshold is reachable here.
|
Verified all five against The bounded acknowledgement is the shape I suggested, and the two skip conditions (unresolved item is first same-repository item; no same-repository items at all) close the case where The one left: |
tend-agent
left a comment
There was a problem hiding this comment.
Three on the new commit, none overlapping the verification comment above. The first is the one I'd want fixed before merge; the other two are cleanup.
Step 4's recipe fails open when run verbatim. Both ACK_CUTOFF assignments are unconditional, and the second wins. date -u -d " -1 second" is valid GNU date — with $UNRESOLVED_AT empty it returns now and exits 0, so an agent that copies the block as written acknowledges every same-repository thread up to the present, including the unresolved item it was meant to stop before and anything delivered after the snapshot. That is the loss the bounded prefix exists to prevent, and it is silent: no non-zero exit, no warning, and the contract test passes on either form. The inline suggestion makes the branch explicit and keeps both pinned substrings.
Checked, not raising
date -u -d "$UNRESOLVED_AT -1 second"parses theZ-suffixed form correctly (2026-08-28T04:00:00Z→2026-08-28T03:59:59Z), and the PUT is repo-scoped, so cross-repository threads keep their individual-ack path untouched.- The literal
group: tend-notifications, where review/mention/triage interpolate${{ github.workflow }}: groups are repo-scoped and nothing else can claim the string, so the only cost is that aworkflow_extrarename wouldn't follow the group. Not worth the interpolation. --argjson own "$GITHUB_RUN_ID"on an 11-digit run id stays exact in jq's double (well under 2^53), so the self-exclusion holds.- The 60-second
DEDUP_CUTOFFpad survived the rewrite but the paragraph justifying it — GitHub's notification indexing running 20–60 s behind the event — didn't. The number is still right; only the reason a future editor would need is gone. - Serializing the poll trades overlap for availability: the notifications job sets no
timeout-minutes, so a wedged poll holds the group for GitHub's 360-minute default while crons keep replacing one pending slot. I asked for this group and I'd still take it — no poll has been observed running near that, so a timeout knob has no evidence behind it yet.
tend-agent
left a comment
There was a problem hiding this comment.
Two on 052c23f. The first is the one I'd want fixed before merge; the second narrows a phrase.
The outage close can't run as written. gh issue close <outage-number> --reason completed sits in a bash block, and bash parses <outage-number> as a stdin redirect — the command aborts with outage-number: No such file or directory and exits 1 before gh is invoked. $OUTAGE is already in scope two lines above, and the [ -n "$OUTAGE" ] guard that used to bound the close moved into prose. The cost when it doesn't fire: report_failure.py appends every later row to the same tracker, and _issue.canonical resolves to the lowest-numbered open one, so the issue grows without bound and each daily sweep re-reads and re-diagnoses its whole accumulated history while still reporting success. CLAUDE.md's authoring rule — "Prefer recipe over narrative", and exact wording reserved "for fragile mechanics: dedup keys, commands, API formats" — points the same way. The test assertion has to move with it, so that's a second inline.
Checked, not raising
- The Step 4 branch is right:
if [ -n "$UNRESOLVED_AT" ]/else ACK_CUTOFF=$CUTOFFcloses the fail-open path, and both arms are pinned bytest_notification_skill_uses_a_bounded_repository_acknowledgement. I ran all six tests in this file against the head tree — green. - The review-runs reorder does what I asked: one tracker read after the exhaustive live scan, no
/tmphandoff, no second read. Theif ! OUTAGE=$(gh issue list ...)guard distinguishing "read failed" from "none open" matches_issue.canonical's own docstring on that distinction, so it's consistent rather than extra machinery. - Dropping the
state == OPENre-check before the close is fine —gh issue closeon an already-closed issue warns and exits 0. - The 60-second
DEDUP_CUTOFFrationale is back in the prose, which was the only thing missing from that recipe. "Bot temporarily unavailable"is still a third copy of a literal that also lives inreport_failure.pyandci-fix/SKILL.md, and still unasserted — I raised that in the comment above and it stands as-is; not restating it as a new finding.
tend-agent
left a comment
There was a problem hiding this comment.
All three from 052c23f are fixed, verified against c38f2d8: the close is executable and guarded, its assertion pins that form instead of the placeholder, and the terminal “no action” bullet is now keyed on the two structural shapes with a 5xx or rate limit left unresolved. The /tmp handoff is right despite my last comment arguing the other way — the lookup and the close are separate Bash calls, so $OUTAGE genuinely does not survive between them, and Step 2's /tmp/review-runs-since is the same pattern one section down. Approving.
One inline, optional: the new contract pins the write side of the handoff and the close line, but nothing pins that the close block reloads $OUTAGE. Dropping OUTAGE=$(cat /tmp/review-runs-outage-number) from that block leaves every assertion in the file green — I ran that mutant — and the close then no-ops silently, which is the failure the last round fixed. Pinning the two lines as one string also makes a path rename move both ends together.
Checked, not raising
test_outage_tracker_title_stays_in_syncasserts the literal in all three files rather than importingreport_failure.TITLE, which catches drift in the reporter too — stricter than what I asked for, and consistent with this file's text-read idiom.[ -n "$OUTAGE" ] && …exits 1 on the no-tracker day, which is most days. The prose gates the block on “if a tracker was found”, and it is the form I suggested, so I'll leave it rather than churn it into anif.- The
> /tmp/review-runs-outage-numberredirect truncates beforeghruns, so a failed lookup leaves an empty file behind theexit 1; if a later block reads it anyway it gets empty and skips the close rather than closing a wrong issue. gh api "$SUBJECT_URL"prints(HTTP 404)for a deleted subject and a distinct rate-limit message otherwise, so the new bullet's 404-vs-transient split is decidable at the call site with the recipe as written.
Release step 11: moves Tend's eight generated workflows and the hand-maintained `review-reviewers.yaml` onto the published `max-sixty/tend/[email protected]` action. `init` rewrites only the generated `tend-*.yaml` files, so the reviewer workflow is restamped by hand; every workflow in the repo now agrees on one ref. Two behavior changes ride along, both already merged into the generator and released: - **`tend-review`** drops its pre-boot gate and the `tend-review/<pr>` commit status the gate read, so reviewed commits no longer carry an extra check row. It gains `queue: max`, so a push cannot displace a pending `ready_for_review` run. ([#1078](#1078)) - **`tend-notifications`** replaces the three-layer inbox sweep with a paginated snapshot taken at a 10-minute cutoff, repairs repository watching on every poll, passes the cutoff through to the agent, and serializes on a `tend-notifications` concurrency group. ([#1074](#1074)) 0.1.20...0.1.21 ## Verification `uvx [email protected] init` reruns to an unchanged generated diff; pre-commit and `uv run pytest` (761 passed) are clean. One caveat, and it is the reason the diff is not purely mechanical: pre-commit's `trailing-whitespace` hook strips a 12-space line the generator emits inside the notifications prompt. `block_prompt` renders it with `indent(12, blank=True)`, which indents the blank line separating the slash command from the cutoff line. #1074 introduced the first multi-line prompt to go through that macro, so this is the first regeneration to hit it. Both forms parse identically inside a YAML block scalar, but the committed file can never match generator output until the macro changes. The generator fix lands separately. > _This was written by Claude Code on behalf of max-sixty_
Review of the first commit turned up two gaps. `indent(12, first=True)` still pads a *blank* first line, because Jinja prepends the indent unconditionally when `first=True` — so dropping `blank=True` closed the instance #1074 hit, not the class. A prompt ending in a blank line had the same shape, tripping end-of-file-fixer instead. Both now go through an `indent_block` filter that indents only non-blank lines and clips trailing ones, which a `|` block scalar does anyway. The test reached seven workflows on one harness: `generate_all` skips ci-fix without `watched_workflows` and install-test without its flag, so neither was covered, and codex was not either. It now runs all eight across both harnesses, with a nightly prompt carrying leading, interior, and trailing blank lines. Restoring `blank=True`, restoring `first=True`, or dropping the trailing-line clip each fails all four parametrizations. > _This was written by Claude Code on behalf of max-sixty_
`block_prompt` rendered its text through `indent(12, blank=True)`, which pads a blank line out to twelve spaces. Adopters run pre-commit's `trailing-whitespace` hook over their generated workflows, so the file they commit could never match what `init` emits — the next regeneration puts the padding back. Nothing hit it until [#1074](#1074) gave `tend-notifications` the first multi-line prompt to go through the macro. Every form here parses to the same string inside a YAML block scalar, so this is churn, not a behavior change. ## Why it matters beyond the diff `tend-nightly` regenerates with `uvx tend@latest init` and opens a PR when `NON_STAMP_DIFF` is non-zero. That guard filters only the `# Generated by tend X.Y.Z` header, so the `-`/`+` whitespace pair counts 2 and the PR gets created. That PR's `lint` job runs `pre-commit/[email protected]`, which defaults to `--all-files`, so `trailing-whitespace` rewrites the file and fails the job — a valueless red PR every night until this ships in a release. ## The whole class, not the one instance Jinja's `indent` cannot render a block scalar without leaking one of these, because it prepends the indent unconditionally when `first=True`: | adopter `prompt:` | what leaks | which hook | |---|---|---| | `"alpha\n\nbeta"` | interior blank padded to 12 spaces | trailing-whitespace | | `"\nalpha"` | blank *first* line padded | trailing-whitespace | | `"alpha\n\n"` | file ends `\n\n` | end-of-file-fixer | | `"alpha\n \n"` | last line flattens to blank, file ends `\n\n` | end-of-file-fixer | All four go through an `indent_block` filter that indents only non-blank lines and clips trailing ones — which a `|` block scalar does anyway, so no prompt value changes. ## Testing The assertion is folded into the test that already guarded the end-of-file-fixer hook, since both are the same failure: whitespace an adopter's pre-commit rewrites. That test reached seven workflows on one harness — `generate_all` skips ci-fix without `watched_workflows` and install-test without its flag, and codex was never exercised. It now covers all eight across both harnesses, with a nightly prompt carrying leading, interior, and trailing blank lines and a whitespace-only last line. Restoring `blank=True`, restoring `first=True`, or narrowing the clip to `rstrip("\n")` each fails all four parametrizations. pytest-regtest normalizes trailing whitespace before comparing, so the recorded outputs could not have caught this and do not change here. > _This was written by Claude Code on behalf of max-sixty_
Patch release carrying one generator fix. A multi-line `prompt:` rendered its blank lines padded out to the block scalar's indent, so an adopter running pre-commit's `trailing-whitespace` or `end-of-file-fixer` hooks could never commit a file matching what `init` emits. The nightly regeneration then opened a PR over that difference every night, and that PR's own `lint` job failed on it. This ships urgently because 0.1.21 is the first release where the bug is reachable: [#1074](#1074) gave `tend-notifications` the first multi-line prompt. Until 0.1.22 is on PyPI every adopter's nightly regeneration produces a red PR — `uvx tend@latest` is what the nightly runs, so merging the fix to `main` alone does not stop it. [#1089](#1089) is also in the range; it moved tend's own workflows onto 0.1.21 and has no adopter-visible effect, so it gets no changelog bullet. > _This was written by Claude Code on behalf of max-sixty_
Automated nightly regeneration of tend's workflow files. **tend version:** 0.1.20 → 0.1.22 ## Notable changes - **Notifications now run off a recovery queue** (max-sixty/tend#1074). The pre-check drops the old layered inbox sweep (shadowed-run and closed-bot-PR marking) in favour of a single paginated snapshot taken before a 10-minute cutoff, passes that cutoff through to the agent, and keeps repository watching enabled with an idempotent `PUT .../subscription` on every cycle. The job also gains a serial `tend-notifications` concurrency group. - **`tend-review` re-targets instead of skipping** (max-sixty/tend#1082). The "skip when the live HEAD is already examined" gate step and its `if:` guards are gone; a live session now re-targets when HEAD moves. The concurrency group adds `queue: max` so a push can't evict a pending `ready_for_review` run. - **Skills check the default branch for a landed fix before opening a PR** (max-sixty/tend#1070), and `review-runs` gains the run census as a second stranded-trigger drain input (max-sixty/tend#1073). - **Poll/rerun script fixes** (max-sixty/tend#1053, max-sixty/tend#1055): `tend-review` no longer gates the CI poll, and an unresolvable commit fails fast rather than passing silently. - **Generator fixes**: `watched_workflows` and `branches` are validated as string lists (max-sixty/tend#1076), and block prompts no longer get padded blank lines (max-sixty/tend#1090). Full upstream diff: max-sixty/tend@0.1.20...0.1.22 Co-authored-by: worktrunk-bot <[email protected]>
Automated nightly regeneration of tend's workflow files. **tend version:** 0.1.20 → 0.1.22 **Notable changes** - Notifications recover work missed while the unread queue was stale, and the job now runs under its own `tend-notifications` concurrency group so overlapping schedules serialize instead of racing (max-sixty/tend#1074). - Skills check the default branch for a landed fix before opening a PR, cutting duplicate PRs for work that already merged (max-sixty/tend#1070). - `review-runs` gains the run census as a second stranded-trigger drain input (max-sixty/tend#1073), and reviews re-target when HEAD moves rather than being discarded (max-sixty/tend#1082). - The CI poll no longer lets `tend-review` gate it, and the commit-resolution script fails fast instead of proceeding on an unresolved SHA (max-sixty/tend#1053, max-sixty/tend#1055). - The generator validates `watched_workflows` and `branches` as string lists, and stops padding blank lines inside block prompts (max-sixty/tend#1076, max-sixty/tend#1090). max-sixty/tend@0.1.20...0.1.22 **Beyond the regeneration:** 0.1.22's `tend-review.yaml` sets `concurrency.queue: max`, which GitHub accepts but the pinned `actionlint` hook rejects, so this PR also adds a scoped `-ignore` for that one schema message to `.pre-commit-config.yaml` — otherwise `lint` is red and the PR can't merge on its own CI. Tracked upstream as max-sixty/tend#1094. --------- Co-authored-by: leaf-agent <[email protected]>
Failed event workflows already leave their triggering notification unread, but that only provides recovery when the bot was subscribed before the event. The notification poll also read just the first page and acknowledged individual threads before deciding whether their work had a real outcome.
This makes the recovery model explicit and small:
Historical workflow runs and the
tend-outageissue remain diagnostic evidence. They are no longer replayed for recovery, so Tend always uses its current workflow and the subject's current state. After its exhaustive live scan, the daily sweep reads every row from the canonical outage tracker and closes it only after the applicable live work is handled.The independent test review caught a lossy one-shot reconciliation flag in the first draft, and hosted review caught overlap, partial-progress, deduplication, unreadable-subject, and outage-lifecycle gaps. The final design has no new durable state: watching is enforced every poll, unread notifications are the recovery queue, and the live-state scan recurs every day. Contract and integration tests cover pagination, the strict cutoff boundary, serialized polling, bounded acknowledgement, permanently unreadable subjects, fragile deduplication queries, install-time watching, and the current-state outage lifecycle.
Follow-up to #1073; implements the recovery behind #1066 and #1067.
Verification:
wt test(723 tests plus worker tests and typecheck),pre-commit run --all-files.