Repository navigation
fix(client-runtime): prefer newer completed compaction over stale liveUsage #39024
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
49e62d4
19a7592
a7a4772
f56a2d7
e3ed130
0a730d0
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 |
|---|---|---|
|
|
@@ -1499,6 +1499,16 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr | |
| ...(summary === undefined || summary.length === 0 ? {} : { summary }), | ||
| }, | ||
| }); | ||
| // The pre-compaction step would otherwise settle the turn as its newest usage. | ||
| if (status === "completed") turn.lastStep = undefined; | ||
|
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. Clear pre-compaction usage even when no compaction start was tracked.
Run the completed-compaction usage reset before the early return, so it does not depend on a tracked compaction item. Keep compaction item emission gated on a tracked start.
|
||
| if (status === "completed" && state.providerThread.contextUsage !== null) { | ||
| state.providerThread = { | ||
| ...state.providerThread, | ||
| contextUsage: null, | ||
| updatedAt, | ||
| }; | ||
| yield* emitProviderThread(state); | ||
| } | ||
| if (status !== "running") turn.compaction = undefined; | ||
| }); | ||
|
|
||
|
|
||
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.
Use fresh provider usage when a count-less compaction is newer than the live usage.
When the latest completed compaction has no
afterTokenCount,deriveLatestContextWindowSnapshotreturnsnullonce the compaction is newer thanliveUsage.updatedAt(packages/client-runtime/src/state/contextWindow.ts:140-155). TheproviderThread.contextUsagebranch is never evaluated. ACP can produce this state. A completed compaction clearscontextUsageand sets noafterTokenCount(packages/provider-acp/src/server/adapter.ts:4573-4590). A laterUsageUpdatedreport then setscontextUsageagain (adapter.ts:5579-5585). Until the next turn updatesliveUsage, the meter stays empty even though fresh usage exists.Compare the compaction time with the time of the provider-reported usage. Use the provider-reported usage when it is newer than the compaction. Return
nullonly when no provider-reported usage is newer than the compaction. Keep the current behavior when the compaction is absent or newer than all usage, and when the usage predates it. Date provider-reported usage by its own refresh, not by a metadata-only update, so that an inherited value does not reappear as fresh.Scope of this finding
The defect applies only when
liveUsageis non-null and older than the post-compaction provider usage. WhenliveUsageis absent, the existing provider-usage branch already handles the case.