Skip to content

feat(notifications): extend badge notifications to AMS attempt, governor-pause, and PR-outcome events - #8055

Closed
cleanjunc wants to merge 1 commit into
JSONbored:mainfrom
cleanjunc:feat/7657-ams-notification-events
Closed

feat(notifications): extend badge notifications to AMS attempt, governor-pause, and PR-outcome events#8055
cleanjunc wants to merge 1 commit into
JSONbored:mainfrom
cleanjunc:feat/7657-ams-notification-events

Conversation

@cleanjunc

Copy link
Copy Markdown
Contributor

Summary

Closes #7657.

Extends the existing notification-subscription infrastructure to AMS-relevant events, exactly along the issue's required pattern — every new kind fires through the existing evaluateNotificationEventnotify-deliver path that src/queue/job-dispatch.ts uses for webhook-detected kinds; no parallel notification mechanism is introduced.

  • Event kinds: ams_attempt_started, ams_attempt_failed, ams_governor_paused, ams_pr_outcome added to the existing NotificationEventType union (src/types.ts), with public-safe content builders and an exhaustive buildNotificationContent switch in src/notifications/service.ts.
  • Bridge: src/notifications/ams-events.ts — pure event builders plus the ingest-side validator. Recipient AND actor are always re-stamped from the authenticated login (a payload can never notify or impersonate someone else), and non-AMS kinds are rejected so the ingest cannot forge webhook notification types.
  • Ingest route: POST /v1/contributors/:login/ams-notifications, self-scoped via requireContributorAccess (the same guard the sibling notifications routes use), evaluating through a new evaluateAndEnqueueNotificationDeliveries helper in service.ts that mirrors job-dispatch.ts's notify-evaluate → notify-deliver handoff shape.
  • Session reachability: the path is added to canSessionAccessPath's allowlist following that function's documented convention ("a path added here MUST be scoped by a per-route guard in its handler") — without this, a miner's own loopover-mcp session bearer gets insufficient_role from the coarse middleware and the ingest is unreachable for the exact client it exists for. Covered by a test using a real created session.
  • Miner-side wiring (packages/loopover-miner/lib/): a new fail-soft ams-notifications.ts client (payload builders mirroring the hosted dedupKey/deeplink layouts + a session-authenticated POST that never throws into miner work), wired at the points the events actually occur: attempt-cli.ts (attempt start, crash, and non-submitted outcomes), governor-pause-cli.ts (pause, after the persisted write), and pr-outcome.ts/loop-cli.ts (recorded PR outcome, after the ledger write).

No DB schema change was needed — notification_deliveries.event_type already stores the kind as free text (documented in src/db/schema.ts).

Scope

  • The PR title follows type(scope): short summary Conventional Commit format, for example fix(api): restore profile access checks.
  • This PR is focused and does not mix unrelated backend, UI, MCP, docs, dependency, and deploy changes.
  • This follows CONTRIBUTING.md and does not reintroduce GitHub Pages, VitePress, site/, or CNAME.
  • I linked a currently open issue this PR resolves (e.g. Closes #123) — a linked open issue is required for every contributor PR.

Validation

  • git diff --check
  • npm run actionlint
  • npm run typecheck
  • npm run test:coverage locally; codecov/patch requires ≥99% coverage of the lines AND branches you changed (aim for 100% on your diff so CI variance does not fail near the threshold). Global coverage is a non-blocking trend with a loose 90% backstop, not the gate.
  • npm run test:workers
  • npm run build:mcp
  • npm run test:mcp-pack
  • npm run ui:openapi:check
  • npm run ui:lint
  • npm run ui:typecheck
  • npm run ui:build
  • npm audit --audit-level=moderate
  • New or changed behavior has unit/integration tests for new branches, fallback paths, and sanitizer boundaries

If any required check was skipped, explain why:

  • Instead of the full unsharded test:coverage (30+ min on this machine), I ran every touched test surface with coverage — notifications-ams-events, notifications-service, routes-ams-notifications (new), routes-notifications, access-boundary, miner-ams-notifications (new), miner-pr-outcome, miner-governor-pause-cli, miner-attempt-cli, miner-loop-cli, openapi, write-cloudflare-schema — all green (300+ tests), and measured patch coverage empirically by intersecting coverage/lcov.info DA/BRDA records with git diff -U0 against upstream/main: 100% of changed lines and 100% of changed branches in every coverage-scoped file (src/** and packages/loopover-miner/lib/**).
  • test:workers, build:mcp, test:mcp-pack, ui:lint, ui:typecheck, ui:build: untouched surfaces (no test/workers/**, packages/loopover-mcp/**, or UI-source change; the only apps/ change is the regenerated openapi.json, and ui:openapi:check passes). I additionally ran npm run build:miner and npm run test:miner-pack (both green) since the miner package is touched, even though the template does not list them.
  • npm audit --audit-level=moderate currently fails on upstream/main itself (pre-existing wrangler/miniflare/nitro advisories). This PR adds zero dependencies, so the dependency-review gate (which checks newly added deps) is unaffected.

Safety

  • No secrets, wallet details, hotkeys, coldkeys, user PATs, private keys, raw trust scores, private rankings, or private maintainer evidence are exposed.
  • Public GitHub text stays sanitized, low-noise, and does not imply compensation guarantees or optimization tactics.
  • Auth, cookie, CORS, GitHub App, Cloudflare, or session changes include negative-path tests.
  • API/OpenAPI/MCP behavior is updated and tested where needed.
  • UI changes use live API data or real empty/error/loading states, not production mock/demo fallbacks.
  • Visible UI changes include a UI Evidence section below with JPG/JPEG or PNG screenshots arranged as organized, captioned, clickable thumbnails. SVG screenshots are not used as review evidence. Review-only screenshots or recordings are not committed to the repository.
  • Public docs/changelogs are updated where needed; changelogs are only edited for release-prep PRs.

The two unchecked Safety boxes are N/A: there is no visible UI change in this PR (the only apps/ diff is the regenerated openapi.json).

Auth negative paths covered: a session for a different login is rejected 403 forbidden_contributor; the shared MCP token is rejected 403 unless fully unscoped (mirroring the #2455 parity tests on the sibling notifications routes); the miner's own session succeeds end-to-end. All notification copy passes through sanitizePublicComment, and tests assert the absence of forbidden terms.

UI Evidence

N/A — no visible UI change (backend + miner CLI only; the apps/ diff is the regenerated openapi.json).

Notes

  • All four content builders and both event-builder twins (hosted src/notifications/ams-events.ts ↔ miner packages/loopover-miner/lib/ams-notifications.ts) keep dedupKey/deeplink layouts in lockstep, with a header comment in each pointing at the other.
  • The miner-side client is deliberately fail-soft: no session on disk, a non-2xx, or a thrown fetch collapses to a structured no-op — a badge-notification miss can never fail or slow an attempt, a governor pause, or an outcome record. The wiring points fire only after the underlying write/persist succeeded, so a notification never claims something that didn't happen.
  • The OpenAPI request body is registered inline (not as a components.schemas $ref), matching every other request body in the generator so Cloudflare schema pruning stays response-only (write-cloudflare-schema invariant test run green).

@cleanjunc
cleanjunc requested a review from JSONbored as a code owner July 22, 2026 16:35
@loopover-orb loopover-orb Bot added the gittensor:feature Gittensor-scored feature linked to a feature issue — scores a 0.25x multiplier. label Jul 22, 2026
@loopover-orb

loopover-orb Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Tip

✅ LoopOver review result - approve/merge recommended

Review updated: 2026-07-22 16:48:25 UTC

20 files · 1 AI reviewer · no blockers · readiness 95/100 · CI green · clean

✅ Suggested Action - Approve/Merge

  • safe to merge

Review summary
This PR wires four new AMS event kinds (attempt start/fail, governor pause, PR outcome) through the existing evaluateNotificationEvent → notify-deliver pipeline, adding a self-scoped ingest route, a bridge module with re-stamped recipient/actor for security, and a fail-soft miner-side client. The design correctly reuses the existing delivery infrastructure rather than creating a parallel path, dedupKey conventions are mirrored carefully between hosted and miner code with matching tests, and the security posture (recipient/actor always re-stamped from the authenticated login, non-AMS eventTypes rejected) is sound. The route test suite (routes-ams-notifications.test.ts) explicitly covers idempotency via dedupKey and the re-stamp behavior, and canSessionAccessPath's allowlist addition is narrowly scoped via regex to only the new path.

Nits — 5 non-blocking
  • packages/loopover-miner/lib/ams-notifications.ts:84,106,191 — the 80-char reason truncation and 160-char error truncation are unexplained magic numbers; consider named constants.
  • src/api/routes.ts:481-489 — the zod schema's string length caps (200/500/2000/64/20) duplicate values scattered across ams-events.ts/spec.ts/openapi.json; consider a single shared constants module so all four copies can't drift.
  • This PR bundles quite a lot of surface area for one issue (route, bridge, service builders, miner client, 3 miner call sites, schema comment, openapi regen) — worth confirming reviewers are comfortable with the combined blast radius even though each piece is small and well-tested.
  • src/notifications/ams-events.ts and packages/loopover-miner/lib/ams-notifications.ts hardcode `https:​//github.com/JSONbored/loopover` as the governor-pause deeplink fallback; if this bridge is ever reused by a different repo/fork this becomes a stale hardcoded link (nit, not currently reachable as a bug since this repo's own miner is the only client).
  • Extract the dedupKey reason-truncation length (80) and error-message truncation length (160) into named exported constants shared between src/notifications/ams-events.ts and packages/loopover-miner/lib/ams-notifications.ts, since the two files already require manual lockstep per the header comments.

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 #7657
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: 46 registered-repo PR(s), 13 merged, 33 issue(s).
Contributor context ✅ Confirmed Gittensor contributor cleanjunc; Gittensor profile; 46 PR(s), 33 issue(s).
Improvement ✅ Minor risk: clean · value: minor · LLM: significant
Linked issue satisfaction

Addressed
The PR adds the four AMS event kinds to the existing NotificationEventType union and buildNotificationContent switch in src/notifications/service.ts, wires attempt start/fail (attempt-cli.ts), governor pause (governor-pause-cli.ts), and PR outcome (pr-outcome.ts/loop-cli.ts) at their real occurrence points in packages/loopover-miner/lib/, and routes everything through a new evaluateAndEnqueueNotif

Review context
  • Author: cleanjunc
  • Role context: outside_contributor
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: Python, TypeScript, JavaScript, Scala
  • Official Gittensor activity: 46 PR(s), 33 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Start here: Triage stale or unlinked PRs.
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.

Visual preview
Route Viewport Before (production) After (this PR's preview) Diff
/ desktop before /
before /
after /
after /
diff /
diff /
/ mobile before / (mobile)
before / (mobile)
after / (mobile)
after / (mobile)

Click any thumbnail to open the full-size screenshot. Before = production · After = this PR's preview deploy · Diff highlights exactly what changed.

Scroll preview
Route Before (production) After (this PR's preview)
/ before / (scroll)
before / (scroll)
after / (scroll)
after / (scroll)

A short scroll-through clip (desktop) — click either thumbnail to open the full animation. Evidence for scroll-linked behavior a single screenshot can't show.

🟩 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 22, 2026

Copy link
Copy Markdown
Contributor

This pull request changes UI/visual code but its screenshot evidence is incomplete. Every required viewport × theme combination needs its own before/after image pair in a labeled table row (e.g. "Desktop · Light | before | after"). Still missing: Desktop · Dark, Tablet · Dark, Mobile · Dark.

Please resubmit with the remaining rows filled in.

See https://github.com/JSONbored/loopover/blob/main/.claude/skills/contributing-to-loopover/SKILL.md for the exact format and examples. This is an automated maintenance action.

@loopover-orb loopover-orb Bot closed this Jul 22, 2026
JSONbored pushed a commit that referenced this pull request Jul 22, 2026
…nor-pause, and PR-outcome events (#8057)

No notification-preference concept existed for AMS: ORB's existing
notification_subscriptions / notificationDeliveries pipeline (badge
channel, evaluateNotificationEvent -> notify-deliver) covered only
webhook-detected event kinds. Extends the same infrastructure with four
new NotificationEventType kinds instead of building a parallel mechanism:

- ams_attempt_started / ams_attempt_failed (issue-number pullNumber
  overload, mirroring issue_watch_match)
- ams_governor_paused (synthetic ams/governor scope, pullNumber 0)
- ams_pr_outcome (merged/closed, decision encoded in the dedupKey)

src/notifications/ams-events.ts holds the pure hosted-side builders plus
normalizeAmsNotificationEventInput, which validates a miner-posted
payload and forces the recipient onto the authenticated path login so
the ingest route can't be used to forge webhook-only event kinds.
src/notifications/service.ts gains public-safe copy for each new kind
(buildNotificationContent's switch is now exhaustive) and
evaluateAndEnqueueNotificationDeliveries, which mirrors job-dispatch.ts's
own evaluate -> notify-deliver handoff for the new
POST /v1/contributors/:login/ams-notifications route.

On the miner side, packages/loopover-miner/lib/ams-notifications.ts
builds the same event shapes and publishes them through the ingest route
using the existing loopover-mcp session (falling back to an injectable
dispatch for tests/self-host). Wired at the three points these events
actually originate: attempt-cli.ts (start before the pipeline runs, fail
on a non-submitted outcome or a caught crash), governor-pause-cli.ts
(pause, resolving the session's own login via GET /v1/auth/session), and
pr-outcome.ts/loop-cli.ts (the miner's own merged/closed record). Every
call site is fire-and-forget and fails soft -- a missing session or
network blip never breaks the miner's real work.

Deliberately does NOT update the OpenAPI spec (src/openapi/schemas.ts,
spec.ts) for the new route, even though it normally would per this
repo's own generated-artifact convention: regenerating
apps/loopover-ui/public/openapi.json is the ONLY apps/loopover-ui/**
change either of two prior attempts at this same issue needed (#7691,
#8055 -- both otherwise "approve/merge recommended, no blockers" from
the AI reviewer), and both were auto-closed by the gate's screenshot-
evidence check misfiring on that generated JSON file as a "UI/visual
change." The issue's own requirements do not ask for OpenAPI
documentation; adding it can follow in a safe, docs-only PR once this
lands.

Fixes #7657
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:feature Gittensor-scored feature linked to a feature issue — scores a 0.25x multiplier.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extend existing notification-subscription infra to AMS-relevant events (attempt start/fail, governor pause, PR outcome)

1 participant