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

opened this

Merged 20d 9h ago, 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.

Notes

opened this

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 creditUsd as 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_LOCAL is unset or unreachable, fundedEnv returns undefined and the run falls back to ownEnv(), 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.ts runs calls through the door with the fundedEnv variables and reads the host's spentUsd. 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. grantPlanCredit runs 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.

Closes #13762

4 earlier comments · 1 event
commented

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 creditUsd as 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_LOCAL is unset or unreachable, fundedEnv returns undefined and the run falls back to ownEnv(), 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.ts runs calls through the door with the fundedEnv variables and reads the host's spentUsd. 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. grantPlanCredit runs 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.

commented

<!-- 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
commented

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.

commented

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

  1. Cause of #13715: I did not fix the silent fallback. A funded child whose parent door is unreachable falls back to ownEnv() in credentialEnv, 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.
  2. 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.
  3. Test hygiene: the dynamic imports are gone, and the plan-line test now lives in test/plan-row-cap.test.ts.
  4. Comment rewraps in src/web/plan_row.ts: I couldn't revert them. gate --fix rewraps those comments again every time it runs, so they stay.
  5. Docs: the new bullets now sit inside the list in docs/features/child-credit.md, one short sentence each.
  6. 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.

the crew's run was interrupted: restart, resumes on the next pass — cancelled
commented

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.md says 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.ts sends calls through a real door and reads the host's spentUsd. 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 --noEmit passes 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

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs