Skip to content

Fix: code review - #17442

Merged
wangq8 merged 2 commits into
infiniflow:mainfrom
Lynn-Inf:fix/go-code-review
Jul 28, 2026
Merged

wangq8 merged 2 commits into
infiniflow:mainfrom
Lynn-Inf:fix/go-code-review

Conversation

@Lynn-Inf

Copy link
Copy Markdown
Contributor

Summary

Check memory accessable before operation, and log error when listModels failed.

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. labels Jul 27, 2026
@Lynn-Inf
Lynn-Inf requested a review from wangq8 July 27, 2026 11:24
@Lynn-Inf Lynn-Inf added the ci Continue Integration label Jul 27, 2026
@coderabbitai

coderabbitai Bot commented Jul 27, 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 Plus

Run ID: ee1e5f42-8b84-456a-b882-2d6bfdbe3cb7

📥 Commits

Reviewing files that changed from the base of the PR and between c82e6cc and 6e7d536.

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

📝 Walkthrough

Walkthrough

Memory deletion and configuration retrieval now authenticate callers and enforce memory access before service operations. Trusted queue processing uses an internal bypass helper, and provider model listing failures now emit warning logs.

Changes

Memory access control

Layer / File(s) Summary
Authenticated memory operations
internal/handler/memory.go, internal/service/memory.go
Memory handlers resolve the authenticated user, pass user.ID to the service, and service methods call requireMemoryAccess before deletion or configuration retrieval.
Trusted queue lookup
internal/service/memory_message_service.go, internal/service/memory.go
Trusted queue processing uses the unexported getMemoryConfig helper without endpoint access control.

Model fallback diagnostics

Layer / File(s) Summary
Remote model warning
internal/service/model_service.go
verifyProviderModel logs a warning containing errors returned by driver.ListModels.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant MemoryHandler
  participant GetUser
  participant MemoryService
  participant memoryDAO
  MemoryHandler->>GetUser: Resolve authenticated user
  GetUser-->>MemoryHandler: Return user.ID
  MemoryHandler->>MemoryService: Call DeleteMemory or GetMemoryConfig
  MemoryService->>MemoryService: requireMemoryAccess
  MemoryService->>memoryDAO: Delete or retrieve memory
  memoryDAO-->>MemoryService: Return result
  MemoryService-->>MemoryHandler: Return result or error
Loading

Possibly related PRs

Poem

I’m a rabbit guarding memory’s door,
Checking each caller before the store.
Trusted queues hop through paths kept clear,
While model-listing warnings now appear.
Hop-hop, safer flows are here!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title is too generic and doesn't clearly describe the actual changes to memory access control and model-listing logging. Rename it to something specific, e.g. "Enforce memory access checks and log listModels failures".
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed The Summary section is present and matches the PR goals, though it is brief and lacks background context.
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.

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
internal/service/memory.go (2)

796-801: 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Remove commented-out code instead of leaving it in the deletion path.

This block of commented-out messageService calls is dead code left behind pending a future implementation.

As per coding guidelines, **/*.go: "remove commented-out Go code," and **/*: "Remove dead tests, commented-out code, stale documentation, and 'move later' notes instead of preserving them."

♻️ Proposed fix
-	// TODO: Delete associated message index - Implementation pending MessageService
-	// messageService := NewMessageService()
-	// hasIndex, _ := messageService.HasIndex(memory.TenantID, memoryID)
-	// if hasIndex {
-	//     messageService.DeleteMessage(nil, memory.TenantID, memoryID)
-	// }
+	// TODO(MessageService): delete associated message index once MessageService exists.
🤖 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 796 - 801, Remove the commented-out
MessageService block in the memory deletion path, including the TODO and the
disabled calls to NewMessageService, HasIndex, and DeleteMessage. Leave the
surrounding deletion logic unchanged.

Source: Coding guidelines


1552-1560: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Check RowsAffected for missing memories instead of rewriting every DB error as “not found”

Raw(...).Scan(...) only sets an error for database failures; a missing memoryID is a successful query with zero rows, so getMemoryConfig returns a zero-value response and QueueSaveToMemoryTask continues instead of adding the ID to res.NotFound. Also preserve real DB errors: the current unconditionally rewritten "memory '%s' not found" makes the handler treat them as 404s.

Fix both internal/dao/memory.go and internal/service/memory.go: distinguish zero rows in the DAO (or check it in the service) and propagate non-not-found DB errors.

🤖 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 1552 - 1560, Update getMemoryConfig
and the underlying memoryDAO.GetWithOwnerNameByID flow to distinguish a missing
memory by checking RowsAffected or an equivalent zero-row result, returning the
existing not-found error only for that case. Propagate genuine database errors
unchanged or with their original cause preserved so QueueSaveToMemoryTask can
classify failures correctly and add missing IDs to res.NotFound.
🤖 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.

Outside diff comments:
In `@internal/service/memory.go`:
- Around line 796-801: Remove the commented-out MessageService block in the
memory deletion path, including the TODO and the disabled calls to
NewMessageService, HasIndex, and DeleteMessage. Leave the surrounding deletion
logic unchanged.
- Around line 1552-1560: Update getMemoryConfig and the underlying
memoryDAO.GetWithOwnerNameByID flow to distinguish a missing memory by checking
RowsAffected or an equivalent zero-row result, returning the existing not-found
error only for that case. Propagate genuine database errors unchanged or with
their original cause preserved so QueueSaveToMemoryTask can classify failures
correctly and add missing IDs to res.NotFound.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9a308cd0-e29c-475e-9cef-79446a0f2f9a

📥 Commits

Reviewing files that changed from the base of the PR and between 5bfd59f and c82e6cc.

📒 Files selected for processing (5)
  • internal/handler/memory.go
  • internal/service/memory.go
  • internal/service/memory_message_service.go
  • internal/service/model_service.go
  • internal/service/tenant.go

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

Thanks for this PR. Overall the changes look good — access control on memory operations and proper error handling are important improvements.

Summary of changes:

  • memory.go (handler): Added GetUser checks for DeleteMemory and GetMemoryConfig — consistent with other handlers that already do this.
  • memory.go (service): Updated signatures to accept userID and use requireMemoryAccess, extracted getMemoryConfig for internal callers.
  • memory_message_service.go: Switched to internal getMemoryConfig (no access control needed in trusted queue path).
  • model_service.go: Added warning log when listModels fails — useful for debugging provider issues.
  • tenant.go: Fixed a bug where tenantDAO.Update error was silently ignored.

One small suggestion (non-blocking):
In GetMemoryConfig you now split into the public GetMemoryConfig(ctx, userID, memoryID) and private getMemoryConfig(ctx, memoryID). The access check + delegate pattern is clean. You may want to do the same for DeleteMemory eventually if there are internal callers that need to bypass access control (e.g. cascading deletes from tenant cleanup). Not required now though — the current internal caller (memory_message_service) doesn't need it.

LGTM otherwise. 👍

@wangq8
wangq8 merged commit 15f8ef7 into infiniflow:main Jul 28, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. 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.

2 participants