Skip to content

Commit 65be69c

Browse files
committed
fix(acp): turn token spend no longer blocks provider handoffs
An idle state_update reports tokens consumed across every model request in the turn, but it was stored as context occupancy and replaced the window size from usage_update. Long Claude ACP turns then exceeded the 128k fallback window and every switch back to ACP was refused. Context usage now comes only from usage_update. Fixes #22407
1 parent 31dcc7c commit 65be69c

4 files changed

Lines changed: 3 additions & 20 deletions

File tree

‎apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1148,7 +1148,6 @@ describe("AcpRegistryAdapterV2", () => {
11481148
[
11491149
{ usedTokens: 2_500, maxTokens: 10_000, cost: { amount: 0.42, currency: "USD" } },
11501150
{ usedTokens: 2_500, maxTokens: 10_000, cost: { amount: 0.42, currency: "USD" } },
1151-
{ usedTokens: 3_000 },
11521151
],
11531152
);
11541153
assert.deepEqual(childThreads.at(-1)?.nativeMetadata, {

‎packages/provider-acp/src/server/adapter.ts‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4524,10 +4524,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
45244524
if (yield* projectAgentTerminalUpdate(notification, context)) return;
45254525
if (
45264526
update.sessionUpdate === "usage_update" ||
4527-
update.sessionUpdate === "session_info_update" ||
4528-
(update.sessionUpdate === "state_update" &&
4529-
update.state === "idle" &&
4530-
update.usage != null)
4527+
update.sessionUpdate === "session_info_update"
45314528
) {
45324529
const stateEvent = parseSessionUpdateEvent(notification).events.find(
45334530
(event) => event._tag === "UsageUpdated" || event._tag === "SessionInfoUpdated",
@@ -4578,7 +4575,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
45784575
providerThread,
45794576
});
45804577
}
4581-
if (update.sessionUpdate !== "state_update") return;
4578+
return;
45824579
}
45834580
if (yield* followNativeChild(notification, context)) return;
45844581
if (

‎packages/provider-acp/src/server/runtimeModel.test.ts‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -954,10 +954,7 @@ describe("AcpRuntimeModel", () => {
954954
data: { rawOutput: "Retained the implementation decisions." },
955955
},
956956
});
957-
expect(idle.events[0]).toMatchObject({
958-
_tag: "UsageUpdated",
959-
usage: { usedTokens: 420 },
960-
});
957+
expect(idle.events).toEqual([]);
961958
});
962959

963960
it("applies ACP v2 agent-owned terminal snapshots and output chunks", () => {

‎packages/provider-acp/src/server/runtimeModel.ts‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,16 +1563,6 @@ export function parseSessionUpdateEvent(params: EffectAcpSchema.SessionNotificat
15631563
}
15641564
break;
15651565
}
1566-
case "state_update": {
1567-
if (upd.state === "idle" && upd.usage !== undefined && upd.usage !== null) {
1568-
events.push({
1569-
_tag: "UsageUpdated",
1570-
usage: { usedTokens: upd.usage.totalTokens },
1571-
rawPayload: params,
1572-
});
1573-
}
1574-
break;
1575-
}
15761566
case "usage_update": {
15771567
const currency = upd.cost?.currency.trim().slice(0, 32);
15781568
events.push({

0 commit comments

Comments
 (0)