Repository navigation
Description
Problem
openapi.Build (pkgs/mcpx/internal/openapi/openapi.go, main c04a943, sha256 79b465b9) is nondeterministic for two spec shapes it explicitly handles: the same specification, built twice by the same binary, can produce different tools. Build is re-run on every mcpx api invocation and every MCP-server start (internal/cli/openapi_tools.go:59-77 buildAPI, used by CmdAPI and apiTools), so the flips happen between ordinary restarts/invocations, not just in theory.
Site 1 — duplicate-operationId disambiguation depends on map iteration order
PathItem.operations()(openapi.go:75-86) returns amap[string]*Operation;Buildranges it at :291. Go randomises map iteration order on each range.- Paths themselves are sorted (:285-288) and the final tool list is sorted by name (:325), but neither fixes which operation owns which name: the collision loop (:302-310) keeps the bare name for the first operation visited and appends
_2to the later one. - The code's own comment (:302-305) says duplicate operationIds occur in practice and are "disambiguated rather than dropped" — but the disambiguation is a coin flip. Example:
GET /petsandPOST /petsboth declaringoperationId: listPets(with methodsall) yieldapi_listpets → GET, api_listpets_2 → POSTon one Build andapi_listpets → POST, api_listpets_2 → GETon the next. - Consequence: a caller (script, saved command, model) invoking
api_listpetscan silently reach the other endpoint after a restart — a read can become a create — or a name it used yesterday now belongs to a different operation. Tool names are the stable surface everything else keys on; here they are not stable.
Site 2 — the request-body schema is whichever JSON media type the map yields first
buildSchema(:498-511) rangesop.RequestBody.Content(a Go map) andbreaks on the first media type whose name contains"json".- A request body declaring two JSON media types with different schemas — e.g.
application/jsonandapplication/vnd.api+json(JSON:API), both containing "json" — advertises one schema on one Build and the other on the next. The tool's publishedinputSchema(what a caller validates against and what a model reads) flips accordingly, whileCallalways sends the same body.
Evidence
- Line trace on main c04a943 (file sha256
79b465b9636fa1e51025824ff395e27bf28d0849fcb0c4bd7a2490a097b7cde5):operations():75-86 builds a map;Buildranges it :291; disambiguation :306-310 is visit-order dependent;buildSchemamedia loop :498-511 breaks on the first map-yielded"json"key. Existing tests (openapi_test.go) cover neither duplicate operationIds nor multi-JSON-media bodies. - Premise exercised this run with a faithful mirror of both loops (goal
hidden_files/probe-2026-10-28-laneB-openapi-nondet/premise.py+premise.log): iteration GET,POST →api_listpets=GET; iteration POST,GET →api_listpets=POST; media iteration json-first → schema A, vnd.api+json-first → schema B. The only input that changes is iteration order, which Go supplies randomly per range.
Disclosure: the prepared Go probe (hidden_files/probe-2026-10-28-laneB-openapi-nondet/probe_laneb_test.go, package openapi_test; builds the same spec 200× and fails if the bare name's owner or the body schema ever flips) was not executed — the laptop was unreachable this run (SSH tunnel closes immediately) and probes are never compiled on the sandbox. Triage should run the probe first and correct this issue if any verdict differs.
Why it matters
Generated tool names and schemas are a contract: scripts, the catalogue/codegen surface and callers' saved invocations all assume the same spec yields the same tools. Nondeterminism here is silent (no error, both outputs look valid) and, for site 1, can route a call to the wrong HTTP method/path.
Acceptance criteria
- Triage runs the prepared probe and confirms/corrects both verdicts.
-
Buildis deterministic: building the same spec any number of times yields byte-identical tool names, method/path bindings and input schemas. - Duplicate operationIds are disambiguated by a stable rule (e.g. method/path order), pinned by a test that builds a colliding spec repeatedly; the operation that keeps the bare name does not depend on iteration order.
- The request-body media pick follows a stated, stable preference (e.g. exact
application/jsonfirst, then lexicographic media type), pinned by a test with two JSON media types carrying different schemas. - Existing
internal/openapitests pass; no change to single-media-type or unique-operationId behaviour.
Activity
dezren39 commentedon Oct 28, 2026
🤖 Agent note · filed
dezren39 commentedon Oct 28, 2026
Related filing from the same run, same package, different defect: #1669 (parameter-identity / override dedup). #1668 remains specifically about map-iteration nondeterminism in name disambiguation and the request-body media pick.
dezren39 commentedon Oct 28, 2026
Intake review
openapi.Build.pkgs/mcpx/internal/openapi/openapi.go) — a worker touching one should re-check the others' line references before editing.kind/bug,source/creator,priority/normal,effort/s,app/mcpx,queue/queued). Markedmeta/enrichedonly.— fleet monitor intake pass, 2026-10-28T13:45Z
5 remaining items
dezren39 commentedon Oct 31, 2026
Triage verdict (task 1869, lane B): CONFIRMED — both sites, as filed
The prepared Go probe (
probe-2026-10-28-laneB-openapi-nondet/probe_laneb_test.go) was executed this run in the real package on the laptop against current main (106b05718). Both probe tests fail in exactly the predicted way:Buildcalls on the same spec (GET and POST/petsboth declaringlistPets), the bare tool nameapi_listpetsis owned by both GET and POST across runs (owners: map[GET:true POST:true]). Root cause verified in source on current main: paths are sorted, but within a pathBuildrangesPathItem.operations(), which returns a Go map — the_2disambiguation suffix goes to whichever operation the map yields second.s advertised body schema flips between theapplication/jsonschema (a) and theapplication/vnd.api+jsonschema (b) — 2 distinct schemas. Root cause verified:buildSchemarangesop.RequestBody.Contentand breaks on the first key containingjson`.Fix direction (pinned for the follow-up): (1) iterate operations in a stable deterministic order before disambiguation — sorted method order within a path (paths are already sorted), so name ownership is a pure function of the spec; (2) a stated stable media preference for the body schema — exact
application/jsonfirst, then lexicographic order among remaining JSON media types; (3) repeated-build determinism tests ininternal/openapi(the probe shapes, run with-countrepetition or an in-test loop) pinning both.dezren39 commentedon Nov 1, 2026
{"agent_note":"v1","kind":"picked_up","task_id":4221,"worker":"repo-worker-code","lane":"openchamber-scheduled-lane","summary":"OpenChamber scheduled laptop lane claimed task 4221 for issue #1668. Revalidated the issue is open, no competing open PR found for the issue or pkgs/mcpx/internal/openapi, and no hard-stop labels are present; preparing a dedicated laptop worktree."}
Merge pull request #3518 from developing-today/queue/4221-1668-openap…