Skip to content

fix(desktop): PR #313 small-model regression (OAuth + provider fallback)#318

Merged
MocA-Love merged 1 commit intomainfrom
fix/pr7-small-model-regression
Apr 18, 2026
Merged

fix(desktop): PR #313 small-model regression (OAuth + provider fallback)#318
MocA-Love merged 1 commit intomainfrom
fix/pr7-small-model-regression

Conversation

@MocA-Love
Copy link
Copy Markdown
Owner

概要

PR #313 (mastracode 0.14 + small-model refactor, 2026-04-18 マージ) で fork 固有の auth 経路を壊した 3 件の regression を修正する hotfix。Codex 3 ラウンドのレビュー後 Yes。

修正対象 regression(取り込み時のバグ)

1. Anthropic OAuth / AUTH_TOKEN が apiKey に誤ルート(High)

PR #313 の get-small-model.ts は ANTHROPIC_AUTH_TOKEN を含むあらゆる credential を createAnthropic({ apiKey }) に流していた。fork の OAuth / gateway proxy 構成では authToken + headers (anthropic-beta: "claude-code-20250219,oauth-2025-04-20", user-agent: "claude-cli/...", x-app: "cli") が必要で、401 になる。

修正: getAnthropicProviderOptions(credentials) を経由し、kind: "oauth" は OAuth header path に流す。AUTH_TOKENkind: "oauth" として ClaudeCredentials に詰めて渡す。

2. Provider fallback 喪失(Medium)

callSmallModel は Anthropic 失敗時に OpenAI へフォールバックしていたが、PR #313 の shim は 1 attempt に縮退。

修正: shim を getSmallModelCandidates() を iterate する実装に戻し、各 candidate で createModel + invoke を試行、失敗時は次へ fall-through。getSmallModel() も全候補を iterate するよう変更。

3. OAuth-only ユーザーに誤って「接続されていません」(High)

auth.json に OAuth entry しか無い場合、apikey:<provider> slot が無いので旧 shim は missing-credentials 2件を返した。

修正: OAuth 資格も候補に積むように credential resolver を拡張。

実装概要

packages/chat/src/server/shared/small-model/get-small-model.ts を再構築

  • getSmallModelCandidates() を新設:Anthropic/OpenAI 候補を優先順序で返す
    • Anthropic: env ANTHROPIC_API_KEY~/.claude* config / keychain (fork sync helpers) → auth-storage anthropic slot (sync, refresh なし) → managed env config ~/.superset/chat-anthropic-env.json (parseAnthropicEnvText で fork 正式パーサ使用、ANTHROPIC_API_KEYANTHROPIC_AUTH_TOKEN)
    • OpenAI: env OPENAI_API_KEYgetOpenAICredentialsFromAnySource (fork の openai / openai-codex 両 slot)
    • OAuth credentials は getAnthropicProviderOptions 経由で正しい AI-SDK options に変換
    • OpenAI Codex OAuth は createOpenAICodexOAuthModel (mastracode authStorage で token refresh + Codex backend endpoint rewrite、旧 small-model.ts と同一実装)
  • expired OAuth token は candidate list から除外(有効な後続候補を塞がないように)
  • getSmallModel() は全候補を iterate、createModel() throw なら次へ

apps/desktop/src/lib/ai/call-small-model.ts shim 再実装

  • getSmallModelCandidates() を iterate
  • 各 candidate で createModel + invoke を試行、失敗時は SmallModelAttempt に記録して次の candidate へ
  • empty-result / failed / succeeded を適切に記録
  • 候補 0 件時のみ synthetic missing-credentials 2件を返す

検証

  • typecheck: 全 26 タスク pass
  • lint: 3件 baseline(regression なし)

Codex pre-review

3 ラウンドで最終 Yes:

  • Round 1: 3 件指摘 → 全修正
  • Round 2: getSmallModel() iteration 追加、expired 候補 skip
  • Round 3: 指摘なし、全項目 Yes

Pre-existing な別問題(本 hotfix 対象外)

  • getSmallModel() 直利用側 (runtime.ts 等) で invoke 時の 401 は依然 fall-through しない。candidate 構築時の filtering で大部分 mitigate されるが、invalid token を持っていて expired frag が立たないケースは未対応。これは PR upstream取り込み: mastracode 0.14 + small-model refactor (#3517) #313 以前から同様の制限があり、今回の hotfix で悪化していない

テストチェックリスト

  • Anthropic OAuth (Claude Code login) で chat title auto generation が動く
  • Anthropic managed env config (~/.superset/chat-anthropic-env.json) の ANTHROPIC_AUTH_TOKEN で proxy 経由で動く
  • Anthropic managed env config の ANTHROPIC_API_KEY で動く
  • OpenAI Codex OAuth で動く
  • OpenAI API key (openai-codex slot) で動く
  • Anthropic 失敗 (expired) → OpenAI にフォールバック
  • 全く未接続 → 「アカウントが接続されていません」案内
  • enhance-text (TODO 書き換え)、git auto commit message 生成も同様に動作

…regression)

PR #313 (mastracode 0.14 + small-model refactor) shipped three
take-home regressions for fork users:

1. Anthropic OAuth / AUTH_TOKEN broken. get-small-model routed the
   token through createAnthropic({ apiKey }), but fork's OAuth /
   managed-proxy credentials require authToken + anthropic-beta /
   user-agent / x-app headers (see getAnthropicProviderOptions).
   Users connected via Claude Code OAuth or a gateway that only
   emits ANTHROPIC_AUTH_TOKEN had all small-model tasks 401.

2. Provider fallback dropped. Old callSmallModel iterated Anthropic
   then OpenAI. The post-superset-sh#3517 shim collapsed to a single attempt,
   so a failing Anthropic account never fell through to OpenAI.

3. OAuth-only users saw 'Account not connected'. When getSmallModel
   returned null (because auth.json only had OAuth entries), the
   shim fabricated two 'missing-credentials' attempts regardless of
   what was actually connected.

Fix: replace the simple getSmallModel() with a fork-maintained
getSmallModelCandidates() that returns the full priority list
(Anthropic env -> keychain/config -> auth-storage -> managed env
config -> OpenAI env -> OpenAI auth-storage) with OAuth / API key /
AUTH_TOKEN each routed through the correct AI-SDK provider options
(getAnthropicProviderOptions for Anthropic, createOpenAICodexOAuthModel
for OpenAI Codex OAuth). getSmallModel() stays as an upstream-
compatible wrapper over the first viable candidate.

The callSmallModel shim now iterates candidates and surfaces
per-attempt outcomes so describeEnhanceFailure keeps its user
messages intact.

Restored behaviors:
- Anthropic OAuth / AUTH_TOKEN via fork-standard header set.
- Anthropic managed env config (~/.superset/chat-anthropic-env.json)
  with both ANTHROPIC_API_KEY (api-key path) and ANTHROPIC_AUTH_TOKEN
  (OAuth path).
- OpenAI Codex OAuth (rewrites to Codex backend, refreshes access
  token via mastracode authStorage).
- OpenAI stock / openai-codex API-key slot.
- Provider fallback: Anthropic failure now tries OpenAI.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 18, 2026

Warning

Rate limit exceeded

@MocA-Love has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 11 minutes and 22 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 11 minutes and 22 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ee484edd-622f-42b0-af9d-5810f7888ae8

📥 Commits

Reviewing files that changed from the base of the PR and between f4b29f4 and db37c71.

📒 Files selected for processing (4)
  • apps/desktop/src/lib/ai/call-small-model.ts
  • packages/chat/src/server/shared/index.ts
  • packages/chat/src/server/shared/small-model/get-small-model.ts
  • packages/chat/src/server/shared/small-model/index.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/pr7-small-model-regression

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@MocA-Love MocA-Love merged commit d4a277e into main Apr 18, 2026
14 checks passed
MocA-Love added a commit that referenced this pull request Apr 18, 2026
…gression"

This reverts commit d4a277e, reversing
changes made to f4b29f4.
MocA-Love added a commit that referenced this pull request Apr 18, 2026
…iewer

revert: PR #313 + #318 (mastracode 0.14 アップグレードに伴う DiffViewer 表示崩れ)
MocA-Love added a commit that referenced this pull request Apr 18, 2026
MocA-Love added a commit that referenced this pull request Apr 18, 2026
restore: PR #313 + #318 を復活 (真犯人は node_modules 重複だった)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant