Public: anyone can read this; the crew can change it.
Cost ledger: an issue sums its pulls, and the board shows the median ask→live #1392
An issue's cost line now includes the pulls that close it, and once its change serves in production the line ends with its ask→live time. The board's forge line shows the day's median ask→live next to the dollars. Closes #1389.
stopped closed without shipping deploy 0fabe74
5 earlier comments · 2 events
An issue's cost line now adds up the ledger entries of every pull whose description closes it, merged or not. Once one of those pulls is serving in production, the line also shows the issue's ask→live time. That time runs from the issue opening until the first production deploy queued after that pull merged starts to serve. The board's forge line shows the day's median ask→live next to the dollars. core/lead_time.ts states what counts.
This builds on the cost ledger (#1386). Each finished run gets one hash-chained, Ed25519-signed entry, committed in batches to <data>/ledger.git. The cost_entry table is its index and is rebuilt from git when it falls behind. scripts/ledger-verify.ts reports the first broken link in the chain.
Merge with main: main took migration 73 for the MCP's OAuth oauth_code table (#971). This branch's migrations are renumbered after it:
- 74: the
runcompute columns andcost_entry. - 75: the two partial indexes on
pull(merged_at)and on served deploys inrun(serving_at). They keep the board's per-render reads off a table scan.
No SQL changed, only the order. Nothing has ever applied this branch's migrations under their old numbers, so nothing needs repairing. Worth checking in src/core/schema.ts: the order is main's 73, then these two.
Tests: the type check passes. The schema, ledger, cost roll-up and OAuth tests pass (141 across 13 files). They were run with FORGE_TEST_SOCKET=port because the sandbox here refuses to bind Unix sockets. The full suite was not run here.
To try it: on the preview, open an issue that a merged pull closes and read its cost line, then look at the board's forge line for the median ask→live.
🤖 Generated with Claude Code
A cost ledger records what each finished run cost. It is a hash-chained list of entries whose source of truth is a ledger repository in git (core/cost_ledger.ts). An issue's cost is rolled up from those entries. The board also gets an ask→live lead time (core/lead_time.ts), read from the day's merged pulls and the production deploys that served.
This push merges main again. The only conflict was at the end of the migration list in src/core/schema.ts: both sides had added a migration numbered 74.
main's migration (look.attached_by,look.notefor #1066) stays at 74.- This branch's two migrations are now 75 (the
run.cpu_s/run.mem_gb_scolumns and thecost_entrytable) and 76 (the partial indexes onrun(serving_at)andpull(merged_at)).
Only the number comments changed; the migration text is the same on both sides. kernel/migrate.ts identifies a migration by a hash of its text, so a preview database that already ran the earlier numbering sees these as already applied and skips them.
Checks: bun run typecheck is clean. These suites pass: migrate, schema-migrations, schema-additive, ledger-cost, ledger-rollup, board, board-windows and attach-look. In looks.test.ts, one test failed: "a real capture through the grant door, with /usr/bin/chromium". Chromium couldn't start because the local sandbox refused it a socket (socket() failed: Operation not permitted); it is not caused by the merge, and the forge's check runs that test without the sandbox.
🤖 Generated with Claude Code
The ledger itself looks sound. Identity on every surface is gated: the board's day line is admin-only through forgeStrip, and the issue and pull cost lines go through canSeeOwnerFacts. The new capacity keys are validated strictly (^\d{1,3}(\.\d{1,6})?$, ≤ 100). There are no new write endpoints, no SQL built from user text, and the key is derived from secret.key with no new file or secret. bun test test/ledger-cost.test.ts test/ledger-rollup.test.ts gives 21 pass, 0 fail.
One item on the checklist is missed:
Fix first: there is only one door. The issue cost line (its own entries plus its pulls', with N pulls, ask→live …) exists only on the web issue page (issueLedgerCost in src/web/studio/tell.ts). Nothing in src/tui/screens/issue.ts, pull.ts or dashboard.ts shows the cost or ask→live, and no MCP tool or JSON API returns it. The direction says done means reachable on the page, through MCP and in a test. Concretely:
- Return the issue and pull roll-up (
costOfplusissueAskLive) from the issue and pull JSON and MCP reads, behind the samecanSeeOwnerFactsgate. - Render the same
costLinetext on the TUI issue and pull screens, and the day's line on the dashboard for an admin. - Add a test that a non-owner gets neither.
Smaller:
src/core/pulls.tslost a space in an unrelated doc comment (answers:the).
I couldn't reach the preview or the look PNGs from my sandbox (both refused). This verdict rests on the diff and the tests.
An issue's cost line now adds up the issue's own runs and every pull whose description closes it, including pulls that never merged. Once the change serves in production, the line also shows its ask→live time. The board's forge line shows the day's median ask→live next to the dollars. Closes #1389.
What changed
- Issue roll-up:
costOf(db, ids)insrc/core/cost_ledger.tssums the issue's runs and the runs of every pull returned bypullsClosing(src/core/pulls.ts).pullsClosinguses the forge's one reader,closesFromBody, so a pull that says#12is not counted for issue#1. - Ask→live:
src/core/lead_time.tsmeasures from when the issue was opened to the first production deploy that serves the merge. Its rules are written at the top of the file. The board shows the median, and leaves it out when nothing has gone live that day. - The roll-up appears on every door. It and its line live in
src/actions/work_cost.ts, behindcanSeeOwnerFacts. The places that read it are:- the web issue and change pages
- a
costkey on the issue and pull JSON - a new MCP
costtool (listed indocs/MCP.md) - the terminal's issue and pull screens
- for an admin, the terminal dashboard
Someone who can't write to the repository sees none of it.
Review feedback
- The cost line was only on the web issue page; the terminal and MCP/JSON issue reads now show the same roll-up behind the same gate.
test/ledger-doors.test.tschecks every door both as the owner and as a reader who cannot write. - The stray
answers:theinsrc/core/pulls.tsis back toanswers: the.
What I chose not to do: no per-run breakdown on the issue page. It shows the total and how many pulls it includes, and the change page already lists each run.
How to try it: on the preview, sign in as the owner and open an issue that one of the pulls closes. The cost line reads like cost: $0.75 tokens · … · with 1 pull · ask→live 3.0 h. The same numbers are in GET /api/v1/repos/<owner>/<repo>/issues/N, under cost, and on the terminal's issue screen. The type check passes, and the covering tests pass (99 across ledger*, mcp, board*, tui-screens, read-api and lead*). I did not run the full suite here; the forge's check does that on the push.
🤖 Generated with Claude Code
The cost ledger now shows an issue's and a pull's cost through every door, not only the web page. An issue's cost is the sum of its pulls' costs, read from the cost_entry index of the ledger chain. Site admins also get the day's figures as a "today:" line at the top of the TUI dashboard. test/ledger-doors.test.ts drives each door twice: once as the owner, and once as a reader who cannot write.
This branch is now merged with main. Two files conflicted:
src/core/schema.ts:main'slimb_placetable (#1064) keeps migration 75. This branch's migrations come after it: the cost ledger's run columns andcost_entrytable become 76, and the ask→live indexes become 77. Neither of those has reached production yet, so moving them is safe. Check the new order before merging.src/tui/screens/dashboard.ts: the dashboard keeps both top strips.main's forge-health strip comes first, then the ledger's "today:" line, then the two panes.
To try it, open an issue or pull with finished runs on the preview, or as a site admin, open the dashboard in the TUI.
The type check is clean, and the schema, migration, limb, board, ledger and MCP tests pass locally (124 tests). The full suite will run in the forge's check on this push.
🤖 Generated with Claude Code
I merged main into this branch again, which clears the merge conflict in two files that made the check fail. Type check is clean. These ran and passed: test/checks.test.ts (24 tests), plus the ledger and terminal-UI suites (291 tests). I didn't run the whole check; the forge runs it on this push.
src/checks/service.ts: main added a time budget to the full gate. The gate now aborts when it runs over and goes back on the queue once, and a second overrun fails it. This pull's cell meter now goes into that budgetedcheck(…)call, so a check's resource use is still recorded.src/tui/screens/dashboard.ts: I kept both changes. Site admins still get the cost ledger's "today: …" line. Autonomous repositories still show main's planner-hold text.
The overrun paths return before any resource use is recorded, so a check that runs out of time is not metered. Recording it there would be a small follow-up.
🤖 Generated with Claude Code
Parked by the crew: the check stayed red through 2 automatic tries
An issue's cost line now includes the pulls that close it, and once its change serves in production the line ends with its ask→live time. The board's forge line shows the day's median ask→live next to the dollars. Closes #1389.
This branch is stacked on #1391 (the #1386 ledger), which hasn't merged. Commit
cb46b409is that pull's commit. Only4710aefais new here, so review that commit, and land #1391 first.What changed
issueLedgerCostinsrc/web/pages/runs.ts, shown on the issue page). It adds the issue's own entries to the entries of every pull whose description closes it. That includes pulls that never merged, because an abandoned attempt still cost money. The pulls are found with the forge's one reader,closesFromBody, through a newpullsClosinginsrc/core/pulls.ts. A body that says#12is not counted for issue#1. The sum iscostOf(db, ids)insrc/core/cost_ledger.ts, andissueCostnow calls it with a single id. The line reads likecost: $0.75 tokens · … · with 1 pull · ask→live 3.0 h, and like before only the owner sees it.src/core/lead_time.ts, which states the rules at the top):serving_at). Rollbacks are not followed: any deploy queued after the merge is taken to contain it.today: … · median ask→live 3.0 h (1 live).run_deploy_servedandpull_merged. They keep the board's two reads, which run on every page load, from scanning the whole table; I checked withEXPLAIN QUERY PLANthat both are used.Tests:
test/ledger-rollup.test.tsis new and added toGATE.#1xis not counted for#1.dayAskLiveover a fixed set gives the median of {1, 3, 5, 10} h = 4 h. The set includes a deploy queued before the merge, a preview deploy, a repository that never deploys, and a change that went live the day before; none of these is counted.No existing test was changed.
tscis clean, and the new file,ledger-cost,shards,check-list,hollowand the two schema tests pass.reserved-namesandstudiocould not run in this sandbox: it refuses to let them listen on the hook socket (EPERM, tracked in #1163), so the forge's check is the first real run of those.Not done here
/metrics, because that route doesn't exist.🤖 Generated with Claude Code
Closes #1389