Repository navigation
factory: spend this month split by repository (factory.spend_by_repo) - #2132
Merged
Merged
Conversation
GET /v1/spend/repos?from=&to= folds the factory's job documents into
{from, to, repos:[{repo, spent_usd, jobs}], total_usd} for the
repositories the caller can read. A job's whole spend is placed on the
day its run started, in the factory's zone, or on its creation day when
it never ran. factory.spend_by_repo carries it over the app wire; hello
announces factory.spend_by_repo and capabilities say spend_by_repo.
time_zone is the IANA name of the factory's clock zone. A process on its Local zone names it from TZ (empty is UTC) or the /etc/localtime link, and leaves the field off when neither names one.
…-repo # Conflicts: # cmd/codeaf/appfactory.go # internal/appwire/factory.go
santoshkumarradha
marked this pull request as ready for review
November 2, 2026 07:21
santoshkumarradha
added a commit
that referenced
this pull request
Nov 2, 2026
* factory: each job names the area of the repository its change touched
A job read and every job on the queue now carry area: the repository's
declared area most of the job's changed files fall under, or else the
top-level directory most of them sit under, written with a trailing slash
("cli/"). A job that changed no file, or only files at the root, carries
none. factory.JobArea is the one pure rule; the queue and the job's own read
apply the repository's declared areas, which they have at hand.
Hello announces factory.job_area.
* factory: each repository's job spend over the factory's days
GET /v1/spend/repos?from=&to= folds the factory's job documents into
{from, to, repos:[{repo, spent_usd, jobs}], total_usd} for the
repositories the caller can read. A job's whole spend is placed on the
day its run started, in the factory's zone, or on its creation day when
it never ran. factory.spend_by_repo carries it over the app wire; hello
announces factory.spend_by_repo and capabilities say spend_by_repo.
* factory e2e: the live local run reads the job's area and step model
The live lane writes its file under greet/ and checks that the queue and
the job's read both say area greet/ and that the write step's recorded model
is the pinned one. factory.local_start now turns the runner on itself, so the
lane no longer expects it off before the explicit run.
* changes: each factory job names its area (#2131)
* changes: each repository's spend by the factory (#2132)
* factory: the spend read names the zone its days are read in
time_zone is the IANA name of the factory's clock zone. A process on its
Local zone names it from TZ (empty is UTC) or the /etc/localtime link,
and leaves the field off when neither names one.
* factory: a job's area is two segments under a container, and one answer everywhere
Under a container directory (src, internal, pkg, lib, app, apps, packages,
crates, cmd; factory.AreaContainers) a job's area is the first two segments,
such as internal/factory/; a file directly inside one counts as the container.
Every job the server sends is judged once, in withVersion, by api.AreaIn
against the areas repositories declared as of the handler's last floor read,
so a verb's job and the queue never name different areas.
* factory api: the codec says area by the same rule the server says it again
FromItem and FromSnapshot keep saying area through api.AreaIn, so a queue
encoded on its own matches the one the server sends; the server's withVersion
says it again with the declarations of its last floor read.
* factory: one repository's facts counted from every job it keeps
factory.repo_facts {factory, repo, days?, months?} reads the factory's
GET /v1/repos/{owner}/{repo}/facts: jobs finished and pull requests merged
in the window and this month, spend by calendar month by the spend-by-repo
placement rule, jobs, rounds and questions by area by the job-area rule, and
jobs stuck on one step for a day or more, each with its own phrase. Bounded
to 20 areas and 20 stuck steps (97 facts); hello word factory.repo_facts and
capabilities repo_facts.
* factory: gofmt the repository facts test
* factory: repository facts say area by the one change-area rule
* factory: a repository's spend under a cent reads as less than a cent
The app test reads the facts at the fixture factory's own clock.
* changes: one repository's facts counted by the factory (#2143)
* factory e2e: the live local run expects local_start to turn the runner on
local_start turns the runner on by design, so the lane now fails when it is
left off, and it reads the recorder's call count under the recorder's lock.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A Repos page can now show what each repository spent this month. The figure comes from the factory, not from this engine.
Why the factory is the source.
spend.reportreads this engine's local ledger. A ledger line has no repository: its filter offers model, kind, subject, session, root, task, automation, run, workspace and agent. It also records only calls made by this machine. In a team factory, jobs run on other people's runners, and this engine never sees those calls. The factory keeps each job's money on the job's document:factory.JobSpentgives the run'sStream.Spent, orChatSpentbefore any run. It keeps every job document, not only the jobs that appear in the queue. So the honest source is a factory-side read over job documents. A repository dimension onspend.reportcells would be both wrong and partial.Placement rule. Each job's whole spend lands on one day in the factory's own zone. That day is the day the job's run started. For a job that never ran, it is the day the job was created, which covers chat spend only. The job document keeps one running total, not spend by day. So a run that crosses midnight or the end of a month counts entirely on its start day.
Time zone.
time_zoneis the IANA name of the zone the days are read in, taken from the factory's clock. When that clock is on the process'sLocalzone, the factory finds the name the way Go does:TZ, where an emptyTZmeansUTC;TZis not set, from the target of the/etc/localtimelink, using the part afterzoneinfo/.When neither gives a name, the field is left off; it is never answered as "Local".
Wire. Hello feature
factory.spend_by_repo.FactoryCapabilities.spend_by_repoistrue.reposis sorted by name. It is[]when nothing was spent.total_usdis the sum ofrepos.jobscounts only jobs that spent something.time_zoneis left off when the factory cannot name its zone.bad_paramsis returned, and nothing is sent, when:fromortois missing or is not aYYYY-MM-DDday,tois beforefrom,Evidence
TestSpendByRepoPlacesEachJobOnItsRunsStartDayForWhatTheCallerCanSeefailed withGET ?from=2026-10-01&to=2026-10-31 = 404 {"error":"factory endpoint not found"...}.TestAppFactorySpendByRepoReadsTheFactorysJobSpendByRepositoryfailed withundefined: appwire.FeatureFactorySpendByRepo.time_zonefollow-up: both tests failed because the field was missing. The route test failed withowner's October = {... TimeZone: ...}, want {... TimeZone:America/Chicago ...}.go test ./internal/appwire/ ./internal/factory/api/ ./internal/factory/serve/passes, including the PROTOCOL.md contract test.America/Chicago, with jobs in two months and two repositories.repos: [].LocalwithTZ=Europe/LondonanswersEurope/London.Localwith noTZresolves from an/etc/localtimetarget.Localthat nothing can resolve leaves the field off.factory.local_start,factory.local_run,factory.job_start, a chat stage, a check, and a stop at the approve gate. Every role was pinned to OpenRouterdeepseek/deepseek-v4.1-flash, andassertFactoryPinchecks every resolved role. A recorder saw 4 calls, all requesting that model. All response chunks nameddeepseek/deepseek-v4.1-flash, with no fallback. GitHub received 0 requests. The job's recorded spend was $0.005720.factory.spend_by_repoover the app wire returned{repos:[{repo:"acme/api", spent_usd:0.005720070999999999, jobs:1}], total_usd:0.005720070999999999}, which is equal to the job's ownStream.Spentand to the recorder's billed cost.time_zonewas added; the field is covered by the tests above.TestLiveLocalRunReachesTheApproveGateOnOneModelwith a local-only patch that is not in this PR. On the base branch that test stops before its run. It asserts thatfactory.local_startleaves the runner off, but the runner now turns on by itself once GitHub is known. I relaxed those two runner assertions and added thefactory.spend_by_reporead at the end. That stale assertion is outside this change.Merge Danger
Door: two-way. This adds one read route, one read method, one hello word and one capability field. It writes nothing and changes nothing that already exists.
Blast Radius: small. An older desk ignores the new word and the new fields. An older factory answers the new route with not found.
Limits, said plainly:
freshStream), so only its latest run's spend counts.owner/nameare left out.🤖 Generated with Claude Code