Repository navigation
Debounce Store.save() so streaming no longer rewrites the whole 15 MB store - #47
Merged
currentbits merged 3 commits intoAug 15, 2026
Merged
Conversation
… Create an OG card for twitter etc to put on the website make
… Agent task shows 'Starting agent' and 'Agent working' checkm
store.save() did a JSON.stringify of all data plus a writeFileSync of the entire file, and ~97 production call sites hit it -- including the per-block assistant/tool stream handlers in runner.js and services.getThreadDetail on every thread selection. On a real 15 MB store the stringify alone measures ~19 ms, blocking the main process on every token block of every concurrent worker. save() now sets a dirty flag and coalesces onto a 250 ms timer; the old synchronous body moves to saveNow(). Every existing caller gets the coalescing for free. A process "exit" hook registered only while a write is pending flushes synchronously, so app quit, smoke.js and acceptance.js stay durable without per-caller wiring; the timer is unref'd so it never holds the loop open. Tests that read the file back switch to saveNow(), and five that relied on a services.* call writing through synchronously now flush first. Co-Authored-By: Claude Opus 5 <[email protected]>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
currentbits
deleted the
coder/store-every-stream-event-rewrites-the-en-b015fa
branch
October 3, 2026 16:07
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #27.
The problem
Store.save()(electron/store.js) did aJSON.stringifyof all data plus awriteFileSyncof the entire file, synchronously. It is called from ~97 production sites — including the per-block assistant/tool stream handlers inelectron/runner.jsandservices.getThreadDetail, which full-saves on every thread selection just to stamplastVisitedAt.On a real store (15 MB / 7000+ messages) the stringify alone measures ~19 ms, so the main process stalled on every token block of every concurrent worker.
The change
Fixed at the shared function rather than at the hot call sites, so all ~97 callers benefit and no sibling path is left broken:
save()now sets a dirty flag and coalesces writes onto a 250 ms timer.saveNow(), for callers that need the bytes on disk right now.process.once("exit")hook — registered only while a write is pending, removed on flush — writes synchronously on exit. That covers app quit,smoke.jsandscripts/acceptance.jsin one place, with no per-caller quit wiring and no listener leak across the manyStoreinstances tests create.unref'd so it never holds the event loop open.A burst of N stream events that used to cost N × (19 ms stringify + 15 MB write) now costs one, at most 250 ms later. Worst case on SIGKILL is 250 ms of stream text.
Tests
electron/test/store.test.js: 20save()calls produce exactly onewriteFileSync, andsaveNow()flushes a pending debounced save.saveNow()(mechanical rename).services.*call writing through synchronously before reloading from disk; they now flush first.Verification
node --test electron/test/store.test.js— 32/32 pass, including both new cases.npm run test:electron— the failing set is byte-identical to the pre-change baseline (verified by diffing sortednot oklines before and after). This worktree fails a large block of provider/gh-dependent tests either way; no test regressed.npm run typecheck— clean.Not included
Deliberately left as separate work, both noted in a
ponytail:comment onsave()or in the issue:Async writes and per-thread message files. The remaining cost is the sync stringify on the flush tick, which async I/O would not remove.
Pruning the 41-of-48 archived threads that grew the store to 15 MB. That is what caused the size and is worth doing independently of this fix.
PR created by the Claude Code agent