Repository navigation
Fix: code review - #17442
Fix: code review#17442
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
📝 WalkthroughWalkthroughMemory 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. ChangesMemory access control
Model fallback diagnostics
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
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 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 |
There was a problem hiding this comment.
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 winRemove commented-out code instead of leaving it in the deletion path.
This block of commented-out
messageServicecalls 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 winCheck
RowsAffectedfor missing memories instead of rewriting every DB error as “not found”
Raw(...).Scan(...)only sets an error for database failures; a missingmemoryIDis a successful query with zero rows, sogetMemoryConfigreturns a zero-value response andQueueSaveToMemoryTaskcontinues instead of adding the ID tores.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.goandinternal/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
📒 Files selected for processing (5)
internal/handler/memory.gointernal/service/memory.gointernal/service/memory_message_service.gointernal/service/model_service.gointernal/service/tenant.go
wangq8
left a comment
There was a problem hiding this comment.
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): AddedGetUserchecks forDeleteMemoryandGetMemoryConfig— consistent with other handlers that already do this.memory.go (service): Updated signatures to acceptuserIDand userequireMemoryAccess, extractedgetMemoryConfigfor internal callers.memory_message_service.go: Switched to internalgetMemoryConfig(no access control needed in trusted queue path).model_service.go: Added warning log whenlistModelsfails — useful for debugging provider issues.tenant.go: Fixed a bug wheretenantDAO.Updateerror 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. 👍
Summary
Check memory accessable before operation, and log error when listModels failed.