Skip to content

Go: add context, part6 - #17399

Merged
JinHai-CN merged 2 commits into
infiniflow:mainfrom
JinHai-CN:fix583
Jul 27, 2026
Merged

JinHai-CN merged 2 commits into
infiniflow:mainfrom
JinHai-CN:fix583

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

Request contexts and explicit database handles now propagate through Langfuse, LLM, user, and admin handler-service-DAO paths. Langfuse verification, persistence, and tests use the supplied context, while related DAO contracts are updated.

Changes

Langfuse context-aware persistence

Layer / File(s) Summary
Handler and service context forwarding
internal/handler/langfuse.go, internal/handler/langfuse_test.go, internal/service/langfuse_service.go, internal/service/langfuse_service_test.go
Langfuse handlers and services accept request contexts and pass them through verification and DAO operations; tests use the revised contracts.
DAO database execution
internal/dao/langfuse.go, internal/dao/langfuse_test.go
Langfuse CRUD, upsert, and transactional deletion methods use explicit database handles with WithContext(ctx).
Shared DAO contracts
internal/dao/license.go, internal/dao/llm.go
License and LLM DAO methods accept contexts and explicit database handles for persistence and queries.
LLM request propagation
internal/handler/llm.go, internal/service/llm.go
LLM handlers pass request contexts into services, which use them for model and factory DAO lookups.
User and admin initialization
internal/handler/user.go, internal/service/user.go, internal/admin/handler.go, internal/admin/service.go
User registration and admin user creation pass contexts into tenant initialization and LLM factory lookups.

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

Suggested labels: ☯️ refactor

Poem

A rabbit follows context’s trail,
Through handler, service, query, and tale.
Explicit handles hop in line,
While tests keep every burrow fine.
The database thumps: “All’s well!”

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is missing the required Summary section and background context from the template. Add a ### Summary section that briefly explains the problem, the goal, and relevant background context.
✅ Passed checks (4 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.
Title check ✅ Passed The title clearly matches the main change: threading context through Go handlers, services, and DAOs.

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 02:48
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jul 27, 2026
@JinHai-CN JinHai-CN added the ci Continue Integration label 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.

Actionable comments posted: 1

🤖 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/langfuse_service.go`:
- Line 77: Propagate the request context through both Langfuse verifier calls:
update AuthCheck in internal/service/langfuse_service.go:77-77 and GetProject in
internal/service/langfuse_service.go:110-110 to pass ctx instead of
context.Background(), preserving cancellation and deadline behavior.
🪄 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 Plus

Run ID: b75ea21c-4b80-4ec4-a560-c6c930b2220d

📥 Commits

Reviewing files that changed from the base of the PR and between 53afc32 and f9120b5.

📒 Files selected for processing (6)
  • internal/dao/langfuse.go
  • internal/dao/langfuse_test.go
  • internal/handler/langfuse.go
  • internal/handler/langfuse_test.go
  • internal/service/langfuse_service.go
  • internal/service/langfuse_service_test.go

Comment thread internal/service/langfuse_service.go Resolved
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Jul 27, 2026
Signed-off-by: Jin Hai <[email protected]>

@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/admin/service.go (1)

369-373: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Do not swallow context cancellation during LLM initialization.

This branch continues on every GetByFactory error, so context.Canceled and context.DeadlineExceeded are treated like optional configuration failures. Return context errors immediately; otherwise CreateUser can commit after the request has been canceled.

🤖 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/admin/service.go` around lines 369 - 373, Update the LLM
initialization error handling around s.llmDAO.GetByFactory so context.Canceled
and context.DeadlineExceeded are returned immediately instead of reaching the
continue path. Preserve the warning and optional-configuration behavior for all
other errors, ensuring CreateUser propagates cancellation before committing.
internal/service/llm.go (1)

61-71: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Apply the request context to these tenant-LLM database operations.

internal/service/llm.go#getMyLLMs and #listLLMs call TenantLLMDAO.ListAllByTenant(tenantID), which uses the global DB without context. Add context-aware variants/signatures for the affected tenant-LLM reads so LLMService.GetMyLLMs and LLMService.ListLLMs can propagate cancellation/deadlines.

🤖 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/llm.go` around lines 61 - 71, The tenant-LLM reads currently
use a contextless global database operation; add a context-aware TenantLLMDAO
read variant/signature and propagate request contexts through
LLMService.GetMyLLMs and LLMService.ListLLMs. Update internal/service/llm.go
lines 61-71, 163-195, and 341-349 to pass their contexts, while updating
internal/service/user.go line 229 and internal/admin/service.go line 288 to use
the new API with their available contexts.
🤖 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/admin/service.go`:
- Around line 369-373: Update the LLM initialization error handling around
s.llmDAO.GetByFactory so context.Canceled and context.DeadlineExceeded are
returned immediately instead of reaching the continue path. Preserve the warning
and optional-configuration behavior for all other errors, ensuring CreateUser
propagates cancellation before committing.

In `@internal/service/llm.go`:
- Around line 61-71: The tenant-LLM reads currently use a contextless global
database operation; add a context-aware TenantLLMDAO read variant/signature and
propagate request contexts through LLMService.GetMyLLMs and LLMService.ListLLMs.
Update internal/service/llm.go lines 61-71, 163-195, and 341-349 to pass their
contexts, while updating internal/service/user.go line 229 and
internal/admin/service.go line 288 to use the new API with their available
contexts.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e285bc67-be24-4776-9d70-d37950828d33

📥 Commits

Reviewing files that changed from the base of the PR and between f9120b5 and e0231e2.

📒 Files selected for processing (9)
  • internal/admin/handler.go
  • internal/admin/service.go
  • internal/dao/license.go
  • internal/dao/llm.go
  • internal/handler/llm.go
  • internal/handler/user.go
  • internal/service/langfuse_service.go
  • internal/service/llm.go
  • internal/service/user.go

@JinHai-CN JinHai-CN changed the title Go: add context Go: add context, part6 Jul 27, 2026
@JinHai-CN
JinHai-CN merged commit 9d4847b into infiniflow:main Jul 27, 2026
3 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant