Skip to content

SSE client cleanup: layered abstractions + tests#9260

Draft
ericpgreen2 wants to merge 2 commits intoericgreen/cloud-editing-mvpfrom
ericgreen/sse-client-cleanup
Draft

SSE client cleanup: layered abstractions + tests#9260
ericpgreen2 wants to merge 2 commits intoericgreen/cloud-editing-mvpfrom
ericgreen/sse-client-cleanup

Conversation

@ericpgreen2
Copy link
Copy Markdown
Contributor

Refactors the SSE client stack in web-common/src/runtime-client/ into discrete layers so JSON parsing, reconnect, lifecycle policy, and typed event routing each live in one place. Migrates FileAndResourceWatcher, Conversation, and ProjectLogsPage onto the new layers, drops the fileAndResourceWatcher singleton in favor of per-mount instances, and adds an onBeforeReconnect hook so the cloud editor can refresh its JWT before long-lived stream reconnects.

  • Plan: .claude/plans/i-want-to-create-lovely-rabbit.md
  • Base: ericgreen/cloud-editing-mvp
  • Staging: lands as two sequential PRs on this branch (core layers + tests, then consumer migrations)

Checklist:

  • Covered by tests
  • Ran it and it works as intended
  • Reviewed the diff before requesting a review
  • Checked for unhandled edge cases
  • Linked the issues it closes
  • Checked if the docs need to be updated. If so, create a separate Linear DOCS issue
  • Intend to cherry-pick into the release branch
  • I'm proud of this work!

Developed in collaboration with Claude Code

Layered abstractions, per-mount watcher instances, and JWT-refresh hook
for long-lived streams in the cloud editor.
@ericpgreen2 ericpgreen2 mentioned this pull request Apr 20, 2026
8 tasks
New `web-common/src/runtime-client/sse/` directory with one concern per
module:

- `sse-protocol.ts` — pure SSE parser (`readSSEStream`).
- `sse-fetch-client.ts` — fetch + abort transport, delegates parsing.
- `sse-connection.ts` — reconnect, backoff, stable-threshold, status
  store. Renamed from `SSEConnectionManager`. Auto-close methods kept as
  thin deprecation shims (removed once consumers migrate).
- `sse-lifecycle.ts` — new, optional. Visibility/focus + idle pausing
  via an injectable signal source. Ships `LIFECYCLE_PRESETS`.
- `sse-subscriber.ts` — new, typed decoder registry over an
  `SSEConnection`. Normalizes untagged frames to `"message"` per the SSE
  spec.

Adds an `onBeforeReconnect` hook on `SSEConnection` so long-lived streams
can refresh auth before each retry; hook rejections count as failed
attempts and walk status to CLOSED.

`createEventBinding` helper unifies the event-emitter boilerplate both
`SSEFetchClient` and `SSEConnection` were duplicating.

Old-path files (`sse-fetch-client.ts`, `sse-connection-manager.ts`) remain
as re-export shims so existing consumers compile unchanged.

45 new unit tests cover the parser, fetch client, reconnect logic,
lifecycle, and subscriber.
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