Skip to content

Settle artifacts before sending terminal#30

Closed
jackcbrown89 wants to merge 2 commits intomainfrom
jb-fix-artifact-drain-timing
Closed

Settle artifacts before sending terminal#30
jackcbrown89 wants to merge 2 commits intomainfrom
jb-fix-artifact-drain-timing

Conversation

@jackcbrown89
Copy link
Copy Markdown
Contributor

@jackcbrown89 jackcbrown89 commented Apr 17, 2026

Summary

PR #29 moved the drain to run before ws.close() on orderly session end. But the log below shows the drain still happens after the WS is closed:

Waiting 3000ms for artifact watcher to drain...
WebSocket connection closed
Requesting upload for artifact: deterministic-test.zip
Stopping artifact watcher
Waiting for 1 artifact round-trips...   ← hangs, upload response will never come

The server closes the WS immediately after sending end_session_message, so anything we try to send between the terminal and close (including late chokidar-triggered artifact_upload_request_messages) is silently dropped by send()'s readyState === OPEN guard.

Chokidar's awaitWriteFinish delays add events by ~2s, so artifacts written by post-agent commands are always discovered after the terminal has already been sent.

Fix: move the drain (sleep + waitForPendingRequests) to run before send(terminal). Now artifacts get uploaded while the server is still waiting on our reply, instead of trying to send on an already-dead socket.

Bumps version to 0.11.2.

Test plan

  • npx vitest run src/session.test.ts — all 29 tests pass

Note

Medium Risk
Changes request completion timing and artifact upload ordering in the WebSocket session, which could impact latency and introduce new waiting/hanging behavior if artifact uploads don’t complete as expected.

Overview
Ensures artifacts produced during an invocation are settled and their queued upload round-trips complete before send(terminal) in WebSocketSession.handleRequest, avoiding artifact upload requests/responses being lost when the server closes the socket immediately after the terminal.

Bumps runtimeuse version from 0.11.1 to 0.11.2 (including package-lock.json).

Reviewed by Cursor Bugbot for commit 97ce6ec. Bugbot is set up for automated code reviews on this repo. Configure here.

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.
@jackcbrown89
Copy link
Copy Markdown
Contributor Author

Superseded by end_session_confirm_message protocol change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant