🤖 feat: custom model → known model mapping for metadata resolution#2500
🤖 feat: custom model → known model mapping for metadata resolution#2500ibetitsmike wants to merge 16 commits intomainfrom
Conversation
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 73587395f4
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
@codex review Both P1 and P2 feedback addressed:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 493ff36fc6
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
@codex review Addressed the P2 consumer cache invalidation:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a2108d4406
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Address Codex P1 (persisted cache rehydration bypass) and P2 (concurrent refresh race) from round 3 review.
|
@codex review Addressed both round 3 issues:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 72bb5f022a
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Use separate version counters for request initiation and successful application so a failed newer request doesn't discard a valid older config snapshot.
|
@codex review Fixed P2 from round 4:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e53c0cfcd5
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
@codex review Addressed both round 5 issues:
|
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0355f316aa
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
Addressed both round 6 P2 issues:
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 604108b62d
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
Addressed the latest Codex feedback:
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a12b376a13
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| return false; | ||
| } | ||
|
|
||
| if (tokenStatsCache.providersConfigVersion !== this.providersConfigAppliedVersion) { |
There was a problem hiding this comment.
Use stable config fingerprint for token-stats cache
This cache gate compares persisted tokenStatsCache.providersConfigVersion to providersConfigAppliedVersion, but that version is an in-memory counter that resets when WorkspaceStore is recreated. Because providersConfigVersion is persisted by TokenizerService, caches written in a prior app session (or after additional refresh increments) can be rejected even when provider mappings are unchanged, forcing unnecessary full token re-calculation on startup/reconnect instead of reusing the persisted cache.
Useful? React with 👍 / 👎.
Summary
Adds a "Treat as" model mapping feature that lets users map custom models (Ollama, OpenRouter, private gateways, etc.) to a known model so the system inherits that model's context window, pricing, capabilities, and tokenizer — without changing which model ID is sent to the provider.
Background
Users running custom or self-hosted models currently get
$0.00pricing, no context window limits, and a generic fallback tokenizer. This makes cost tracking, compaction warnings, and token breakdowns useless for these models. By mapping to a known model, all metadata-dependent features "just work."Implementation
Data model: Added
mappedToModel?: stringtoProviderModelEntryschema, persisted inproviders.jsonc.Resolution layer: A single
resolveModelForMetadata(fullModelId, providersConfig)function inmodelEntries.tshandles the mapping lookup. All metadata consumers (stats, capabilities, context limit, cost display, tokenizer) resolve through this function before looking up metadata. The actual model ID sent to the provider is never changed.Metadata wrappers:
getModelStatsResolvedandgetModelCapabilitiesResolvedwrap existing functions with mapping resolution.createDisplayUsageandgetTokenizerForModelgained optionalmetadataModelOverrideparams.UI: Custom models show a "Treat as" searchable dropdown in edit mode (using the existing
SearchableModelSelect). View mode shows a muted "→ ModelName" badge when mapped.Call site wiring: WorkspaceStore, CostsTab, StreamManager, AIService, StreamContextBuilder, StreamingTokenTracker, ChatInput, and useCreationWorkspace all resolve mappings at the appropriate points.
Robustness (from Codex review):
onConfigChangedfor live config refresh (not just on init)tokenStatsCache) is invalidated on config changesnullFiles changed (22+)
schemas/api.tsmodelEntries.tsmodelStats.ts,modelCapabilities.tscontextLimit.ts,displayUsage.ts,tokenizer.tsModelRow.tsx,ModelsSection.tsxWorkspaceStore.ts,WorkspaceConsumerManager.ts,CostsTab.tsx,streamManager.ts,aiService.ts,streamContextBuilder.ts,StreamingTokenTracker.ts,tokenStatsCalculator.ts,tokenizerService.ts,router.ts,ChatInput/index.tsx,useCreationWorkspace.ts,agentSession.tsmodelEntries.test.ts,modelStats.test.ts,contextLimit.test.tsValidation
make static-checkpasses (typecheck + lint + fmt)Risks
agentSession.tsusesgetModelCapabilitiesResolved(model, null)since no provider service is injected — falls back to current behavior.Generated with
mux• Model:anthropic:claude-opus-4-6• Thinking:xhigh• Cost:$5.39