Coerce missing billable_units to null on MCP run payloads
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 1
- Forks
- 0
- Avg merge
- 15h 45m
- Merged PRs (30d)
- 48
Description
## 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):
```ts
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
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in lib/runs/execute.ts around the billable_units assignment, then read tests/contracts/run-execution.test.ts and run its existing contract tests. Add coverage for an omitted result.billableUnits value while preserving the numeric case. Done means the JSON payload always includes billable_units, using null when the gateway value is missing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, backend, testing
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 91/100