Skip to content

fix: 提供終了したOpenRouter無料モデルを置き換え、フォールバックを追加 - #203

Merged
Tatsu723 merged 2 commits into
mainfrom
fix/openrouter-free-model
Nov 30, 2026
Merged

Tatsu723 merged 2 commits into
mainfrom
fix/openrouter-free-model

Conversation

@Tatsu723

@Tatsu723 Tatsu723 commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

背景

作文・翻訳セクションのAI添削で使っていた nvidia/nemotron-3-super-120b-a12b:free が、OpenRouterの無料モデル一覧から削除されていました。そのため添削リクエストが失敗していました。

変更内容

  • app/lib/shared/openrouter.ts を新規作成し、作文・翻訳で別々に持っていたモデル設定を1か所にまとめた
  • OpenRouterの models フォールバックを使い、先頭のモデルが使えないときは次のモデルに自動で切り替える
    1. nvidia/nemotron-3.5-super-vl:free(今までのモデルの後継)
    2. google/gemma-4-31b-it:free
    3. openrouter/free(その時に使える無料モデルをOpenRouterが自動で選ぶ)
  • OPENROUTER_MODEL 環境変数を指定した場合は、そのモデルを最優先にする
  • 実際に応答したモデル名(レスポンスの model)をDBに保存する
  • resolveModels の単体テストを追加

確認

  • npm run lint / npm run typecheck / npm test(557件すべて通過)
  • 実際のAPIキーで作文・翻訳の添削が返ってくること(ローカルの .env のキーが正しくなかったため、まだ確認していない)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Essay and translation grading now support automatic fallback across free AI models when the preferred model is unavailable. A configured model is tried first, and duplicate model options are avoided.

AI添削で使っていた nvidia/nemotron-3-super-120b-a12b:free がOpenRouterから削除され、
作文・翻訳の添削が失敗していたため、現行の無料モデルに切り替える。
今後の提供終了にも備えて、OpenRouterの `models` フォールバックで
nemotron-3.5-super-vl → gemma-4-31b-it → openrouter/free の順に自動で切り替える。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Explain Change →

Walkthrough

Changes: OpenRouter model fallback

Layer / File(s) Summary
Shared model resolution
app/lib/shared/openrouter.ts, app/lib/shared/openrouter.test.ts, .env.example
The shared module defines the OpenRouter URL, three default models, and a resolver that trims overrides, removes duplicates, and limits the list to three. Tests cover defaults and overrides. The environment example documents the fallback.
Grading integration
app/lib/shared/essay/grading.ts, app/lib/shared/translation/grading.ts
Both grading functions send the resolved model list. Each returns the model reported by OpenRouter, or the first candidate when the response omits it.

Suggested reviewers: tknkaa

Change: Bug fix

Merge Risk: Minimal · up to d1555

Essay and translation grading now use a shared model list with automatic fallback, which should fix failures caused by the removed free model. No concrete merge-blocking risk was found. Live grading requests were not exercised, so a quick manual check after deploy is advisable.

Security architecture risk: Moderate · up to d1555

The change makes grading more resilient, but it also lets the external service choose from a broader set of processors for learner submissions. The record used to investigate grading issues can also name the wrong processor if a fallback succeeds without identifying itself.

Retained concerns

  • Minor · security · inferred: Compared with requesting one model, the default route now permits OpenRouter to choose another downstream model for the same learner text, including through a dynamic router. The three-entry cap does not bound that router to three downstream processors, and neither grading request expresses provider or data-handling restrictions. The effective processor set depends on account policy that was not available for review.
  • Trivial · security · inferred: If a fallback model returns feedback without a model identifier, both flows persist the first candidate rather than marking the responder as unknown. Unlike the prior single-model request, the requested first candidate is no longer the only possible responder. This can mislead processor attribution during an audit or incident investigation.

View findings in the submitted review

Security review details

Security Blast Radius

  • inferred — The wider route applies to learner text and accompanying grading context in both features when fallback is used. The changed requests do not add bulk reads of stored submissions, a new client-selected destination, or a new credential.

Trust Boundaries and Controls

  • observed — Learners control submitted text, while server configuration supplies the endpoint, bearer credential, and candidate list. The external response supplies the reported model identifier; the application uses a TypeScript assertion rather than runtime validation before passing it to persistence.

Hardening Proposals

  • proposed — Constrain fallback to processors that meet the deployment's data-handling requirements, and provide an operator setting that can disable fallback without reverting the application.
  • proposed — Validate the reported identifier and record unknown attribution explicitly rather than using the first requested candidate as evidence of who answered.
Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 51.12% 1773 / 3468
🔵 Statements 50.62% 1990 / 3931
🔵 Functions 39.07% 390 / 998
🔵 Branches 38.24% 924 / 2416
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
app/lib/shared/openrouter.ts 100% 100% 100% 100%
app/lib/shared/essay/grading.ts 2.56% 0% 0% 2.56% 31-164
app/lib/shared/translation/grading.ts 3.03% 0% 0% 3.03% 27-140
Generated in workflow #104 for commit d15553a by the Vitest Coverage Report Action

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@coderabbitai coderabbitai 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.

Architecture findings (2)

Advisory architecture findings (2)

  • Minor — Compared with requesting one model, the default route now permits OpenRouter to choose another downstream model for the same learner text, including through a dynamic router. The three-entry cap does not bound that router to three downstream processors, and neither grading request expresses provider or data-handling restrictions. The effective processor set depends on account policy that was not available for review.
  • Trivial — If a fallback model returns feedback without a model identifier, both flows persist the first candidate rather than marking the responder as unknown. Unlike the prior single-model request, the requested first candidate is no longer the only possible responder. This can mislead processor attribution during an audit or incident investigation.
Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: af54be2c-7986-436c-be91-b1f038fc5ae2
Commits

Reviewing files that changed from the base of the PR and between 35cfa60 and d15553a.

Files selected for processing: 5

  • .env.example
  • app/lib/shared/essay/grading.ts
  • app/lib/shared/openrouter.test.ts
  • app/lib/shared/openrouter.ts
  • app/lib/shared/translation/grading.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@Tatsu723
Tatsu723 merged commit 298cc15 into main Nov 30, 2026
9 checks passed
@Tatsu723
Tatsu723 deleted the fix/openrouter-free-model branch November 30, 2026 04:57
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