Repository navigation
feat(pm-stack): freshness reconciliation + push-health surfaces (#3976) - #9193
Conversation
Anti-entropy for the #3977 journal: a FreshnessReconciler runs on the 5-minute design cadence, reads each canonical source accepted revision (fleet-feed wired: the collector notice identity, generatedAt + sha256 of the feed file), and publishes a synthetic invalidation under the revision own eventId (reason reconcile) when no notice matches — a dropped event is repaired and the late real notice dedupes against the repair. Push health is exposed on /health and /api/health from the same assembly: push up/degraded/down, last event, last successful reconcile, journal cursor, per-source state/age/lag/notices, and open/repaired/reset gap counts. Push connectivity and source freshness stay separate: a quiet source is silent, never an outage; an unreadable journal is down, never a healthy guess; a non-durable synthetic notice leaves its gap open. The existing 15-minute feed stale chip threshold is untouched. Browser degraded mode: freshness-client.js rides the #3978 EventSource stream and, while it is down, polls /api/freshness-events.json on the collectors 5-minute cadence (policy in freshness-fallback.ts, unit-tested), refreshing through dashrefresh fragment rereads — never a reload — and stops polling the moment the stream resumes. Tests (freshness-reconcile-3976, freshness-fallback-3976): dropped event repaired (real FreshnessStore), producer outage/recovery, journal loss/reset counted and repaired, quiet-but-healthy silent, stale data visibly stale, pending notice leaves gap open, journal down, fleet-feed reader identity, health-surface exposure + render, fallback cadence/resume. Live boot verified end-to-end: an empty journal + noticeless feed file was repaired at boot and /api/health reported push up with the synthetic notice as last event.
|
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 22 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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ce9a5625eb
ℹ️ 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".
| this.lastAttemptAtMs = nowMs; | ||
| let page: { cursor: number; resetRequired: boolean; events: FreshnessNotice[] }; | ||
| try { | ||
| page = await this.journal.listAfter(0); |
There was a problem hiding this comment.
Verify the durable journal instead of only its cached listing
If the journal file is deleted, replaced, or becomes unreadable after startup, this call cannot detect it: FreshnessStore.load() returns immediately once loaded is true, and listAfter() serves the in-memory events and cursor. Consequently, reconciliation can continue reporting push up, advancing the successful-reconcile timestamp, and reporting zero resets even though the durable journal has disappeared. The reset test exercises a fake journal whose cursor changes, but the production store never observes that filesystem change. Add a durable-state verification seam so reconciliation can detect journal loss or unreadability.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 0966a06: FreshnessStore.verifyDurable() re-reads the journal file inside the operation chain and throws when it is missing while the in-memory journal is non-empty, unreadable, corrupt, or diverged in cursor, length, or last notice. FreshnessReconciler calls the seam on every pass and reports push down on failure instead of trusting the cached listing. Covered by store-level tests plus reconciler tests, including a real-store test that deletes the journal file after startup.
| var moved = envelope.cursor !== cursor || envelope.resetRequired === true; | ||
| cursor = envelope.cursor; | ||
| if (moved) refresh(); |
There was a problem hiding this comment.
Retry canonical refreshes independently of the notice cursor
While SSE is down, a successful notice poll advances cursor before the asynchronous fragment reread has succeeded. If that reread fails transiently, later polls with the same cursor never dispatch another dashrefresh, so the dashboard remains stale even after the canonical endpoint recovers, until another notice arrives or the user navigates manually. Dispatch canonical refreshes on every fallback interval, as described in freshness-fallback.ts, or track successful canonical reads before suppressing retries.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 0966a06: the SSE-down fallback now dispatches the canonical refresh on every successful poll, per the freshness-fallback.ts cadence policy, instead of only when the notice cursor moved. A fragment reread that fails transiently after a notice was consumed is retried on the next cadence tick. Asset test added in freshness-fallback-3976.test.ts.
| this.unavailable.set(reader.source, err instanceof Error ? err.message : String(err)); | ||
| continue; |
There was a problem hiding this comment.
Keep failed source reads from advancing reconcile success
When a canonical reader throws, this branch records the source as unavailable but leaves durable true. With the production configuration's single fleet-feed reader, every pass during a missing or invalid feed therefore advances lastSuccessfulReconcileAt, even though no canonical revision could be checked. The overall state is degraded, but the health page and API misleadingly report a recent successful reconciliation throughout the outage. Mark the pass unsuccessful on reader failure and preserve the previous successful timestamp.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 0966a06: a throwing canonical reader now marks the pass not durable (durable = false in the reader catch), so lastSuccessfulReconcileAt no longer advances while a source cannot be checked; the previous successful timestamp is preserved and the source still reports unavailable. Regression test in freshness-reconcile-3976.test.ts: a failed read after a healthy pass leaves lastSuccessfulReconcileAt unchanged.
| stream.addEventListener("freshness", function (ev) { | ||
| if (ev && typeof ev.lastEventId === "string" && /^\d+$/.test(ev.lastEventId)) { | ||
| cursor = Number(ev.lastEventId); | ||
| } | ||
| refresh(); |
There was a problem hiding this comment.
Invalidate server-side caches before refreshing on a notice
If a source notice arrives within ten seconds of an overview or today assembly, this refresh successfully fetches the old data: /frag/overview and /frag/today use overviewContextCache and todayContextCache in server.ts, whose TodayCache.get() returns the cached assembly until its TTL expires. Neither freshness publication nor delivery clears those caches. The client consumes the notice once, and cache expiry does not trigger another browser request, so the accepted revision can remain invisible until another notice or manual refresh despite a healthy stream. Invalidate the affected assembly caches when a notice is accepted, or provide a freshness-aware fragment read that cannot reuse an assembly predating the notice.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 0966a06: FreshnessStore.onNotice fires at the moment a notice becomes durable (direct publish persist or outbox flush; never for duplicates or still-pending notices), and server.ts registers a listener that clears overviewContextCache and todayContextCache. Every acceptance path (in-process recordFreshness, the IPC handler, and reconciler synthetic invalidations) publishes through the same store, so none can bypass the invalidation. Store tests cover the fire-once semantics, including the outbox-flush moment.
…3976) 1. FreshnessStore.verifyDurable() re-reads the journal file and throws on loss/replacement/corruption; FreshnessReconciler calls the seam per pass and reports push down instead of serving health from the cached listing. 2. A failed canonical read no longer advances lastSuccessfulReconcileAt (durable=false on reader failure). 3. The SSE-down client refreshes canonical data on every successful fallback poll (the freshness-fallback.ts cadence policy), not only when the notice cursor moved. 4. FreshnessStore.onNotice fires when a notice becomes durable (publish persist or outbox flush, never duplicates); server.ts clears the overview/today assembly caches on notice so a pre-notice assembly cannot be served after acceptance. Tests: 58 pass across freshness suites (new verifyDurable/onNotice store tests, failed-read and durable-loss reconciler tests, fallback asset test); tsc output identical to baseline.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0966a065b7
ℹ️ 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".
| refresh(); | ||
| } |
There was a problem hiding this comment.
Refresh canonical fragments even when journal polling fails
When SSE is down and /api/freshness-events.json returns an error or rejects while the canonical fragment endpoints remain available, the fallback never refreshes the dashboard. refresh() is inside the successful-response branch, while failed polls merely advance lastRefreshAt and schedule another journal poll. Simulating three fallback intervals with HTTP 500 responses produces three polls but zero canonical refreshes. Run the canonical refresh independently of journal-poll success so the five-minute fallback described in freshness-fallback.ts still works during a freshness-transport outage.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in ee6827a: the fallback poll now dispatches the canonical refresh after the try/catch, on every poll attempt, instead of only inside the successful-response branch. A journal poll that returns an error or rejects no longer blocks the fragment reread; the cursor update still happens only on a successful journal response. Regression test in freshness-fallback-3976.test.ts asserts the refresh dispatch sits after the catch in poll() and that the asset documents refreshing even when the journal poll fails.
|
|
||
| function refresh() { | ||
| lastRefreshAt = Date.now(); | ||
| window.dispatchEvent(new CustomEvent("dashrefresh")); |
There was a problem hiding this comment.
Wire refresh dispatches to a registered Datastar listener
Even when a live freshness notice arrives successfully, this dispatch cannot trigger a canonical reread: the fragment containers in server.ts use data-on-dashrefresh__window, but the shipped assets/datastar.js requires data-on:dashrefresh__window. Its attribute parser splits the plugin and event on :, so the existing attributes resolve to an unregistered on-dashrefresh plugin rather than the registered on plugin. Repository-wide search found no alternate JavaScript listener or compatibility bridge; render.ts also documents the colon-syntax requirement in themeToggle(). Wire the new client to working listeners or provide a bridge, otherwise its live-refresh path remains inert.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in ee6827a: every dashrefresh listener now uses the colon form the vendored Datastar v1 binds — all 10 fragment containers across render.ts, server.ts, and freshness-delivery.ts converted from data-on-dashrefresh__window to data-on:dashrefresh__window, so the freshness client's window dashrefresh dispatch (and the dashboard's own dispatches in render.ts) reach a registered on plugin. Verified against render.ts themeToggle(), which documents the colon requirement from live testing of the vendored bundle. Regression test in freshness-fallback-3976.test.ts asserts the colon form is present and the dash form absent in all three sources.
P1: dashrefresh listeners used data-on-dashrefresh__window, which the vendored Datastar v1 does not bind (it splits plugin/event on the colon); every dashrefresh dispatch was inert. Convert all 10 fragment containers in render.ts, server.ts and freshness-delivery.ts to data-on:dashrefresh__window. P2: the SSE-down fallback only refreshed inside the journal poll success branch, so a freshness-journal outage froze the dashboard even though the fragment endpoints were healthy. Dispatch the canonical refresh on every fallback poll, after the try/catch. Tests: freshness-fallback-3976 gains a colon-form oracle over the three sources and a poll-structure oracle for refresh-on-failed-poll. Targeted freshness suites 58 pass; full aggregator suite matches the clean-tree baseline (17 pre-existing live-source/boot failures, unchanged).
Closes the implementation scope of #3976 (task 8755): anti-entropy + honest push-health for event-driven freshness, on top of the merged #3977 journal (PR #5720) and #3978 SSE delivery (PR #8241).
What lands
5-minute reconciliation with synthetic invalidation —
src/freshness-reconcile.tsFreshnessReconcilerruns on the 5-minute design cadence (boot pass + interval inserver.ts, live mode).eventIda source-event notice for that revision carries — and compares it with the journal. A revision with no matching notice gets a synthetic invalidation published under the revision's own eventId withreason: "reconcile", so the late real notice dedupes against the repair instead of double-invalidating.fleet-feed:<generatedAt>:<sha256>, mirroringscripts/collect-fleet-feed.ts). Further sources plug in throughCanonicalRevisionReaderwithout changing the loop.Push health on
/health,/api/health, and the health page's freshness chips —src/health.ts,src/server.ts,src/render.tspush: stateup | degraded | down, detail, last event, last successful reconcile, last attempt, journal cursor, per-source rows (state, last event, age, detection lag, notice count, missing-notice flag), and gap counts (open / repaired / resets + last reset).silent, not an outage; an unreadable journal isdown(and degrades the health view), never a healthy guess; no assembled view in fixtures mode renders asnull, never invented. The existing 15-minute feed stale threshold (render chip) is untouched, as is the 5-minute collector fallback.SSE-down browser fallback —
src/assets/freshness-client.js, policy insrc/freshness-fallback.ts/freshness/stream; while the stream is down it polls/api/freshness-events.jsonon the collector's 5-minute cadence and refreshes through the existingdashrefreshfragment reread — never a page reload, so view state survives — and stops polling the moment the stream reopens. The cadence/resume policy is a pure module with unit tests; the asset implements the same constants.Tests
New:
test/freshness-reconcile-3976.test.ts,test/freshness-fallback-3976.test.ts— the issue's five scenarios (dropped event repaired, producer outage/recovery, journal loss/reset, quiet-but-healthy, stale stays visibly stale) plus pending-gap, journal-down, reader identity, health-surface exposure/render, and fallback cadence/resume.Verified locally (laptop worktree):
PM_AGG_FRESHNESS_PORTon a free port), render, conflicts, nav, boot, overview, ui/dashboard overhaul, views, watchdog, events — all pass.tsc --noEmit: no errors in any touched file (pre-existing errors in unrelated test files unchanged).reason: "reconcile") and/api/healthreported pushup, fleet-feedlivewith measured lag, other sourcessilent.Known pre-existing failure, unchanged by this PR:
test/health.test.ts's spawned fixtures server binds the default freshness port 4871, which the live laptop aggregator already holds (EADDRINUSEat the #3977 IPC listener) — it fails identically on pristineorigin/mainon this machine and passes when the port is free.🤖 Queue task 8755 · lane code-c
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.