Skip to content

Go: context, part8 - #17405

Merged
JinHai-CN merged 1 commit into
infiniflow:mainfrom
JinHai-CN:fix585
Jul 27, 2026
Merged

JinHai-CN merged 1 commit into
infiniflow:mainfrom
JinHai-CN:fix585

Conversation

@JinHai-CN

Copy link
Copy Markdown
Member

No description provided.

Signed-off-by: Jin Hai <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

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

Changes

Memory context propagation

Layer / File(s) Summary
DAO context and database injection
internal/dao/memory.go
MemoryDAO queries now use injected *gorm.DB handles with db.WithContext(ctx), including CRUD, filtering, owner lookup, and accessibility checks.
Service context propagation
internal/service/memory.go
MemoryService methods pass contexts through DAO operations, validation, access checks, filtering, and configuration retrieval.
Request, async, and test wiring
internal/handler/memory.go, internal/service/memory_message_service.go, internal/service/memory_message_test.go
Handlers, queued memory tasks, and affected tests pass contexts to updated service methods.

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

Possibly related PRs

Suggested labels: size:M

Suggested reviewers: haruko386

Poem

I’m a rabbit passing context along,
Through memory paths where queries belong.
From handler to service, then DAO below,
Every request now knows where to go.
Hop, hop—database calls flow right!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Description check ⚠️ Warning No PR description was provided, so the required Summary section is missing. Add the required Summary section with a brief purpose, background, and what this PR changes.
Title check ❓ Inconclusive The title is too generic and doesn't describe the actual context refactor in this PR. Use a concise, specific title that mentions the main change, such as context propagation through memory DAO and service methods.
✅ Passed checks (3 passed)
Check name Status Explanation
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.

@JinHai-CN
JinHai-CN marked this pull request as ready for review July 27, 2026 03:24
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jul 27, 2026
@JinHai-CN JinHai-CN added ci Continue Integration and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Jul 27, 2026

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

1442-1457: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Keep the tenant lookup in the request context.

When tenantIDs is empty, Line 1446 calls GetUserTenantRelationByUserID rather 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 win

Enforce 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: add userID and call requireMemoryAccess before DeleteByID.
  • 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 win

Collapse the duplicate GetByIDWithContext API.

GetByIDWithContext is only used internally, including from GetByID, so keep one context-aware path and update the caller in internal/service/memory.go to use GetByID. Eliminate the compatibility wrapper and avoid applying WithContext(ctx) twice in internal/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

📥 Commits

Reviewing files that changed from the base of the PR and between 1571abd and 00d8f04.

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

@JinHai-CN
JinHai-CN merged commit f5aa5f7 into infiniflow:main Jul 27, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant