fix(serviceoffercontroller): align well-known/x402 resource path with openapi for inference/agent#791
Merged
Merged
Conversation
… openapi for inference/agent Reported by a teammate during v0.14.0-rc0 field testing. https://claude.ai/code/session_01PnhCQLz7CHuDBUhWd5xF8v
OisinKyne
force-pushed
the
fix/discovery-x402-resource-path
branch
from
July 20, 2026 17:43
c70634a to
576cac6
Compare
OisinKyne
approved these changes
Jul 20, 2026
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.
Problem
For hostname-bound inference and agent ServiceOffers (the common case:
spec.typeempty/inference/agent, no customspec.routes), the two discovery surfaces advertised different paths for the same paid operation:buildOfferScopedOpenAPI→openAPIPathsForOffer, which special-cases inference/agent and always emits a single path/v1/chat/completions, ignoringspec.routes.buildOfferWellKnownX402, which iteratesEffectiveRoutes()and maps each route path viaopenAPIRelPathForRoute. With no declared routes,EffectiveRoutessynthesizes a paid catch-all/*;openAPIRelPathForRoute("/*")collapses to"", so the resource URL became<origin>/(offer root).An x402 crawler that cross-references openapi.json with
/.well-known/x402therefore saw<origin>/v1/chat/completionsvs<origin>/and treated them as disagreeing resources. HTTP/fine-tuning offers with an explicit route table already agreed; the bug was only the inference/agent hardcoded-path special-case known to one builder.Fix
In
internal/serviceoffercontroller/offerbundle.goonly:openAPIRelPathForOfferRoute(offer, routePath), which mirrorsopenAPIPathsForOffer's per-type path selection: inference/agent → fixed/v1/chat/completions; every other type → existingopenAPIRelPathForRoute(routePath).buildOfferWellKnownX402now builds each resource URL with that helper instead of callingopenAPIRelPathForRoutedirectly.openAPIPathsForOffer,openAPIRelPathForRoute, andbuildOfferWellKnownX402FromOpenAPIare unchanged.Regression pin:
TestBuildOfferBundles_InferenceOfferAgreesWithOpenAPIinhostoffer_test.go— hostname-bound inference offer with noSpec.Routes; asserts openapipathsis exactly/v1/chat/completionsandx402.jsonresources[0].resourceishttps://…/v1/chat/completions.Diagram
flowchart LR subgraph offer [ServiceOffer inference/agent] Type["spec.type = inference|agent"] Routes["spec.routes empty → EffectiveRoutes synthesizes /*"] end subgraph builders [Discovery builders] OA["openapi.json builder\nopenAPIPathsForOffer"] XK["/.well-known/x402 builder\nbuildOfferWellKnownX402"] end subgraph pathLogic [Shared per-type path logic] Helper["openAPIRelPathForOfferRoute\n(or openAPIPathsForOffer equivalent)"] Fixed["/v1/chat/completions"] end Type --> OA Type --> XK Routes --> XK OA --> Helper XK --> Helper Helper --> Fixed Fixed --> OAOut["openapi paths:\n/v1/chat/completions"] Fixed --> XKOut["x402 resource:\norigin + /v1/chat/completions"] OAOut -.->|agree| XKOutValidation
https://claude.ai/code/session_01PnhCQLz7CHuDBUhWd5xF8v