feat: add modelBlacklistRegex system setting to filter channel-derive…#1673
Conversation
…d models Add a regex-based blacklist on system model settings. When QueryAllChannelModels is enabled, channel-derived model IDs matching the pattern are excluded from /v1/models output. Configured Model entities are never filtered, and the setting is grayed out / ineffective when QueryAllChannelModels is off. Server-side validation rejects invalid regex on save via xregexp.ValidateRegex (regexp2 / .NET-style engine). The frontend defers all syntax validation to the server to avoid divergence with the ECMAScript engine. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Greptile SummaryThis PR adds a
Confidence Score: 5/5Safe to merge — blacklist filtering is additive, opt-in, and defaults to an empty string (disabled). The change is isolated to the channel-model merge loop; configured Model entities are pre-populated in modelSet before the blacklist runs, so they are structurally protected. Server-side validation at SetModelSettings prevents invalid patterns from being persisted. The exactMatch fast-path and the ensureAnchored full-string semantics are both exercised by the new integration tests. No existing code paths are modified in a breaking way. No files require special attention. The generated GQL resolver (generated.go) is the largest change by line count but is mechanical and consistent with existing field patterns. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[ListEnabledModels] --> B[queryConfiguredModelFacades]
B --> C[ModelSettingsOrDefault]
C --> D{QueryAllChannelModels?}
D -- false --> E[Return configuredModels only]
D -- true --> F[Init modelSet from configuredModels]
F --> G[Iterate channel entries]
G --> H{modelSet contains ID?}
H -- yes --> G
H -- no --> I{blacklist != '' AND MatchString?}
I -- yes --> J[modelSet ID = true — skip]
J --> G
I -- no --> K[Add to models + modelSet]
K --> G
G -- done --> L{allowedModelIDs filter?}
L -- yes --> M[Filter by key profile]
L -- no --> N[Return merged models]
M --> N
Reviews (2): Last reviewed commit: "perf: cache blacklist-matched model IDs ..." | Re-trigger Greptile |
| if err := xregexp.ValidateRegex(settings.ModelBlacklistRegex); err != nil { | ||
| return fmt.Errorf("invalid model blacklist regex: %w", err) | ||
| } |
There was a problem hiding this comment.
Validation error discards root cause
xregexp.getOrCreatePattern calls regexp2.Compile and, on failure, sets only compileErr = true — the original error value is never stored. As a result, ValidateRegex can only produce "invalid regex pattern: <pattern>", and the caller sees "invalid model blacklist regex: invalid regex pattern: [unclosed" with no indication of what is syntactically wrong. Since the PR description explicitly positions server-side validation as the user-facing feedback mechanism, this means a user submitting a bad pattern has no actionable error message to guide correction.
There was a problem hiding this comment.
Code Review
This pull request introduces a 'Model Blacklist Regex' feature, allowing administrators to exclude specific channel-derived models from the /v1/models API output using regular expressions. The changes include UI updates to the settings dialog, new translation strings, and backend logic to validate and apply the regex filter during model listing. A performance improvement was suggested to cache blacklisted model IDs in the modelSet to avoid redundant regex evaluations when the same model ID is encountered across multiple channels.
| if blacklist != "" && xregexp.MatchString(blacklist, requestModel) { | ||
| continue | ||
| } |
There was a problem hiding this comment.
To improve performance when multiple channels provide the same model IDs, you should add the blacklisted model to modelSet. This ensures that the regex match is only performed once per unique model ID across all channels, avoiding redundant computations in the nested loop.
| if blacklist != "" && xregexp.MatchString(blacklist, requestModel) { | |
| continue | |
| } | |
| if blacklist != "" && xregexp.MatchString(blacklist, requestModel) { | |
| modelSet[requestModel] = true | |
| continue | |
| } |
When a channel model matches the blacklist regex, mark its ID in modelSet so the same model ID coming from a subsequent channel is short-circuited by the existing modelSet check instead of re-running the regex match. Addresses Gemini review feedback on PR looplj#1673.
…d models
Add a regex-based blacklist on system model settings. When QueryAllChannelModels is enabled, channel-derived model IDs matching the pattern are excluded from /v1/models output. Configured Model entities are never filtered, and the setting is grayed out / ineffective when QueryAllChannelModels is off.
Server-side validation rejects invalid regex on save via xregexp.ValidateRegex (regexp2 / .NET-style engine). The frontend defers all syntax validation to the server to avoid divergence with the ECMAScript engine.