Skip to content

factory: one repository's facts counted from every job it keeps - #2143

Merged
santoshkumarradha merged 25 commits into
app/v3from
c32/engine-repo-facts
Nov 2, 2026
Merged

santoshkumarradha merged 25 commits into
app/v3from
c32/engine-repo-facts

Conversation

@santoshkumarradha

@santoshkumarradha santoshkumarradha commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Depends on #2131 (job.area, factory.JobArea) and #2132 (factory.spend_by_repo). Both are merged into this branch with merge commits; review only the commits after them.

Summary

A desk can now ask the factory for one repository's facts. The factory counts them over every job document it keeps, not only the recent jobs that factory.queue holds. Each fact has its own phrase, and a number never appears without its noun. A desk can use these facts to write about a repository without counting anything itself.

factory.repo_facts {factory, repo, days?, months?}            (hello: factory.repo_facts, caps: repo_facts)
  GET /v1/repos/{owner}/{repo}/facts?days=&months=          (visibility as the queue's; unreadable repo → 404)
    api.RepoFactsOf(floor items, floor repos, repo, now, days, months)
      finishedFact   n.finished.<N>d, n.finished.month     shipped, by the day the run ended
      mergedFact     n.merged.<N>d,   n.merged.month       PRs merged, by merged_at
      spendFacts     usd.month:YYYY-MM × months            factory.SpentIn (the spend_by_repo rule, now shared)
      stuckFacts     n.stuck, n.stuck.<step>               open job, current step began ≥ 24 h ago
      areaFacts      area:<a>, area:<a>.rounds, .asks      factory.JobArea over the run's change (shared with api.AreaIn)
  • days is 1–366 calendar days ending today (default 30). months is 1–12 calendar months of spend, this one included (default 3). On the app wire, an absent or zero value means the default.
  • Bound: at most 20 areas and 20 stuck steps, busiest first, so at most 97 facts. truncated counts what the bound left out.
  • Area ids are the area exactly as factory.JobArea names it: area:webhooks for a declared area, area:cli/ for a top-level fallback.
  • A spend under half a cent reads "less than $0.01", so a run that cost something never shows as $0.00.

Example answer:

{"factory":"f1","repo":"acme/api","as_of":"2026-11-20T12:00:00Z","time_zone":"UTC","days":30,"months":2,"facts":[
 {"id":"n.finished.30d","kind":"count","value":2,"phrase":"2 jobs finished in the last 30 days","about":"jobs shipped, by the day their run ended, 2026-10-22 to 2026-11-20","source":"engine:repo_facts.finished"},
 {"id":"n.merged.month","kind":"count","value":1,"phrase":"1 pull request merged in November 2026","about":"pull requests the factory opened that merged, 2026-11-01 to 2026-11-20","source":"engine:repo_facts.merged"},
 {"id":"usd.month:2026-10","kind":"usd","value":3.5,"phrase":"$3.50 spent on 2 jobs in October 2026","about":"each job's whole spend on the day its run started","source":"engine:repo_facts.spend"},
 {"id":"n.stuck.review","kind":"count","value":1,"phrase":"1 job stuck in review for a day or more","about":"open jobs whose current step began 24 hours or more ago","source":"engine:repo_facts.stuck"},
 {"id":"area:webhooks","kind":"area","value":2,"phrase":"webhooks: 2 jobs in the last 30 days","about":"jobs whose run started in the window, by the area their change touched most","source":"engine:repo_facts.area"},
 {"id":"area:webhooks.rounds","kind":"rounds","value":7,"phrase":"7 rounds in webhooks in the last 30 days","about":"rounds every step of those jobs ran","source":"engine:repo_facts.area"},
 {"id":"area:webhooks.asks","kind":"count","value":2,"phrase":"2 questions asked in webhooks in the last 30 days","about":"questions those jobs asked a person, answered or open","source":"engine:repo_facts.area"}]}

A fact is {id, kind, value, phrase, about?, source}. value is always present and can be 0. time_zone is absent when the factory cannot name its zone. truncated is absent when nothing was cut.

Evidence

  • Before:
    • Builder test: repo_facts_test.go:114:9: undefined: RepoFactsOf … [build failed].
    • Sub-cent phrase test: FAIL internal/factory/api.
    • The app-wire test failed first because it read at real time and not at the fixture's clock. I fixed the test, not the code.
    • Route test: I wrote the handler before the test's first run, so I proved it red afterwards. In a throwaway worktree with only the handler and its registration removed, it fails: repo_facts_test.go:53: GET /v1/repos/acme/api/facts = 404 … "error":"factory endpoint not found".
  • After:
    • make test-focus on ./internal/factory/api, ./internal/factory/serve, ./internal/appwire and ./cmd/codeaf passed. It covered TestRepoFacts*, TestAppFactoryRepoFacts…, the spend-by-repo regressions, the protocol-document test and the schema test.
    • make test-touched BASE=origin/app/v3 passed. In cmd/codeaf, TestCopiedChatDoorsKeepDistinctStableDraftKeys failed once and passed on rerun; the harness marked it flaky.
  • Real-model e2e:
    • I ran CODEAF_LIVE_FACTORY=1 go test -tags e2e -run '^TestLiveLocalRunReachesTheApproveGateOnOneModel$' ./cmd/codeaf with every role on OpenRouter deepseek/deepseek-v4.1-flash.
    • The test was extended locally to read factory.repo_facts for the job's repository after the job ran. That extension is not in this PR.
    • The job stopped at its approve gate and made 0 GitHub requests.
    • The job's own record names deepseek/deepseek-v4.1-flash as the write step's model. The request models and the response models were all deepseek/deepseek-v4.1-flash (one_model true).
    • factory.repo_facts answered area:greet/ "greet/: 1 job in the last day", area:greet/.rounds "2 rounds in greet/ in the last day", and usd.month:2026-11 "$0.01 spent on 1 job in November 2026" for a $0.0053 run. It also answered time_zone.
  • Gates that are red on the base, not from this change:
    • test-laws: internal/taxonomy flags internal/factory/serve/idempotency.go; internal/session reports the task-engine and memory-engine complexity ceilings.
    • changelog-check: entries already in docs/changes/unreleased fail the check.

Merge Danger

Door: two-way

This is a new read method, a new route and a new hello word. An older desk ignores them. A newer desk sees no word from an older engine, and an older factory answers the route not found.

Blast Radius: small

There are two small reuse refactors. spend_by_repo now places spend through factory.SpentIn, with the same rule. api.AreaIn now uses the shared changeArea, with the same rule. Their existing tests still pass. No manual page changes: this is an app-wire read with no chat or resident surface.

🤖 Generated with Claude Code

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.
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.
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.
# Conflicts:
#	docs/design/app-v3/PROTOCOL.md
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.
…er 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.
…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.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.
The app test reads the facts at the fixture factory's own clock.
…r 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.
Spend by repository keeps one placement rule, factory.SpentIn, which the
landed spend read now calls. Area facts say area through api.AreaIn, the
landed one function, and the change-area helper is gone. Capabilities,
hello and the protocol document carry repo_read and repo_facts together.
@santoshkumarradha
santoshkumarradha marked this pull request as ready for review November 2, 2026 08:28
@santoshkumarradha
santoshkumarradha merged commit 6eab88a into app/v3 Nov 2, 2026
@santoshkumarradha
santoshkumarradha deleted the c32/engine-repo-facts branch November 2, 2026 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant