Repository navigation
factory: the AI filter's model-backed judge (lane A) - #2479
Merged
Merged
Conversation
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.
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.
Lane A of the general-intake wave (docs/design/factory-general/DESIGN.md §1b): the model-backed
route.Judgebehind a rule'swhen.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 withtriage.Untrusted.{"yes":bool,"why":"…"}. One wrapping code fence is tolerated. Prose, extra keys, duplicate keys, a string"true"or an empty why all returnErrNoAnswer, which is never a yes.judge.Timeout). A transient failure (timeout, net error, or a taxonomy transport class via the caller'sTransient) gets one retry after 2s. A refusal or a garbled answer is not retried. The clock (After) and the provider (Call) are injectable.WithRuleModel(ctx, m)(the seam for a rule's own model), then the factory default, then the arrival read's model.Verdict.Modelis the model that served the answer, andKey = route.VerdictKey(ask, it).Spent, failed attempts included.cmd/codeaf/factory_judge.go(factoryJudge(st, load), ready for lane R to inject into intake) books each call underfactory filterthroughfactoryAIAccounting, the same path triage uses.factory filteris 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.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=5passes.TestFactoryJudgeBooksItsQuestionOnTheLedgerpasses.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-lawsstill fails onTestOnlyOneVerdictTypeExists(internal/taxonomy). That law allows only one type namedVerdictin the module, androute.Verdictcomes 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 exampleroute.Answer.🤖 Generated with Claude Code