Skip to content

fix(go): resolve tenant model IDs in memory create/update without hard failure - #17176

Merged
wangq8 merged 3 commits into
infiniflow:mainfrom
euvre:fix/go-memory-model-config
Jul 22, 2026
Merged

wangq8 merged 3 commits into
infiniflow:mainfrom
euvre:fix/go-memory-model-config

Conversation

@euvre

@euvre euvre commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Summary

In Go mode, the memory configuration page could not set LLM and embedding model parameters because the Go MemoryService diverged from the Python implementation in two ways:

  1. CreateMemory hard-failed on model resolution: When ResolveModelID returned an error (e.g. for Builtin models that have no tenant_model row), the entire memory creation was aborted. Python's ensure_tenant_model_ids_for_params catches LookupError and silently skips, allowing the operation to proceed.

  2. UpdateMemory did not resolve tenant model IDs: When llm_id or embd_id was updated, the corresponding tenant_llm_id / tenant_embd_id was never re-resolved, leaving them stale or null. Python's update_memory API handler calls ensure_tenant_model_ids_for_params before processing the update.

Both are now fixed to match Python behavior:

  • CreateMemory: resolution failure is non-fatal — if ResolveModelID fails or returns empty, the tenant_*_id field is left nil and the memory is still created.
  • UpdateMemory: when llm_id / embd_id is provided and the corresponding tenant_*_id is not explicitly set, the backend resolves it via ResolveModelID. Resolution failure is non-fatal.

Testing

bash build.sh --test ./internal/service/...
ok  ragflow/internal/service  1.996s
ok  ragflow/internal/service/chunk  0.202s
ok  ragflow/internal/service/dataset  1.261s
ok  ragflow/internal/service/document  1.012s
ok  ragflow/internal/service/file  0.262s
ok  ragflow/internal/service/graph  0.115s
ok  ragflow/internal/service/nlp  0.024s

euvre added 2 commits July 21, 2026 15:52
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.
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jul 21, 2026
@euvre euvre added the ci Continue Integration label Jul 21, 2026
@euvre
euvre requested a review from wangq8 July 21, 2026 09:31
@coderabbitai

coderabbitai Bot commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ee2da735-428a-4249-8bc6-610d709bdb75

📥 Commits

Reviewing files that changed from the base of the PR and between 34d9bd4 and bf17dc2.

📒 Files selected for processing (1)
  • internal/service/memory.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/service/memory.go

📝 Walkthrough

Walkthrough

The memory service now tolerates tenant model ID resolution failures and backfills missing tenant IDs during updates. Shared button and checkbox styles replace outline-0 with outline-none.

Changes

Memory model resolution

Layer / File(s) Summary
Non-fatal tenant model resolution
internal/service/memory.go
CreateMemory and UpdateMemory conditionally resolve tenant LLM and embedding model IDs, log failures, and continue operations.

UI outline utilities

Layer / File(s) Summary
Shared outline styling
web/src/components/ui/button.tsx, web/src/components/ui/checkbox.tsx
Button and checkbox base classes now use outline-none instead of outline-0.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • infiniflow/ragflow#17211: Uses tenant model fields populated by memory creation and update flows when listing memories.

Suggested labels: 🐞 bug, size:M

Poem

A rabbit hops through models bright,
Resolution fails, but paths stay right.
Buttons and checkboxes softly gleam,
With outlines neat as carrot cream.
“Ship it!” I twitch my ears with cheer.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: non-fatal tenant model ID resolution during memory create/update.
Description check ✅ Passed The description includes the required Summary with background context and adds testing details, matching the template.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@wangq8 wangq8 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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 wangq8 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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 no tenant_model row, matching Python's ensure_tenant_model_ids_for_params
  • UpdateMemory: tenant_llm_id / tenant_embd_id are now re-resolved when llm_id / embd_id is 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.

@coderabbitai coderabbitai Bot left a comment

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.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 20b760f and 34d9bd4.

📒 Files selected for processing (3)
  • internal/service/memory.go
  • web/src/components/ui/button.tsx
  • web/src/components/ui/checkbox.tsx

Comment on lines +483 to +505
// 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
}
}

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.

🗄️ 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.

Suggested change
// 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',

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.

🎯 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.

@wangq8
wangq8 requested review from Lynn-Inf and dcc123456 July 22, 2026 04:13

@Lynn-Inf Lynn-Inf left a comment

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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants