Skip to content

Cap transcript growth and stop whole-store synchronous stringify on flush #89

Closed

Description

@currentbits

electron/store.js:613-632 — appendMessage/appendWorkLog never cap transcript size. electron/runner.js:854 already admits "the largest threads are megabytes". saveNow (store.js:579-580) does a synchronous JSON.stringify of the entire blob plus writeFileSync on every flush, and lastPushByThread in runner.js:860 retains full message arrays per thread for the process lifetime. A few heavy long-lived threads will progressively stall the main process during active runs.

Options: per-thread retention cap (drop/compact old messages), per-thread store files so a flush only writes the dirty thread, or async stringify/write off the event loop.

Found during the 2026-08-16 improvement audit.

Activity

  1. added
    enhancement
    plan:todo
    plan:doing
    and removed
    plan:todo
    on Aug 16, 2026
  2. currentbits commented on Aug 16, 2026

    @currentbits
    OwnerAuthor

    Implemented:

    • Per-thread retention caps in electron/store.js: 1000 messages / 500 work-log items per thread, with overflow slack (100/50). Appends may overshoot the cap by the slack; crossing cap + slack drops the oldest entries back to the cap and plants a single event marker so the gap is visible in the transcript. The slack amortizes the index-shifting drop (it breaks the runner's prefix diff, forcing one full transcript push) over ~100 appends instead of every append.
    • Async debounced flush: save()'s debounced flush now stringifies once (bounded by the caps) and writes tmp-then-rename via fs.promises, off the event loop. saveNow() stays synchronous for the exit hook / shutdown / tests, and a write-generation counter keeps an in-flight async flush from renaming a stale payload over a saveNow(). Flush failures re-mark dirty and retry instead of throwing async.
    • lastPushByThread (runner.js) retains shallow slices that share element refs with the store; with the caps its per-thread footprint is now bounded. Comments updated.
    • Also armed the process exit hook once instead of registering one listener per save() call.

    Not taken: per-thread store files (the heavier option). The stringify itself still runs on the main thread but is now bounded by the caps.

    Tests: cap boundary at cap+slack untouched, marker shape / single-marker-on-append, work-log cap, coalesced async flush, stale async flush never overwrites a saveNow(). Electron suite: 767/768; the one failure (budget-spend.test.js settings shape, missing notifications key) is pre-existing on master from the #87 work, unrelated.

  3. added
    plan:done
    and removed
    plan:doing
    on Aug 16, 2026
  4. added a commit that references this issue on Aug 16, 2026
    0cf65b7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementplan:done

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions