Repository navigation
feat(pm-aggregator): needs-Drew questions + stack sentinel — notifications Phase 1 aggregator half (#8568) - #8597
Conversation
…tions Phase 1 aggregator half (#8568)
|
Warning Review limit reachedYou'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. View limit details
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. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
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. |
There was a problem hiding this comment.
💡 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".
| 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 }), | ||
| }); |
There was a problem hiding this comment.
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 👍 / 👎.
| const v = validateNeedsDrew(ext.needsDrew); | ||
| if (!v.ok) return json({ error: v.error }, 400); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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 👍 / 👎.
Refs #8568 — PM-stack notifications Phase 1, aggregator half. The fleet lane builds against the same fixed wire contract.
Wire contract (unchanged shapes)
POST /api/alerts(Bearer, secret namepm-aggregator.alerts-intake-token). Incident fields unchanged, plus optionally ONE ofneedsDrew/stackHealthextensions.POST /api/needs-drew/<ledgerId>/answerwith{token, optionId?, freeText?}(no bearer; per-question token is the authority).GET /answer/<ledgerId>?t=<token>.fleet-feed.jsongains top-levelanswers.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 (envPM_AGG_NEEDS_DREW_FILE, default~/.local/state/pm-aggregator/needs-drew.json), idempotentraiseNeedsDrew(token minted once viacrypto.randomUUID, original fields kept), first-answer-winsrecordAnswer,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+stackHealthFilefollowing 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;needsDrewresponse carries{ledgerId, answerUrl};stackHealth"up" closes the open incident via newAlertsStore.closeOpenIncidentByKey; both callrequestAlertTick(). 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 gainsneedsDrewRaised/stackHealthDown/stackHealthStates; needs-drew candidates are breakthrough with theneedsDrewpayload field; sentinel-down candidates useservice:<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; exportedrequestAlertTick()hook registered bystartAlertEngine(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-levelanswers: [{ledgerId, optionId, freeText, answeredAt, via}];FleetFeed.answerstyped;assembleCollectorFeedpasses it through.scripts/stack-sentinel.ts(new) — 30s probe loop with the live-verified alive-sets: aggregator/board200 (15s timeout), projector/health200, kaneo/api/health200, dispatch/404 is alive (200/401/403/404 accepted), opencode/global/health200, 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 viasrc/secrets.ts, never printed.Evidence
bunx tsc --noEmitoutput byte-identical to an origin/main baseline worktree (77 lines of pre-existing errors, none in touched files)./answer/<id>url, needsDrew field),service:kaneopresent exactly once,health:kaneosuppressed, non-sentinelhealth:gristuntouched — PROOF OK.Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.