Skip to content

mcpx(openapi): Build is nondeterministic — duplicate operationIds swap tool names between runs, and the body schema is whichever JSON media type the map yields first #1668

Closed

Description

@dezren39

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 a map[string]*Operation; Build ranges 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 _2 to 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 /pets and POST /pets both declaring operationId: listPets (with methods all) yield api_listpets → GET, api_listpets_2 → POST on one Build and api_listpets → POST, api_listpets_2 → GET on the next.
  • Consequence: a caller (script, saved command, model) invoking api_listpets can 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) ranges op.RequestBody.Content (a Go map) and breaks on the first media type whose name contains "json".
  • A request body declaring two JSON media types with different schemas — e.g. application/json and application/vnd.api+json (JSON:API), both containing "json" — advertises one schema on one Build and the other on the next. The tool's published inputSchema (what a caller validates against and what a model reads) flips accordingly, while Call always sends the same body.

Evidence

  1. Line trace on main c04a943 (file sha256 79b465b9636fa1e51025824ff395e27bf28d0849fcb0c4bd7a2490a097b7cde5): operations() :75-86 builds a map; Build ranges it :291; disambiguation :306-310 is visit-order dependent; buildSchema media 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.
  2. 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.
  • Build is 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/json first, then lexicographic media type), pinned by a test with two JSON media types carrying different schemas.
  • Existing internal/openapi tests pass; no change to single-media-type or unique-operationId behaviour.

Activity

  1. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    source/creatorFiled by the new-issue-creator job
    task/triageQueue packet kind: verify, reproduce, and route this item
    priority/normalOrdinary priority (the default)
    app/mcpxPackage/app: mcpx (pkgs/ or apps/ in this repo)
    effort/sSmall: expected under 2 hours of work
    on Oct 28, 2026
  2. dezren39 commented on Oct 28, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

    • Agent: new-issue-creator (new-issue-creator-code-b)
    • Session / ID: new-issue-creator-code-b run 2026-10-28 07:50 CDT
    • Found via: filed this run
    • Task: Triage the nondeterministic openapi.Build findings (duplicate-operationId name ownership and multi-JSON-media body-schema pick both depend on Go map iteration order); first step is running the prepared Go probe in the real package on the laptop.
    • Expectation: effort/s — done when Build is deterministic for colliding operationIds and multi-JSON-media bodies, pinned by repeated-build tests, with existing openapi tests green.
    • Links: queue packet packet-1668.json (repo-health-code-pilot, triage)
  3. dezren39 commented on Oct 28, 2026

    @dezren39
    MemberAuthor

    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.

  4. dezren39 commented on Oct 28, 2026

    @dezren39
    MemberAuthor

    Intake review

    — fleet monitor intake pass, 2026-10-28T13:45Z

  5. added
    meta/enrichedIntake review done: acceptance criteria, links, and normalized labels added
    and removed on Oct 28, 2026
  6. 5 remaining items

  7. dezren39 commented on Oct 31, 2026

    @dezren39
    MemberAuthor

    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:

    • Duplicate operationIds: over 200 Build calls on the same spec (GET and POST /pets both declaring listPets), the bare tool name api_listpets is 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 path Build ranges PathItem.operations(), which returns a Go map — the _2 disambiguation suffix goes to whichever operation the map yields second.
    • Body schema media pick: over 200 Builds, the single tools advertised body schema flips between the application/json schema (a) and the application/vnd.api+json schema (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/json first, then lexicographic order among remaining JSON media types; (3) repeated-build determinism tests in internal/openapi (the probe shapes, run with -count repetition or an in-test loop) pinning both.

  8. added
    queue/claimedQueue worker lifecycle state
    work/assignedQueue worker lifecycle state
    and removed
    queue/claimedQueue worker lifecycle state
    work/assignedQueue worker lifecycle state
    on Oct 31, 2026
  9. dezren39 commented on Nov 1, 2026

    @dezren39
    MemberAuthor

    {"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."}

  10. added a commit that references this issue on Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

app/mcpxPackage/app: mcpx (pkgs/ or apps/ in this repo)effort/sSmall: expected under 2 hours of workkind/bugSomething isn't working (prefixed form of the classic bug label)meta/enrichedIntake review done: acceptance criteria, links, and normalized labels addedpriority/normalOrdinary priority (the default)source/creatorFiled by the new-issue-creator jobtask/triageQueue packet kind: verify, reproduce, and route this item

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions