Skip to content

fix(streaming): stop writing workflow stream frames after the client cancels - #9197

Merged
waleedlatif1 merged 1 commit into
stagingfrom
fix/workflow-stream-write-after-cancel
Oct 18, 2026
Merged

waleedlatif1 merged 1 commit into
stagingfrom
fix/workflow-stream-write-after-cancel

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • After a client disconnects, the ReadableStream's cancel() closes the controller, but start() kept enqueueing frames: the "Client cancelled request" error, final, [DONE], chunk/thinking/tool frames, and selected-output frames from onBlockComplete
  • Each of those enqueues threw Invalid state: Controller is already closed. The terminal path logged a spurious "Stream error" (the catch's own enqueue then threw out of start()), and the block-completion path logged "Failed to materialize selected output" and rejected the executor callback. It also finished selected-output materialization and base64 hydration for a client that was already gone
  • cancel() now sets a streamCancelled flag first. Every enqueue in start() goes through one helper that does nothing once the stream is cancelled, controller.close() is skipped after cancel, and onBlockComplete returns early (and stops between descriptors) before any materialization work
  • Everything else cancel() does is unchanged: abort propagation, keepalive stop, base64 cache cleanup, and marking the logging session failed with "Client cancelled request". A client that stays connected gets byte-identical output

Type of Change

  • Bug fix

Testing

  • New regression test in streaming.test.ts: cancel the reader mid-execution, run the captured onBlockComplete with a selected output, then resolve the execution as cancelled. It asserts the callback resolves and no "Stream error" is logged
  • Red on the pre-fix code: the callback rejects with Controller is already closed. With only that assertion relaxed, the "Stream error" assertion fails on its own
  • streaming.test.ts: 32/32 passing. check:comment-hygiene and check:test-patterns clean

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing (new tests pass the test-audit authoring gate)
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercel Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Oct 18, 2026 9:05pm UTC

Request Review

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

@greptile-apps

greptile-apps Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

Stops workflow response writes after the client cancels.

  • Canceled workflow streams stop writing frames and selected outputs.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Client cancels response] --> B[Set streamCancelled]
  B --> C[Stop keepalive and abort execution]
  C --> D[Clean up request hooks and cache]
  B --> E[Later frame writes do nothing]
  B --> F[Skip new selected-output work]
  E --> G[Skip final controller close]
Loading

Reviews (1) · Last reviewed commit: "fix(streaming): stop writing workflow st..." · Reviewed by Greptile

@waleedlatif1
waleedlatif1 merged commit 246ff83 into staging Oct 18, 2026
53 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/workflow-stream-write-after-cancel branch October 18, 2026 22:12

This branch was previously deployed

1 inactive deployment
Preview — a09fa561 Deployed Oct 18, 2026 by vercel[bot]
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