Skip to content

Share one server-sent events helper across the four streams #325

Open

Description

@abhishekgahlot2

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

  1. 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.
  2. Move the run stream, the thread stream, the chat stream and the changes stream onto it, keeping every frame they send byte for byte.
  3. Add a unit test for the helper: headers, the opening comment, heartbeat and cleanup on abort.

Code to look at:

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

  1. Parth-Jadhav-2004 commented on Oct 26, 2026

    @Parth-Jadhav-2004

    Can I grab this? I looked at runs/changes-route.ts and it's the same pattern you describe: send(), ": open\nretry: 1500\n\n", a setInterval(..., 25_000) ping with unref, abort-driven cleanup(), and the four text/event-stream / no-cache / keep-alive / X-Accel-Buffering headers. I'd add backend/src/util/sse.ts exporting something like sseResponse(signal, start) that owns the ReadableStream, send/sendEvent, a named SSE_HEARTBEAT_MS, cleanup on abort and the headers, then move the run, thread, chat and changes streams onto it. Each route's own setup (like subscribeOrg) would go through an onClose hook, so frames stay byte for byte. Tests: a unit test for the helper (headers, opening comment, heartbeat with fake timers, cleanup on abort), and thread-events.test.ts, chat-routes.test.ts and the run stream tests should pass unchanged.

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

    enhancementNew feature or requesthacktoberfestOpen for Hacktoberfest contributorshelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions