Skip to content

Failed renders record zero cost instead of the tokens they spent #11

Open

Description

@hampsterx

A render that fails after spending tokens writes a failed receipt with tokens: {fresh: 0, reused: 0} and model: "none", so reactor status and receipts cost report the most expensive runs as free.

Seen on @openprose/reactor 0.3.3 under reactor serve, OpenRouter provider. A self-driven node's render grew its context for about 12 minutes until the provider rejected the next request. The receipt it left:

"cost": {"model": "none", "provider": "none", "surprise_cause": "self", "tokens": {"fresh": 0, "reused": 0}},
"semantic_diff": {"failure_reason": "400 This endpoint's maximum context length is 1048576 tokens. However, you requested about 1079532 tokens ..."},
"status": "failed"

The rejected request itself was probably not billed, but the requests before it grew toward that size over the whole run, and the ledger holds zero for all of them.

Two paths at 510af62 end the same way:

  • Provider or network error. render-backend.ts rethrows anything that isn't MaxTurnsExceededError, and runAsyncMountedRender in sdk/mounted-dag.ts catches it and substitutes noneCost(...). The usage the session accumulated before the throw is dropped.
  • Turn cap. The MaxTurnsExceededError branch in render-backend.ts returns an all-zero usage, with the comment "No usage is recoverable from the thrown error". In @openai/agents-core 0.11.8, MaxTurnsExceededError is constructed with the run state (runner/turnPreparation.mjs:20), and AgentsError.state.usage is the accumulated usage, so this path looks recoverable.

This is different from openprose/prose#175, which covers a completed render whose unchanged output drops its cost. Here the render never completes.

Where usage can't be recovered, should the receipt say the cost is unknown instead of zero? Right now a consumer summing fresh can't tell a render that cost nothing from one whose cost wasn't recorded.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions