Skip to content

factory: the AI filter's model-backed judge (lane A) - #2479

Merged
santoshkumarradha merged 3 commits into
factory/general-intakefrom
factory/gi-judge
Nov 6, 2026
Merged

santoshkumarradha merged 3 commits into
factory/general-intakefrom
factory/gi-judge

Conversation

@santoshkumarradha

Copy link
Copy Markdown
Member

Lane A of the general-intake wave (docs/design/factory-general/DESIGN.md §1b): the model-backed route.Judge behind a rule's when.ask.

What lands

  • internal/factory/route/judge: New(Options) route.Judge. A fixed system instruction (judge.System), then the question, then the item between <item> tags as untrusted data: source, author tier, repository, title (300 runes), labels (20), body (2000 runes). Closing tags inside the item are broken with triage.Untrusted.
  • Strict parse: exactly one object {"yes":bool,"why":"…"}. One wrapping code fence is tolerated. Prose, extra keys, duplicate keys, a string "true" or an empty why all return ErrNoAnswer, which is never a yes.
  • Each attempt times out after 20s (judge.Timeout). A transient failure (timeout, net error, or a taxonomy transport class via the caller's Transient) gets one retry after 2s. A refusal or a garbled answer is not retried. The clock (After) and the provider (Call) are injectable.
  • Model order: WithRuleModel(ctx, m) (the seam for a rule's own model), then the factory default, then the arrival read's model. Verdict.Model is the model that served the answer, and Key = route.VerdictKey(ask, it).
  • Spend: every attempt's cost goes to Spent, failed attempts included. cmd/codeaf/factory_judge.go (factoryJudge(st, load), ready for lane R to inject into intake) books each call under factory filter through factoryAIAccounting, the same path triage uses. factory filter is added to session's factory AI roles, so it counts toward the factory's day, and to the replay tag table and the spend-owner ledger.
  • judge/judgetest: a fake judge for other lanes' tests.
  • Manual: a new section in internal/manual/chat/factory.md, "start work with an AI filter — a rule that asks a question", plus two probes.

Proof

  • make test-focus PKGS='./internal/factory/route/...' RUN=. passes, and -race -count=5 passes.
  • TestFactoryJudgeBooksItsQuestionOnTheLedger passes.
  • Manual probes pass.
  • Live run: go test -tags e2e -run TestLiveJudge ./internal/factory/route/judge/ on deepseek/deepseek-v4.1-flash. All 24 answers came back as expected (20 asserted, 4 logged only). The stranger's injection item was answered no to all four questions. The run cost $0.00794 and took 30s.

Known red, not from this lane

make test-laws still fails on TestOnlyOneVerdictTypeExists (internal/taxonomy). That law allows only one type named Verdict in the module, and route.Verdict comes from the base contract (21ae3d0, route.go, which this lane may not edit). It fails on the base too. The fix is a rename in the contract, for example route.Answer.

🤖 Generated with Claude Code

internal/factory/route/judge implements route.Judge: a fixed system
instruction, the rule's question, then the item as delimited untrusted
data (body cut at 2000 runes). The answer must be exactly
{"yes":bool,"why":"..."}; anything else is an error, never a yes.
20s per attempt, one retry on a transient failure, every attempt's cost
told to Spent. Model: the rule's (WithRuleModel), else the factory's
default, else the arrival read's. judgetest is a fake for other lanes.

cmd/codeaf/factory_judge.go builds it on the provider and books each
call under "factory filter", counted as the factory's own AI.
A -tags e2e test asks deepseek/deepseek-v4.1-flash 4 questions over 6
items, a prompt-injection item among them.
@santoshkumarradha
santoshkumarradha merged commit a471337 into factory/general-intake Nov 6, 2026
1 check passed
@santoshkumarradha
santoshkumarradha deleted the factory/gi-judge branch November 6, 2026 21:03
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