Skip to content

refactor(sse): serialize backend writes and add directory-aware frontend batching#256

Open
chriswritescode-dev wants to merge 7 commits into
mainfrom
refactor/sse-queued-writer
Open

refactor(sse): serialize backend writes and add directory-aware frontend batching#256
chriswritescode-dev wants to merge 7 commits into
mainfrom
refactor/sse-queued-writer

Conversation

@chriswritescode-dev
Copy link
Copy Markdown
Owner

SSE writes from the backend could arrive out of order under concurrent load. The frontend parts batcher also lacked directory awareness, making it unreliable when multiple directories are monitored.

Changes:

  • Add QueuedSSEWriter that serializes SSE frames via promise chaining with backpressure handling and error isolation
  • Refactor SSE route to use QueuedSSEWriter instead of raw encoder
  • Make frontend parts batcher directory-aware: operations grouped by (sessionID, directory) composite key; flush() accepts optional target filter
  • Decouple batcher lifecycle from directory dependency in useSSE hook
  • Add comprehensive tests for all new behavior

Files

  • backend/src/routes/sse-writer.ts
  • backend/src/routes/sse.ts
  • backend/test/routes/sse-writer.test.ts
  • frontend/src/hooks/useSSE.ts
  • frontend/src/hooks/useSSE.test.tsx
  • frontend/src/lib/partsBatcher.ts
  • frontend/src/lib/partsBatcher.test.ts
  • frontend/src/lib/opencode-event-stream/openCodeEventStream.ts
  • frontend/src/lib/opencode-event-stream/testTransport.ts
  • frontend/src/lib/opencode-event-stream/tests/openCodeEventStream.test.ts

chriswritescode-dev and others added 7 commits June 6, 2026 01:07
…end batching

SSE writes from the backend could arrive out of order under concurrent load.
The frontend parts batcher also lacked directory awareness, making it
unreliable when multiple directories are monitored.

Changes:
- Add QueuedSSEWriter that serializes SSE frames via promise chaining with
  backpressure handling and error isolation
- Refactor SSE route to use QueuedSSEWriter instead of raw encoder
- Make frontend parts batcher directory-aware: operations grouped by
  (sessionID, directory) composite key; flush() accepts optional target filter
- Decouple batcher lifecycle from directory dependency in useSSE hook
- Add comprehensive tests for all new behavior
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.

1 participant