From 873223e9f93181ab24872c207d11fcf1b435048a Mon Sep 17 00:00:00 2001 From: Jack Brown Date: Fri, 17 Apr 2026 16:47:53 -0700 Subject: [PATCH 1/2] Settle artifacts before sending terminal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The prior fix drained before closing the socket, but the server closes the WS immediately after sending end_session_message — so any artifact upload request fired between terminal and end_session_message still never gets its response back. Chokidar's awaitWriteFinish delays `add` events ~2s, so artifacts written by post-agent commands are always discovered *after* we respond. Move the drain (sleep + waitForPendingRequests) to run before the terminal is sent, so uploads complete while the server is still waiting on our reply. --- packages/runtimeuse/src/session.ts | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/packages/runtimeuse/src/session.ts b/packages/runtimeuse/src/session.ts index e4397ae..235d058 100644 --- a/packages/runtimeuse/src/session.ts +++ b/packages/runtimeuse/src/session.ts @@ -188,11 +188,22 @@ export class WebSocketSession { } } - // The artifact watcher stays alive for the whole session, so we no - // longer block each request on a 3s drain. Artifacts that finish - // writing after the terminal will still fire chokidar events and be - // uploaded; on session close we do a single drain for any that were - // written right before the ws closed. + // Settle any artifacts written by this request before sending the + // terminal. Chokidar's awaitWriteFinish delays `add` events by ~2s, + // and the server typically closes the socket immediately after we + // respond — so artifacts requested *after* the terminal would never + // get their upload response back. Wait for chokidar to catch up, then + // wait for the upload round-trips we've queued. + if (this.artifactManager) { + const delayMs = this.config.postInvocationDelayMs ?? 3_000; + if (delayMs > 0) { + this.logger.log(`Waiting ${delayMs}ms for artifacts to settle...`); + await sleep(delayMs); + } + await this.artifactManager.waitForPendingRequests( + this.config.artifactWaitMs ?? 60_000, + ); + } this.send(terminal); } finally { this.currentAbortController = null; From 97ce6ecf70752a3c7aa886eb509ca5f5ffdbbff2 Mon Sep 17 00:00:00 2001 From: Jack Brown Date: Fri, 17 Apr 2026 16:48:24 -0700 Subject: [PATCH 2/2] bump version to 0.11.2 --- packages/runtimeuse/package-lock.json | 4 ++-- packages/runtimeuse/package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/runtimeuse/package-lock.json b/packages/runtimeuse/package-lock.json index a61bdd3..4fd1514 100644 --- a/packages/runtimeuse/package-lock.json +++ b/packages/runtimeuse/package-lock.json @@ -1,12 +1,12 @@ { "name": "runtimeuse", - "version": "0.11.1", + "version": "0.11.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "runtimeuse", - "version": "0.11.1", + "version": "0.11.2", "license": "FSL", "dependencies": { "@anthropic-ai/claude-agent-sdk": "^0.2.73", diff --git a/packages/runtimeuse/package.json b/packages/runtimeuse/package.json index 792d558..b36273a 100644 --- a/packages/runtimeuse/package.json +++ b/packages/runtimeuse/package.json @@ -1,6 +1,6 @@ { "name": "runtimeuse", - "version": "0.11.1", + "version": "0.11.2", "description": "AI agent runtime with WebSocket protocol, artifact handling, and secret management", "license": "FSL", "type": "module",