Skip to content

fix(aggregator): serialize JSON store persists + unique temp paths, 5xx on persistence failure (#1509) - #1640

Merged
dezren39 merged 2 commits into
mainfrom
queue/1769-1509-store-serialize
Oct 28, 2026
Merged

dezren39 merged 2 commits into
mainfrom
queue/1769-1509-store-serialize

Conversation

@dezren39

@dezren39 dezren39 commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Fixes #1509 (queue task 1769, from triage task 1548).

Problem: the aggregator JSON stores persisted through a temp file named only by pid with no write serialization — concurrent writes shared one temp path, the first rename won, the rest threw ENOENT, and records on disk diverged from calls that succeeded (triage repro: 20 concurrent adds → 2 fulfilled, 18 ENOENT, 19 on disk).

Fix:

  • comments.ts / actions.ts: persists serialized through a per-store promise chain; unique temp path per write (tmp-<pid>-<seq>); snapshot taken when the queued write runs so the last write carries full current state; a failed write rejects its own caller without poisoning the chain.
  • sources/live.ts registry write: same serialization + unique temp (its best-effort catch stays, but serialized writes no longer lose updates into it).
  • Second race found by the new regression test: load() set a boolean flag and let concurrent first callers proceed before the read finished; the read's completion then reset the in-memory array, wiping records just pushed (5 concurrent first adds → 1 in memory, even with serialized persists). load() is now a memoized promise in both stores. Without this, the acceptance criterion (fulfilled == reloaded) cannot hold for a cold store.
  • server.ts: POST /api/comments and /api/actions return 500 on persistence failure; 400 remains for validation/body-parse errors only.

Tests: new test/store-concurrency.test.ts — 20 concurrent adds per store, fulfilled == reloaded == 20, no ENOENT. Full aggregator suite on the laptop: 303 pass / 0 fail; tsc --noEmit clean. CI verification pending (fleet runner stall #1599).


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

…x on persistence failure (#1509)

Comments/Actions stores and the live session registry persisted via a
pid-only temp path with no serialization: concurrent writes shared the
temp file, the first rename won, the rest threw ENOENT, and fulfilled
calls diverged from disk. Persists now run through a per-store promise
chain with a unique temp path per write and the snapshot taken when
the queued write runs.

Fixing that exposed a second race the regression test caught: load()
set a boolean and let concurrent first callers proceed before the
read finished; the read completion then reset the in-memory array and
wiped records just pushed (5 concurrent first adds -> 1 in memory).
load() is now a memoized promise in both stores.

POST /api/comments and /api/actions return 500 on persistence failure;
400 remains for validation/body errors only.

Regression: test/store-concurrency.test.ts - 20 concurrent adds per
store, fulfilled == reloaded == 20. Full aggregator suite on laptop:
303 pass / 0 fail; tsc --noEmit clean.
@dezren39
dezren39 requested a review from a team as a code owner October 28, 2026 09:41
@coderabbitai

coderabbitai Bot commented Oct 28, 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 3 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: be4e9c32-d9ac-4c1c-82f4-c114d475d728
Commits

Reviewing files that changed from the base of the PR and between ed8e591 and 6bee82d.

Files selected for processing: 5
  • pm-stack/aggregator/src/actions.ts
  • pm-stack/aggregator/src/comments.ts
  • pm-stack/aggregator/src/server.ts
  • pm-stack/aggregator/src/sources/live.ts
  • pm-stack/aggregator/test/store-concurrency.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

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-28T09:43:09.710977Z eb0ffe7 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
dezren39 merged commit b97d8f3 into main Oct 28, 2026
4 checks passed
@dezren39
dezren39 deleted the queue/1769-1509-store-serialize branch October 28, 2026 10:46
@dezren39
dezren39 restored the queue/1769-1509-store-serialize branch November 1, 2026 07:54
@dezren39
dezren39 deleted the queue/1769-1509-store-serialize branch November 1, 2026 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant