feat(router): bandit foundation — propensity + reward logging, gated explorer#338
Merged
Conversation
…explorer Stage a contextual-bandit capability as additive, reversible steps. The deterministic argmax scorer and all frozen artifacts are unchanged; new behavior is gated OFF by default. - router: widen RoutingMetadata with CandidateScores + Propensity; scorer surfaces the pre-argmax score vector (propensity=1.0 for argmax). - telemetry: nullable candidate_scores (jsonb) + propensity columns (migration 0012 + sqlc regen); wired through observation.go into both the Anthropic and OpenAI telemetry paths and as additive OTel span attrs. - banditexplore: new sibling Router that samples within the quality-tie band and logs the sampling probability as propensity; falls back to argmax on any unsafe condition. Wired in main.go behind ROUTER_EXPLORE_ENABLED (default false) + ROUTER_EXPLORE_EPSILON. Prod stays argmax.
- BYOK: surface per-request CandidateProviders on RoutingMetadata; explorer resolves an in-band peer's provider from the request binding (correct under narrowed EnabledProviders) before the boot-time default. (High) - propensity: build the servable tie-band (peers with a resolvable provider) before sampling, so logged propensity 1/|band| is always exact and the post-sample reject path is gone. (Medium) - telemetry: gate obs.Propensity on a non-empty score vector so non-scoring routers leave the column NULL instead of logging 0.0. (Low)
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 9780445. Configure here.
The semantic cache keys on embedding/cluster/version/knobs-hash but not the served model. With exploration on, the explorer can serve different in-band models for the same embedding, so a hit could return another model's body. Fold the served model into EffectiveKnobsHash on a real switch (not when the argmax is drawn), keeping argmax-cache reuse intact.
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.

Summary
Stages a contextual-bandit capability for the router as additive, reversible steps. The deterministic argmax scorer and all frozen artifacts are unchanged; every new behavior is gated OFF by default, so production stays pure argmax.
RoutingMetadatawithCandidateScores+Propensity. The scorer now surfaces its pre-argmax blended score vector (restricted to eligible models) and reportspropensity = 1.0for the deterministic argmax. No decision logic changes.candidate_scores(jsonb) +propensitycolumns (migration0012+ sqlc regen), wired throughobservation.gointo both the Anthropic and OpenAI telemetry paths and emitted as additive OTel span attributes. Off-policy substrate only; never read back on the request path.Routerthat samples within the predicted quality-tie band and logs the sampling probability asPropensity(1/|band|), falling back to argmax on any unsafe condition (nil metadata, singleton band, etc.). Wired inmain.gobehindROUTER_EXPLORE_ENABLED(defaultfalse) +ROUTER_EXPLORE_EPSILON.The matching offline scripts (reward-dataset builder, off-policy estimator, Thompson-posterior trainer) and the gitlink bump land in the WorkWeave repo PR.
Test plan
make build(no-CGO stub embedder = CI build gate) passesmake vetcleanmake test— full suite green, incl. newbanditexploretests + extendedservice_observation_test.go0012in staging; confirmcandidate_scores/propensitypopulate with explorer enabled on a small sliceMade with Cursor