Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/ten-berries-start.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@workflow/core": patch
---

Ensure open stream flush is await-able in pendingOps
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Default owners for the entire repository
* @vercel/workflow

packages/next/ @ijjk @vercel/workflow
packages/next/src @ijjk @vercel/workflow
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This ensures JJ doesn't get accidentally tagged on every release PR when only changesets change

15 changes: 15 additions & 0 deletions docs/content/docs/changelog/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
title: Changelog
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is a stub so we can add changelog entries for bigger changes later

description: Latest updates and new features in Workflow DevKit.
type: overview
---

# Changelog

Stay up to date with the latest changes to Workflow DevKit.

---

## 2026

- TBD
5 changes: 5 additions & 0 deletions docs/content/docs/changelog/meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"title": "Changelog",
"pages": ["index", "eager-processing"],
"defaultOpen": false
}
36 changes: 34 additions & 2 deletions packages/core/src/serialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -501,12 +501,27 @@ export class WorkflowServerWritableStream extends WritableStream<Uint8Array> {
buffer = [];
};

/** Resolvers/rejectors waiting for the current scheduled flush */
let flushWaiters: Array<{
resolve: () => void;
reject: (err: unknown) => void;
}> = [];

const scheduleFlush = (): void => {
if (flushTimer) return; // Already scheduled

flushTimer = setTimeout(() => {
flushTimer = null;
flushPromise = flush();
const currentWaiters = flushWaiters;
flushWaiters = [];
flushPromise = flush().then(
() => {
for (const w of currentWaiters) w.resolve();
},
(err) => {
for (const w of currentWaiters) w.reject(err);
}
);
}, STREAM_FLUSH_INTERVAL_MS);
};

Expand All @@ -520,6 +535,15 @@ export class WorkflowServerWritableStream extends WritableStream<Uint8Array> {

buffer.push(chunk);
scheduleFlush();

// Wait for the scheduled flush to complete so that callers
// (like flushablePipe) know data has reached the server
// before decrementing pendingOps. Without this, pendingOps
// reaches 0 when the buffered write returns (instant), but
// the 10ms flush timer hasn't fired yet.
await new Promise<void>((resolve, reject) => {
flushWaiters.push({ resolve, reject });
});
},
async close() {
// Wait for any in-progress flush to complete
Expand All @@ -533,14 +557,22 @@ export class WorkflowServerWritableStream extends WritableStream<Uint8Array> {

await world.closeStream(name, runId);
},
abort() {
abort(reason) {
// Clean up timer to prevent leaks
if (flushTimer) {
clearTimeout(flushTimer);
flushTimer = null;
}
// Discard buffered chunks - they won't be written
buffer = [];
// Reject any pending flushWaiters so the write() promises settle
// and don't leak. Without this, write() hangs forever on an
// unsettled promise because the cleared timer will never fire.
const waiters = flushWaiters;
flushWaiters = [];
const abortError =
reason ?? new Error("Stream aborted");
for (const w of waiters) w.reject(abortError);
},
});
}
Expand Down
Loading
Loading