Skip to content

[Bug]: Terminal continuation guard settles both legs against the last send, leaving the first spend reservation unresolved #8902

Closed

Description

@lidge-jun

Client or integration

Direct HTTP/API client

Area

Proxy and routing

Summary

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

  1. Configure a provider routed through the terminal continuation guard with a spend limit active, so every send takes a reservation.
  2. Send a request whose first leg ends with an action announcement without a tool call (the guard re-asks), and whose second leg completes.
  3. 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.

Version

dev at b7519e8

Operating system

Any (reproduced in Bun tests on macOS)

Provider and model

Anthropic (terminal continuation guard default); any opted-in openai-chat provider

Logs or error output

No response

Screenshots and supporting files

No response

Redacted configuration

No response

Checks

  • I searched existing issues and documentation.
  • I removed secrets, tokens, account details, request credentials, and personal data.

Activity

  1. added
    bug
    on Nov 18, 2026
  2. added
    proxy
    tools
    on Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugproxytools

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions