Skip to content

Coerce missing billable_units to null on MCP run payloads #76

Description

@eliteprox

Summary

billable_units is forwarded from result.billableUnits without coercion in lib/runs/execute.ts. When that value is undefined (non-blocking/queued executions or older gateway responses), JSON.stringify omits the key even though the intended contract is number | null and the field should always be present.

Caught on main by a follow-up review of code that has not changed since the last PR review.

Location

lib/runs/execute.ts (~line 252):

billable_units: result.billableUnits,

Contract tests already assert the field is present as number | null:

  • tests/contracts/run-execution.test.ts"never repeats paid execution when terminal storage fails" expects billable_units to be null
  • "forwards billable_units from the gateway result" expects a numeric value when the gateway provides one

There is no coverage for the missing/undefined case.

Proposed fix

Coerce missing units to null before putting them on the payload, e.g. result.billableUnits ?? null.

Add a contract test where the gateway result omits billableUnits (queued / non-blocking / older response) and assert the JSON payload still includes "billable_units": null.

Test plan

  • Coerce undefined / omitted billableUnits to null in the execute payload
  • Keep forwarding numeric values unchanged
  • Add a contract test for the omitted-units path

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