Skip to content

fix(pm-stack): health snapshot, incremental reconcile streams, single-flight, cached attention (#9850) - #10466

Merged
dezren39 merged 1 commit into
mainfrom
fix/9850-health-attention
Nov 15, 2026
Merged

dezren39 merged 1 commit into
mainfrom
fix/9850-health-attention

Conversation

@dezren39

@dezren39 dezren39 commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

Refs #9850 — round 2. The round-1 fix (PR #10084) isolated the /health client and batched the writes, but the stalls came back: the projector was marked down twice more on the new build (2026-11-15 01:49Z and 02:55Z, ~3 min each), and /api/attention.json timed out four times in a row at the 03:00 CT reconcile fire on 2026-11-15 (35 s client timeouts, load 14→26) after flapping three times on 2026-11-14. This PR removes the mechanisms instead of widening the margins. The sentinel is unchanged — it was correctly reporting real stalls.

Root cause

  1. The reconcile reviews stream ignored its cursor. Every pass re-read the full PR list and made one GitHub call per PR — for developing-today/code that is 4,758 PRs — then upserted every review found: the journal shows reviews: written=5433 ms=1692265 (28 minutes of sustained writes) and whole passes of ~11.5k rows taking 22–35 minutes, recurring roughly hourly. The prs stream likewise re-upserted all ~4,757 PRs every pass.
  2. /health still did live DB work on the request path (a COUNT over three tables, 5 s timeout → 503). Any contention past 5 s — the mega-pass write flood above, on a loaded box — became a sentinel "down" even though the process never died.
  3. POST /reconcile had no single-flight: the timer fires every ~15 min regardless, so passes overlapped and multiplied the load.
  4. The aggregator's /api/attention.json re-assembled the whole view on every request (no caching), so under CPU load each request cost seconds — measured live 2026-11-15: avg 0.98 s, worst completed 24.8 s, four consecutive 35 s timeouts at the 03:00 CT reconcile fire. It was the one assembly not behind the codebase's TodayCache.

Fix

Evidence

  • New regression tests: reviews-stream incremental sweep (seeded cursor → only the updated PR is fetched), prs no-re-upsert below cursor, /health serves the snapshot with a wedged DB, stale snapshot → 503, reconcile gate no-op.
  • Projector suite: 142 pass, 0 fail. Aggregator attention suites pass. Note: aggregator test/today-cache-1179.test.ts currently fails its 5 s hook timeout on pristine main as well under this box's load (verified both trees back to back) — pre-existing, unrelated to this change; the cache primitive itself is untouched.
  • Live A/B on a copy of the production DB (old code vs this branch): unloaded /health 4.3 ms (old, live query) vs 0.9 ms (new, snapshot, snapshotAgeMs present). A local write flood does not reproduce the production stall physics (production writes queue on a remote libSQL service; a local WAL file answers readers instantly), so the request-path invariant is proven by the wedged-DB test instead: /health answers 200 from the snapshot while its DB client throws on every call.
  • Production sampler (1 Hz, 502 samples, 2026-11-15 02:50–03:18 CT): /health max 299 ms, zero non-200; /api/attention.json avg 982 ms, worst completed 24.8 s, 4 timeouts of 35 s at 03:00–03:02 CT while load rose 13.9 → 26.1 — the flap this PR's cache removes.

Deploy note: takes effect at the next switch after merge (server code is read at start). The soak gate on #9850 (gate-code-9850-soak) should restart from this deploy.


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 15, 2026 09:04
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

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

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-15T09:04:42.031678Z
We couldn’t complete this review. Comment @codex review to try again.
59119b4 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.

@coderabbitai

coderabbitai Bot commented Nov 15, 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 5 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: 21013b4a-8720-4db5-820d-896daa059f8b
Commits

Reviewing files that changed from the base of the PR and between 9ce1dbf and 59119b4.

Files selected for processing: 6

  • pm-stack/aggregator/src/server.ts
  • pm-stack/projector/src/github.ts
  • pm-stack/projector/src/reconcile.ts
  • pm-stack/projector/src/server.ts
  • pm-stack/projector/test/health-isolation.test.ts
  • pm-stack/projector/test/reconcile.test.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

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

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