Skip to content

Docs: Need better documentation for using streams #25

@mmmcccarter

Description

@mmmcccarter
  • Workflow DevKit: 4.0.1-beta.2
  • Next.js: 16
  • node: 22
  • World: world-local

Problem

Workflow streaming writes chunks successfully to .next/workflow-data/streams/chunks/ but workflowHandle.getReadable() never yields them. The stream reader blocks forever.

Expected:

const handle = await run(myWorkflow, 'test-stream');
const readable = await handle.getReadable({ startIndex: 0 });
const reader = readable.getReader();
const { value } = await reader.read(); // Should return chunk

Actual:

  • reader.read() blocks indefinitely
  • Chunks exist on disk with correct data
  • Workflow completes successfully
  • No errors logged

Reproduction:

// workflow
export async function testWorkflow(streamName: string) {
  'use workflow';
  const writer = await getWritable(streamName);
  for (let i = 0; i < 3; i++) {
    await writer.write({ chunk: i });
  }
  await writer.close();
}

// route handler
export async function POST(req: Request) {
  const handle = await run(testWorkflow, 'test');
  const readable = await handle.getReadable({ startIndex: 0 });
  const reader = readable.getReader();
  const { value } = await reader.read(); // Blocks forever
  return Response.json({ value });
}

Hypothesis

The readFromStream() function should:

  1. Read existing chunk files from disk
  2. Subscribe to EventEmitter for real-time chunks

Both appear broken - EventEmitter likely doesn’t work across Next.js route boundaries, and file reading logic may also have issues.

Note: This may be the first streaming bug report for world-local. Happy to provide additional debugging info.

Have reviewed all examples but no luck

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions