Repository navigation
fix(go): resolve tenant model IDs in memory create/update without hard failure - #17176
Conversation
Chromium ignores outline-width when outline-style is auto (set by the UA :focus-visible rule), so outline-0 fails to suppress the native focus ring. The ring is painted inside the 14px checkbox and covers its left border, making the checkbox look incomplete when focused. Switch Checkbox and Button to outline-none, which sets outline-style to solid with a transparent color and properly overrides the UA rule.
…d failure In Go mode, memory configuration could not set LLM and embedding model parameters because: 1. CreateMemory returned a hard error when ResolveModelID failed (e.g. for Builtin models that have no tenant_model row), preventing memory creation entirely. Python's ensure_tenant_model_ids_for_params catches LookupError and silently skips. 2. UpdateMemory did not resolve tenant_llm_id / tenant_embd_id when llm_id / embd_id was updated, leaving them stale or null. Python's update_memory handler calls ensure_tenant_model_ids_for_params before processing the update. Both are now fixed to match Python behavior: resolution failure is non-fatal, and UpdateMemory resolves tenant model IDs when the corresponding model name field is updated.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe memory service now tolerates tenant model ID resolution failures and backfills missing tenant IDs during updates. Shared button and checkbox styles replace ChangesMemory model resolution
UI outline utilities
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested labels: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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. Comment |
wangq8
left a comment
There was a problem hiding this comment.
LGTM on the memory service changes. The model resolution fix is correct and necessary.
What's good:
- : Model resolution failure is now non-fatal — correctly handles Builtin models that have no row, matching Python's
- : / are now re-resolved when / is updated, keeping the tenant model ID fields consistent after updates — this was a real bug
- Resolution guard is correct — skips empty/invalid resolutions silently
One note: The PR also changes → in and . These appear unrelated to the memory fix. If intentional (e.g., tailwind v4 migration cleanup), it's fine — but next time consider separating unrelated UI polish into its own PR to keep the diff focused.
wangq8
left a comment
There was a problem hiding this comment.
LGTM on the memory service changes. The model resolution fix is correct and necessary.
What's good:
CreateMemory: Model resolution failure is now non-fatal — correctly handles Builtin models that have notenant_modelrow, matching Python'sensure_tenant_model_ids_for_paramsUpdateMemory:tenant_llm_id/tenant_embd_idare now re-resolved whenllm_id/embd_idis updated, keeping the tenant model ID fields consistent after updates — this was a real bug- Resolution guard (
err == nil && resolved != "") is correct — skips empty/invalid resolutions silently
One note: The PR also changes outline-0 to outline-none in web/src/components/ui/button.tsx and web/src/components/ui/checkbox.tsx. These appear unrelated to the memory fix. If intentional (e.g., tailwind v4 migration cleanup), it's fine — but next time consider separating unrelated UI polish into its own PR to keep the diff focused.
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/service/memory.go`:
- Around line 483-505: Update the LLMID and EmbdID handling around
ResolveModelID to act only when the incoming model ID differs from the existing
model value and no tenant model ID was explicitly supplied. When resolution
succeeds, store the resolved tenant ID; when it returns an empty result or
fails, explicitly set the corresponding tenant_llm_id or tenant_embd_id in
updateDict to clear the stale value. Preserve the existing behavior for
unchanged models and explicitly provided tenant IDs.
In `@web/src/components/ui/button.tsx`:
- Line 11: Update the shared Button styling and variant definitions so every
variant, especially icon and link, retains a visible keyboard focus indicator.
Add token-backed focus-visible styling to the variants lacking it, or limit
outline-none to variants that already provide equivalent focus treatment, while
preserving existing styling for other variants.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 7c9ee654-8c5d-48d8-82f2-568e4ab2bd31
📒 Files selected for processing (3)
internal/service/memory.goweb/src/components/ui/button.tsxweb/src/components/ui/checkbox.tsx
| // Resolve tenant model IDs when llm_id / embd_id is provided, mirroring | ||
| // Python's ensure_tenant_model_ids_for_params. The frontend sends model | ||
| // names (or model_id UUIDs); the backend must resolve them to | ||
| // tenant_model row IDs so downstream code that depends on | ||
| // tenant_llm_id / tenant_embd_id stays consistent after an update. | ||
| // Resolution failure is non-fatal (e.g. Builtin models). | ||
| modelProvider := NewModelProviderService() | ||
| if req.LLMID != nil { | ||
| updateDict["llm_id"] = *req.LLMID | ||
| if req.TenantLLMID == nil && *req.LLMID != "" { | ||
| if resolved, err := modelProvider.ResolveModelID(tenantID, entity.ModelTypeChat, *req.LLMID); err == nil && resolved != "" { | ||
| updateDict["tenant_llm_id"] = resolved | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if req.EmbdID != nil { | ||
| updateDict["embd_id"] = *req.EmbdID | ||
| if req.TenantEmbdID == nil && *req.EmbdID != "" { | ||
| if resolved, err := modelProvider.ResolveModelID(tenantID, entity.ModelTypeEmbedding, *req.EmbdID); err == nil && resolved != "" { | ||
| updateDict["tenant_embd_id"] = resolved | ||
| } | ||
| } |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Clear the old tenant model ID when the model changes and resolution yields no ID.
The current logic does not verify if the model ID actually changed before resolving it, which contradicts the PR objective ("when llm_id or embd_id changes"). More importantly, if the new model is a Builtin model (which resolves to "") or if resolution fails, updateDict["tenant_*_id"] is not populated. This means the old tenant model ID is retained in the database alongside the newly updated model ID, causing a data integrity mismatch.
To fix this, check if the model has changed before attempting resolution, and explicitly clear the tenant ID if the resolution yields an empty result.
🛠️ Proposed fix to explicitly clear mismatched tenant IDs
if req.LLMID != nil {
updateDict["llm_id"] = *req.LLMID
- if req.TenantLLMID == nil && *req.LLMID != "" {
- if resolved, err := modelProvider.ResolveModelID(tenantID, entity.ModelTypeChat, *req.LLMID); err == nil && resolved != "" {
- updateDict["tenant_llm_id"] = resolved
- }
+ if req.TenantLLMID == nil && strings.TrimSpace(*req.LLMID) != strings.TrimSpace(currentMemory.LLMID) {
+ if resolved, _ := modelProvider.ResolveModelID(tenantID, entity.ModelTypeChat, *req.LLMID); resolved != "" {
+ updateDict["tenant_llm_id"] = resolved
+ } else {
+ updateDict["tenant_llm_id"] = ""
+ }
}
}
if req.EmbdID != nil {
updateDict["embd_id"] = *req.EmbdID
- if req.TenantEmbdID == nil && *req.EmbdID != "" {
- if resolved, err := modelProvider.ResolveModelID(tenantID, entity.ModelTypeEmbedding, *req.EmbdID); err == nil && resolved != "" {
- updateDict["tenant_embd_id"] = resolved
- }
+ if req.TenantEmbdID == nil && strings.TrimSpace(*req.EmbdID) != strings.TrimSpace(currentMemory.EmbdID) {
+ if resolved, _ := modelProvider.ResolveModelID(tenantID, entity.ModelTypeEmbedding, *req.EmbdID); resolved != "" {
+ updateDict["tenant_embd_id"] = resolved
+ } else {
+ updateDict["tenant_embd_id"] = ""
+ }
}
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // Resolve tenant model IDs when llm_id / embd_id is provided, mirroring | |
| // Python's ensure_tenant_model_ids_for_params. The frontend sends model | |
| // names (or model_id UUIDs); the backend must resolve them to | |
| // tenant_model row IDs so downstream code that depends on | |
| // tenant_llm_id / tenant_embd_id stays consistent after an update. | |
| // Resolution failure is non-fatal (e.g. Builtin models). | |
| modelProvider := NewModelProviderService() | |
| if req.LLMID != nil { | |
| updateDict["llm_id"] = *req.LLMID | |
| if req.TenantLLMID == nil && *req.LLMID != "" { | |
| if resolved, err := modelProvider.ResolveModelID(tenantID, entity.ModelTypeChat, *req.LLMID); err == nil && resolved != "" { | |
| updateDict["tenant_llm_id"] = resolved | |
| } | |
| } | |
| } | |
| if req.EmbdID != nil { | |
| updateDict["embd_id"] = *req.EmbdID | |
| if req.TenantEmbdID == nil && *req.EmbdID != "" { | |
| if resolved, err := modelProvider.ResolveModelID(tenantID, entity.ModelTypeEmbedding, *req.EmbdID); err == nil && resolved != "" { | |
| updateDict["tenant_embd_id"] = resolved | |
| } | |
| } | |
| // Resolve tenant model IDs when llm_id / embd_id is provided, mirroring | |
| // Python's ensure_tenant_model_ids_for_params. The frontend sends model | |
| // names (or model_id UUIDs); the backend must resolve them to | |
| // tenant_model row IDs so downstream code that depends on | |
| // tenant_llm_id / tenant_embd_id stays consistent after an update. | |
| // Resolution failure is non-fatal (e.g. Builtin models). | |
| modelProvider := NewModelProviderService() | |
| if req.LLMID != nil { | |
| updateDict["llm_id"] = *req.LLMID | |
| if req.TenantLLMID == nil && strings.TrimSpace(*req.LLMID) != strings.TrimSpace(currentMemory.LLMID) { | |
| if resolved, _ := modelProvider.ResolveModelID(tenantID, entity.ModelTypeChat, *req.LLMID); resolved != "" { | |
| updateDict["tenant_llm_id"] = resolved | |
| } else { | |
| updateDict["tenant_llm_id"] = "" | |
| } | |
| } | |
| } | |
| if req.EmbdID != nil { | |
| updateDict["embd_id"] = *req.EmbdID | |
| if req.TenantEmbdID == nil && strings.TrimSpace(*req.EmbdID) != strings.TrimSpace(currentMemory.EmbdID) { | |
| if resolved, _ := modelProvider.ResolveModelID(tenantID, entity.ModelTypeEmbedding, *req.EmbdID); resolved != "" { | |
| updateDict["tenant_embd_id"] = resolved | |
| } else { | |
| updateDict["tenant_embd_id"] = "" | |
| } | |
| } | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@internal/service/memory.go` around lines 483 - 505, Update the LLMID and
EmbdID handling around ResolveModelID to act only when the incoming model ID
differs from the existing model value and no tenant model ID was explicitly
supplied. When resolution succeeds, store the resolved tenant ID; when it
returns an empty result or fails, explicitly set the corresponding tenant_llm_id
or tenant_embd_id in updateDict to clear the stale value. Preserve the existing
behavior for unchanged models and explicitly provided tenant IDs.
| const buttonVariants = cva( | ||
| cn( | ||
| 'inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm transition-colors outline-0', | ||
| 'inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm transition-colors outline-none', |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Preserve a visible focus indicator for every Button variant.
outline-none applies to all variants, but the icon and link variants do not define replacement focus-visible styles (Lines 58 and 92). Keyboard users can therefore lose visible focus. Add a token-backed focus indicator to those variants or scope outline removal only to variants with equivalent focus styling.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@web/src/components/ui/button.tsx` at line 11, Update the shared Button
styling and variant definitions so every variant, especially icon and link,
retains a visible keyboard focus indicator. Add token-backed focus-visible
styling to the variants lacking it, or limit outline-none to variants that
already provide equivalent focus treatment, while preserving existing styling
for other variants.
Lynn-Inf
left a comment
There was a problem hiding this comment.
For branches where err != nil, it's better to add some logging to avoid masking the actual error. Other parts LGTM.
…service Add slog.Warn logging in CreateMemory and UpdateMemory for the four ResolveModelID error branches that were previously silently swallowed, so the actual error is no longer masked while remaining non-fatal.
Summary
In Go mode, the memory configuration page could not set LLM and embedding model parameters because the Go
MemoryServicediverged from the Python implementation in two ways:CreateMemoryhard-failed on model resolution: WhenResolveModelIDreturned an error (e.g. for Builtin models that have notenant_modelrow), the entire memory creation was aborted. Python'sensure_tenant_model_ids_for_paramscatchesLookupErrorand silently skips, allowing the operation to proceed.UpdateMemorydid not resolve tenant model IDs: Whenllm_idorembd_idwas updated, the correspondingtenant_llm_id/tenant_embd_idwas never re-resolved, leaving them stale or null. Python'supdate_memoryAPI handler callsensure_tenant_model_ids_for_paramsbefore processing the update.Both are now fixed to match Python behavior:
CreateMemory: resolution failure is non-fatal — ifResolveModelIDfails or returns empty, thetenant_*_idfield is left nil and the memory is still created.UpdateMemory: whenllm_id/embd_idis provided and the correspondingtenant_*_idis not explicitly set, the backend resolves it viaResolveModelID. Resolution failure is non-fatal.Testing