Skip to content

fix(services): enqueue notify-deliver for the approval-queue staged-action and reminder badges - #10182

Merged
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
shin-core:fix/approval-queue-notify-deliver-10025-v2
Jul 31, 2026
Merged

fix(services): enqueue notify-deliver for the approval-queue staged-action and reminder badges#10182
loopover-orb[bot] merged 1 commit into
JSONbored:mainfrom
shin-core:fix/approval-queue-notify-deliver-10025-v2

Conversation

@shin-core

Copy link
Copy Markdown
Contributor

What & why

A notification_deliveries row is only visible in the recipient's feed once something promotes it out of pending — and the only thing that does is a notify-deliver queue job. Every insert in src/notifications/service.ts is paired with an enqueue (evaluateAndEnqueueNotificationDeliveries, the notify-evaluate handler). The approval queue's two inserts were not:

Neither passed a status, so both rows were created at "pending", and neither sent a notify-deliver job. Both badges therefore sat invisible in notification_deliveries. The only thing that eventually delivered them was sweepStrandedNotificationDeliveries, whose own doc frames it as a rescue for a failed enqueue and which deliberately waits STRANDED_NOTIFICATION_GRACE_MS (10 min). So these notifications were structurally dependent on an unrelated self-heal, delayed 10+ minutes, and would vanish entirely if that sweep were ever scoped — directly contradicting agent-approval-staleness.ts's framing of the staging badge as the notification the maintainer "gets."

The fix

At both sites, when insertNotificationDeliveryIfAbsent reports created: true and the returned delivery's status is "pending", send { type: "notify-deliver", requestedBy: "agent-approval", deliveryId: delivery.id } on env.JOBS — mirroring evaluateAndEnqueueNotificationDeliveries. A dedup hit (created: false) or a rate-limit-suppressed non-pending row enqueues nothing, preserving the "exactly one badge per (PR, actionClass)" / "one badge per reminder bucket" contracts.

Both sends are best-effort: a rejected env.JOBS.send is caught, emits one structured console.warn (event: "approval_notification_enqueue_failed" with deliveryId/repoFullName/pullNumber), and does not abort staging (stageForApproval still returns true) or the sweep loop (still counts the reminder, continues to the next row). The notify-deliver requestedBy union is extended with "agent-approval".

Unchanged: the two dedup keys, insertNotificationDeliveryIfAbsent, deliverNotification, buildNotificationFeed, and sweepStrandedNotificationDeliveries.

Tests (agent-approval-queue.test.ts, approval-queue-staleness.test.ts)

  • Staging an auto_with_approval action enqueues exactly one notify-deliver carrying the inserted delivery's id; a second staging (dedup) enqueues none.
  • A row aged past APPROVAL_REMINDER_INTERVAL_MS enqueues exactly one reminder notify-deliver; a second sweep in the same bucket enqueues none.
  • A rejected env.JOBS.send on either path warns approval_notification_enqueue_failed and does not change the return (queued / reminded: 1).
  • REGRESSION: after staging + running deliverNotification for the enqueued id, buildNotificationFeed for the recipient now contains the staged-action item — against today's code the feed is empty (the row is still pending).
  • All new assertions fail on main.

Validation

  • Diff coverage on both service files is 100% line and branch (the created+pending / created+suppressed / not-created / send-rejects arms per call site). types.ts is a type-only change.
  • npm run typecheck clean; npm run engine-parity:drift-check, ui-derived-types:check, and manifest:drift-check all pass (the types.ts change touches no generated artifact); dead-exports:check clean; both suites (117 tests) green.
  • git diff --check clean; no schema/migration change.

Closes #10025

…ction and reminder badges

A notification_deliveries row is only visible in the feed once notify-deliver
promotes it out of pending, and every other insert in the codebase pairs the insert
with an enqueue. The approval queue's two inserts did not: stageForApproval's
staged-action badge and sweepStaleApprovalQueue's JSONbored#9032 reminder badge were both
created at pending with no notify-deliver job, so they sat invisible until the
stranded-delivery sweep rescued them 10+ minutes later (a rescue for a FAILED enqueue,
not the primary path) -- contradicting the staleness module's framing of the staging
badge as the notification the maintainer gets.

Enqueue one notify-deliver per freshly-created pending delivery at both sites, mirroring
evaluateAndEnqueueNotificationDeliveries' created + pending guard: a dedup hit or a
suppressed non-pending row enqueues nothing. Best-effort: a rejected send is caught,
warns approval_notification_enqueue_failed, and does not abort staging (still returns
true) or the sweep loop (still counts the reminder). Extend the notify-deliver
requestedBy union with agent-approval. The dedup keys, the insert helper,
deliverNotification, buildNotificationFeed, and the stranded sweep are unchanged.

Closes JSONbored#10025
@shin-core
shin-core requested a review from JSONbored as a code owner July 31, 2026 11:16
@superagent-security

Copy link
Copy Markdown
Contributor

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

@loopover-orb

loopover-orb Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Tip

✅ LoopOver review result - approve/merge recommended

Review updated: 2026-07-31 11:29:49 UTC

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

✅ Suggested Action - Approve/Merge

  • safe to merge

Review summary
This PR closes a real gap: both notification-delivery inserts in the approval-queue path (stageForApproval and sweepStaleApprovalQueue's reminder branch) never enqueued a notify-deliver job, leaving badges stranded until the unrelated 10-minute stranded-delivery sweep rescued them. The fix mirrors the existing evaluateAndEnqueueNotificationDeliveries pattern (`created && status === "pending"`), is best-effort (a failed send is caught and logged, never aborts the caller), and is backed by new tests exercising the enqueue, dedup-skip, and send-failure paths plus an end-to-end feed-visibility regression test. The `/* v8 ignore next */` comments on the `status === "pending"` checks are justified in the diff's own comments — both call sites' inserts never pass a status, so the false arm is genuinely unreachable from these callers, matching the existing convention already used elsewhere in this file.

Nits — 3 non-blocking
  • The two `console.warn(JSON.stringify({...message: errorMessage(error).slice(0, 200)}))` blocks in agent-action-executor.ts:1492 and agent-approval-queue.ts:642 duplicate the same 200-char truncation magic number and warn-shape; consider a small shared helper if this pattern grows a third call site.
  • The three `services(approval-queue): enqueue notify-deliver for the staged-action and reminder badges so they reach the feed #10025` doc comments in agent-approval-queue.ts and agent-action-executor.ts are fairly verbose for a mirrored one-line guard; a shorter pointer to the shared contract (e.g. 'mirrors evaluateAndEnqueueNotificationDeliveries') would read faster on a second pass.
  • Consider extracting the repeated `{ type: "notify-deliver", requestedBy: "agent-approval", deliveryId }` send + catch/warn shape (agent-action-executor.ts:~1490, agent-approval-queue.ts:~640) into a tiny shared helper (e.g. `enqueueApprovalNotifyDeliver(env, delivery, context)`) since it's now duplicated verbatim across both call sites.

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 #10025
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: 88 registered-repo PR(s), 68 merged, 0 issue(s).
Contributor context ✅ Confirmed Gittensor contributor shin-core; Gittensor profile; 88 PR(s), 0 issue(s).
Improvement ✅ Minor risk: clean · value: minor · LLM: moderate
Linked issue satisfaction

Addressed
Both stageForApproval and sweepStaleApprovalQueue now enqueue a notify-deliver job guarded by created && status==="pending", with best-effort catch/console.warn using the required event name and fields, dedup keys unchanged, and no changes to insertNotificationDeliveryIfAbsent/deliverNotification/buildNotificationFeed/sweepStrandedNotificationDeliveries; new tests cover single-enqueue-on-create, n

Review context
  • Author: shin-core
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: TypeScript, JavaScript, Solidity, Dart, Python, CSS, PHP, Rust
  • Official Gittensor activity: 88 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 <question> answers contribution-quality Q&A with source citations and freshness.
  • @loopover chat <question> 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 added the gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. label Jul 31, 2026
@codecov

codecov Bot commented Jul 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.60%. Comparing base (c1484f5) to head (cde3959).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10182      +/-   ##
==========================================
+ Coverage   80.44%   80.60%   +0.15%     
==========================================
  Files         282      285       +3     
  Lines       58764    59316     +552     
  Branches     6965     7203     +238     
==========================================
+ Hits        47274    47811     +537     
- Misses      11199    11205       +6     
- Partials      291      300       +9     
Flag Coverage Δ
backend 97.28% <100.00%> (?)

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

Files with missing lines Coverage Δ
src/services/agent-action-executor.ts 96.92% <100.00%> (ø)
src/services/agent-approval-queue.ts 98.13% <100.00%> (ø)
src/types.ts 100.00% <ø> (ø)

@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 ffb4a0c into JSONbored:main Jul 31, 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.

services(approval-queue): enqueue notify-deliver for the staged-action and reminder badges so they reach the feed

1 participant