Skip to content

Generic provider stream path writes the store and pushes IPC per raw stdout chunk, unthrottled #640

Closed

Description

@currentbits

The generic provider's onChunk (electron/runner.js:2333-2347) runs on every raw stdout data event — arbitrary byte-boundary chunks, dozens per second on a fast stream — and each chunk does:

  1. store.updateMessage(threadId, assistantMsgId, { text }) — copy-on-write: getMessages().slice() + findIndex + setMessages over the whole message list (electron/store.js:1851-1858)
  2. store.save() (arms the flush debounce — fine on its own)
  3. pushDetail(threadId, realState) — full getThreadDetail (another getMessages().slice()), a firstChanged rescan of messages + workLog, and an IPC thread:updated to the renderer

The codex (runner.js:3762 throttledPush) and kimi/opencode (runner.js:4142) stream paths already coalesce with a trailing-edge throttle; the generic path never got it. For a capped thread (1000+ messages) every chunk is several O(messages) array passes plus a renderer round-trip, purely to append a few characters.

Fix: route the generic onChunk through the same throttledPush-style coalescer (batch the in-memory text update to one store write + one push per ~100-150 ms window, with a final flush on onDone). Behaviour should be visually identical; the store-write and IPC rate stops tracking stdout chunking.

Activity

  1. added
    plan:todo
    plan:doing
    plan:done
    and removed
    plan:todo
    plan:doing
    on Aug 21, 2026
  2. currentbits commented on Aug 22, 2026

    @currentbits
    OwnerAuthor

    Generic onChunk now goes through the same 250ms leading+trailing coalescer as kimi/opencode: pending text is applied in one updateMessage + pushDetail per window, with a final flush on onDone and on clearRun (stop/error/quit) so a delayed write cannot drop the last characters.

    Tests in electron/test/runner.test.js (generic onChunk throttle (#640)): 20 sync chunks → ≤2 store writes and ≤3 assistant thread:updated tails; stop still lands the full text.

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

    plan:done

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions