-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat(sdk): persist compaction and injected context through the transcript storage state #4894
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
Draft
ericallam
wants to merge
1
commit into
feat/transcript-storage-seam-tri-13667
from
feat/transcript-storage-changesets-tri-13667
+611
−16
Draft
Changes from all commits
Commits
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
Oops, something went wrong.
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.
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.
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
Background injections drained through the inner-loop
prepareSteppath are never tracked, so they are silently lost fromaccumulatedMessagesand never persisted.This drain only runs when the last accumulated model message is not a
toolmessage. The comment on this block states the fallback: when the tail is atoolmessage, the queued messages are picked up instead bytoStreamTextOptions()'s own auto-injectedprepareStep(the background-context-injection step further up in this file). That sibling drain returns the injected content only insideresultMessagesfor the currentstreamTextstep. It does not push intoaccumulatedMessagesand does not push an entry intolaneInjections.Two consequences follow from the missing sync:
accumulatedMessagesno longer reflects what the model actually saw for that step. Outer-loop compaction,onTurnComplete.messages/newMessages, and any later reconversion checkpoint all operate on a lane that is missing the injected content.restoreModelLanehas no record of that injection (it was never added tolaneInjections, and it is not part of the transcript, so it cannot be recovered by reconverting UI messages either). This directly contradicts the PR's stated goal that "Injected messages are stored with anchors to the transcript messages they followed and reinserted on continuation" — for this specific, already-documented fallback case, they are not.This is reachable whenever a
chat.inject()call queues conversational content while the accumulator's last model message is atoolmessage (for example, right after a HITL tool-result exchange), and the agent's turn involves multiplestreamTextsteps (tool calls).Fix this by reconciling the inner-loop background-injection drain the same way
drainSteeringQueue/reconcilePendingSteerreconcile steering messages: record what was actually drained and its anchor, then merge it back intoaccumulatedMessagesandlaneInjectionsonce the turn'suserRun/streamTextcall returns (before the turn's snapshot is written). For example, in thetoStreamTextOptions()prepareStep step handling background context (around the block that doesconst injected = bgQueue.splice(0); resultMessages = [...(resultMessages ?? messages), ...injected];), also stashinjectedalongside the current tail id so the caller can merge it back:Then, after
userRun/streamTextreturns, mergechatPendingBackgroundInjectionKeyintoaccumulatedMessagesandlaneInjectionsthe same way the existing pre-run drain does at lines 8627-8632.None of the new tests exercise this fallback (they only cover the pre-run drain, triggered from
onTurnComplete). Consider adding a test that forces the accumulator's tail to be atoolmessage before queuing achat.inject()call, to lock in the fix.