Skip to content

fix: apply model metadata overrides to provider models#25

Merged
Alph4d0g merged 6 commits into
Alph4d0g:release/v1.2.2from
abien:main
May 21, 2026
Merged

fix: apply model metadata overrides to provider models#25
Alph4d0g merged 6 commits into
Alph4d0g:release/v1.2.2from
abien:main

Conversation

@abien
Copy link
Copy Markdown
Contributor

@abien abien commented May 20, 2026

Summary

  • apply user modelMetadata overrides to fetched/default models before converting them to OpenCode provider models
  • keep raw user-authored modelMetadata separate from plugin-generated metadata across config/provider/auth hook runs
  • refresh plugin-generated provider models on repeated config hook runs while preserving explicit user-defined provider.omniroute.models
  • add regression coverage for config hook, provider hook, auth loader, alias canonicalization, addIfMissing, and JSON-cloned raw metadata

Review note

This PR intentionally does not address regex/ReDoS behavior for modelMetadata.match. Upstream already documents RegExp matchers and accepts regex-like match blocks; this change only starts evaluating those existing user-configured matchers inside the plugin while applying overrides before toProviderModels(). If maintainers want stricter regex safety, that should be handled as a separate behavior/security hardening change.

Verification

  • npm test
  • npm run prepublishOnly
  • git diff --check upstream/main...HEAD

Copilot AI review requested due to automatic review settings May 20, 2026 14:15
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a robust mechanism for applying user-defined model metadata overrides within the OmniRoute plugin. It adds logic to preserve raw user configurations across lifecycle hooks using internal markers and Symbols, ensuring that fetched models correctly reflect user-specified limits and features. The review feedback suggests minor refactorings to improve maintainability, specifically by simplifying redundant string comparisons in the matcher logic and using a more concise, loop-based approach for extracting metadata properties.

Comment thread src/plugin.ts Outdated
Comment on lines +607 to +615
if (typeof match === 'string') {
if (match === modelId) return true;

try {
return new RegExp(match).test(modelId);
} catch {
return false;
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The if (match === modelId) return true; check is redundant as the calling function metadataBlockMatches already performs an exact string comparison before calling this function. You can remove this check to simplify the logic.

  if (typeof match === 'string') {
    try {
      return new RegExp(match).test(modelId);
    } catch {
      return false;
    }
  }

Comment thread src/plugin.ts Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the OmniRoute auth plugin so user-specified modelMetadata overrides are applied to fetched/default OmniRoute models before converting them into OpenCode provider models, while also preserving raw user-authored metadata across repeated hook runs and config cloning.

Changes:

  • Apply user modelMetadata overrides to fetched/default models prior to toProviderModels() in config/provider/auth flows.
  • Persist “raw user modelMetadata” separately from plugin-generated metadata across hook runs (including JSON-clone scenarios).
  • Refresh plugin-generated provider.models on repeated config hook runs while preserving explicit user-defined provider.omniroute.models, with added regression tests.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/plugin.ts Applies model metadata overrides earlier in the pipeline; preserves raw user metadata and marks plugin-generated models for refresh/preservation logic.
test/plugin.test.mjs Adds regression coverage for override application, alias canonicalization, addIfMissing, repeated hook runs, and JSON-cloned raw metadata behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/plugin.ts Outdated
@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot Bot commented May 20, 2026

Code Review Roast 🔥

Verdict: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
🚨 critical 0
⚠️ warning 0
💡 suggestion 1
🤏 nitpick 0
Issue Details (click to expand)
File Line Roast
src/plugin.ts 624 The . (dot) regex metacharacter is missing from the character class in isConcreteModelIdMatch, meaning strings like gpt-5.5 would be incorrectly treated as concrete model IDs

🏆 Best part: Finally removing that dead isProviderAlias import - dead code elimination is the best code addition.

💀 Worst part: The isConcreteModelIdMatch function has a bug where . is not considered a regex metacharacter, so gpt-5.5 slips through as a "concrete" match when it should be recognized as potentially a regex pattern.

📊 Overall: Like a regex that's almost perfect but misses the dot - technically functional but not quite matching the spec.

Files Reviewed (2 files)
  • src/plugin.ts - 1 issue
  • test/plugin.test.mjs - clean

Comment thread src/plugin.ts Outdated
@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot Bot commented May 20, 2026

Code Review Roast 🔥

Verdict: No Issues Found | Recommendation: Merge

Oh wait, this PR is actually clean. I had my flamethrower warmed up and everything.

📊 Overall: Like finding a unicorn in production — I didn't think clean PRs existed anymore, but here we are.

Files Reviewed (2 files)
  • src/plugin.ts
  • test/plugin.test.mjs

Comment thread src/plugin.ts Outdated
@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot Bot commented May 20, 2026

Code Review Roast 🔥

Verdict: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
🚨 critical 0
⚠️ warning 0
💡 suggestion 1
🤏 nitpick 0
Issue Details (click to expand)
File Line Roast
src/plugin.ts 624 The . (dot) regex metacharacter is missing from the character class, so gpt-5.5 silently passes as a concrete model ID

🏆 Best part: Removing that unused isProviderAlias import - dead code elimination is the best code addition.

💀 Worst part: The isConcreteModelIdMatch function has a bug where . is not considered a regex metacharacter, so gpt-5.5 slips through as a "concrete" match when it should be recognized as potentially a regex pattern.

📊 Overall: Like a regex that's almost perfect but misses the dot - technically functional but not quite matching the spec.

Files Reviewed (2 files)
  • src/plugin.ts - 1 issue
  • test/plugin.test.mjs - clean

@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot Bot commented May 20, 2026

Code Review Roast 🔥

Verdict: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
🚨 critical 0
⚠️ warning 0
💡 suggestion 1
🤏 nitpick 0
Issue Details (click to expand)
File Line Roast
src/plugin.ts 624 The . (dot) regex metacharacter is missing from the character class, so gpt-5.5 silently passes as a concrete model ID

🏆 Best part: Removing that unused isProviderAlias import - dead code elimination is the best code addition.

💀 Worst part: The isConcreteModelIdMatch function has a bug where . is not considered a regex metacharacter, so gpt-5.5 slips through as a "concrete" match when it should be recognized as potentially a regex pattern.

📊 Overall: Like a regex that's almost perfect but misses the dot - technically functional but not quite matching the spec.

Files Reviewed (2 files)
  • src/plugin.ts - 1 issue
  • test/plugin.test.mjs - clean

Fix these issues in Kilo Cloud


Reviewed by nemotron-3-super-120b-a12b-20230311:free · 216,180 tokens

@Alph4d0g Alph4d0g self-assigned this May 20, 2026
@Alph4d0g Alph4d0g changed the base branch from main to release/v1.2.2 May 20, 2026 18:19
Comment thread src/plugin.ts Outdated
Comment thread test/plugin.test.mjs Outdated
@Alph4d0g
Copy link
Copy Markdown
Owner

Review Fixes Applied

Pushed fixes to branch pr-25-review-fixes addressing all actionable review feedback.

Issues Fixed

Review Source Fix
String matcher overmatch @copilot-pull-request-reviewer discussion_r3274699369 String match values are now treated as literal model IDs with alias/canonical normalization. Only RegExp objects and serialized { source, flags } objects perform regex matching. This also resolves the missing dot metacharacter issue flagged by @kilo-code-bot (discussion_r3274710574).
Redundant exact comparison @gemini-code-assist discussion_r3274676051 Removed the redundant if (match === modelId) check from metadataMatcherMatches() since string exact matches now happen exclusively in metadataBlockMatches().
Verbose metadata extraction @gemini-code-assist discussion_r3274676077 Replaced spread-heavy extractModelMetadata() with a MODEL_METADATA_KEYS constant array and Object.fromEntries() projection. No any types used.
Legacy stale model refresh @Alph4d0g discussion_r3276266675 Added structural detection for legacy plugin-generated models: if all existing provider.models have providerID === "omniroute" and api.npm === "@ai-sdk/openai-compatible", they are treated as generated and refreshed. Explicit user-authored models are preserved.
XDG auth store isolation @Alph4d0g discussion_r3276266680 Tests now sandbox XDG_DATA_HOME alongside HOME via a createTempAuthHome() helper. Added restoreEnv() in afterEach() to prevent cross-test contamination.

Verification

  • Full test suite: 54/54 passing (npm test)
  • XDG regression: 24/24 passing with isolated XDG_DATA_HOME
  • Package build: npm run prepublishOnly succeeds
  • Whitespace: git diff --check clean

Commits

  1. d8a39ef — test: isolate auth store XDG data home
  2. 23922a5 — fix: treat string metadata matches as literals
  3. 259cc61 — refactor: centralize metadata extraction keys
  4. 3d8988f — fix: refresh legacy generated provider models

Ready for re-review.

@Alph4d0g
Copy link
Copy Markdown
Owner

Update: All 4 fix commits have been pushed directly to this PR's source branch (). No separate branch needed — the commits are now part of this PR.

@Alph4d0g
Copy link
Copy Markdown
Owner

Merge Conflict Resolved

Merged release/v1.2.2 into this PR and resolved the conflict in test/plugin.test.mjs. The afterEach hook now correctly combines both:

  • Our XDG_DATA_HOME / HOME environment restoration
  • Base branch's clearModelCache() and clearModelsDevCache() cache clearing

All 66 tests passing.

@Alph4d0g Alph4d0g merged commit 70ec3da into Alph4d0g:release/v1.2.2 May 21, 2026
1 check passed
Alph4d0g added a commit that referenced this pull request May 22, 2026
Brings in PR #25 fixes (model metadata overrides to provider models)
alongside the local AGENTS.md consolidation and CLAUDE.md symlink.
Alph4d0g added a commit that referenced this pull request May 25, 2026
…olidation (#26)

* fix: apply model metadata overrides to provider models (#25)

* fix: apply model metadata overrides to provider models

* test: isolate auth store XDG data home

* fix: treat string metadata matches as literals

* refactor: centralize metadata extraction keys

* fix: refresh legacy generated provider models

---------

Co-authored-by: Sebastian Rumpf <alp4d0g007@googlemail.com>

* docs: consolidate agent guidelines into AGENTS.md and symlink CLAUDE.md

- Rewrite AGENTS.md by cherry-picking the best of AGENTS.md and CLAUDE.md:
  - Keep generic Agent Guidelines framing and all code style rules
  - Add Architecture section (dual entry points, core modules, fetch interceptor, caching)
  - Expand Common Commands (test runner, check:exports, single-file typecheck)
  - Add Testing, Important Configuration, and full Release Process sections
- Delete CLAUDE.md and replace with symlink to AGENTS.md so both Claude Code
  and other agents read from the same canonical source.

* chore: bump version to 1.2.2

* style: fix indentation in getApiMode warn() call

Fixes pre-existing indentation issue flagged by kilo-code-bot review.
No functional change.

* perf: pre-process metadata blocks to avoid redundant regex/alias calculations

Addresses gemini-code-assist review feedback on PR #26:
- Pre-process array-based metadata blocks once: canonicalize string matches,
  compile regexes, and extract metadata upfront.
- Replaces O(N*M) redundant resolveProviderAliasForMetadata + coerceRegExp
  calls inside per-model loops with a single pass over config blocks.
- Adds processedBlockMatches() helper that uses pre-computed canonicalMatch
  instead of re-resolving aliases on every comparison.
- No functional change — all 66 tests pass.

---------

Co-authored-by: Alexander Bien <abien@gmx.net>
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.

3 participants