Skip to content

Go: add context, part12 - #17435

Merged
JinHai-CN merged 3 commits into
infiniflow:mainfrom
JinHai-CN:fix589
Jul 27, 2026
Merged

JinHai-CN merged 3 commits into
infiniflow:mainfrom
JinHai-CN:fix589

Conversation

@JinHai-CN

Copy link
Copy Markdown
Member

No description provided.

@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: e6690334-91f9-4e90-a9bf-d9f010a8336c

📥 Commits

Reviewing files that changed from the base of the PR and between 097c396 and 4ff5233.

📒 Files selected for processing (1)
  • internal/handler/mindmap.go

📝 Walkthrough

Walkthrough

Tenant DAO operations, service methods, handlers, and ingestion dispatchers now propagate request contexts and explicit GORM database handles. Related tests and resolver mocks were updated for the new call signatures.

Changes

Context propagation and tenant access

Layer / File(s) Summary
Tenant access and application propagation
internal/dao/tenant.go, internal/handler/*, internal/service/*, internal/ingestion/task/task_context.go
Tenant DAO methods use db.WithContext(ctx), and application call paths pass request contexts and explicit database handles through tenant, permission, model, dataset, chat, and task operations.
Context-aware ingestion dispatch
internal/ingestion/component/*.go
Parser, media, DOCX, Markdown, and PDF vision dispatchers pass ctx and *gorm.DB into tenant-model resolution; parser error prefixes are standardized.
Dispatch and DAO test updates
internal/dao/tenant_test.go, internal/ingestion/component/*_test.go, internal/service/tenant_test.go
Tests and resolver mocks now provide contexts and database handles while preserving existing behavioral assertions.

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

Possibly related PRs

Suggested labels: ☯️ refactor

Suggested reviewers: wangq8

Poem

A rabbit threads context through the burrow bright,
With GORM in paw and requests in sight.
Models follow each query’s trail,
Tests hop along without fail.
“One DB, one ctx!” the bunny sings.

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (2 warnings, 1 inconclusive)

Check name Status Explanation Resolution
Description check ⚠️ Warning No pull request description was provided, so the required Summary section and background context are missing. Add a Summary section that briefly explains the PR goal, the problem it solves, and any relevant background context.
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title is related to the change, but it is too generic to clearly describe the main update. Use a more specific title that names the main change, such as the context propagation across DAO, service, and handler layers.
✅ Passed checks (2 passed)
Check name Status Explanation
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 10:07
@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 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

Caution

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

⚠️ Outside diff range comments (1)
internal/service/tenant.go (1)

835-840: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Return the tenant update error.

A failed update is currently reported as success, leaving the default model unchanged while callers proceed as though it was saved.

Proposed fix
  err = s.tenantDAO.Update(ctx, dao.DB, ownedTenant.TenantID, map[string]interface{}{
    modelTypeID:       defaultModel,
    tenantModelTypeID: tenantModelID,
  })

- return nil
+ return err
🤖 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/tenant.go` around lines 835 - 840, Return the error from the
tenantDAO.Update call in the surrounding tenant service method instead of
unconditionally returning nil. Preserve the existing update arguments and
successful nil return, allowing callers to receive failures when the default
model update does not persist.
🧹 Nitpick comments (2)
internal/ingestion/component/parser.go (1)

488-492: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Remove Python migration-history references from Go comments.

Describe the current Go behavior without Mirrors Python paths or legacy implementation notes.

  • internal/ingestion/component/parser.go#L488-L492: retain the Markdown vision behavior description, but remove the Python _Markdown reference.
  • internal/ingestion/component/pdf_vision_dispatch.go#L102-L103: document the MinerU request/response behavior without referencing mineru_parser.py.

As per coding guidelines, “Keep Go package comments and doc comments aligned with the current runtime path rather than migration history.”

🤖 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/ingestion/component/parser.go` around lines 488 - 492, Remove the
Python migration reference from the Markdown vision comment above
maybeDispatchMarkdownVision in internal/ingestion/component/parser.go lines
488-492 while retaining its description of enriching referenced images with
LLM-generated descriptions. Update the MinerU comment in
internal/ingestion/component/pdf_vision_dispatch.go lines 102-103 to describe
the current request/response behavior without mentioning mineru_parser.py.

Source: Coding guidelines

internal/ingestion/component/parser_dispatch_test.go (1)

429-432: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Assert the injected context and database are forwarded.

The updated stubs accept but ignore ctx and db, while each test invokes ParserComponent.Invoke with nil. Pass sentinel values and assert identity in the PDF vision and MinerU resolvers so a regression to a global or unrelated DB cannot pass unnoticed.

  • internal/ingestion/component/parser_dispatch_test.go#L429-L432: assert the PDF vision resolver receives the supplied context and database.
  • internal/ingestion/component/parser_dispatch_test.go#L509-L512: assert the empty-page PDF vision path receives the supplied context and database.
  • internal/ingestion/component/parser_dispatch_test.go#L567-L568: assert the MinerU resolver receives the supplied context and database.
🤖 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/ingestion/component/parser_dispatch_test.go` around lines 429 - 432,
Update the PDF vision resolver stubs at
internal/ingestion/component/parser_dispatch_test.go:429-432 and :509-512, and
the MinerU resolver stub at :567-568, to assert that the received context and
database are identical to supplied sentinel values. Replace nil arguments in the
corresponding ParserComponent.Invoke calls with those sentinels, while
preserving the existing tenant/model assertions and test behavior.
🤖 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/handler/mindmap.go`:
- Line 77: Update the timeout context initialization near the fallback lookup in
the handler so it derives from the incoming request context rather than
context.Background(). Ensure GetDefaultModelName receives this derived context,
preserving request cancellation and deadlines.

---

Outside diff comments:
In `@internal/service/tenant.go`:
- Around line 835-840: Return the error from the tenantDAO.Update call in the
surrounding tenant service method instead of unconditionally returning nil.
Preserve the existing update arguments and successful nil return, allowing
callers to receive failures when the default model update does not persist.

---

Nitpick comments:
In `@internal/ingestion/component/parser_dispatch_test.go`:
- Around line 429-432: Update the PDF vision resolver stubs at
internal/ingestion/component/parser_dispatch_test.go:429-432 and :509-512, and
the MinerU resolver stub at :567-568, to assert that the received context and
database are identical to supplied sentinel values. Replace nil arguments in the
corresponding ParserComponent.Invoke calls with those sentinels, while
preserving the existing tenant/model assertions and test behavior.

In `@internal/ingestion/component/parser.go`:
- Around line 488-492: Remove the Python migration reference from the Markdown
vision comment above maybeDispatchMarkdownVision in
internal/ingestion/component/parser.go lines 488-492 while retaining its
description of enriching referenced images with LLM-generated descriptions.
Update the MinerU comment in internal/ingestion/component/pdf_vision_dispatch.go
lines 102-103 to describe the current request/response behavior without
mentioning mineru_parser.py.
🪄 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: 116f0b55-6a17-4902-b43d-70946bd84e11

📥 Commits

Reviewing files that changed from the base of the PR and between 0a8f28f and d5b71fe.

📒 Files selected for processing (36)
  • internal/dao/tenant.go
  • internal/dao/tenant_test.go
  • internal/handler/dataset.go
  • internal/handler/document.go
  • internal/handler/mindmap.go
  • internal/handler/providers.go
  • internal/handler/searchbot.go
  • internal/handler/tenant.go
  • internal/ingestion/component/dispatch_model.go
  • internal/ingestion/component/docx_vision_dispatch.go
  • internal/ingestion/component/docx_vision_dispatch_test.go
  • internal/ingestion/component/markdown_vision_dispatch.go
  • internal/ingestion/component/media_dispatch.go
  • internal/ingestion/component/media_dispatch_test.go
  • internal/ingestion/component/parser.go
  • internal/ingestion/component/parser_dispatch_pdf_vision_cgo_test.go
  • internal/ingestion/component/parser_dispatch_test.go
  • internal/ingestion/component/pdf_vision_dispatch.go
  • internal/ingestion/task/task_context.go
  • internal/service/chat.go
  • internal/service/chat_session.go
  • internal/service/chunk/chunk.go
  • internal/service/dataset/crud.go
  • internal/service/dataset/permission.go
  • internal/service/document/file2document.go
  • internal/service/file_permission.go
  • internal/service/mcp.go
  • internal/service/model_service.go
  • internal/service/oauth_login.go
  • internal/service/related_question.go
  • internal/service/search.go
  • internal/service/skill_space.go
  • internal/service/team_permission.go
  • internal/service/tenant.go
  • internal/service/tenant_test.go
  • internal/service/user.go

Comment thread internal/handler/mindmap.go Resolved
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 (1)
internal/handler/mindmap.go (1)

64-66: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Bound the mindmap request context.

ChatStream now forwards ctx into the model driver, and the fallback lookup/stream also uses ctx, so an unbounded request can hang indefinitely inside ChatStreamlyWithSender or database lookups. Use context.WithTimeout(ctx, 10*time.Minute) for the stream and derived fallback lookup, while still honoring the original request cancellation.

🤖 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/handler/mindmap.go` around lines 64 - 66, Update the mindmap handler
around ChatStream and ChatStreamlyWithSender to derive a context with a
10-minute timeout from the incoming ctx, and use that derived context for the
model stream and fallback database lookup. Preserve propagation of the original
request cancellation and ensure the timeout context is properly released.
🤖 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/handler/mindmap.go`:
- Around line 64-66: Update the mindmap handler around ChatStream and
ChatStreamlyWithSender to derive a context with a 10-minute timeout from the
incoming ctx, and use that derived context for the model stream and fallback
database lookup. Preserve propagation of the original request cancellation and
ensure the timeout context is properly released.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1ccdfb4d-cfe9-43be-ad28-a89f8241f236

📥 Commits

Reviewing files that changed from the base of the PR and between d5b71fe and 097c396.

📒 Files selected for processing (2)
  • internal/handler/mindmap.go
  • internal/service/tenant.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/service/tenant.go

Signed-off-by: Jin Hai <[email protected]>
@JinHai-CN
JinHai-CN merged commit f73f4cb into infiniflow:main Jul 27, 2026
3 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Aug 11, 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