Skip to content

feat(pm-aggregator): needs-Drew questions + stack sentinel — notifications Phase 1 aggregator half (#8568) - #8597

Merged
dezren39 merged 1 commit into
mainfrom
queue/8568-notifications-phase1-agg
Nov 11, 2026
Merged

dezren39 merged 1 commit into
mainfrom
queue/8568-notifications-phase1-agg

Conversation

@dezren39

@dezren39 dezren39 commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Refs #8568 — PM-stack notifications Phase 1, aggregator half. The fleet lane builds against the same fixed wire contract.

Wire contract (unchanged shapes)

  • Throat intake stays POST /api/alerts (Bearer, secret name pm-aggregator.alerts-intake-token). Incident fields unchanged, plus optionally ONE of needsDrew / stackHealth extensions.
  • Answer endpoint: POST /api/needs-drew/<ledgerId>/answer with {token, optionId?, freeText?} (no bearer; per-question token is the authority).
  • Answer page: GET /answer/<ledgerId>?t=<token>.
  • fleet-feed.json gains top-level answers.

What landed

  • src/needs-drew.ts — the question store is appended to the existing pm-stack: one Needs-Drew queue of record — reconcile user/* labels with the aggregator Needs-you page #1226 label-census module (the file already existed; overwriting would have killed the census): file-backed store (env PM_AGG_NEEDS_DREW_FILE, default ~/.local/state/pm-aggregator/needs-drew.json), idempotent raiseNeedsDrew (token minted once via crypto.randomUUID, original fields kept), first-answer-wins recordAnswer, getNeedsDrew, listOpenNeedsDrew (unanswered, < 7 days), listAnswers, intake validator (options 1–8 with id+label, links strings). Atomic tmp+rename writes, serialized per file.
  • src/stack-health.ts (new) — sentinel state store (PM_AGG_STACK_HEALTH_FILE), setStackHealth (returns previous state), listStackHealthDown, readStackHealthStates, validator, SENTINEL_SERVICE_IDS = aggregator, projector, kaneo, dispatch, opencode, queue-broker.
  • src/config.ts — needsDrewFile + stackHealthFile following the existing state-dir pattern.
  • src/server.ts — intake extensions after the unchanged incident insert: validation failure = 400, store failure logged and never fails the incident post; needsDrew response carries {ledgerId, answerUrl}; stackHealth "up" closes the open incident via new AlertsStore.closeOpenIncidentByKey; both call requestAlertTick(). Answer endpoint + server-rendered answer page (403 without rendering the question on unknown id/token mismatch; escaped interpolation). Snapshot builder reads both stores.
  • src/notifications.ts — snapshot gains needsDrewRaised / stackHealthDown / stackHealthStates; needs-drew candidates are breakthrough with the needsDrew payload field; sentinel-down candidates use service:<id>; health-derived candidate suppressed for any sentinel-covered service with a sentinel record.
  • src/alerts.ts — PushPayload.answer; dashboard tick sets it (and the payload URL) to the token-carrying answer URL; exported requestAlertTick() hook registered by startAlertEngine (in-flight guard respected, no-op when not started).
  • src/sw-source.ts — push handler turns the first 2 answer options into notification actions and carries {answerLedgerId, answerToken, answerUrl}; an action tap POSTs the answer and closes.
  • scripts/collect-fleet-feed.ts + src/feed.ts — collector reads the needs-drew store fail-soft and emits top-level answers: [{ledgerId, optionId, freeText, answeredAt, via}]; FleetFeed.answers typed; assembleCollectorFeed passes it through.
  • scripts/stack-sentinel.ts (new) — 30s probe loop with the live-verified alive-sets: aggregator /board 200 (15s timeout), projector /health 200, kaneo /api/health 200, dispatch / 404 is alive (200/401/403/404 accepted), opencode /global/health 200, queue-broker on its tailnet IP only (any HTTP response = alive; 401 expected). Baseline-without-posting on first run unless a service is down; pending transitions retried each round; token resolved by name via src/secrets.ts, never printed.

Evidence

  • Typecheck: bunx tsc --noEmit output byte-identical to an origin/main baseline worktree (77 lines of pre-existing errors, none in touched files).
  • Tests: 208 pass / 0 fail across alerts, notifications, needs-drew, feed, config, notification-preferences, contract-collector, collect-fleet-feed-publication; 45 pass / 0 fail across boot, api-health-comments, health (with a free freshness port — the default 4871 is held by the live service, a pre-existing environmental conflict).
  • Synthetic derivation proof (throwaway bun script, synthetic snapshot): needs-drew candidate shaped per contract (breakthrough, /answer/<id> url, needsDrew field), service:kaneo present exactly once, health:kaneo suppressed, non-sentinel health:grist untouched — PROOF OK.
  • Store proof: raise idempotence/token stability, first-answer-wins, validators, stack-health previous-state — OK.
  • Sentinel dry run against a dead mock throat (never the live throat): dispatch 404=up, queue-broker 401=up, a projector 3s timeout recorded as down with the post left pending for retry.

Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

@dezren39
dezren39 requested a review from a team as a code owner November 11, 2026 07:37
@coderabbitai

coderabbitai Bot commented Nov 11, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 52 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7bdb137a-d384-4819-8215-e363db921759
Commits

Reviewing files that changed from the base of the PR and between 1a06801 and ecbed1f.

Files selected for processing: 10

  • pm-stack/aggregator/scripts/collect-fleet-feed.ts
  • pm-stack/aggregator/scripts/stack-sentinel.ts
  • pm-stack/aggregator/src/alerts.ts
  • pm-stack/aggregator/src/config.ts
  • pm-stack/aggregator/src/feed.ts
  • pm-stack/aggregator/src/needs-drew.ts
  • pm-stack/aggregator/src/notifications.ts
  • pm-stack/aggregator/src/server.ts
  • pm-stack/aggregator/src/stack-health.ts
  • pm-stack/aggregator/src/sw-source.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-11T07:44:45.491994Z ecbed1f PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@dezren39

Copy link
Copy Markdown
Member Author

Merging on local evidence while CI checks are still QUEUED (9 pending, 1 skipping, none red at merge time), per standing merge authority. Local evidence: typecheck output byte-identical to an origin/main baseline worktree (no new errors); 208/208 tests pass across the touched areas (alerts, notifications, needs-drew, feed, config, contract-collector, collect-fleet-feed) plus 45/45 boot/health tests with a free freshness port; synthetic derivation proof and store/sentinel dry-runs pass (details in the PR body). Post-merge deploy read-backs will be recorded on #8568.

@dezren39
dezren39 merged commit ef02d88 into main Nov 11, 2026
1 of 10 checks passed
@dezren39
dezren39 deleted the queue/8568-notifications-phase1-agg branch November 11, 2026 07:39

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ecbed1fa83

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +65 to +69
await fetch('/api/needs-drew/' + encodeURIComponent(nd.answerLedgerId) + '/answer', {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ token: nd.answerToken, optionId: event.action }),
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve a recovery path when an answer action fails

If Drew taps an answer while offline or the endpoint returns an error, the handler has already closed the notification, ignores unsuccessful HTTP responses and network exceptions, and returns without opening the answer page or retrying. The answer is never recorded, leaving the worker blocked with no visible failure indication. Because decideNotification() deduplicates the unchanged question after its initial successful push, subsequent ticks will not replace the lost notification. Check res.ok and provide a recovery path, such as reopening the answer page or retaining a retryable notification.

Useful? React with 👍 / 👎.

Comment on lines +2477 to +2478
const v = validateNeedsDrew(ext.needsDrew);
if (!v.ok) return json({ error: v.error }, 400);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Validate extensions before persisting the incident

An authenticated request with valid incident fields but an invalid extension, such as needsDrew.options: [], has already persisted an open incident through postIncident() before this validation returns 400. No question is stored and the incident is not rolled back or closed; if its severity is critical, the periodic alert engine can deliver and escalate the rejected request as a generic incident. Validate both extensions and their mutual exclusion before calling postIncident() so rejected requests do not leave actionable alerts behind.

Useful? React with 👍 / 👎.

} else {
entry.detail = detail;
}
if (entry.postedState !== entry.state) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reconcile state after an unacknowledged transition

If the intake records a down transition but its HTTP response is lost or times out, postTransition() returns false and postedState remains "up". If the service recovers before a successful retry, the transition branch preserves that value, making both state and postedState equal to "up"; this condition then skips the recovery POST. The aggregator retains its persisted down record indefinitely because subsequent healthy probes also skip posting. Track delivery uncertainty separately and reconcile the current state after an attempted transition, even when it matches the last acknowledged state.

Useful? React with 👍 / 👎.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant