Page get_result by stored byte range without reading the whole stash (#540) - #550
Merged
Merged
Conversation
…540) A stashed result is stored as base64 chunks under one key each — 48 KiB of result text per chunk, widening past roughly 1.5 MB so a result never occupies more than 33 keys — and get_result reads and decodes only the chunks a page covers plus a few bytes of UTF-8 boundary lookaround. Paging cost now tracks the page rather than the total: a 1.2 MB result and a 300 KB one cost the same per page. Offsets, nextOffset, totalBytes, and character-boundary alignment are unchanged, an envelope is still one stash entry charged its total ASCII length, and entries stashed in the two earlier formats stay readable for the rest of their 15-minute TTL. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #540.
#546 already removed the per-page full encode the issue describes:
get_resultdecodes only the page's base64 range. What remained was the storage read. The whole envelope lived under one key, so every page fetched the full stored value (about 1.33 million characters per 1 KB page of a 1 MB result), whichdocumentation/meta-tools.mdadmitted in as many words.What changes
get_resultreads only the chunks a page covers.nextOffset,totalBytes, and UTF-8 boundary alignment are unchanged. Entries stashed in the v1 single-key format and as pre-v1 raw text stay readable for the rest of their 15-minute TTL.Trade-off
One stash write becomes up to 33.
fileStoragerewrites its file per write and already reads from memory, so Node deployments pay more per stash and gain nothing on reads; Workers KV is where the read saving lands. The chunk width and key cap (RESULT_CHUNK_BYTES,RESULT_MAX_CHUNKS) are the dials.Tests
In
test/meta-tools-call.test.ts: a structural read-count test (same page against a 300 KB and a 1.2 MB result reads the same amount, within a 33-key bound), byte-exact reassembly across chunk boundaries at a page size coprime with the chunk width, and both pre-chunk formats still paging.npm run checkpasses: 120 files, 3274 tests passed, 37 skipped.🤖 Generated with Claude Code