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", 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;