Skip to content

[world-local] Tidy stream chunk list code#1494

Merged
VaguelySerious merged 38 commits into
mainfrom
peter/updates-stream-metadata
Mar 30, 2026
Merged

[world-local] Tidy stream chunk list code#1494
VaguelySerious merged 38 commits into
mainfrom
peter/updates-stream-metadata

Conversation

@VaguelySerious
Copy link
Copy Markdown
Member

No description provided.

VaguelySerious and others added 30 commits March 19, 2026 17:44
c
Signed-off-by: Peter Wielander <mittgfu@gmail.com>
Negative startIndex values (e.g. -3) resolve to n chunks before the
known end of the stream. All world implementations (local, postgres,
vercel) support this. Includes unit tests, e2e test, and doc updates.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Peter Wielander <mittgfu@gmail.com>
Replaces three separate tests (no startIndex, positive, negative) with a
single describe block that iterates over startIndex cases. Fixes the
negative startIndex test by waiting for workflow completion before
connecting the reader — the backend resolves negative indices at
connection time using knownChunkCount, which is 0 if the stream hasn't
been fully written yet.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Peter Wielander <mittgfu@gmail.com>
Signed-off-by: Peter Wielander <mittgfu@gmail.com>
Replaces three separate tests (no startIndex, positive, negative) with a
single describe block that iterates over startIndex cases. Fixes the
negative startIndex test by waiting for workflow completion before
connecting the reader — the backend resolves negative indices at
connection time using knownChunkCount, which is 0 if the stream hasn't
been fully written yet.

Signed-off-by: Peter Wielander <mittgfu@gmail.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Peter Wielander <mittgfu@gmail.com>
- Clarify that negative startIndex is for custom consumers, not WorkflowChatTransport
- Add live-stream caveat for negative startIndex resolution timing
- Add pagination limitation callout for live streams
- Use explicit typeof guards for negative startIndex checks (world-local, world-postgres)
- Add cost comment for EOF marker disk read in world-local

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Peter Wielander <mittgfu@gmail.com>
c
Signed-off-by: Peter Wielander <mittgfu@gmail.com>
Co-authored-by: Pranay Prakash <pranay.gp@gmail.com>
Signed-off-by: Peter Wielander <mittgfu@gmail.com>
Signed-off-by: Peter Wielander <mittgfu@gmail.com>
Signed-off-by: Peter Wielander <mittgfu@gmail.com>
Signed-off-by: Peter Wielander <mittgfu@gmail.com>
Signed-off-by: Peter Wielander <mittgfu@gmail.com>
Signed-off-by: Peter Wielander <mittgfu@gmail.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Signed-off-by: Peter Wielander <mittgfu@gmail.com>
Copy link
Copy Markdown
Member

@TooTallNate TooTallNate left a comment

Choose a reason for hiding this comment

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

Clean refactoring — the listChunkFilesForStream helper is a correct, character-for-character extraction of the duplicated file-listing logic from getStreamChunks and getStreamInfo. The new unit tests are solid and cover pagination, in-progress streams, empty/nonexistent streams, invalid cursors, and single-chunk edge cases.

What I verified:

  • The extracted helper logic is semantically identical to both original inline blocks (only cosmetic differences: a removed comment, variable renames fileExtMapextMap / chunkFilesfiles restored via destructuring at call sites).
  • The helper is correctly defined outside createStreamer and takes tag as an explicit parameter rather than closing over it.
  • The helper uses its own local tagSfx, distinct from createStreamer's tagSuffix — no variable shadowing issues.
  • All downstream references to chunkFiles and fileExtMap in both methods are preserved via destructuring aliases.
  • Test coverage is good: getStreamChunks tests pagination, in-progress, nonexistent, and invalid cursor; getStreamInfo tests completed, in-progress, nonexistent, and single-chunk.
  • 100 CI checks pass. However, the DCO check fails because the first commit ("c") lacks a Signed-off-by line.

Two issues:

  1. Blocking (DCO): The first commit 5d243a3 has message "c" without a Signed-off-by line, failing the DCO check. This needs a rebase/amend to add the sign-off.

  2. Non-blocking (missed third duplicate): readFromStream (~lines 472-498) contains an identical copy of the same file-listing logic that was not refactored. See inline comment.

@@ -55,6 +55,43 @@ export function deserializeChunk(serialized: Buffer) {
return { eof, chunk };
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Non-blocking: readFromStream (around lines 472-498 in the current file) contains a third identical copy of the file-listing logic that this PR extracts into listChunkFilesForStream. Since the whole point of this PR is DRYing up this pattern, it would be worth updating readFromStream too:

const { files: chunkFiles, extMap: fileExtMap } =
    await listChunkFilesForStream(chunksDir, name, tag);

This would eliminate the last remaining duplicate. Fine to do in a follow-up if you prefer.

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.

Done — replaced the inline file-listing logic in readFromStream with listChunkFilesForStream(chunksDir, name, tag). All 41 streamer tests pass.

Copy link
Copy Markdown
Member

@TooTallNate TooTallNate left a comment

Choose a reason for hiding this comment

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

Updating my review — the DCO sign-off is a process issue for the author to fix, not a code blocker.

The refactoring is correct and the tests are solid. LGTM with one optional suggestion (see prior inline comment about the third duplicate in readFromStream).

Addresses review feedback: replaces the third inline copy of the
file-listing logic in readFromStream with the extracted helper.

Signed-off-by: Peter Wielander <peter@vercel.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@VaguelySerious VaguelySerious merged commit bd1f7e4 into main Mar 30, 2026
102 of 103 checks passed
@VaguelySerious VaguelySerious deleted the peter/updates-stream-metadata branch March 30, 2026 19:15
@ghost ghost mentioned this pull request Mar 30, 2026
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.

2 participants