Skip to content

factory: the router — routing rules, the AI filter and priority order (lane R) - #2480

Merged
santoshkumarradha merged 2 commits into
factory/general-intakefrom
factory/gi-router
Nov 6, 2026
Merged

santoshkumarradha merged 2 commits into
factory/general-intakefrom
factory/gi-router

Conversation

@santoshkumarradha

@santoshkumarradha santoshkumarradha commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Lane R of the general-factory wave (docs/design/factory-general/DESIGN.md §1, §1b).

What changes

  • Router (internal/factory/route). Matches is pure and table-tested. A source matches a job's Origin or SourceRef, whole or up to ://. AnswerKey is a 16-hex SHA-256 of the question, title, body and sorted labels. Clean is the one check of a table, shared by the store, the factory service and the wire. Preview backs the "test these rules" view.
  • Storage. store.Routes / KeptRoutes / SetRoutes(rules, by, expect) use factory-routes.json, kept beside the house rules. An unreadable file is an error, never an empty table.
  • Wire. factory.routes, factory.routes_set (operator only, expect gives stale) and factory.routes_test (no writes, no model calls), behind the hello feature factory.routes. The factory side is GET/PUT /v1/routes with the phase marker, plus POST /v1/routes/test.
  • Intake. Intake.admit is one ordered filter: the job's own state first, then routing, then the label skip (unmatched jobs only), then the repository as routed, its switch, and jobs already filed. A rule's decision is applied in one place (intake/route.go: applyRoute, stage, startDecision). The rule's pipeline comes from factory.Recipe.Named, the same lookup job_start {pipeline} now uses. auto uses the new pipeline.File.DecideAdmitted: the rule stands in for the start label, and size, cost and protected paths still apply. ask holds with routing rule <name>. backlog files the job.
  • AI filter. Every host's intake (factoryIntakeOwned: app, codeaf factory serve, CLI) now gets lane A's factoryJudge. When Decide returns Pending, Options.Judge is called once per rule per job per pass. The answer is kept on Item.Judged under the write lock. A judge error counts as "no" and is kept as couldn't judge: … with no key, so it is asked again next pass. With no judge, a rule that asks never matches. When an AI yes matches a stranger's ticket, auto becomes ask. The activity line names the rule and the answer's reason.
  • Queue order. lease.runsBefore: Start now, then p0, p1, p2, p3, then no priority, then oldest. All priority spellings come from one table in factory/jobs.go.
  • Manual. Sections on routing rules, the AI question, who can change the table, and priority ordering. The "oldest first" queue line is corrected. Probes added.

Shared changes outside lane R's files

  • Uses the contract names from 80c0415 (route.Answer, Answers, AnswerKey, Outcome.Answer, factory.RouteAnswer). Adds Item.Judged map[string]RouteAnswer, which the contract described but did not declare.
  • judge.WithRuleModel is not called, because route.Match has no model field yet. The factory's default model answers every question.
  • factory.Recipe.Named replaces serve's private pipelineStages, which is deleted.
  • pipeline.File.DecideAdmitted is split out of DecideJob. DecideJob behaves as before.
  • factory.RepoName moves into the factory package so route can use it without depending on the store. store.RepoName delegates to it.
  • factory.PriorityRank / ValidPriority now read the shared table. PriorityShort / PriorityFromShort are added.
  • TestPriorityMarksDoNotReorderExecution is replaced by TestPriorityOrdersExecutionAtOneJobAtOnce, because the contract reverses it.

Proof

make test-focus PKGS='./internal/factory/route ./internal/factory/intake ./internal/factory/lease ./internal/factory/store ./internal/appwire' RUN=.   # ok
go test ./internal/factory/route/... ./internal/factory/serve ./internal/factory/pipeline ./internal/factory ./internal/factory/inbox ./internal/manual   # ok
make test-focus PKGS=./cmd/codeaf RUN='Judge|FactoryPipeline|Intake|ReadLoops|Routes'   # ok
make test-laws   # ok, 166 files in 46 packages

With no rules, intake is unchanged: every existing intake test passes as written. Two serve tests failed once when nine packages ran together (TestThePullCarriesEachStepsWholeReportAndAReaderNone, TestFactorySetupDoubleContinueEndsReadingOnce). Both pass alone, and the whole serve package passes on a fresh -count=1 run.

No change entry yet: this PR targets the integration branch, not dev.

🤖 Generated with Claude Code

factoryIntakeOwned hands intake.Options.Judge the floor's model-backed judge
(factoryJudge), so the app, a team server and the command line ask a
routing rule's question the same way, booked as `factory filter`. A rule
names no model yet, so the factory's default answers.

The manual's routing section now defers to lane A's page for model, cost
and what the model sees, and keeps what intake adds: the answer kept on a
job, "couldn't judge", the activity line and test these rules.
@santoshkumarradha
santoshkumarradha merged commit e5effe0 into factory/general-intake Nov 6, 2026
1 check passed
@santoshkumarradha
santoshkumarradha deleted the factory/gi-router branch November 6, 2026 21:24
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