From 57c1356d8f9a1d30f5421f2d70fbcca48ba46e84 Mon Sep 17 00:00:00 2001 From: Pranay Prakash Date: Thu, 20 Nov 2025 18:10:18 -0500 Subject: [PATCH 1/2] Attempt to fix local straming --- packages/world-local/src/streamer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/world-local/src/streamer.ts b/packages/world-local/src/streamer.ts index 9667b6afe..e58df6a08 100644 --- a/packages/world-local/src/streamer.ts +++ b/packages/world-local/src/streamer.ts @@ -182,7 +182,7 @@ export function createStreamer(basedir: string): Streamer { break; } if (chunk.chunk.byteLength) { - controller.enqueue(chunk.chunk); + controller.enqueue(new Uint8Array(chunk.chunk)); } } From 3b65788b0df546fb3049c6b4ba9def6606dd44f7 Mon Sep 17 00:00:00 2001 From: Pranay Prakash Date: Thu, 20 Nov 2025 18:17:22 -0500 Subject: [PATCH 2/2] add test and changeset . another fix . --- .changeset/curvy-showers-count.md | 5 ++ packages/world-local/package.json | 2 +- packages/world-local/src/streamer.test.ts | 56 +++++++++++++++++++++++ packages/world-local/src/streamer.ts | 3 +- 4 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 .changeset/curvy-showers-count.md diff --git a/.changeset/curvy-showers-count.md b/.changeset/curvy-showers-count.md new file mode 100644 index 000000000..4a61eddb3 --- /dev/null +++ b/.changeset/curvy-showers-count.md @@ -0,0 +1,5 @@ +--- +"@workflow/world-local": patch +--- + +Create a copy of the data when resolving a stream to rpevent detachment diff --git a/packages/world-local/package.json b/packages/world-local/package.json index 44fbc30dd..d882b966f 100644 --- a/packages/world-local/package.json +++ b/packages/world-local/package.json @@ -1,6 +1,6 @@ { "name": "@workflow/world-local", - "version": "5.0.0-beta.10", + "version": "4.0.0-beta.10", "description": "Local development World implementation for Workflow DevKit", "type": "module", "main": "dist/index.js", diff --git a/packages/world-local/src/streamer.test.ts b/packages/world-local/src/streamer.test.ts index 0ad2e1d86..0745ba938 100644 --- a/packages/world-local/src/streamer.test.ts +++ b/packages/world-local/src/streamer.test.ts @@ -318,6 +318,62 @@ describe('streamer', () => { expect(chunks.join('')).toBe('123'); }); + + it('should read from stream starting at specified startIndex', async () => { + const { streamer } = await setupStreamer(); + const streamName = 'startindex-stream'; + + // Write 5 chunks with delays to ensure different ULID timestamps + for (let i = 0; i < 5; i++) { + await streamer.writeToStream(streamName, TEST_RUN_ID, `${i}`); + await new Promise((resolve) => setTimeout(resolve, 2)); + } + await streamer.closeStream(streamName, TEST_RUN_ID); + + // Read from startIndex=2 (should get chunks 2, 3, 4) + const stream = await streamer.readFromStream(streamName, 2); + const reader = stream.getReader(); + + const chunks: string[] = []; + let done = false; + + while (!done) { + const result = await reader.read(); + done = result.done; + if (result.value) { + chunks.push(Buffer.from(result.value).toString()); + } + } + + expect(chunks.join('')).toBe('234'); + }); + + it('should read from stream starting from first chunk with startIndex=0', async () => { + const { streamer } = await setupStreamer(); + const streamName = 'startindex-zero-stream'; + + await streamer.writeToStream(streamName, TEST_RUN_ID, 'first'); + await new Promise((resolve) => setTimeout(resolve, 2)); + await streamer.writeToStream(streamName, TEST_RUN_ID, 'second'); + await streamer.closeStream(streamName, TEST_RUN_ID); + + // Read from startIndex=0 (should get all chunks) + const stream = await streamer.readFromStream(streamName, 0); + const reader = stream.getReader(); + + const chunks: string[] = []; + let done = false; + + while (!done) { + const result = await reader.read(); + done = result.done; + if (result.value) { + chunks.push(Buffer.from(result.value).toString()); + } + } + + expect(chunks.join('')).toBe('firstsecond'); + }); }); describe('integration scenarios', () => { diff --git a/packages/world-local/src/streamer.ts b/packages/world-local/src/streamer.ts index e58df6a08..1c27bad01 100644 --- a/packages/world-local/src/streamer.ts +++ b/packages/world-local/src/streamer.ts @@ -182,7 +182,8 @@ export function createStreamer(basedir: string): Streamer { break; } if (chunk.chunk.byteLength) { - controller.enqueue(new Uint8Array(chunk.chunk)); + process.stdout.write('.'); + controller.enqueue(Uint8Array.prototype.slice.call(chunk.chunk)); } }