Skip to content

Debounce channel history persistence - #109

Merged
ctoth merged 2 commits into
masterfrom
agent/issue-105-channel-save-debounce
Aug 12, 2026
Merged

Debounce channel history persistence#109
ctoth merged 2 commits into
masterfrom
agent/issue-105-channel-save-debounce

Conversation

@daiverd

@daiverd daiverd commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Fixes #105

useChannelHistory re-serialized every buffer and synchronously wrote about 85 KB (observed live) to localStorage on every channel message.

Changes

  • Coalesce saves with a 500 ms trailing debounce, mirroring the output history behavior.
  • Defer serialization into the flush so a burst of messages costs one serialization and one write.
  • Flush a pending write synchronously on pagehide, beforeunload, and React unmount.
  • Cancel the pending timer before flushing so consecutive browser lifecycle events do not duplicate writes.

TDD and verification

  • RED: the focused hook suite failed both new pagehide and beforeunload cases because no history was persisted inside the debounce window.
  • GREEN: focused hook suite 18/18.
  • Full suite: 107 files and 1,065 tests passed.
  • TypeScript typecheck passed; staged lint passed with existing warnings only; staged diff check passed.

useChannelHistory re-serialized every buffer and wrote ~85 KB to
localStorage synchronously on every single channel message. Saves are
now coalesced with a 500 ms trailing debounce mirroring output.tsx's
scheduleSave, with the serialization itself deferred into the flush so
a burst of messages costs one serialize + one write. A pending save is
flushed from the latest state on unmount so nothing is lost.

Fixes #105

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@ctoth
ctoth merged commit 3b19a0f into master Aug 12, 2026
1 check passed
github-actions Bot pushed a commit that referenced this pull request Aug 12, 2026
…-debounce

Debounce channel history persistence 3b19a0f
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.

useChannelHistory: full buffer serialization + localStorage write on every message

2 participants