Skip to content

Wait for the final WebSocket result - #109

Draft
amirgholipour wants to merge 1 commit into
aws-samples:mainfrom
amirgholipour:agent/websocket-final-result-ordering
Draft

Wait for the final WebSocket result#109
amirgholipour wants to merge 1 commit into
aws-samples:mainfrom
amirgholipour:agent/websocket-final-result-ordering

Conversation

@amirgholipour

Copy link
Copy Markdown

What changed

  • Treat Strands' early complete lifecycle marker as non-terminal.
  • Keep the WebSocket stream open until the later AgentResult event is emitted.

Why this change is proposed

The runtime emits a lifecycle completion marker before it emits the final result object. The UI server treats a completion event as terminal and closes its WebSocket immediately. As a result, the final response and any result-level metrics can be lost even though processing completed successfully.

The runtime now waits for the event that actually carries the final result before allowing the client to close the stream.

Benefits

  • Prevents successful responses from appearing empty or incomplete.
  • Preserves final response content and result-level metadata.
  • Aligns the runtime event sequence with the current UI server's terminal-event behavior.
  • Changes only the incorrect lifecycle ordering assumption.

Validation

  • Confirmed the early lifecycle marker precedes AgentResult in a deployed runtime.
  • Verified a short deployed WebSocket request reaches the final result event.
  • Verified the changed runtime module compiles.
  • Reviewed the one-file diff against the current upstream main.

Authored by Saeed Kasmani (amirgholipour).

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