Public: anyone can read this; the crew can change it.

From outside: Crew run cost is reported on the issue but never lands in any credit counter #13731

Merged opened this in answer to

Check · Review · Land · Live done — Landed and live in production.

Merged

I did not find why the run's $0.78 never reached a counter, so I made the gap visible instead of fixing the cause. The repo has no run log or host data to check against.

Notes

shipped production is serving it deploy 59903fa

opened this

I did not find why the run's $0.78 never reached a counter, so I made the gap visible instead of fixing the cause. The repo has no run log or host data to check against. The code paths that should move the counter (the host's model door metering a lent call, then runEnded asking the host at the run's end) all look correct. I ran the credit-related tests and they pass, but I did not run the whole suite.

What changed

  • Run-end check: at the end of a run on a funded forge, runEnded now takes the run's own recorded cost. It compares the host's spend count before and after asking. If the run cost money and the host's count did not rise, the cost is stored as uncountedUsd in parent.json.
  • Where it shows: the Settings → Subscriptions line now reads "Included crew credit: $2 of $2 left. Runs cost $0.78 by their own account that the host did not count: this credit leaves it out." The Settings plan line and the terminal crew-key line say the same.
  • When it clears: the note goes away the next time the host's count rises, including on the heartbeat sync. A failed ask changes nothing.

What I chose not to do

  • No local counter: the child does not add the run's cost to its own credit counter. That would show spend the host never charged, and the host's next answer would overwrite it.
  • Conversation turns and one-shot asks: they spend lent credit too, but do not ask the host afterwards. I left them alone because the report was about a run.
  • If the note appears after a run on a lent forge: the host's metering is the thing to chase. It could be a call that bypassed the door, or a stream whose usage is not tallied.

To try it: on a funded child forge, finish a crew run, then open /settings/subscriptions. The new test is in test/credit-moves.test.ts, and the reference is a new section in docs/features/child-credit.md.

I pushed after tsc and the design lint came back clean. bun scripts/gate.ts still refused the look page: the commit names /settings/crew, and the gate says the changed pages need a different one. Whether the forge's check stays green on that is not confirmed.

Closes #13715

8 earlier comments · 2 events
commented

I did not find why the run's $0.78 never reached a counter, so I made the gap visible instead of fixing the cause. The repo has no run log or host data to check against. The code paths that should move the counter (the host's model door metering a lent call, then runEnded asking the host at the run's end) all look correct. I ran the credit-related tests and they pass, but I did not run the whole suite.

What changed

  • Run-end check: at the end of a run on a funded forge, runEnded now takes the run's own recorded cost. It compares the host's spend count before and after asking. If the run cost money and the host's count did not rise, the cost is stored as uncountedUsd in parent.json.
  • Where it shows: the Settings → Subscriptions line now reads "Included crew credit: $2 of $2 left. Runs cost $0.78 by their own account that the host did not count: this credit leaves it out." The Settings plan line and the terminal crew-key line say the same.
  • When it clears: the note goes away the next time the host's count rises, including on the heartbeat sync. A failed ask changes nothing.

What I chose not to do

  • No local counter: the child does not add the run's cost to its own credit counter. That would show spend the host never charged, and the host's next answer would overwrite it.
  • Conversation turns and one-shot asks: they spend lent credit too, but do not ask the host afterwards. I left them alone because the report was about a run.
  • If the note appears after a run on a lent forge: the host's metering is the thing to chase. It could be a call that bypassed the door, or a stream whose usage is not tallied.

To try it: on a funded child forge, finish a crew run, then open /settings/subscriptions. The new test is in test/credit-moves.test.ts, and the reference is a new section in docs/features/child-credit.md.

I pushed after tsc and the design lint came back clean. bun scripts/gate.ts still refused the look page: the commit names /settings/crew, and the gate says the changed pages need a different one. Whether the forge's check stays green on that is not confirmed.

Changes requested — before the latest push

The issue says the run's cost never lands in a credit counter. This pull does not find why. It adds a note that the counter missed it. That can be a fair first step, but as written the note can be wrong, and the new paths are untested.

  1. src/crew/runner.ts (runEnded call): the call fires for every funded forge, whatever paid for the run. When the owner has added their own key (crewHasCredential), the run never drew on the host's credit. Its costUsd is then always 'uncounted', and the page tells the owner the credit 'leaves it out' when it was never involved. Pass the cost only when the run was on lent credit, and add a test for the own-key case.
  1. src/spawn/funding.ts runEnded: the before/after comparison races. Two runs that end close together each ask the host. Run A's ask can see B's spend, or neither run's, so a counted run is flagged as uncounted. The note also accumulates uncountedUsd until the host's count next rises, and that can take a long time. Judge a single run against that run's own metering, or at least do not stack the figure across runs. When before.spentUsd is null, moved is always false, so the first run on a fresh child is always flagged. Treat null as 'unknown', not as 'did not move'.
  1. Tests (principle: every added behaviour fails without its test). Only the runEnded to uncountedUsd path and its clearing in askHost are covered. These have no test: the syncFunding branch that keeps or clears the note on the heartbeat; the failed-ask case, where nothing must change; planLine showing the sentence; crewKeyLine in the terminal showing it; and the page line in /settings/subscriptions. At least one assertion should hit the rendered page and one the terminal line.
  1. Plain words (DESIGN principle 8, docs/WRITING.md): 'by their own account that the host did not count: this credit leaves it out' is hard to read and says the same thing twice. Say what the owner can act on, for example 'Runs cost $0.78 that this credit did not count.' Use one wording on the page, the plan line and the terminal.
  1. Clean: runEnded's signature changed to (app, costUsd = 0, fetcher), so the existing test needed edits. Keep the old positional order and put the cost in an options argument. Also, the diff rewraps comments in code it does not touch (readDoc, fundedEnv, planRow, crewNote, payingCard, crewKeyCard). That is fine if the gate's --fix did it, but keep it to its own commit. The author also reports scripts/gate.ts refusing the look page. Resolve that so the check is green.
  1. The docs entry is fine (docs/features/child-credit.md, not README). It should also say that the note can appear wrongly under the cases in 1 and 2, once those are fixed.

First fix: item 1. Showing a false 'not counted' warning to owners on their own key is worse than showing nothing.

I did not open the preview. This is a server-side note on the subscriptions page, and I judged it from the diff.

commented

I fixed item 1 and part of items 2 and 5. Items 2 (racing and stacking), 3, 4, 5 (the comment rewraps) and 6 are still open. I didn't find why the cost never reached a credit counter, so this pull is still only the note.

Done

  • Own-key runs (item 1): runEnded no longer gets a cost when the owner has their own key. A new lentCost(app, costUsd) in src/spawn/funding.ts returns 0 when crewHasCredential is true, and src/crew/runner.ts calls it. A new test in test/credit-moves.test.ts adds an own-key subscription, ends a run that cost $0.78, and checks that no uncountedUsd is set.
  • Null count (item 2, null part only): when the host's count was null before the run, the run is no longer flagged as uncounted. It stays unflagged if the new count is also null.
  • Signature (item 5): runEnded is back to (app, fetcher, opts?), with the cost in opts.costUsd. The existing tests use the old positional order again.

Checks

  • bun x tsc --noEmit is clean.
  • test/credit-moves.test.ts and test/stranger-first-fixes.test.ts pass (14 tests).
  • scripts/gate.ts --fix exits 0. Its look-page line is a note, not a refusal, because the commit names /settings/crew. I kept that Looks: trailer on the new commit.

Not done yet

  • Race and stacking (item 2): runEnded still compares the host's count before and after, so two runs ending close together can still be mis-flagged. uncountedUsd still adds up across runs. Judging each run by its own metering needs a decision on where that figure comes from.
  • Missing tests (item 3): none for the syncFunding heartbeat keep/clear, the failed-ask case, planLine, crewKeyLine, or the /settings/subscriptions page line.
  • Wording (item 4): still the old sentence. It should become one plain line on the page, the plan line and the terminal, for example "Runs cost $0.78 that this credit did not count."
  • Comment rewraps (item 5): not split into their own commit.
  • Docs (item 6): docs/features/child-credit.md doesn't yet say the note can appear wrongly in the race case.

The credit-moves test for item 1 checks crewHasCredential against process.env as well. A runner credential set in the environment would change what the lent-credit test sees.

commented

<!-- look-pages d5ddc7b1d8f8 --> Look pages for d5ddc7b, from the gate:

  • look pages (named): this pull changes src/web/pages/subscriptions.ts, src/web/plan_row.ts, src/web/studio/crew_key.ts; a commit names /settings/crew
commented

The look-pages note needed no code change, so I pushed nothing new.

It is the gate's own confirmation, not a request. It says the pull changes src/web/pages/subscriptions.ts, src/web/plan_row.ts and src/web/studio/crew_key.ts, and that a commit names /settings/crew. The commits carry Looks: /settings/crew. That path is in both app.looks and app.looksAsOwner in forge.json, so the before/after pictures cover the changed pages.

I re-ran bun scripts/gate.ts and it passes with the working tree clean. I did not run the tests or bun x tsc --noEmit again, since nothing changed since the last push.

Pull description: a crew run's cost that the host did not count is now said beside the included-credit and plan lines on /settings/crew, instead of being silently left out. A run on the owner's own key never carries a cost to the "not counted" note. Try it at /settings/crew on the preview.

🤖 Generated with Claude Code

Changes requested — before the latest push

Earlier asks, round by round: (1) own-key runs no longer carry a cost — met, with a test. (2a) null count — met. (2b) race and stacking — NOT met: runEnded still compares before/after counts, so two runs ending together can be mis-flagged, and uncountedUsd still sums across runs; a wrong "the host did not count" note on a person's credit line is worse than none. Fix first: judge each run by its own metering (or keep only the latest run's cost, not a running sum) and say in the docs that the note is a hint. (3) tests — NOT met: nothing covers the syncFunding heartbeat keep/clear (src/spawn/funding.ts syncFunding), the failed-ask path, planLine, crewKeyLine, or the #included-credit line on /settings/subscriptions; each behaviour added needs a test that fails without it. (4) wording — NOT met: "Runs cost $0.78 by their own account that the host did not count: this credit leaves it out." (uncountedWords in src/actions/crew_means.ts) is long and says one thing twice (docs/WRITING.md, DESIGN principle 8); use one plain line, e.g. "Runs cost $0.78 that this credit did not count." (5) comment rewraps in funding.ts, plan_row.ts, crew_key.ts are unrelated to the issue and still in the same commit: split them out. (6) docs/features/child-credit.md does not say the note can be wrong in the race case. Also: the pull still does not find why cost never reaches a counter; it only reports the gap, and it is off the pipeline-first direction. Acceptable only if kept small and correct, and an issue is opened for the real metering cause. Non-blocking: the plan_row.ts import of uncountedWords from actions/crew_means.ts and crewkey.ts import via web/studio re-export differ; pick one.

commented

When a crew run on included credit costs money by its own account and the host's counter does not rise, this pull says so beside the credit lines. It does not fix the counting itself: why the spend never reaches the counter is opened as #13762.

Changes since the last review:

  • Race and stacking (2b): each run is now judged against the count it began with. work() in src/crew/runner.ts reads the count as the run starts and passes it to runEnded. Another run's end can no longer make this run look uncounted. uncountedUsd now holds the last run's cost only, never a sum.
  • Tests (3): the new test/credit-uncounted.test.ts covers:

- judging a run against its own start: the copy already moved by another run gives no false note; - no stacking: two uncounted runs keep the last one's cost; - an unknown count at the start says nothing; - a failed ask, refused (500) or thrown, keeps the stored copy and adds nothing; - the syncFunding heartbeat keeps the note while the count stands and clears it when the count moves; - planLine and crewKeyLine, with and without the note; - the #included-credit line on /settings/subscriptions.

  • Wording (4): the note is now one plain line, "A run cost $0.78 that this credit did not count."
  • Comment rewraps (5): reverted to main's form, so the pull's diff no longer carries them. History can't be rewritten without a force push, so I couldn't split them out of the earlier commit. The gate only notes the long comments and leaves them to the nightly rewrap on main, so I did not run gate.ts --fix this time.
  • Docs (6): docs/features/child-credit.md calls the note a hint and lists when it is wrong:

- the host counts the run late; - two runs end together: another run's counted spend hides this one, and when neither is counted only the later cost shows; - a count is unknown at either end.

It points at #13762 for the cause.

  • Imports: uncountedWords is imported from actions/crew_means.ts everywhere. The web/studio re-export is gone, and src/web/studio/crew_key.ts is now unchanged from main.

The release hold on trevato/forge does not touch this pull: pushing to a pull branch only redeploys its preview, not production.

Checks run:

  • bun x tsc --noEmit, bun scripts/gate.ts and bun scripts/design-lint.ts are clean.
  • The new test file plus credit-moves, funding-sync, credit-one-figure, included-credit-figure, mcp-here-plan and grace-calm all pass (28 tests).
  • Twelve more files that touch parent.json and lent credit all pass (68 tests).
  • scripts/fast.ts named 2,467 files because runner.ts changed, so the forge's check runs the rest.

Try it: on a funded child with no key of its own, finish a run while the host's count stays put. /settings/subscriptions, the Settings plan line and the terminal crew-key line then end with "A run cost $X that this credit did not count."

Looks: /settings/crew

🤖 Generated with Claude Code

commented

<!-- look-pages b6e8ddf76669 --> Look pages for b6e8ddf, from the gate:

  • look pages (named): this pull changes src/web/pages/subscriptions.ts, src/web/plan_row.ts; a commit names /settings/crew
commented

When the owner's crew runs on the host's included credit and a run's cost doesn't show up in the host's count, the app now says so in one plain sentence ("A run cost $0.78 that this credit did not count.") beside the credit lines. It appears on the plan line, the terminal's crew-key line and the included-credit line on /settings/subscriptions, and nothing is added when there is no such cost.

  • How a run is judged: each run is compared with the count it started with, not the app's current copy, so a run whose count was already moved by a later run is not flagged.
  • Which runs count: only the last uncounted run's cost is kept, never a sum. A run on the owner's own key never carries a cost to the note.
  • When nothing changes: an unknown starting count says nothing, and a failed ask to the host, refused or thrown, keeps the copy and its note as they were.
  • Heartbeat: it keeps the note while the host's count stands still and clears it once the count moves.

The last commit fixes the gate failure: test/credit-uncounted.test.ts cast its input with as never at lines 97 and 100. It now reads the crew-key line through a real signed-out Session, and bun scripts/gate.ts --fix rewrapped the long comments in src/spawn/funding.ts and src/web/plan_row.ts.

scripts/fast.ts named 2467 test files (about 208 minutes), too many to run here. Instead I ran the 19 test files that use the changed modules (funding, plan line, crew key, crew means, subscriptions page): 151 pass. The gate and bun x tsc --noEmit are clean. Some tests tried to reach forge.test and localhost hosts and the sandbox refused them, but no test failed.

Not done: test/credit-one-figure.test.ts:104 still has the same as never cast. It isn't part of this change, so the gate doesn't flag it.

To try it, write a funding.json that carries an uncountedUsd under the app's data directory and open /settings/subscriptions, or run bun test test/credit-uncounted.test.ts.

🤖 Generated with Claude Code

commented

<!-- look-pages a2e7e1bddff3 --> Look pages for a2e7e1b, from the gate:

  • look pages (named): this pull changes src/web/pages/subscriptions.ts, src/web/plan_row.ts; a commit names /settings/crew
commented

When the owner's crew runs on the host's included credit and a run's cost doesn't show up in the host's count, the app now says so in one plain sentence ("A run cost $0.78 that this credit did not count."). It appears in three places:

  • the plan line at the top of /settings
  • the terminal's crew-key line
  • the included-credit line on /settings/subscriptions

Nothing is added when there is no such cost.

How the cost is judged:

  • Starting count: each run is compared with the host's count when it started, not the app's current copy. So a run whose count a later run already moved is not flagged.
  • Last run only: only the last uncounted run's cost is kept, never a sum.
  • Owner's own key: a run on the owner's own key never carries a cost to the note.
  • No change when unsure: if the starting count is unknown, nothing is said. If the ask to the host fails, refused or thrown, the copy and its note stay as they were.
  • Heartbeat: the heartbeat keeps the note while the host's count stands still and clears it once the count moves.

The changes are in src/spawn/funding.ts, src/actions/crew_means.ts, src/web/plan_row.ts, src/web/pages/subscriptions.ts and src/tui/screens/crewkey.ts.

The look-pages note: earlier commits said Looks: /settings/crew, but that page shows neither changed line. The sentence is on /settings and /settings/subscriptions, and neither is in app.looks. It also only appears on a child forge with an uncounted run, which no preview seeds. The last commit therefore carries a No look: line saying so, and the gate no longer prints the note. Instead of a picture, test/credit-uncounted.test.ts asserts the exact words on all three surfaces. I did not add /settings/subscriptions to app.looks: that list is capped at 32 and its slots are chosen on purpose, and a picture of the preview would not show the sentence anyway.

The test no longer uses an as never cast; it reads the crew-key line through a real signed-out Session. test/credit-one-figure.test.ts:104 still has the same cast, but it is outside this change and the gate doesn't flag it.

Checks: the gate and bun x tsc --noEmit pass. scripts/fast.ts named 2467 test files, too many to run in the sandbox, so I ran the 19 that use the changed modules: 151 pass. Some of them tried to reach forge.test and localhost hosts and the sandbox refused those connections, but no test failed.

To try it: bun test test/credit-uncounted.test.ts. Or put a funding.json with an uncountedUsd in a child forge's data directory and open /settings/subscriptions.

🤖 Generated with Claude Code

Approved

Earlier asks are met. Each run is now judged against the count it started with. Only the last cost is kept, never a sum. Own-key runs pass no cost. The wording is one plain sentence on the page, the plan line and the terminal. The failed-ask, heartbeat, plan-line, crew-key-line and /settings/subscriptions cases all have tests. The docs name the cases where the hint is wrong, and the long comments are back to main's form. It adds no new component, no new dependency and no write path. The note is muted text inside the existing paragraph, so it works with JavaScript off. The terminal says the same sentence as the page.

Two things to do next:

  1. Non-blocking: in src/spawn/funding.ts, move the new ../core/subscriptions.ts import below the node: imports to match the file's order.
  2. Non-blocking: land #13762, which finds why the spend never reaches the counter. This pull only makes the gap visible.
Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs