fix(agent): seed hydrated transcripts with estimated context usage#3335
Closed
tatoalo wants to merge 2 commits into
Closed
fix(agent): seed hydrated transcripts with estimated context usage#3335tatoalo wants to merge 2 commits into
tatoalo wants to merge 2 commits into
Conversation
Hydrated session transcripts write usage: 0 on every message, so a resumed SDK session believes its context is empty and cannot trigger auto-compaction until the first API response comes back (or fails). Seed the last assistant message with the estimated token count of the rebuilt conversation so context accounting starts near reality. Generated-By: PostHog Code Task-Id: c6065620-5694-4478-a20a-fec4ccde8f1a
|
Merging to
After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here |
|
React Doctor found no issues in the changed files. 🎉 Reviewed by React Doctor for commit |
…d lines Generated-By: PostHog Code Task-Id: c6065620-5694-4478-a20a-fec4ccde8f1a
Contributor
Author
|
with the hydration budgets capped at ~half the window (#3331) and the workspace transcript mirror making cold hydration rare (#3333), the SDK learns its real context size from the first API response anyway, so seeding estimated usage adds little. The prompt-too-long fallback (#3334) covers the residual risk. |
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.
Problem
When a cold resume rebuilds the session transcript from S3 logs, every rebuilt message carries
usage: 0. The resumed SDK session therefore believes its context is nearly empty: it cannot trigger auto-compaction proactively and only learns the real context size from the first API response — or from a "prompt is too long" rejection, at which point compaction itself is already impossible. This was visible in a real failure where the SDK reported a compact boundary of ~16k pre-tokens while the actual request weighed over 1.1M tokens.Follow-up to #3331.
Changes
usage.input_tokenswith the estimated token count of the rebuilt conversation, so the SDK's context accounting starts near reality and auto-compaction can fire before the first API call when warranted.How did you test this?
pnpm exec vitest run src/adapters/claude/session/jsonl-hydration.test.ts— 58 passed, 1 pre-existing failure (sanitizeSessionJsonlwarn-path test) that also fails onmain.tsc --noEmiton the agent package.Automatic notifications
Created with PostHog Code