Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(acp): preserve Grok context usage on wake replay #42610

Closedgujunxiang(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/42610/headopened View on GitHub

Showing 6 changed files with 34 additions and 11 deletions (loading 5).

x
0 of 6 viewed, 6 left
34 additions and 11 deletionsapps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.tsModified
View file
@@ -11555,6 +11555,10 @@
capabilities: AcpProviderCapabilitiesV2,
enablePostSettleContinuation: true,
deferFinalizeForBackgroundWork: true,
+ extractContextUsage: (notification) =>
+ typeof notification._meta?.totalTokens === "number"
+ ? { usedTokens: notification._meta.totalTokens }
+ : undefined,
registerExtensions: (context) =>
Effect.sync(() => {
applyMutation = context.applyBackgroundTaskMutation;
@@ -11595,8 +11599,16 @@
runtimePolicy,
const events = yield* Queue.unbounded<ProviderAdapter.ProviderAdapterV2Event>();
+ const observedContextUsages: Array<unknown> = [];
yield* runtime.events.pipe(
- Stream.runForEach((event) => Queue.offer(events, event)),
+ Stream.runForEach((event) =>
+ Effect.gen(function* () {
+ if (event.type === "provider_thread.updated") {
+ observedContextUsages.push(event.providerThread.contextUsage);
+ yield* Queue.offer(events, event);
+ }),
+ ),
Effect.forkScoped,
const providerThread = yield* runtime.ensureThread({