-
Notifications
You must be signed in to change notification settings - Fork 445
feat(runtime): report a provider dropping context across the send boundary #4669
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -814,6 +814,7 @@ export class AiSdkCompaction { | |
| if (persisted) { | ||
| state.baselineTokens = persisted.inputTokens + (persisted.outputTokens ?? 0); | ||
| state.lastAcceptedTotalTokens = state.baselineTokens; | ||
| state.priorAcceptedInputTokens = persisted.inputTokens; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3 Related to the equality change: this is where the pre-compaction anchor gets carried into the next send. If you would rather not touch the comparison itself, the alternative fix lives here, in Separately, P3 on the note itself: it carries no numbers while its four siblings do, so a claim the user cannot dismiss is also one they cannot check. Putting |
||
| } | ||
| if (persisted) state.replyReserveTokens = replyReserveTokens(persisted.outputTokens); | ||
| return state; | ||
|
|
@@ -1464,6 +1465,14 @@ export class MidTurnCapacityCompactState { | |
| * rejection about what remains in it. | ||
| */ | ||
| compactionAppliedThisSend = false; | ||
| /** | ||
| * Input tokens of the last request a provider accepted before this send. | ||
| * | ||
| * Input against input, across the send boundary: the first request of a send | ||
| * has no earlier step to compare with, and `baselineTokens` counts the reply | ||
| * too, which the next request does not always carry. | ||
| */ | ||
| priorAcceptedInputTokens: number | undefined; | ||
|
|
||
| constructor( | ||
| readonly headAnchor: RuntimeEvent, | ||
|
|
||
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.
P2
toolSchemaShrankreadslastStepActiveToolCount, which is declared inside the send at:1565and is therefore alwaysundefinedat step 0, so this exclusion is dead across the boundary. Your own comment says it exists because Maka shaped the request and the provider dropped nothing, and that reasoning holds across turns just as well: switching permission mode, disconnecting an MCP server, or a subagent with a different tool set all shrink the schema legitimately, by thousands of tokens.The anchor does not record a tool count, so there is no cheap check here; widening it would change the
token_usageshape and cost an epoch, which is not worth it. Equality on the cross-boundary comparison sidesteps it entirely.