Repository navigation
Share one server-sent events helper across the four streams #325
Description
Four routes hand-roll the same event stream code (encoder and send, an opening comment, a 25 second heartbeat, cleanup on abort, and the same four headers), so a fix to one stream never reaches the others.
Where to start
- Add one small helper (for example backend/src/util/sse.ts) that owns the ReadableStream, send and sendEvent, the heartbeat as a named constant, abort cleanup and the response headers.
- Move the run stream, the thread stream, the chat stream and the changes stream onto it, keeping every frame they send byte for byte.
- Add a unit test for the helper: headers, the opening comment, heartbeat and cleanup on abort.
Code to look at:
backend/src/runs/routes.ts:589backend/src/runs/routes.ts:676backend/src/runs/routes.ts:853backend/src/runs/routes.ts:1004backend/src/chat/routes.ts:149backend/src/chat/routes.ts:221backend/src/runs/changes-route.ts:33backend/src/runs/changes-route.ts:58
Done when
- The literal 25_000 heartbeat and the four-header block each appear once in backend/src.
- Existing tests for these streams pass unchanged (backend/test/thread-events.test.ts, backend/test/chat-routes.test.ts and the run stream tests).
Free to try
Sign up free at app.useagent.org. New accounts get free model credits (GLM or Claude Opus, up to a limit) and free cloud sandbox time, enough to finish this task without paying or adding a key.
Send it a small task in plain words and watch it work. You'll see the screens this issue is about. The link in the sign-up email works for 24 hours. Not there? Check spam.
Stuck? Comment here with a screenshot and we'll help.
Keep private details out of here
This page is public. Don't post your real email, phone number, address, payment details, API keys, or screenshots that show any of them. Send anything private, including how you'd like to be paid, to hi@useagent.org with a link to your comment here.
Claim it
Comment /take and the issue is assigned to you. First come, first served.
Rules
- Use the app while you work, and put before and after screenshots or a short recording in your pull request. For backend or docs work, show the result end to end.
- One change per pull request. Run the checks in CONTRIBUTING.md.
- AI help is fine, blind AI output is not. You must understand, run and explain every line you submit.
- Untested or generated pull requests, and pull requests on an issue someone else claimed, are closed without a reply and don't count for Hacktoberfest.
Activity
Parth-Jadhav-2004 commentedon Oct 26, 2026
Can I grab this? I looked at
runs/changes-route.tsand it's the same pattern you describe:send(),": open\nretry: 1500\n\n", asetInterval(..., 25_000)ping withunref, abort-drivencleanup(), and the fourtext/event-stream/ no-cache / keep-alive /X-Accel-Bufferingheaders. I'd addbackend/src/util/sse.tsexporting something likesseResponse(signal, start)that owns the ReadableStream,send/sendEvent, a namedSSE_HEARTBEAT_MS, cleanup on abort and the headers, then move the run, thread, chat and changes streams onto it. Each route's own setup (likesubscribeOrg) would go through anonClosehook, so frames stay byte for byte. Tests: a unit test for the helper (headers, opening comment, heartbeat with fake timers, cleanup on abort), andthread-events.test.ts,chat-routes.test.tsand the run stream tests should pass unchanged.