Repository navigation
fix(cli): setup-opencode respects --api-key/OMNIROUTE_API_KEY over context token (#12783) - #13246
Merged
Merged
Conversation
Githab-capibara
added a commit
to Githab-capibara/OmniRoute
that referenced
this pull request
Sep 17, 2026
…ntext token (cheaper-inference#12783) (cheaper-inference#13246) Merged as part of the 39-PR owner batch of 2026-09-11, validated as a unit. Boarded into one consolidated worktree cut from `release/v3.8.51` with the other 38 — zero conflicts between them. - ESLint over every changed file: no errors (the only finding was one suppression entry the batch emptied, pruned on cheaper-inference#13243) - `typecheck:core` clean; `check:dashboard-typecheck` OK (206 pre-existing, within baseline); `check:changelog-integrity` OK - complexity 2821 / baseline 3218 and cognitive-complexity 1272 / baseline 1437 — both under baseline - 256 assertions green: 246 under node:test and 10 under vitest, which is where `tests/unit/**/*.test.tsx` actually runs - `check-file-size`: `chatCore.ts` rebaselined 6144 → 6146 for cheaper-inference#13278 and cheaper-inference#13276, annotated and landed on cheaper-inference#13243⚠️ base-red inherited: cheaper-inference#12732 — the provider count (356 in the docs vs the 358 the modules define) and `open-sse/utils/stream.ts` at 3115 > frozen 3098 both reproduce on the pure tip with zero contribution from this batch.
muhamadgalihsaputra
pushed a commit
to niyatna/NiyatnaRoute
that referenced
this pull request
Sep 27, 2026
…ntext token (cheaper-inference#12783) (cheaper-inference#13246) Merged as part of the 39-PR owner batch of 2026-09-11, validated as a unit. Boarded into one consolidated worktree cut from `release/v3.8.51` with the other 38 — zero conflicts between them. - ESLint over every changed file: no errors (the only finding was one suppression entry the batch emptied, pruned on cheaper-inference#13243) - `typecheck:core` clean; `check:dashboard-typecheck` OK (206 pre-existing, within baseline); `check:changelog-integrity` OK - complexity 2821 / baseline 3218 and cognitive-complexity 1272 / baseline 1437 — both under baseline - 256 assertions green: 246 under node:test and 10 under vitest, which is where `tests/unit/**/*.test.tsx` actually runs - `check-file-size`: `chatCore.ts` rebaselined 6144 → 6146 for cheaper-inference#13278 and cheaper-inference#13276, annotated and landed on cheaper-inference#13243⚠️ base-red inherited: cheaper-inference#12732 — the provider count (356 in the docs vs the 358 the modules define) and `open-sse/utils/stream.ts` at 3115 > frozen 3098 both reproduce on the pure tip with zero contribution from this batch.
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.
Closes #12783
Root cause
Two compounding bugs in the
setup-opencodeCLI path:bin/cli/program.mjsregisters a top-level--api-key <key>option bound to.env("OMNIROUTE_API_KEY"). Commander parses that flag against the ancestorprogramregardless of where it appears in argv, soomniroute setup-opencode --remote <url> --api-key sk-...stores the value onprogram.opts().apiKey, never onsetup-opencode's own local--api-keyoption. The action handler only read its own localopts, soopts.apiKeywas alwaysundefinedeven when the user explicitly passed the flag.resolveOpencodeTarget()tried the active context'saccessToken/apiKeybefore falling back toprocess.env.OMNIROUTE_API_KEY. A CLI management token (oma_live_...) has no/v1/*inference scope, so a purely env-var-supplied inference key also lost to the context's management token — causing the reported 401 from/v1/models.Fix
registerSetupOpencode's action handler now readscmd.optsWithGlobals().apiKey(falling back to the localopts.apiKey) so the CLI-supplied value — wherever Commander actually stored it — reachesresolveOpencodeTarget().resolveOpencodeTarget()now checks the explicit flag, thenOMNIROUTE_API_KEY, and only then the active context's token — matching the explicit > ambient-env > context precedence already documented and used bybin/cli/api.mjs'sbuildHeaders().Regression test (TDD)
tests/unit/repro-12783-setup-opencode-apikey.test.ts:capturedLocalApiKeystayedundefinedwhileprogram.opts().apiKeyheld the passedsk-...value.--api-keyreaches the action handler, andresolveOpencodeTarget()is unit-tested directly for all three precedence cases (flag > context, env > context, context-only fallback) plus the empty-fallback case.Gates run
node scripts/check/check-file-size.mjs→ OKnode scripts/check/check-complexity.mjs→ OK (2798 violations, baseline 3218)node scripts/check/check-cognitive-complexity.mjs→ OK (1265 violations, baseline 1437)npm run typecheck:core→ clean, no errorsnpx eslint --suppressions-location config/quality/eslint-suppressions.json <changed files>→ 0 errors (bin/** is globally eslint-ignored in this project; only the new test file is linted)node --import tsx/esm --test tests/unit/repro-12783-setup-opencode-apikey.test.ts→ 5/5 passtests/unit/cli/setup-opencode.test.ts,tests/unit/cli-setup-opencode.test.ts,tests/unit/cli/alias-resolver-7791.test.ts,tests/unit/opencode-target-format-alias-11045.test.ts,tests/unit/api/cli-tools/apply-container-guard.test.ts→ 41/41 passnode scripts/check/check-changelog-integrity.mjs→ OKScope note
The same local-flag-collides-with-global-flag pattern exists in several other
setup-*commands (e.g.setup-claude.mjs), but the plan-file for #12783 scopes this fix tosetup-opencode.mjsonly — left untouched here to keep the diff surgical to the reported issue.