Repository navigation
fix(claude): keep session identity when the per-turn tk is oversized #8568
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vadymhimself
wants to merge
4
commits into
lidge-jun:dev
Choose a base branch
from
vadymhimself:fix/claude-oversized-tk-identity
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9d60128
fix(claude): keep session identity when the per-turn tk is oversized
vadymhimself 7171468
Merge remote-tracking branch 'upstream/dev' into fix/claude-oversized…
3903f11
Merge remote-tracking branch 'upstream/dev' into fix/claude-oversized…
vadymhimself cfc89a2
Merge remote-tracking branch 'upstream/dev' into fix/claude-oversized…
vadymhimself File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script executed:
Repository: lidge-jun/opencodex
Length of output: 42513
Script executed:
Repository: lidge-jun/opencodex
Length of output: 31334
Script executed:
Repository: lidge-jun/opencodex
Length of output: 23386
Script executed:
Repository: lidge-jun/opencodex
Length of output: 19955
Script executed:
Repository: lidge-jun/opencodex
Length of output: 4474
Bound metadata parsing before materializing
tk.The Messages body limit still permits a
user_idcontaining a very large JSON array insidetk. Insrc/server/request-log-conversation.ts:234,JSON.parsematerializes that array synchronously before discarding it. This can block the event loop and exhaust memory, including on native passthrough requests.Process
tkwithout materializing its contents, and bound the remaining identity before serialization. Preserve support for a largetkwith a short session ID.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Declining, for these reasons. This restores the parse that
devran before #8423, and it adds no new class of exposure:src/claude/inbound.ts:605already runsclaudeSessionUserId(raw.metadata.user_id)on every metadata-keyed Messages request at any length to buildprompt_cache_key. TheclaudeNativeSessionIdgate atclaude-messages.ts:1226only runs after that.user_id, and the request body itself is already fullyJSON.parsed. Parsing a string from that body costs the same order as the body parse that already happened.tkback into the identity for long values. The per-turn key would then change on every turn, which is the cache and routing regression this PR fixes.A streaming parse that skips
tkwithout materializing it would be a separate hardening change across both call sites. It isn't a regression introduced here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Analysis chain
Script executed:
Length of output: 64620
@vadymhimselfThanks for the explanation. I accept deferring the parser hardening.One distinction:
src/server/claude-messages.tsLine 737 runs before native passthrough at Line 763, so that path does not reachsrc/claude/inbound.tsLine 605. The outer body parse also leavesuser_idas a string; the nested parse materializes an array insidetk. The body limit bounds the input size, but the array can use more memory than its encoded input.Would you like a follow-up issue for the shared parser hardening?
Learnings used
You are interacting with an AI system.