@womp/spark-agent 15.0.1 → 15.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,20 @@ Notable changes to `@womp/spark-agent`, newest first. Versions follow
4
4
  [Semantic Versioning](https://semver.org/). Add an entry with each version bump; describe what
5
5
  changed for hosts and users, and how to migrate across breaking changes.
6
6
 
7
+ ## 15.0.2 — 2026-10-22
8
+
9
+ ### Fixed
10
+
11
+ - The Express `/runs/:runId/stream` route ends when its client disconnects. A write waiting for
12
+ `drain` on a backed-up response waited forever once the client left, because a closed response
13
+ emits `close`, not `drain`. That covers a large chunk, or the closing `[DONE]` written after the
14
+ client has already gone. The route never reached its cleanup, so it kept its request, response and
15
+ socket, and, when stuck mid-stream, its `streamRun` listener and every later chunk of the run. The
16
+ route now also listens for `close` before its first lookup, so a client that leaves during it is
17
+ noticed.
18
+ - `SparkAgentService.streamRun` ends when its signal aborts while it is reading the run. Before, it
19
+ then waited for the run's next chunk, or forever for a run waiting on the user.
20
+
7
21
  ## 15.0.1 — 2026-10-21
8
22
 
9
23
  ### Fixed
@@ -33,10 +33,26 @@ function parseSequence(value) {
33
33
  function encodeFilename(value) {
34
34
  return encodeURIComponent(value).replace(/[!'()*]/gu, (character) => `%${character.charCodeAt(0).toString(16).toUpperCase()}`);
35
35
  }
36
- async function write(response, value) {
36
+ /**
37
+ * Writes one SSE frame, waiting for `drain` when the socket is backed up.
38
+ * `drain` never fires once the client is gone, so the wait also ends when
39
+ * `signal` aborts (the response closed). Without that, a client that
40
+ * disconnected mid-backpressure left the stream route waiting forever, and its
41
+ * `streamRun` listener collecting the rest of the run's chunks for good.
42
+ */
43
+ async function write(response, value, signal) {
44
+ if (signal.aborted || response.destroyed)
45
+ return;
37
46
  if (response.write(value))
38
47
  return;
39
- await once(response, "drain");
48
+ try {
49
+ await once(response, "drain", { signal });
50
+ }
51
+ catch (error) {
52
+ if (signal.aborted)
53
+ return;
54
+ throw error;
55
+ }
40
56
  }
41
57
  export function createSparkAgentRouter(options) {
42
58
  const router = express.Router();
@@ -118,10 +134,14 @@ export function createSparkAgentRouter(options) {
118
134
  response.json({ run: await options.service.cancelRun(ownerId, request.params.runId) });
119
135
  });
120
136
  router.get("/runs/:runId/stream", async (request, response) => {
121
- const ownerId = await resolveOwnerId(request);
122
- await options.service.getRun(ownerId, request.params.runId);
137
+ // Listening for `close` before the first await: a client that leaves
138
+ // while the owner or run is being looked up still ends this stream.
123
139
  const abortController = new AbortController();
124
140
  response.on("close", () => abortController.abort());
141
+ const ownerId = await resolveOwnerId(request);
142
+ await options.service.getRun(ownerId, request.params.runId);
143
+ if (response.destroyed)
144
+ abortController.abort();
125
145
  response.status(200);
126
146
  response.set({
127
147
  "Cache-Control": "no-cache, no-transform",
@@ -144,16 +164,16 @@ export function createSparkAgentRouter(options) {
144
164
  if (heartbeatTimer !== undefined)
145
165
  clearTimeout(heartbeatTimer);
146
166
  if (next.type === "heartbeat") {
147
- await write(response, ": ping\n\n");
167
+ await write(response, ": ping\n\n", abortController.signal);
148
168
  continue;
149
169
  }
150
170
  if (next.result.done)
151
171
  break;
152
172
  const chunk = next.result.value;
153
- await write(response, `id: ${chunk.sequence}\ndata: ${JSON.stringify(chunk)}\n\n`);
173
+ await write(response, `id: ${chunk.sequence}\ndata: ${JSON.stringify(chunk)}\n\n`, abortController.signal);
154
174
  pending = chunks.next();
155
175
  }
156
- await write(response, "data: [DONE]\n\n");
176
+ await write(response, "data: [DONE]\n\n", abortController.signal);
157
177
  }
158
178
  finally {
159
179
  await chunks.return(undefined);
@@ -518,7 +518,12 @@ export class SparkAgentService {
518
518
  resolve();
519
519
  };
520
520
  signal.addEventListener("abort", onAbort, { once: true });
521
- if (notification !== observedNotification || queue.length > 0)
521
+ // An abort while the run was being read has already fired, so the
522
+ // listener above never would: without this the stream waited for
523
+ // the run's next chunk, or forever for a run parked on the user.
524
+ if (signal.aborted)
525
+ onAbort();
526
+ else if (notification !== observedNotification || queue.length > 0)
522
527
  wake?.();
523
528
  });
524
529
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@womp/spark-agent",
3
- "version": "15.0.1",
3
+ "version": "15.0.2",
4
4
  "description": "Portable skills-based AI agent with local and durable chat transports for Womp",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",