Skip to content

fix(ndc): record what a refused compression cost - #188

Merged
fdaviddpt merged 2 commits into
mainfrom
max/ndc-token-accounting-180
Jul 26, 2026
Merged

fdaviddpt merged 2 commits into
mainfrom
max/ndc-token-accounting-180

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

Closes #180.

log_tokens sat inside the success branch of the NDC block. Since #178 that block has a third outcome — the model answering with a refusal or a clarification — and those calls went out, spent input and output tokens, and cost money that was never recorded.

The failure mode is the one #178 was about: a model that starts refusing compression gives a run where memory stops growing and reported cost drops to zero. That reads as "nothing happened" rather than "this failed repeatedly and was paid for".

The call is now accounted for before its verdict is read, because spending it is what already happened.

The issue suggested checking the summarize path in Step 6 for the same shape — it already logs before it branches, so it needs nothing.

Test

tests/test_ndc_reject_gate.py gains a case that drives a rejected NDC call with real token counts and asserts the numbers reaching the log are the ones the call spent, not merely that some line exists. The reject-gate stub gains STUB_NDC_TOKENS for that; unset, it emits zeros exactly as before, so no existing test changes behaviour.

Red against pre-fix code, green after. Full suite: 735 passed, 41 skipped.

fdaviddpt pushed a commit that referenced this pull request Jul 26, 2026
Review of #188 pointed out the entry read as though every NDC call is now
accounted for. It is not: a call that times out or exits non-zero raises inside
call_haiku before any token counts exist, so there is nothing to log on that
path. Narrowed to what the change actually does, with the remaining gap tracked
in #190 rather than implied away.

Co-Authored-By: Max <noreply>
@fdaviddpt

Copy link
Copy Markdown
Contributor Author

Review point taken — the entry did read as though every NDC call is now accounted for, and it is not.

A call that times out or exits non-zero raises inside call_haiku before any token counts exist, so there is nothing to log on that path: cmd_call_haiku catches the RuntimeError and exits 1 without ever emitting TK_*. That is a real hole of the same shape, one branch over, and it needs either parsing usage out of the JSON failure payload or logging the attempt with an explicit unknown cost — neither of which belongs in this diff.

CHANGELOG narrowed to the outcomes this actually covers, and the remaining gap is tracked in #190 rather than implied away.

vsajan added 2 commits July 26, 2026 23:53
`log_tokens` sat inside the success branch of the NDC block, so a call the
model answered with a refusal or a clarification — which since #178 has its own
branch — was never accounted for. The call had already gone out and already
cost money; what came back does not change that.

The failure mode is the one #178 was about. A model that starts refusing
compression gives a run where memory stops growing AND reported cost drops to
zero, which reads as "nothing happened" rather than "this failed repeatedly and
was paid for".

Moved above the branch, so every outcome is recorded. The summarize path in
Step 6 already logs before it branches — checked while in there, it needs
nothing.

The reject-gate stub gains configurable token counts (STUB_NDC_TOKENS, default
unchanged) so the new test can assert the logged numbers are the ones the call
actually spent, not just that some line exists.

Co-Authored-By: Max <noreply>
Review of #188 pointed out the entry read as though every NDC call is now
accounted for. It is not: a call that times out or exits non-zero raises inside
call_haiku before any token counts exist, so there is nothing to log on that
path. Narrowed to what the change actually does, with the remaining gap tracked
in #190.

Co-Authored-By: Max <noreply>
@fdaviddpt
fdaviddpt force-pushed the max/ndc-token-accounting-180 branch from 5b9811a to 723b7a8 Compare July 26, 2026 21:53
@fdaviddpt
fdaviddpt merged commit 9d02e05 into main Jul 26, 2026
12 checks passed
@fdaviddpt
fdaviddpt deleted the max/ndc-token-accounting-180 branch July 26, 2026 22:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NDC reject path spends Haiku tokens that never reach log_tokens

2 participants