Skip to content

pm-stack notifications Phase 1: wire the missing producers — queue escalations + stack-health into the throat, fix subscription class backfill, answerable needs-drew pushes #8568

Closed

Description

@dezren39

Phase 1 — the stack speaks for itself (no platform move)

Design: pm-stack-notifications-design-2026-11-11.md (goal keep-the-four-repos-healthy, files/). Parent design context: #1254 (closed — PWA + push design), #3676 (closed — alert throat), #1226 (closed — needs-drew census), #8097 (queue/lane record where the 268-task audit landed).

What recon established (2026-11-11, wire-verified)

The push machinery from #1254/#3676 EXISTS and works: POST /api/alerts throat (Bearer intake) → Supabase alerts store → in-aggregator engine tick (60s) → Web Push (VAPID, src/push.ts, /sw.js). Drew's phone holds the one live subscription (Android Chrome / FCM, subscribed 2026-11-01; pushes delivered 2026-11-01 self-test and 2026-11-09 globalping criticals). Drew got no pushes on 2026-11-11 because of four specific gaps — this phase closes all four:

  1. His subscription predates the classes. NOTIFICATION_CLASS_DEFAULTS turns needs-drew / quota-wall / quota-near-wall / stack-health / blocked-age ON for new rows, but classEnabled() preserves old rows: for the 2026-11-01 subscription every class except incident is effectively OFF. The candidates are derived every tick (buildNotificationCandidates) and filtered out for his only subscription.
  2. Queue escalations never enter the stack. The aggregator's needs-drew census reads GitHub labels (user/review, user/escalated) via the fleet feed. The 268 "waiting on Drew" tasks from the 2026-11-11 audit live in the fleet-queue Turso DB; the broker / repo-queue block path has NO emission into the throat or the feed.
  3. Nobody posts stack-down. The only incident source that has ever posted is globalping-watch (public endpoints only). The board's own ~dozen 503 episodes on 2026-11-11 produced zero incidents — the aggregator cannot report itself, and no on-host sentinel watches it or its siblings.
  4. stack-health is a class with no producer. Watchdog diagnoses exist (src/watchdog.ts, needs-orchestrator tier items) but nothing turns them into notification candidates/incidents.

Work

  • Broker / repo-queue block-with-escalation path POSTs a needs-drew event to the throat (POST /api/alerts, intake token) at block time, carrying: ledger id, the question, the option list, issue links. The task row records the ledger id so an answer can unblock it mechanically.
  • Subscription class backfill: subscriptions created before a class existed get the reviewed defaults for that class (or a one-tap "apply reviewed defaults" on /alerts/preferences). Drew's existing phone subscription must end with needs-drew + quota-wall + stack-health ON without re-subscribing.
  • Independent stack-health sentinel: a tiny systemd user unit (NOT inside the aggregator) probing loopback health of aggregator :4870, projector :7801, Kaneo :5173, dispatch :4879, OpenCode :13420, queue broker :4801 every ~30s, POSTing stack-health incidents to the throat on transitions. Honest limit: it cannot report the aggregator itself being dead to the throat — that case is Phase 2's dead-man's switch.
  • stack-health candidate producer in the aggregator from the watchdog diagnoses.
  • Answerable choices v1: a needs-drew push carries the question; ≤2 options ride as notification actions, more options deep-link to an answer page on the board listing every option as a tap target. Answer endpoint POST /api/needs-drew/:ledgerId/answer (per-question token from the push payload, single-question scope) writes an answers outbox in aggregator state; the fleet-feed collector carries answers into fleet-feed.json; the dropped-thread catcher applies them to pending-questions.json (status answered + answer text) and unblocks the originating queue task.

Acceptance (Drew's terms)

  • Block a queue task as escalated-to-Drew → a push with the question and answer choices reaches Drew's phone in under a minute, no cron involved anywhere in the path.
  • Tap an answer on the phone → the ledger shows the item answered and the blocked task unblocks, without Drew opening this chat.
  • Kill the projector → a stack-health push arrives in under a minute.
  • A sole-door pool hits a quota wall → a quota-wall push arrives in under a minute (proving the already-built candidate path end to end, live).

Activity

  1. added
    kind/featureNew feature or capability request
    priority/normalOrdinary priority (the default)
    app/pm-stackpm-stack (Pad/Grist) in developing-today/code
    on Nov 11, 2026
  2. developing-today commented on Nov 11, 2026

    @developing-today
    Contributor
  3. dezren39 commented on Nov 11, 2026

    @dezren39
    MemberAuthor

    Phase 1 progress — step 1 (subscription class backfill): DONE, live.

    Drew's existing phone subscription (id cf18884d-214b-4402-95f1-3c3d1eb25aa6, created 2026-11-01) preserved in place; only its classes flags changed, via the aggregator's own Supabase path:

    • Before: {"incident": true} — every other class effectively OFF (the 2026-11-11 silence).
    • After: {"incident": true, "needs-drew": true, "quota-wall": true, "quota-near-wall": true, "stack-health": true, "blocked-age": true} — the reviewed NOTIFICATION_CLASS_DEFAULTS for every class the row didn't name; nothing the row named was altered.

    Read back twice: direct store query and the live GET /api/push/subscriptions projection agree. No re-subscribe was needed. (His quiet-hours pref is enabled: false, so no class is time-gated for him.)

  4. dezren39 commented on Nov 11, 2026

    @dezren39
    MemberAuthor

    Phase 1 progress — catcher answer-application is live.

    • The dropped-thread catcher's body (job dropped-thread-catcher, hourly) now carries Step 2B — Apply needs-Drew push answers: on each run it reads the answers section of ~/.local/state/pm-aggregator/fleet-feed.json, and for each new answer (deduped via a new appliedPushAnswers state key): writes the ledger item answered in the same shape a chat answer uses (status: "answered", answer = chosen option label or free text, answered_at, via: "push"), unblocks the originating queue task found by progress.needs_drew.ledger_id with the audited fleet queue unblock verb (reason names Drew's answer), and records the outcome. Fail-soft: an absent answers section is a no-op, so the step is safe before the feed producer lands. The run-log line gained answers applied <n>.
    • Verified by cron.view read-back after cron.update: Step 2B present, all prior steps unchanged.
  5. added a commit that references this issue on Nov 11, 2026
  6. dezren39 commented on Nov 11, 2026

    @dezren39
    MemberAuthor

    Fleet half of Phase 1 landed — PR #8598, merged as ab15e73114a5c3234f7a18c20667cfb6e4d942ad.

    CLI half (live on CLI binary replacement): repo-queue block gains --ledger-id / --question / --context / --options-json / --links-json. An escalated-to-user block carrying ledger-id + question now (a) sends needs_drew in the /block body, (b) merges needs_drew: {ledger_id} into the progress object so the current broker stamps the ledger id onto the task row with no broker change, and (c) after the block lands, posts to the throat per the fixed contract (POST 127.0.0.1:4870/api/alerts, FLEET_ALERTS_URL override, source fleet-queue, key needs-drew:<ledgerId>, severity warning). The intake token (pm-aggregator.alerts-intake-token — verified present in the secrets broker's name list) resolves by name in-process via fleet_secrets::Resolver::default_chain, the machinery behind fleet secrets get. Emission failure warns on stderr and still exits 0; stdout shape unchanged; escalated blocks without the flags are byte-for-byte the old behavior.

    Broker half (live only at the next broker binary replacement — the coordinated switch): the /block route raises the same post fire-and-forget on a spawned thread after a successful escalated block with a needs_drew payload, token via the in-process DirectSecrets source, failures to stderr only. One wrinkle found on contact: dispatch() hands /block to the Turso backend before the Postgres match arm when QUEUE_BROKER_BACKEND=turso, so the hook was applied on both branches — a Postgres-arm-only hook would never have fired on a Turso-backed broker.

    Verification: cargo test -p fleet-queue --all-features — 257 lib tests passed (7 new needs_drew tests pin the exact throat body shape) + 2 broker_bin_args; default-features run 30 passed; cargo build --release -p fleet clean. No live block was performed (it would block a real task and push a phone).

    Staged, not deployed: release binary at ~/tools/staging/fleet-8568/fleet (sha256 5735008dd51b85a11ee2412351e130dd416fab5155aca826b2ba691e683a0b90, 6,982,776 bytes). ~/.local/bin/fleet untouched, queue-broker not restarted — deployment is the coordinated switch's step, not this PR's.

    Contract notes: everything in the fixed wire contract held up. answerUrl is returned from post_needs_drew when the throat includes one (top-level or nested under alert); a successful raise without one returns an empty string rather than an error. The throat body's body field is context-when-present, else the blocker text, per the contract wording.

  7. dezren39 commented on Nov 11, 2026

    @dezren39
    MemberAuthor

    Aggregator half landed — PR #8597, merged ef02d88

    Implemented the full aggregator side of Phase 1 against the fixed wire contract (intake extensions on POST /api/alerts, POST /api/needs-drew/<ledgerId>/answer, GET /answer/<ledgerId>?t=<token>, feed answers):

    • Needs-Drew question store — appended to the existing src/needs-drew.ts (that file already held the pm-stack: one Needs-Drew queue of record — reconcile user/* labels with the aggregator Needs-you page #1226 label census, so the store was added as a new section rather than overwriting it): idempotent raise (token minted once via crypto.randomUUID), first-answer-wins, open list < 7 days, atomic writes; config needsDrewFile (PM_AGG_NEEDS_DREW_FILE).
    • Stack-health store — new src/stack-health.ts with SENTINEL_SERVICE_IDS (aggregator, projector, kaneo, dispatch, opencode, queue-broker), previous-state return, config stackHealthFile.
    • Intake — extensions validated after the unchanged incident insert (bad extension = 400; store failure logged, never fails the post); needsDrew response carries {ledgerId, answerUrl}; stackHealth "up" closes the open incident via AlertsStore.closeOpenIncidentByKey; both trigger requestAlertTick() (new export, hooks the engine's guarded tick).
    • Candidates — needs-drew breakthrough candidates with the needsDrew payload field; sentinel-down service:<id> candidates; health-derived candidate suppressed for sentinel-covered services with a sentinel record (full state map in the snapshot).
    • Push — PushPayload.answer set from the store token; payload URL becomes the token-carrying answer URL. Service worker — first 2 options become notification actions; an action tap POSTs the answer (token parsed from the answer URL into notification data) and closes.
    • Answer page — server-rendered, escaped; 403 without rendering the question on unknown id/token mismatch; answered state shown once recorded.
    • Feed — collector reads the needs-drew store fail-soft and emits top-level answers: [{ledgerId, optionId, freeText, answeredAt, via}].
    • Sentinel — new scripts/stack-sentinel.ts (30s loop) with the live-verified alive-sets: dispatch / 404 = alive, queue-broker probed on its tailnet IP only (any HTTP response = alive; 401 expected), aggregator /board with a 15s timeout. First run baselines without posting unless a service is down; unposted transitions retry each round.

    Evidence

    • Typecheck output byte-identical to an origin/main baseline (no new errors).
    • 208/208 tests pass across touched areas + 45/45 boot/health (free freshness port; 4871 is held by the live service).
    • Synthetic derivation proof: needs-drew candidate shaped per contract, service:kaneo exactly once, health:kaneo suppressed, health:grist untouched — PROOF OK. Store proof + sentinel dry run (against a dead mock throat, never the live one) pass: dispatch 404=up, queue-broker 401=up, projector 3s-timeout recorded down with post pending retry.

    Deploy read-backs (after the one permitted pm-aggregator restart)

    • Primary checkout synced by pm-git-sync to ab15e73 (includes this merge).
    • GET /api/alerts.json → 200.
    • GET /api/push/subscriptions → the subscription row carries all 6 classes (incident, needs-drew, quota-wall, quota-near-wall, stack-health, blocked-age).
    • GET /sw.js → contains the new answer-action handling.
    • GET /answer/nonexistent?t=x → 403.
    • No test push sent; no test needsDrew/stackHealth events posted to the live throat; no service other than pm-aggregator restarted.

    One contact note: during the sentinel dry run the projector probe timed out once at 3s while the verified fact is a 200 — probe flakiness under load, handled by design (recorded as a pending down post, retried next round).

  8. dezren39 commented on Nov 11, 2026

    @dezren39
    MemberAuthor

    Phase 1 status: everything that can be live IS live; the broker's in-process half is staged for the coordinated switch (by design — the running broker binary is pre-fix and was not restarted).

    Step 1 — subscription backfill (live). Drew's row cf18884d-214b-4402-95f1-3c3d1eb25aa6: {"incident":true} → all six classes true (incident, needs-drew, quota-wall, quota-near-wall, stack-health, blocked-age), row and endpoint preserved, quiet hours untouched (23:00–07:00 America/Chicago, enabled: false). Read back twice. (Earlier comment on this issue.)

    Step 2 — stack-health sentinel (live). Aggregator producer merged in PR #8597 (merge ef02d881): POST /api/alerts accepts stackHealth payloads, service:<id> incidents, "up" closes the open incident (AlertsStore.closeOpenIncidentByKey). Independent sentinel scripts/stack-sentinel.ts runs as its own user unit pm-stack-sentinel.service (enabled, active, Restart=always), probing aggregator/projector/kaneo/dispatch/opencode/queue-broker every 30s and posting transitions only. Wire facts honored: the broker binds only its tailnet IP (any HTTP response = alive), dispatch's alive answer is 404, the aggregator board probe gets 15s. Baseline at 2026-11-11T07:41:49Z recorded all six services up and posted nothing; /api/alerts.json confirms zero service: incidents. For sentinel-covered services the sentinel state is authoritative — the pre-existing health-derived candidates are suppressed for those ids (no double-reporting).

    Step 3 — needs-drew producer + answer path (live, except the broker half).

    • Aggregator (PR feat(pm-aggregator): needs-Drew questions + stack sentinel — notifications Phase 1 aggregator half (#8568) #8597, merged, deployed, only pm-aggregator.service restarted): needsDrew intake on the throat, question store (needs-drew.json, per-question token, first-answer-wins), breakthrough needs-drew candidates carrying the question + options, push payload answer enrichment, service-worker notification actions (first two options as tappable actions; other questions open the answer page), GET /answer/<ledgerId>?t=<token> page (403 without rendering the question on a bad token), POST /api/needs-drew/<ledgerId>/answer, and the fleet feed's new answers section.
    • CLI producer (PR fleet-queue: needs-drew alerts into the PM throat on escalated blocks (code#8568) #8598, merge ab15e731): fleet queue block with --ledger-id/--question/--context/--options-json/--links-json on an escalated-to-user block stamps progress.needs_drew.ledger_id and POSTs the question to the throat (token resolved in-process by name; failure = stderr warning, exit unchanged). Deployed live: ~/.local/bin/fleet is now the staged build, sha256 5735008dd51b85a11ee2412351e130dd416fab5155aca826b2ba691e683a0b90.
    • Broker producer (same PR, STAGED for the coordinated switch): the broker's /block hook raises the same event in-process. The running broker binary contains neither 6a792f60 nor aba44429 and was NOT restarted; ~/.local/libexec/queue-coverage/fleet is untouched. It goes live when the switch deploys a current binary. Wrinkle found on contact: the broker hands /block to the Turso backend before the Postgres arm, so the hook is wired on both branches.
    • Answer application (live): the dropped-thread catcher gained Step 2B — hourly it applies the feed's answers to the decisions ledger (answered, via: "push") and unblocks the originating task by needs_drew.ledger_id with the audited verb. Fail-soft while the section is absent; verified by cron read-back.

    Step 4 — the one live proof push. Sacrificial task 14917 (enqueued @90, claimed by id as muse-8568-proof):

    • Block (escalated-to-user, new flags) started 2026-11-11T07:44:10.261Z.
    • The push service accepted the needs-drew push for Drew's subscription at 2026-11-11T07:44:12.982Z — 2.7 seconds block→sent, no cron in the path (CLI → throat → immediate alert tick). Log line: class needs-drew, objectRef needs-drew:proof-8568-needs-drew, outcome sent, subscriptionId cf18884d-… (the step-1 row).
    • Answer path verified server-side: POST with the per-question token recorded the answer (optionId: seen, 07:44:35Z, via api); a bad token was rejected first ("unknown question or bad token"); the answer surfaced in fleet-feed.json's answers within ~2 minutes (collector cadence). Drew's own tap was not simulated.
    • Cleanup: task 14917 unblocked (audited) then cancelled — Turso read-back says cancelled. The test incident was closed by hand through the aggregator's Supabase client; the missing auto-close is filed as needs-drew: close the alert incident when the question is answered #8605.

    Proof-run disclosure. While probing CLI usage, a bare fleet queue claim claimed real task 5865 under a default identity (the known trap, fourth firing). It was released within the minute with an explanatory reason and read back queued @30 in Turso; no work was done on it.

    Design points that proved wrong on contact. (1) The design named src/needs-drew.ts as a new file — it already existed (the #1226 census); the question store was appended as a delimited section instead. (2) The design assumed a 3s probe budget is safe — the projector probe flaked once at 3s under load during the sentinel dry run (handled: recorded down, post left pending for retry). (3) Answered needs-drew incidents do not auto-close (#8605). Everything else in the design's wire model held.

    Remaining for full Phase 1 close-out: the broker producer rides the coordinated switch; after it lands, one escalated block through a worker (not the CLI) re-proves the broker half.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    app/pm-stackpm-stack (Pad/Grist) in developing-today/codedesign/pm-notificationsDesign: pm-notifications - all issues of this effort carry itkind/featureNew feature or capability requestpriority/normalOrdinary priority (the default)status:done

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions