Repository navigation
Go: context, part8 - #17405
Go: context, part8#17405
Conversation
Signed-off-by: Jin Hai <[email protected]>
📝 WalkthroughWalkthroughMemory DAO methods now accept request contexts and injected database handles. Memory services and HTTP handlers propagate those contexts through memory CRUD, listing, configuration, access checks, queued tasks, and related tests. ChangesMemory context propagation
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 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)
1442-1457: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick winKeep the tenant lookup in the request context.
When
tenantIDsis empty, Line 1446 callsGetUserTenantRelationByUserIDrather than the context-aware variant already used at Line 1116. A canceled request can therefore leave this database lookup running.Suggested change
- userTenants, err := userTenantService.GetUserTenantRelationByUserID(userID) + userTenants, err := userTenantService.GetUserTenantRelationByUserIDWithContext(ctx, userID)🤖 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 1442 - 1457, Update ListMemories so the empty-tenant branch uses the context-aware user-tenant lookup already used elsewhere, passing its ctx argument to GetUserTenantRelationByUserID. Preserve the existing tenant ID assembly and error handling.
789-803: 🔒 Security & Privacy | 🟠 Major | ⚡ Quick winEnforce tenant authorization for ID-based memory operations.
These flows act on a memory ID without validating the caller’s access. An authenticated user who obtains another tenant’s memory ID can delete it or retrieve its configuration, including prompts.
internal/service/memory.go#L789-L803: adduserIDand callrequireMemoryAccessbeforeDeleteByID.internal/handler/memory.go#L267-L270: obtain the current user and pass its ID to the authorization-enforcing delete service.internal/handler/memory.go#L389-L392: obtain the current user and call an access-checked config service method; retain the context-only lookup for trusted internal queue processing.🤖 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 789 - 803, Enforce tenant authorization for ID-based memory operations: update MemoryService.DeleteMemory to accept userID and call requireMemoryAccess before DeleteByID; update the delete handler to obtain the current user and pass its ID. In the config handler, obtain the current user and use the access-checked config service method, while preserving the context-only lookup for trusted internal queue processing. Apply these changes in internal/service/memory.go:789-803, internal/handler/memory.go:267-270, and internal/handler/memory.go:389-392.
🧹 Nitpick comments (1)
internal/dao/memory.go (1)
128-135: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winCollapse the duplicate
GetByIDWithContextAPI.
GetByIDWithContextis only used internally, including fromGetByID, so keep one context-aware path and update the caller ininternal/service/memory.goto useGetByID. Eliminate the compatibility wrapper and avoid applyingWithContext(ctx)twice ininternal/dao/memory.go.🤖 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/dao/memory.go` around lines 128 - 135, Remove the duplicate GetByIDWithContext method from MemoryDAO and make GetByID contain the single context-aware database lookup. Update internal/service/memory.go callers to use GetByID, and ensure the query applies WithContext(ctx) only once.Source: Coding guidelines
🤖 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 1442-1457: Update ListMemories so the empty-tenant branch uses the
context-aware user-tenant lookup already used elsewhere, passing its ctx
argument to GetUserTenantRelationByUserID. Preserve the existing tenant ID
assembly and error handling.
- Around line 789-803: Enforce tenant authorization for ID-based memory
operations: update MemoryService.DeleteMemory to accept userID and call
requireMemoryAccess before DeleteByID; update the delete handler to obtain the
current user and pass its ID. In the config handler, obtain the current user and
use the access-checked config service method, while preserving the context-only
lookup for trusted internal queue processing. Apply these changes in
internal/service/memory.go:789-803, internal/handler/memory.go:267-270, and
internal/handler/memory.go:389-392.
---
Nitpick comments:
In `@internal/dao/memory.go`:
- Around line 128-135: Remove the duplicate GetByIDWithContext method from
MemoryDAO and make GetByID contain the single context-aware database lookup.
Update internal/service/memory.go callers to use GetByID, and ensure the query
applies WithContext(ctx) only once.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 272ed2c6-a0c8-405b-8f12-bd9c92d0408f
📒 Files selected for processing (5)
internal/dao/memory.gointernal/handler/memory.gointernal/service/memory.gointernal/service/memory_message_service.gointernal/service/memory_message_test.go
No description provided.