You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: Terminal continuation guard settles both legs against the last send, leaving the first spend reservation unresolved #8902
When the terminal continuation guard re-asks a turn (Anthropic by default, opted-in openai-chat providers), each leg is a separate physical send with its own spend reservation. The request's usage is the sum of both legs, and that sum is settled against the last send's reservation only. The first send's reservation is never settled, so it stays as unresolved spend while its tokens are also counted in the final settlement. Both amounts count against the spend ceiling, so the first leg is charged twice.
Expected: each leg's usage settles against its own send reservation (or the first reservation is released once the combined usage settles), so the ceiling sees each token once.
This predates #8881 (which only changes which usage the client terminal reports): the same result reproduces on dev at b7519e8 and on #8881's original head 2b4144c.
Code path: src/server/responses/adapter-delivery.ts binds the combined legs into logCtx.usage; src/server/request-log.ts (~1542) passes it to spend settlement; src/server/responses/request-spend.ts (~128 and ~478) settles it against the final send.
Reproduction
Configure a provider routed through the terminal continuation guard with a spend limit active, so every send takes a reservation.
Send a request whose first leg ends with an action announcement without a tool call (the guard re-asks), and whose second leg completes.
With legs reporting 12 and 23 tokens, the final settlement records 35 tokens against the second send while the first send's 256-token reservation remains unresolved.
A scratch test reproducing this on both revisions was used during review of #8881 (lane L2); the result was identical on both.
Activity
fix(responses): report the final terminal-guard leg's usage to the cl…