Skip to content

Fix nested model selectors in Pi exports - #8287

Merged
lidge-jun merged 4 commits into
devfrom
codex/8172-pi-selector
Nov 12, 2026
Merged

lidge-jun merged 4 commits into
devfrom
codex/8172-pi-selector

Conversation

@lidge-jun

@lidge-jun lidge-jun commented Nov 7, 2026 •

Copy link
Copy Markdown
Owner

Summary

Pi exports routed models under the proxy's encoded key, so OpenRouter's nested openrouter/free is exported as openrouter/openrouter-free. That key routes only while the router's inventory can decode it; with a cold inventory the proxy forwards openrouter-free and the upstream rejects it (#8172).

Following the owner decision on #8172 (the serving proxy is authoritative; ambiguous, colliding, wrong-model and cold-inventory routes are refused), Pi now gets the raw selector only where the serving proxy proves it:

  • src/clients/config-export/nested-selectors.ts runs inside loadExportModels against the admitted configuration and router inventory of that load. The raw selector, and its --fast form for a Fast row, must reach the encoded key's provider, model and account, and no other row of the full roster may claim it. The proof is the alias proof, factored out of alias-selectors.ts into proveExportSelector and uniqueExportCandidates.
  • Cold inventory, a self-namespaced model that owns the raw spelling (acme/org/model next to org/model), a policy or combo result, or a collision keeps the encoded key, which is today's output.
  • ocx export --client pi fetches its document from /api/client-config, the route the dashboard download already uses, so the CLI's saved configuration never proves a selector.
  • A managed Pi Apply or overwrite re-proves captured selectors against the live configuration (model-name-guard.ts) and refuses with conflict if one changed.
  • Explicit aliases, native rows and other Pi-format clients (omo, Gentle Shell) keep their keys. The Pi guide (English and seven locales) and structure/clients/export-model-names.md describe the rule.

Carries the approach from #8171; the first commit includes the original author's Co-authored-by trailer.

Closes #8172

Verification

All runs used Bun 1.4.4 with env -i and temporary HOME, OPENCODEX_HOME, CODEX_HOME and CLAUDE_CONFIG_DIR.

  • Failing-first: tests/cli/cli-export-command.test.ts "the serving proxy proves the raw selector…" (serving config knows org/free, saved config does not) fails with either the CLI routing change or the loadExportModels attachment reverted, and passes with both. The guard case in tests/clients/client-export-model-names.test.ts fails with model-name-guard.ts reverted.
  • Proof cases in tests/config/client-config-export.test.ts: proven with Fast, cold inventory, self-namespaced collision, roster collision, explicit alias and a stale candidate on reload.
  • One file at a time: client-config-export 100/0, cli-export-command 33/0, client-export-model-names 12/0, management-client-config-route 43/0, api-catalog-route 9/0, loopback-listener-integration 38/0.
  • tests/clients plus the export and management route files in one process: 3029 pass, 9 fail. All nine pass when their files run alone (cross-file state in a single process).
  • bun run typecheck, bun run structure:check, bun run privacy:scan and git diff --check pass.
  • Cost: proving 400 nested rows takes about 110 ms per roster load, on the export and integration path only.
  • NOT RUN: the full bun run test, the docs-site build, and a live Pi client against OpenRouter.
  • Pushed with --no-verify; the repository has no pre-push hook.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults. Selector serialization and a write guard only; no credential or admission change.

Co-authored-by: Juan Fernando Huenchun Barra <jhuenchunbarra@gmail.com>
@coderabbitai

coderabbitai Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the bug Something isn't working label Nov 7, 2026
Pi now receives a raw nested selector only when the serving proxy's own
configuration and inventory prove it reaches the encoded key's model and
account, Fast row included, with no other row claiming it. Cold, ambiguous,
colliding and wrong-model routes keep the encoded key. ocx export --client pi
takes its document from /api/client-config, and a managed Pi write refuses
when a captured selector stopped proving.
@lidge-jun

Copy link
Copy Markdown
Owner Author

Maintainer judgment: hold (not merging)

The rework at 4be22db follows the owner decision on #8172 for the surfaces the proxy serves: proof runs in loadExportModels against the serving configuration and inventory, cold, ambiguous, colliding and wrong-model routes keep the encoded key, and Fast rows are proven with their base. An independent review confirmed those parts (alias output unchanged, all new tests fail on the pre-fix source). It also found two problems that keep this from merging:

  1. ocx sync still proves Pi selectors from the CLI's saved configuration. src/cli/sync-command.ts (~L166-171) loads the CLI config and calls loadExportModels(config) in the CLI process, then refreshes the managed Pi integration through buildPiContribution. The write guard re-proves against that same config, so it cannot catch a difference from the live proxy. That is the case the owner decision rules out, and it contradicts the new structure note.
  2. ocx export --client pi changes output in Codex Direct mode. The CLI's local build drops native rows under Codex Direct (omitNative in opencodeCatalogFromProxyRows); the server roster does not, so routing the CLI through /api/client-config adds the native GPT rows, which Pi cannot use there (its loopback placeholder is not a ChatGPT bearer). The dashboard download already behaves this way today, so the two surfaces already disagree in that mode.

Fixing either one means choosing who owns Pi's catalog, and each choice changes something users see:

  • (a) Route ocx sync's Pi refresh through the proxy (as /api/sync does) and apply the Codex Direct native-row rule in the Pi builder, so the CLI export, dashboard download and managed refresh all agree. This removes unusable native rows from managed Pi files in Direct mode.
  • (b) Keep raw selectors server-only: the CLI export and ocx sync keep encoded keys (today's output); the dashboard download and dashboard-driven refresh get proven raw selectors. A managed Pi file could then flip between spellings depending on which path refreshed it last.
  • (c) Close this without merging. Since fix(router): decode routed slugs via modelDisplayNames ids #7979 (v2.95.0) the encoded key decodes whenever the router knows the model, and the owner decision refuses cold inventories, so the raw selector only helps in the window where the proxy has restarted but not yet rediscovered the model. That benefit may not justify (a) or (b).

The branch is left as a draft at 4be22db; the review findings are recorded here so the next owner does not repeat them.

…ws in Codex Direct

Pi may carry raw nested selectors that only the serving proxy can prove (#8172), but ocx sync rebuilt the Pi file in the CLI process from the CLI's saved configuration and router cache, and the write guard re-proved against the same snapshot. ocx sync now leaves Pi out of its local refresh and asks the running proxy to refresh an owned Pi file through POST /api/client-integrations/pi/sync, which builds it from that process's own configuration, router and roster; a refusal or an older proxy is reported as a Pi outcome with no local fallback.

The Pi export moved onto the serving proxy's roster, which kept native OpenAI rows in Codex Direct mode; Direct forwards the caller's own bearer and Pi sends a placeholder key, so those rows only answered 401. The Pi builder now drops them in Direct mode, as the CLI-built export did.
@lidge-jun

Copy link
Copy Markdown
Owner Author

Maintainer judgment: merge

Head reviewed: 9d76a420fb3a8bc714e76551e4c8fb6706676906. It contains the original lane's commits through 4be22db, carried after that lane went offline, plus a maintainer dev merge (18795c40f) and the option (a) fix 9d76a420f.

Value. Fixes #8172. A routed model whose upstream ID contains a slash was exported to Pi only under its encoded key, which routes only while the router's inventory can decode it. Pi now gets the raw provider/upstream-id selector, and its Fast row, when the serving proxy proves the raw selector reaches the same model. Ambiguous, colliding, wrong-model, cold-inventory, combo and policy rows keep the encoded key. No other open PR covers this.

Owner rule and decision applied (option a). The serving proxy is authoritative, so every Pi document is now built inside it:

  • ocx export --client pi reads /api/client-config.
  • ocx sync no longer rebuilds Pi in the CLI process. For an owned Pi file, it calls the new POST /api/client-integrations/pi/sync route, which runs refreshOwnedCatalogIntegrations(..., ["pi"]) with that process's own config, router and roster. A refusal, or an older proxy without the route, is reported as a Pi outcome with no local fallback. A user with no Pi connection never makes the request.

User-visible change.

  • Pi may show raw nested selectors.
  • ocx sync refreshes Pi through the running proxy.
  • In Codex Direct mode, Pi's export again leaves out native OpenAI rows. Direct forwards the caller's own bearer and Pi sends a placeholder key, so those rows only answered 401. The CLI-built export omitted them before this PR moved the export onto the server roster.

omo, prime, aside, gentle-shell, Hermes and Command Code exports are unchanged. Docs: docs-site/.../guides/pi.md (the locales carry the selector rule and do not contradict the Direct-mode sentence) and structure/clients/export-model-names.md. The generated ocx skill surface is updated for the new route.

No regression for existing users.

  • The new route sits behind the same /api authentication gate as the other client-integration routes; without an admin or dashboard credential it returns 401.
  • A sibling instance is refused before the handler runs, and the refresh does nothing under a sibling.
  • The route accepts only an empty JSON object and echoes nothing from the request.
  • Other clients' refreshes and the ocx sync exit code are unchanged.
  • Residual: the write guard re-proves only rows that already carry a raw selector. It now runs against the serving proxy's config, and the gap is documented.

Windows. No platform-specific code changed.

Evidence.

  • Fresh independent final review of this exact head, on xai/grok-4.7 (reasoning effort high) per the owner's final-gate rule: PASS, no findings, including the security check of the new route. It made an unauthenticated POST (refused with 401), then an authenticated one (admitted), and checked sibling refusal, body validation and that no CLI-process path builds Pi. Its run of eleven test files: 319 pass, 0 fail. Typecheck, the file-size ratchet, structure:check, skill:surface:check and privacy:scan all passed.
  • Earlier history: the final review at 4be22db failed on CLI-config proof, Direct-mode native rows, and guard scope. The first two are fixed here; the third is the documented residual above.
  • My own runs, in an isolated home: the new tests/clients/pi-sync-owner.test.ts passes 9 / 0. With the old sync-command.ts and config-export.ts, the Direct-mode case and the sync-list case fail. The 23 related files pass 523 / 0.
  • CI on this head was still pending at merge time. CI is not a merge gate under the current rule, and no failure is visible.

NOT RUN: full bun run test; macOS and Windows lanes.

@lidge-jun
lidge-jun marked this pull request as ready for review November 12, 2026 20:19
@lidge-jun
lidge-jun requested a review from Ingwannu as a code owner November 12, 2026 20:19
@lidge-jun
lidge-jun merged commit 7ce7d5a into dev Nov 12, 2026
27 of 29 checks passed
@lidge-jun
lidge-jun deleted the codex/8172-pi-selector branch November 12, 2026 20:20
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-12T20:23:02.258200Z 9d76a42 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9d76a420fb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

const omitNative = options.omitNativeInCodexDirect === true
&& providerCodexAccountMode("openai", ctx.config?.providers?.openai) === "direct";
for (const model of normalizeExportModels(roster)) {
if (omitNative && model.native === true) continue;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Retain account-qualified native rows in Direct mode

When a Direct-mode configuration exposes account-qualified native models, this filter removes working models from dashboard exports and managed Pi refreshes. listManagementModelRows also marks account-bound rows as native: true, but the account-namespace branch in src/router.ts explicitly sets codexAccountMode: "pool" and pins the stored account even when the provider globally uses Direct mode. Those rows therefore do not depend on Pi supplying an OpenAI credential. Restrict the omission to rows whose resolved route actually uses Direct mode, preserving account-qualified rows.

Useful? React with 👍 / 👎.

lidge-jun added a commit that referenced this pull request Nov 12, 2026
#8287 moved Pi out of the direct ocx sync fan-out into the serving proxy
(refreshPiThroughServer). Two sync oracles still listed "pi", so dev was red
from 7ce7d5a. Assert the list without "pi" and that Pi takes the server
path, and stub that path in the dispatch test.
lidge-jun added a commit that referenced this pull request Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Pi export emits invalid IDs for nested provider model slugs

1 participant