Skip to content

fix(notifications): rescue notification_deliveries rows stranded at pending by a failed enqueue - #9393

Merged
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
bitfathers94:fix/issue-9320
Jul 27, 2026
Merged

fix(notifications): rescue notification_deliveries rows stranded at pending by a failed enqueue#9393
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
bitfathers94:fix/issue-9320

Conversation

@bitfathers94

Copy link
Copy Markdown
Contributor

fix(notifications): rescue notification_deliveries rows stranded at pending by a failed enqueue

evaluateAndEnqueueNotificationDeliveries commits each fresh delivery row
before enqueuing its notify-deliver job, so a rejected JOBS.send leaves the
committed rows at pending. A client retry finds them already present
(idempotent) and omits them, so no deliver job is ever re-sent and the
notification stays invisible to the recipient until the 90-day retention
sweep deletes it.

Add a periodic sweep, mirroring sweepStrandedPendingClosures: a bounded
lookback window, a grace period so an in-flight row is not mistaken for a
lost one, and a minimum re-sweep interval so a row stuck for another reason
is retried periodically rather than every tick. A new repository query lists
pending rows within the window, the sweep re-enqueues notify-deliver for each
and fails open on a DB read error, and it is wired into the periodic queue
tick alongside the sibling repair scans.

Closes #9320

Validation

Verified locally on this branch before opening:

  • npm run typecheck
  • npx turbo run build:tsc build:verify
  • npm run test:coverage — patch coverage 100.0% of changed lines

…ending by a failed enqueue

evaluateAndEnqueueNotificationDeliveries commits each fresh delivery row
before enqueuing its notify-deliver job, so a rejected JOBS.send leaves the
committed rows at pending. A client retry finds them already present
(idempotent) and omits them, so no deliver job is ever re-sent and the
notification stays invisible to the recipient until the 90-day retention
sweep deletes it.

Add a periodic sweep, mirroring sweepStrandedPendingClosures: a bounded
lookback window, a grace period so an in-flight row is not mistaken for a
lost one, and a minimum re-sweep interval so a row stuck for another reason
is retried periodically rather than every tick. A new repository query lists
pending rows within the window, the sweep re-enqueues notify-deliver for each
and fails open on a DB read error, and it is wired into the periodic queue
tick alongside the sibling repair scans.
@bitfathers94
bitfathers94 requested a review from JSONbored as a code owner July 27, 2026 15:50
@superagent-security

Copy link
Copy Markdown
Contributor

Superagent didn't find any vulnerabilities or security issues in this PR.

@codecov

codecov Bot commented Jul 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.15%. Comparing base (995cd78) to head (ea1f546).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9393      +/-   ##
==========================================
+ Coverage   75.38%   76.15%   +0.77%     
==========================================
  Files         275      278       +3     
  Lines       58023    60168    +2145     
  Branches     6181     6882     +701     
==========================================
+ Hits        43739    45821    +2082     
- Misses      14014    14023       +9     
- Partials      270      324      +54     
Flag Coverage Δ
backend 97.06% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/db/repositories.ts 96.79% <100.00%> (ø)
src/notifications/stranded-delivery-sweep.ts 100.00% <100.00%> (ø)
src/queue/job-dispatch.ts 99.46% <100.00%> (ø)

@loopover-orb loopover-orb Bot added the gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. label Jul 27, 2026
@loopover-orb

loopover-orb Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Tip

✅ LoopOver review result - approve/merge recommended

Review updated: 2026-07-27 16:08:10 UTC

5 files · 1 AI reviewer · no blockers · readiness 98/100 · CI green · clean

✅ Suggested Action - Approve/Merge

  • safe to merge

Review summary
Adds a periodic sweep (`sweepStrandedNotificationDeliveries`) that rescues `notification_deliveries` rows stuck at `pending` when the accompanying `notify-deliver` enqueue was lost, mirroring the existing `sweepStrandedPendingClosures` pattern almost line-for-line (grace window, lookback bound, per-row audit-event spacing gate, fail-open on DB read errors, bounded scan limit). The new repository query correctly bounds both ends of the `createdAt` window and orders oldest-first under the limit, and it's wired into the `agent-regate-sweep` tick alongside its sibling repair scans with the same best-effort `.catch(() => null)` pattern so a failure here can't cost the tick its re-gate work. Tests seed rows directly via raw SQL to control `created_at`/`status` and cover grace/lookback edges, the already-delivered no-op case, DB-read failure, unreachable-JOBS-send failure, and the audit-ledger-read/-write failure arms — this is solid, well-targeted coverage of the real code path.

Nits — 4 non-blocking
  • The spacing gate does one extra `countRecentAuditEventsForActorAndTarget` DB round-trip per stranded row (up to 500/tick) — bounded and consistent with the sibling watchdog, but worth noting as the tick's main added DB cost.
  • Comment in stranded-delivery-sweep.ts:13 and repositories.ts:2319 references the '90-day retention sweep' only in prose, not as a shared named constant — fine for now but drifts silently if that retention window ever changes elsewhere.
  • The external brief's 'debug leftover console' flags on job-dispatch.ts:321 and stranded-delivery-sweep.ts:54 are false positives — both are the same structured `console.log`/`console.warn` JSON logging convention used by every sibling reconciler in this file, not debug leftovers.
  • Consider whether `STRANDED_NOTIFICATION_REQUEUED_EVENT` audit rows should eventually be pruned by the retention sweep like the deliveries themselves, to avoid unbounded audit_events growth for chronically-stuck rows (same question applies to the pending-closure sibling, so likely already handled/acceptable).

Decision drivers

  • ✅ Code review — No blockers (1 reviewer)
  • ✅ Gate result — Passing (No configured blocker found.)
Context & advisory signals — never blocks the verdict
Signal Result Evidence
Linked issue ✅ Linked #9320
Related work ✅ No active overlap found No same-issue or scoped active PR overlap found.
Change scope ✅ 20/20 Low review scope from cached public metadata (1 linked issue).
Validation posture ✅ 25/25 PR body includes validation/test evidence.
Contributor workload ✅ 10/10 Author activity: 80 registered-repo PR(s), 54 merged, 0 issue(s).
Contributor context ✅ Confirmed Gittensor contributor bitfathers94; Gittensor profile; 80 PR(s), 0 issue(s).
Improvement ✅ Minor risk: clean · value: minor · LLM: moderate
Linked issue satisfaction

Addressed
The PR adds a DB query for stale pending notification_deliveries, a sweep function mirroring sweepStrandedPendingClosures with grace period, lookback window, and re-sweep spacing (via audit-event check), fails open on DB read errors, filters by status:"pending" so already-delivered rows aren't re-enqueued, and wires the sweep into the periodic queue tick alongside the sibling reconcilers with the

Review context
  • Author: bitfathers94
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: TypeScript
  • Official Gittensor activity: 80 PR(s), 0 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Keep the PR focused and include validation evidence before maintainer review.
Signal definitions
  • Related work = same linked issue, overlapping active PRs, or title/path similarity.
  • Change scope = cached public metadata such as size labels, draft state, and review-burden hints.
  • Validation posture = whether the PR provides enough public validation/test evidence for maintainer review.
  • Contributor workload = public contributor activity and cleanup pressure, not a repo-wide quality failure.
  • Contributor context = public GitHub/Gittensor identity context; non-Gittensor status is not a blocker.
🧪 Chat with LoopOver

Ask LoopOver a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.

  • @loopover ask &lt;question&gt; answers contribution-quality Q&A with source citations and freshness.
  • @loopover chat &lt;question&gt; answers in natural prose from cached decision-pack facts via local inference (maintainer/collaborator; read-only).
  • A plain-language @loopover mention with a real question is routed to the closest matching read-only command automatically — no exact syntax required.

Full command reference: https://loopover.ai/docs/loopover-commands

🧪 Experimental — new and may change.

🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed


💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →.

Checked by LoopOver, a quiet PR intelligence layer for OSS maintainers.

  • Re-run LoopOver review

@loopover-orb loopover-orb Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LoopOver approves — the gate is satisfied and CI is green.

@loopover-orb
loopover-orb Bot merged commit 7e98041 into JSONbored:main Jul 27, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(notifications): a notification_deliveries row stuck at pending from a failed enqueue is never rescued

1 participant