Repository navigation
Price-aware routing in the mesh head (Phase 1 market signal) - #1
Merged
Merged
Conversation
The billing gate stamps X-Otela-Allowed-Peers cheapest-affordable-first; the head now lets that order influence selection instead of load-balancing the affordable set uniformly: - parseAllowedPeerOrder captures the gate's price order. - routing.price_weight_decay (env OF_ROUTING_PRICE_WEIGHT_DECAY, default 0 = legacy uniform policies) turns the order into exponentially decaying selection weights (rank r weighs decay^r): with 0.5 and three affordable peers the cheapest wins ~57% of first picks while the rest still serve. - orderCandidatesByPrice + the order-preserving retry exclusion make a failed attempt deterministically prefer the next-cheapest allowed peer. - X-Otela-Allowed-Peers remains the hard affordability constraint; the new signal only reorders/weights within it. Docs: routing.mdx gains a "Price-aware routing (billing market)" section; settlement.mdx gains an explicit do-not-combine warning separating the legacy peer-to-peer settlement rail (rates.yaml, per-1000, direct SPL transfers) from the api.opentela.ai market (per-1M asks, credit accounts), which double-bill if both run on the same traffic. Tests: 9 new server tests (order parsing, decay weights, tail weights, cheapest-dominance simulation, cheapest-first ordering, stable unknown peers, next-cheapest retry); full internal/server suite green. Tracks api.opentela.ai#3 and api.opentela.ai#4 (this repo has issues disabled; the API repo owns the billing design).
Better Auth's jwt plugin attaches the set-auth-jwt header only to GET /get-session (after-hook matcher: context.path === "/get-session"). Sign-in/email merely sets the HttpOnly session cookie and its body offers no guaranteed-JWT field, so a successful sign-in must be followed by an authenticated /get-session call carrying that cookie; the usable JWT then travels in that response's set-auth-jwt header.
xzyaoi
commented
Sep 14, 2026
xzyaoi
left a comment
Author
There was a problem hiding this comment.
Code review (full-diff pass)
Verdict: approvable. Verified locally against current main (post-eth-easl#64 rebase): go build ./..., go vet, and go test ./internal/server/ ./internal/account/ green. Note this fork has Actions disabled, so these local runs are the verification of record.
Verified correct
- Price-aware routing (closes opentela-ai/api.opentela.ai#3): switch precedence is right —
priceAware(when0 < price_weight_decay < 1and the header is present) overridesscalability.weighted_routing, and absent header / decay 0 keeps byte-for-byte legacy behavior (wire-compatible for existing callers).X-Otela-Allowed-Peersremains the hard constraint; the signal only reorders/weights within it. - Retry semantics:
orderCandidatesByPrice+ order-preservingexcludePeersmakeremaining[0]after a failed attempt deterministically the next-cheapest surviving allowed peer — exactly the issue's "prefer the next-cheapest allowed peer" ask. priceAwareScores:decay^rankweighting with defensive tail weight for peers absent from the order; empty-input guard.SignInEmail(account): matches Better Auth's actual JWT semantics — sign-in only sets the HttpOnly session cookie, and the jwt plugin attachesset-auth-jwtonly onGET /get-session; the cookie-jar follow-up call is the correct fix. 2FA-redirect detection gives actionable guidance. Response close/error handling hardened.- Docs:
routing.mdxdocuments the knob; thesettlement.mdxdual-rail callout is accurate about the double-billing hazard and does not overstate (unification explicitly left to opentela-ai/api.opentela.ai#4).
Non-blocking nits (follow-ups)
- When
routing.price_weight_decayandscalability.weighted_routingare both enabled, price-aware silently wins — worth one sentence inrouting.mdxstating the precedence. - No metrics on price-aware selection (e.g. picks-by-rank histogram) — would help operators tune the decay knob.
- Account library ships without a call site in
entry/— boot wiring is a stated follow-up; fine to merge as-is.
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.
Implements the routing side of Phase 1 (price-aware peer selection). API half: opentela-ai/api.opentela.ai#7.
Part 1 — the gate's price order now reaches routing (Closes opentela-ai/api.opentela.ai#3)
X-Otela-Allowed-Peersremains the hard affordability constraint; within it, selection is no longer uniform:src/internal/server/proxy_handler.go:parseAllowedPeerOrdercaptures the billing gate's cheapest-affordable-first peer order from the header.orderCandidatesByPricere-orders routing candidates to follow that order;priceAwareScoresturns it into exponentially decaying selection weights (rank r weighsdecay^r) — with 0.5 and three affordable peers the cheapest wins ~57% of first picks while the rest still serve.src/entry/cmd/root.go:routing.price_weight_decay(envOF_ROUTING_PRICE_WEIGHT_DECAY, default 0 = legacy uniform policies) — the policy is a tunable knob, not hardcoded.docs/content/docs/tutorial/routing.mdx: documents the knob and the market-signal semantics.src/internal/server/allowed_peers_test.go(order parsing, re-ordering, decay weighting, retry preference).Part 2 — account sign-in produces a usable JWT (provider onboarding support; no tracked issue)
src/internal/account/link.goSignInEmailhardened to match how Better Auth actually issues JWTs:--tokenpath).set-auth-jwtonly toGET /get-session.SignInEmailnow keeps the cookie jar and follows up with an authenticated/get-sessioncall to extract the usable JWT.src/internal/account/link_test.go, including the sign-in →/get-session→ JWT round-trip against an in-process auth server.Note: this ships the account library path; wiring it into the provider boot flow is a small follow-up once the seller-side console flow lands.
Docs: dual-rail warning (related: opentela-ai/api.opentela.ai#4)
docs/content/docs/tutorial/settlement.mdxgains a prominent callout documenting the two independent billing models (legacyrates.yamlper-1000 direct-SPL settlement vs the API market's per-1M asks and credit ledger), the double-billing hazard of running both on the same traffic, and "deploy exactly one model per traffic path". Retiring/unifying the legacy rail is tracked in opentela-ai/api.opentela.ai#4 and not addressed here.Verification
main(post-feat(attestation): make the build-attestation trust anchor configurable eth-easl/OpenTela#64);go build ./...andgo vetclean.go test ./internal/server/ ./internal/account/green (server suite is DB-backed).