Repository navigation
feat(go): port the routing half of laya.router (Route, RouteBatch) - #1310
Conversation
names, language codes, workflow match, question signatures, 1,058 route decisions (the .NET probe corpus inputs plus seeded fuzz) and 63 route_batch calls, all run through laya.router.Router.
Route and RouteBatch name a checkpoint and the reason without loading anything: NormaliseName, EnglishFromCode, MatchTypedDecisionsWorkflow and QuestionSchema, with laya's reason strings (repr quoting, half-even percent, code-point cut at 60). Hooks, lifecycle and routed inference are later. Not ported: custom checkpoints (register), explain=True, non-string names.
Restore upstream's predict_plan values in go_extra.json (only the router family differs from upstream/main); golden pair check for QuestionSchema (Python-equal implies Go-equal, Go-equal implies same render, 11 coarser pairs listed); zzz superset case for the workflow match; LangHint concurrency doc.
Three things my conflict resolution got wrong across #1306, #1307, #1308, #1309, #1310 and #1311, which all touch go.yml, README.md, gen_go_fixtures.py and go_extra.json: 1. `shortlist_order_family` lost its `return {"cases": cases}`. The conflict boundary fell on that line, so the function built its cases and returned None, and go_extra.json carried `"shortlist_order": null`. Found by parsing the merged file and checking all 98 top-level names against the PR each came from; only this one and `build` failed, and `build` is the validated union of all 23 keys. 2. go.yml lost four of #1309's parity steps (the samples module's golden check, build, test and no-cgo build). #1310 conflicted over the same hunk and my resolver kept one side. Restored; the merged file now holds every step name from every PR in the series and none that is not in one of them. 3. `build()` had `email_fuzz` ahead of `router`. They are the only two of the new families that draw from the shared `rng`, so that order re-drew the corpus #1311 recorded `router.signatures` from, and `router/golden_test.go` pins how many of those 107 signatures come out byte-identical to Python's: 42 instead of 50. Nothing was wrong with that constant, or with Go. Putting `router` first gives it the stream #1311 measured, and `email_fuzz` is the one re-drawn, which it can be: it has no such constant, only a 1500-case count, and it still holds 1500. With that, `gen_go_fixtures.py --check` passes and each PR's own key reproduces verbatim from this tree: calibration (#1306), shortlist_order (#1307), email_fold (#1308) and router (#1311). `go build`, `go vet` and `go test` are green across all 12 packages. `--min-tests` is left at 3869 as a floor rather than an exact count, because the figure a full lane reports cannot be measured here: several goldens need ONNX exports. The comment says so and asks for it to be tightened on the next green run. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Merged into 0.4.14, with #1306, #1307, #1308, #1309 and #1311. The routing half is the right place to cut this.
One thing to know about the merge. This PR's
|
What and why
routerNewwithWithDefault,WithAutoTaskDetection,WithStandaloneRepos,WithLangGuess,WithSource,WithSourceIn.RouteandRouteBatchreturn aDecision(model, repo, reason, detection, workflow) and load nothing. Per-callForModel,ForTask,ForLang,ForLangGuess. AlsoNormaliseName,CanonicalName,ResolveModelSpec,EnglishFromCode,MatchTypedDecisionsWorkflow,QuestionSchemascripts/gen_go_fixtures.pyrouterfamily ingo_extra.json, recorded fromlaya.router.Router. Inputs: thelaya-dotnet/tools/routing_cases.pycorpus plus seeded fuzz. The dotnet golden JSON is not read--min-tests). No--onlychange: the family lives ingo_extra.json, which the existing step regeneratesNames follow Java (
Router,normaliseName,matchTypedDecisionsWorkflow) and .NET (Route,RouteBatch) in Go idiom: a closedCheckpointtype,Decision, functionalOption(router) andCallOption(per call), andLangHint(concurrent calls possible, so a hint must be goroutine-safe). Precedence is Python's: model, task, workflow (opt-in), lang, call hint, installed hint, detection, default. The default ismultilingual.Later changes: router hooks (
on_route), model lifecycle, routed inference, config surface.Differences from Python
register,unregister, custom checkpoint namesWithSourcerepoints a built-in, any other name is an*UnknownModelErrorroute(explain=True)lang.Analysiscarries nodiagnosticstr(x)stringlang_guesscallable returning anythingLangHint func(state any) string;""abstains_question_schema(dict)signs the dict as writtenQuestionSchemasigns the validatedQuestionsin canonical wire form{}/none/blank, labels in another key order). For R4: Go batch grouping yields fewer forward passes than Python with identical promptsroute_batchrequest dict checks (missing key, wrong type)Request; a nilStateis refused with laya's textRouter.routehooksmodelsvalue~os.path.expanduser(HOME, else the account;~name) forWithSource; not forWithSourceInEvidence
go_extra.jsonrouterfamily differs from upstream/main (the other families are byte-equal; no predict_plan churn)models, a callable hint), seeds 7, 11, 12gen_go_fixtures --check,gen_tables --check, workflow folding, ruffMutants
Each compiles and fails the named test.
TestPrecedence,TestLangHintReceivesStatemultilingualflipped toenglishortyped-decisionsTestDefaultIsMultilingualTestMixedSegmentCutsAtCodePointsTestPercentRoundsHalfToEven%qinstead of repr; unquoted langTestReasonQuotingTestWorkflowNeedsExactIDs,TestWorkflowReportedWithoutAutoDetectionundnot abstaining;.UTF-8not cut;_not split;englishdropped; blank decidesTestEnglishFromCodeGolden,TestRouteGoldenTestNamesGoldenTestTaskSpelling,TestUnknownModelTextTestRouteBatchRefusesNilState,TestRouteBatchGoldenTestQuestionSchemaGoldenEquivalent, not killable: dropping the
-to_rewrite fortask.NormaliseNamealready resolvestyped-decisionsandtyped_decisionsin any case, so the rewrite only mirrors Python.Real-weights e2e
Not applicable: routing runs no model.
Scanners and review