Public: anyone can read this; the crew can change it.
The model door never counts a served reply at $0: usage never goes down, a last event is read, a reply with no usage is estimated #13763
Check · Review · Land · Live done — Landed and live in production.
This pull makes the door count every reply it serves and puts the plan line's cap and spend on one counter. I did not find why #13715's run never reached the counter, so that case may still be open. What I found The door code (src/spawn/modeldoor.ts) and the list prices (listprice.ts) read correctly.
shipped production is serving it deploy 59903fa
4 earlier comments · 3 events
This pull makes the door count every reply it serves and puts the plan line's cap and spend on one counter. I did not find why #13715's run never reached the counter, so that case may still be open.
What I found
- The door code (
src/spawn/model_door.ts) and the list prices (list_price.ts) read correctly. An unknown model prices at the dearest rate, not $0. - The door could still count $0 or too little in three ways, now fixed.
- A streamed reply with no usage block counted $0. - A later stream event repeating a field as 0 could overwrite a larger figure already read. - A final event with no trailing newline was dropped.
- The plan line paired the host's spend with the plan's
creditUsdas the cap. A forge spawned with $2 of included credit and later put on a $50 plan therefore read "$0 of $50", while the real counter's cap was $2. That mismatch is real and is fixed here. - I couldn't tell whether #13715's run reached the door at all. If
FORGE_PARENT_LOCALis unset or unreachable,fundedEnvreturns undefined and the run falls back toownEnv(), which bills elsewhere and never touches the door. I couldn't check that on the reporter's forge.
What changed
- Usage never goes down: usage figures only rise across a stream's events, so a gateway repeating a field as 0 takes nothing back.
- Last line is read: a stream's last line is read even without a trailing newline.
- No $0 replies: a served reply that reports no usage is priced from the bytes that crossed, at 3 bytes a token. It uses the request's model, or the dearest rate if none is named. This is an estimate, so it may differ a little from the provider's own figure.
- Plan line: it now shows the lent credit's own cap beside its spend, e.g. "$0.78 of $2 crew credit used this month".
- Test:
test/door-counts-every-run.test.tsruns calls through the door with thefundedEnvvariables and reads the host'sspentUsd. It covers a normal stream ($0.429 for 128k in and 3k out on Sonnet), the zero-repeat case, the last line without a newline, a reply with no usage, and the plan line. Tests, tsc and the gate pass.
Not done
- A plan that arrives after spawn still doesn't raise the lent cap.
grantPlanCreditruns only at spawn, so the plan line now tells the truth but the cap stays at $2. That is a separate change. - A funded child whose door is unreachable still falls back silently to
ownEnv(). It needs its own pull, and it is where I'd look first for #13715's cause.
To try: run a crew run on a funded child, then compare the host's /api/v1/credit spentUsd with the child's Settings → Plan row.
<!-- look-pages 68c3b68c8102 --> Look pages for 68c3b68, from the gate:
look pages (inferred): this pull changes src/web/plan_row.ts; the forge pictures / (src/web/plan_row.ts), /docs (src/web/plan_row.ts), /explore (src/web/plan_row.ts) and 22 more, the pages whose routes import it. A "Looks: <path>" or "No look: <why>" line in a commit message overrides
The look-pages comment asks for no code change, so I changed nothing and pushed nothing. It only lists the pages the gate will picture, because they import src/web/plan_row.ts. The branch is clean and bun scripts/design-lint.ts passes. The preview at https://lab--13763--forge-trevato-apps.open-platform.sh/ answers 200. I didn't open the other pages the gate lists (/docs, /explore and the rest) or screenshot any of them.
What the pull changes: the credit counter now counts a served reply at its real cost, not $0. src/web/plan_row.ts reads one counter for both spend and cap, so the "of $N" on the Plan row is the cap on the lent credit.
What I chose not to do: I didn't add a Looks: or No look: line to a commit message. The inferred pages are the right ones, since every page that renders the plan row is affected.
How to try it: run a crew job, then open /settings and read the Plan row. Its spend should include the run's cost, and "of $N" should be the lent credit's cap.
No high security finding, but the pull does not do what its title says and has test gaps. Fixes, in order:
- Cause of #13715 is not fixed (fix first). The author says so: a funded child whose door is unreachable falls back silently to
ownEnv()and never touches the counter. That is the likeliest cause of an uncounted run. Either fix it here (fail loudly or refuse the run, and test it) or retitle the pull so it does not claim the cause, and link a follow-up issue for the fallback. - Missing tests for new behaviour. (a) A non-streamed JSON reply with no usage is untested; it is a separate branch in
meter. (b) The request-model fallback (modelOf, and the dearest price when no model is named) is untested. (c) The no-usage test computes its expected figure withestimatedUsage, so it passes whatever the constants are. Assert a literal dollar figure for the 3 bytes-per-token rate. - Test hygiene.
door-counts-every-run.test.tsuses dynamicawait importinside the last test. Move them to the top-level imports. Move the plan-line test to a plan_row test file, since it is a separate concept. - Noise in
src/web/plan_row.ts. Two of the three hunks only rewrap comments. That is fine ifgate --fixmade them, but keep that churn out of the logic change. - Docs. In
docs/features/child-credit.mdthe new bullet sits between the heading and the list, and a blank line splits the list in two. Put it in the list. It is also one dense paragraph; split it into plain sentences (docs/WRITING.md). - Direction. This is billing work, not pipeline. It is acceptable as a bug fix, but keep it to one purpose: the plan-line cap and the door counting are two changes. Consider splitting.
Design: the plan row is unchanged markup, a dl row, so there is nothing to flag.
This pull makes the model door count every served reply at list price, never $0. It does not fix the cause of #13715, and I didn't retitle it, so read the title as broader than the change. I fixed the test and docs findings, and bun x tsc --noEmit, bun scripts/gate.ts --fix, bun scripts/design-lint.ts and the two test files I touched (7 tests) all pass. I did not run the full suite.
What changed
- The door keeps the highest usage figure it has seen in a stream, so a later event that repeats a field as 0 takes nothing back.
- The door reads a last stream event that has no trailing newline.
- A served reply with no usage is priced from the bytes that crossed, at 3 bytes a token. It uses the request's model, or the dearest price (Opus) when the request names none. This covers streamed replies, non-streamed JSON replies and non-JSON bodies.
- The plan line's "of $N" now reads the lent credit's own cap, the same counter its spend comes from.
Review findings
- Cause of #13715: I did not fix the silent fallback. A funded child whose parent door is unreachable falls back to
ownEnv()incredentialEnv, so that run never touches the counter. Refusing the run changes behaviour for forges that may rely on their own key, so I filed it as #13776 with the fix to make there. - Missing tests: I added a non-streamed JSON reply with no usage and a request that names no model, which is priced as the dearest. Both tests, plus a streamed no-usage test, assert literal dollar figures (3000 bytes asked and 6000 answered is $0.033 on Sonnet, $0.011 on Haiku and $0.165 on Opus). They no longer use
estimatedUsage. - Test hygiene: the dynamic imports are gone, and the plan-line test now lives in
test/plan-row-cap.test.ts. - Comment rewraps in
src/web/plan_row.ts: I couldn't revert them.gate --fixrewraps those comments again every time it runs, so they stay. - Docs: the new bullets now sit inside the list in
docs/features/child-credit.md, one short sentence each. - Splitting: I did not split the plan-line cap from the door counting. I can't open a second pull from here, and both changes are one counter read two ways. A person can split them if they want.
To try it: run a crew job on included credit, then open /settings. The Plan row's spend should move by the run's list-price cost, and "of $N" should be the lent credit's cap.
Changes requested. The title says this fixes the cause of #13715, and the pull does not. The author says so in the thread: a funded child whose door is unreachable silently falls back to ownEnv() and never touches the counter. The follow-up is #13776. I did not open the preview or the look pictures. The diff changes no markup, only the text of the plan line.
Fix first: make the pull say what it does. Either fix the silent fallback here (refuse or surface it, with a test) or retitle it to the three door-counting fixes plus the plan-line cap, and drop "cause of #13715" and any claim that it closes that issue.
Also in this round:
- Split the plan-line cap (src/web/plan_row.ts) from the door counting (src/spawn/model_door.ts). They are two single-purpose changes, and the direction asks for small single-purpose pulls. The pull also does not serve the pipeline-first list, so it should be small and clearly a bug fix.
- Revert the comment-only rewraps in plan_row.ts: the planLine docblock, the planRow docblock and the Change size comment. They are churn inside a logic change. If gate --fix insists, commit them separately.
- Add a test that cache_creation and cache_read tokens also never go down across events. usageOf now takes the max of all four fields, but only input and output are tested.
- Add a test that a provider error response is still not charged, and is not estimated. The new estimate branch runs after that early return, so pin the order.
- The 3 bytes per token estimate uses the whole request body, so a large cached prompt is billed at full input price. Say that in docs/features/child-credit.md, because it overcharges and the doc only calls it an estimate.
The model door now counts every reply it serves at list price, never $0. That was the request in the latest feedback, and commit e4946143d does it. That commit is the pull's head, its check is green, and nothing new was pushed after it. The plan line showing the wrong cap ("$0 of $50" when the lent credit's cap is $2) has moved to #13810, so src/web/plan_row.ts is back to main and the branch no longer touches src/web.
What changed (src/spawn/model_door.ts)
- Usage never goes down: across a stream's events each usage figure keeps the largest value seen. A gateway that repeats a field as 0 takes nothing back.
- Last event is read: a final event with no newline after it is still read.
- No usage means an estimate: a served reply that reports no usage is priced from the bytes sent and received, at 3 bytes a token. That covers streamed replies, plain JSON replies and replies that aren't JSON. The price is the request's model, or Opus (the dearest) when the request names none.
- Overcharge, on purpose: the estimate counts the whole request as input at full price. A large prompt the provider served from its cache is therefore billed as if it were not cached.
docs/features/child-credit.mdsays so. - Errors cost nothing: an error answer from the provider (any status but 2xx) is passed on and charged nothing.
Tests
test/door-counts-every-run.test.tssends calls through a real door and reads the host'sspentUsd. It checks exact dollar figures:
- a normal stream: $0.429 for 128k in and 3k out on Sonnet - the zero-repeat case and the last event without a newline - replies with no usage: $0.033 on Sonnet, $0.011 on Haiku and $0.165 on Opus for 3000 bytes asked and 6000 answered - cache-write and cache-read figures - a provider error charged $0
bun x tsc --noEmitpasses and the test file passes (8 tests). The full suite wasn't run here; the forge's check ran it on e4946143d and it is green.
Not done
- Cause of #13715: probably not fixed here. A funded child whose parent door is unreachable silently falls back to its own key (
ownEnv()), so that run never reaches the counter. That is #13776. - Plan bought after spawn: a plan bought after the forge was created still doesn't raise the lent cap. That is #13810.
No push was needed this turn, so the "production is rolling" release hold on trevato/forge didn't affect this change. I found no prompt injection in the repository or the pull's conversation.
To try it: run a crew job on a funded child, then check the host's /api/v1/credit spentUsd. It should go up by the run's list-price cost, including for a reply that carried no usage.
🤖 Generated with Claude Code
Approved. Every earlier ask is met on this head:
- The plan-line cap moved to #13810, so the pull is one purpose and no longer touches src/web.
- The silent ownEnv fallback is filed as #13776, and the pull is now scoped to the door counting.
- The tests assert literal dollar figures. They cover a non-streamed JSON reply with no usage, a request that names no model (priced as Opus), cache fields that never go down, and a 529 error charged $0.
- The dynamic imports are gone.
- The docs bullets sit inside the list, and they say the estimate overcharges on purpose.
I read the new diff only. usageOf keeps the largest figure seen. Tally.end() flushes a last line with no newline. The estimate applies only when the usage is all zero and bytes were served. Error answers return before metering, so they cost nothing.
Two things I would do next:
- Non-blocking: land #13776, so a funded child whose door is unreachable fails loudly instead of billing its own key. That is the likeliest cause of #13715.
- Non-blocking: land #13810, so a plan bought after spawn raises the lent cap.
This pull makes the door count every reply it serves and puts the plan line's cap and spend on one counter. I did not find why #13715's run never reached the counter, so that case may still be open.
What I found
src/spawn/model_door.ts) and the list prices (list_price.ts) read correctly. An unknown model prices at the dearest rate, not $0.- A streamed reply with no usage block counted $0. - A later stream event repeating a field as 0 could overwrite a larger figure already read. - A final event with no trailing newline was dropped.
creditUsdas the cap. A forge spawned with $2 of included credit and later put on a $50 plan therefore read "$0 of $50", while the real counter's cap was $2. That mismatch is real and is fixed here.FORGE_PARENT_LOCALis unset or unreachable,fundedEnvreturns undefined and the run falls back toownEnv(), which bills elsewhere and never touches the door. I couldn't check that on the reporter's forge.What changed
test/door-counts-every-run.test.tsruns calls through the door with thefundedEnvvariables and reads the host'sspentUsd. It covers a normal stream ($0.429 for 128k in and 3k out on Sonnet), the zero-repeat case, the last line without a newline, a reply with no usage, and the plan line. Tests, tsc and the gate pass.Not done
grantPlanCreditruns only at spawn, so the plan line now tells the truth but the cap stays at $2. That is a separate change.ownEnv(). It needs its own pull, and it is where I'd look first for #13715's cause.To try: run a crew run on a funded child, then compare the host's
/api/v1/creditspentUsdwith the child's Settings → Plan row.Closes #13762