Skip to content

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

Closed
shin-core wants to merge 1 commit into
JSONbored:mainfrom
shin-core:fix/approval-queue-notify-deliver-10025
Closed

fix(services): enqueue notify-deliver for the approval-queue staged-action and reminder badges#10173
shin-core wants to merge 1 commit into
JSONbored:mainfrom
shin-core:fix/approval-queue-notify-deliver-10025

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) -- directly 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'  guard: a
dedup hit or a rate-limit-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 10:53
@superagent-security

Copy link
Copy Markdown
Contributor

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

@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

❌ Patch coverage is 81.81818% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.60%. Comparing base (7510075) to head (2e51a95).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
src/services/agent-action-executor.ts 75.00% 0 Missing and 1 partial ⚠️
src/services/agent-approval-queue.ts 85.71% 0 Missing and 1 partial ⚠️

❌ Your patch check has failed because the patch coverage (81.81%) is below the target coverage (99.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@             Coverage Diff             @@
##             main   #10173       +/-   ##
===========================================
- Coverage   92.21%   80.60%   -11.62%     
===========================================
  Files         932      285      -647     
  Lines      114104    59322    -54782     
  Branches    27559     8923    -18636     
===========================================
- Hits       105220    47815    -57405     
- Misses       7583    11205     +3622     
+ Partials     1301      302      -999     
Flag Coverage Δ
backend 96.95% <81.81%> (+1.27%) ⬆️

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

Files with missing lines Coverage Δ
src/types.ts 100.00% <ø> (ø)
src/services/agent-action-executor.ts 96.69% <75.00%> (-0.24%) ⬇️
src/services/agent-approval-queue.ts 97.56% <85.71%> (-0.57%) ⬇️

... and 779 files with indirect coverage changes

@loopover-orb

loopover-orb Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Caution

🛑 LoopOver review result - fixes required

Review updated: 2026-07-31 11:10:10 UTC

5 files · 1 AI reviewer · no blockers · CI failing · unstable

🛑 Suggested Action - Fix Blockers

Review summary
This PR wires `notify-deliver` enqueue calls into the two approval-queue notification insert sites (`stageForApproval` and `sweepStaleApprovalQueue`) that were previously missing them, matching the existing `created && status === "pending"` guard pattern from `evaluateAndEnqueueNotificationDeliveries`. The fix is correct and well-traced: both call sites now check the actual returned `delivery.status` before enqueueing, correctly skip on dedup hits (`created: false`), and fail open with a caught, logged warning so a queue-send failure never aborts staging or the reminder count. Tests exercise the real dedup path, the failure path, and a full end-to-end regression (stage → deliver job → feed visibility), which is exactly the coverage this kind of wiring fix needs.

Nits — 3 non-blocking
  • src/services/agent-action-executor.ts:1487 and src/services/agent-approval-queue.ts:639 hardcode the 200-char truncation length for the warn message inline; consider hoisting it to a shared constant given it's duplicated across both new call sites.
  • The `console.warn` calls in both files are intentional structured logging (matching the existing pattern elsewhere in the codebase, e.g. stranded-delivery-sweep.ts), not debug leftovers — but consider extracting a shared helper since the JSON.stringify shape is duplicated verbatim in two files.
  • Consider factoring the duplicated `{ type: "notify-deliver", requestedBy: "agent-approval", deliveryId }` send-and-catch-and-warn block (identical in agent-action-executor.ts and agent-approval-queue.ts, twice within the latter) into a small shared helper in src/notifications/service.ts to avoid drift between the three call sites.

CI checks failing

  • codecov/patch — 81.81% of diff hit (target 99.00%)

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

Addressed
The diff adds the required notify-deliver enqueue at both stageForApproval and sweepStaleApprovalQueue, gated on created:true and status 'pending', with best-effort try/catch producing the specified console.warn shape and preserving dedup/no-op behavior on created:false, matching the issue's required pattern and adding regression tests confirming feed visibility.

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: not available
  • Official Gittensor activity: 78 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 commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

LoopOver is closing this pull request on the maintainer's behalf (CI is failing (codecov/patch)). This is an automated maintenance action — to pursue this change, please open a new pull request with the issues resolved. Closed PRs may be analyzed later to improve review accuracy, but they are not automatically reopened or re-reviewed.

@loopover-orb loopover-orb Bot closed this Jul 31, 2026
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