Skip to content

feat(router): bandit foundation — propensity + reward logging, gated explorer#338

Merged
aminsamir45 merged 3 commits into
mainfrom
bandit-router-foundation
Jun 9, 2026
Merged

feat(router): bandit foundation — propensity + reward logging, gated explorer#338
aminsamir45 merged 3 commits into
mainfrom
bandit-router-foundation

Conversation

@aminsamir45

Copy link
Copy Markdown
Contributor

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.

  • Routing metadata — widen RoutingMetadata with CandidateScores + Propensity. The scorer now surfaces its pre-argmax blended score vector (restricted to eligible models) and reports propensity = 1.0 for the deterministic argmax. No decision logic changes.
  • Telemetry — add nullable candidate_scores (jsonb) + propensity columns (migration 0012 + sqlc regen), wired through observation.go into 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.
  • banditexplore — new sibling Router that samples within the predicted quality-tie band and logs the sampling probability as Propensity (1/|band|), falling back to argmax on any unsafe condition (nil metadata, singleton band, etc.). Wired in main.go behind ROUTER_EXPLORE_ENABLED (default false) + 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) passes
  • make vet clean
  • make test — full suite green, incl. new banditexplore tests + extended service_observation_test.go
  • sqlc regenerated, no drift
  • Apply migration 0012 in staging; confirm candidate_scores/propensity populate with explorer enabled on a small slice

Made with Cursor

…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.
Comment thread internal/router/banditexplore/explorer.go
Comment thread internal/router/banditexplore/explorer.go Outdated
Comment thread internal/proxy/observation.go Outdated
- 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)

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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.

Comment thread internal/proxy/service.go
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.
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