Skip to content

Go: add context, part11 - #17426

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

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

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

📝 Walkthrough

Walkthrough

Task DAO operations now use request-scoped contexts and database handles. Document ownership error messages are standardized across services, REST endpoints, documentation, and API tests, with related deletion and cancellation handling updated.

Changes

Task access and error contracts

Layer / File(s) Summary
Context-aware TaskDAO contract
internal/dao/task.go, internal/dao/task_test.go, internal/agent/sandbox/manager_test.go
Task DAO methods and tests now pass explicit contexts and database handles, while the test double ignores unused parameters.
Service context propagation
internal/service/chunk_types.go, internal/service/dataset/index.go, internal/service/document/..., internal/service/memory_message_service.go, internal/service/document/document_test.go
Services pass request context and database handles into task operations; document deletion paths classify cancellation and deadline errors.
Ownership error contract and coverage
api/apps/restful_apis/..., internal/service/chunk/chunk.go, docs/references/http_api_reference.md, test/testcases/...
Ownership error text is changed to lowercase you without trailing periods across API responses, documentation, and REST, HTTP, SDK, and web tests.

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

Possibly related PRs

Suggested reviewers: xugangqiang

Poem

I’m a rabbit with context tucked tight,
Passing DB handles through the night.
“you don’t own…” now speaks with care,
Tests and docs repeat it everywhere.
Hop, hop—clean contracts in flight!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is missing entirely, so the required Summary section and background context are absent. Add a Summary section that briefly explains the goal of the context-related changes and any reviewer background needed.
Docstring Coverage ⚠️ Warning Docstring coverage is 8.57% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title is related to the main change because the PR primarily adds context to DAO and service calls.
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 08:15
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. 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: 3

🤖 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/document/document_crud.go`:
- Around line 279-281: The task-deletion error is currently ignored, allowing
cleanup to continue and potentially leave inconsistent data. In
internal/service/document/document_crud.go lines 279-281, update
RemoveDocumentKeepFile to return the DeleteByDocIDs error before deleting engine
data or the document record. In internal/service/document/document_ingest.go
lines 129-130, propagate the deletion error before deleting chunks, and add a
regression test covering this failure path.

In
`@test/testcases/test_http_api/test_file_management_within_dataset/test_stop_parse_documents.py`:
- Line 72: Update the remaining invalid-document parameter in the stop_parsing
test cases to expect the lowercase, periodless missing-document message returned
by stop_parsing, replacing the outdated ownership message while preserving the
existing document ID and status code.

In
`@test/testcases/test_sdk_api/test_chunk_management_within_dataset/test_update_chunk.py`:
- Around line 170-171: Update the assertion in the chunk ownership test to
compare message directly with ownership_message, removing message.rstrip(".")
while preserving the alternative missing-chunk message check.
🪄 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: c22dca45-68a1-49f9-9c7f-a7f47f922592

📥 Commits

Reviewing files that changed from the base of the PR and between 49e6181 and 452d6e8.

📒 Files selected for processing (28)
  • api/apps/restful_apis/chunk_api.py
  • api/apps/restful_apis/document_api.py
  • docs/references/http_api_reference.md
  • internal/agent/sandbox/manager_test.go
  • internal/dao/task.go
  • internal/dao/task_test.go
  • internal/service/chunk/chunk.go
  • internal/service/chunk_types.go
  • internal/service/dataset/index.go
  • internal/service/document/document_crud.go
  • internal/service/document/document_ingest.go
  • internal/service/document/document_test.go
  • internal/service/memory_message_service.go
  • test/testcases/restful_api/test_chunks.py
  • test/testcases/restful_api/test_documents.py
  • test/testcases/test_http_api/test_chunk_management_within_dataset/test_add_chunk.py
  • test/testcases/test_http_api/test_chunk_management_within_dataset/test_delete_chunks.py
  • test/testcases/test_http_api/test_chunk_management_within_dataset/test_list_chunks.py
  • test/testcases/test_http_api/test_chunk_management_within_dataset/test_update_chunk.py
  • test/testcases/test_http_api/test_file_management_within_dataset/test_list_documents.py
  • test/testcases/test_http_api/test_file_management_within_dataset/test_stop_parse_documents.py
  • test/testcases/test_sdk_api/test_chunk_management_within_dataset/test_add_chunk.py
  • test/testcases/test_sdk_api/test_chunk_management_within_dataset/test_update_chunk.py
  • test/testcases/test_sdk_api/test_file_management_within_dataset/test_list_documents.py
  • test/testcases/test_web_api/test_chunk_app/test_chunk_routes_unit.py
  • test/testcases/test_web_api/test_chunk_app/test_create_chunk.py
  • test/testcases/test_web_api/test_chunk_app/test_update_chunk.py
  • test/testcases/test_web_api/test_document_app/test_list_documents.py

Comment on lines +279 to 281
if _, delErr := s.taskDAO.DeleteByDocIDs(ctx, dao.DB, []string{docID}); delErr != nil {
common.Logger.Warn(fmt.Sprintf("RemoveDocumentKeepFile: failed to delete tasks for %s: %v", docID, delErr))
}

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.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Do not continue cleanup after task-deletion failures.

Both paths discard deletion errors—including context cancellation errors—then remove external data or report success. This can leave task rows pointing at removed document content.

  • internal/service/document/document_crud.go#L279-L281: return the deletion error before deleting engine data and the document record.
  • internal/service/document/document_ingest.go#L129-L130: propagate the deletion error before deleting chunks; add a regression test for the error path.
📍 Affects 2 files
  • internal/service/document/document_crud.go#L279-L281 (this comment)
  • internal/service/document/document_ingest.go#L129-L130
🤖 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/document/document_crud.go` around lines 279 - 281, The
task-deletion error is currently ignored, allowing cleanup to continue and
potentially leave inconsistent data. In
internal/service/document/document_crud.go lines 279-281, update
RemoveDocumentKeepFile to return the DeleteByDocIDs error before deleting engine
data or the document record. In internal/service/document/document_ingest.go
lines 129-130, propagate the deletion error before deleting chunks, and add a
regression test covering this failure path.

Comment on lines +170 to 171
ownership_message = f"you don't own the document {chunks[0].document_id}"
assert message.rstrip(".") == ownership_message or message == f"Can't find this chunk {chunks[0].id}", message

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Enforce the exact no-period ownership message.

message.rstrip(".") still accepts a trailing period, so this test does not detect a regression to the superseded response format. Compare message directly with ownership_message.

🤖 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
`@test/testcases/test_sdk_api/test_chunk_management_within_dataset/test_update_chunk.py`
around lines 170 - 171, Update the assertion in the chunk ownership test to
compare message directly with ownership_message, removing message.rstrip(".")
while preserving the alternative missing-chunk message check.

@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/document/document_ingest.go`:
- Around line 131-136: Update the DeleteIngestionTasksByDocIDs error handling in
the document ingestion flow so every non-nil delErr immediately returns an error
instead of only logging and continuing. Preserve the existing
cancellation/deadline wrapping behavior, and consider performing this cleanup
before the document update to reduce partial-state risk.
🪄 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: a5ed183f-8d06-47c9-83dc-acdbbe6d52a9

📥 Commits

Reviewing files that changed from the base of the PR and between 452d6e8 and aef70bd.

📒 Files selected for processing (3)
  • internal/service/document/document_crud.go
  • internal/service/document/document_ingest.go
  • test/testcases/test_http_api/test_file_management_within_dataset/test_stop_parse_documents.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/service/document/document_crud.go

Comment on lines +131 to +136
if _, delErr := s.taskDAO.DeleteIngestionTasksByDocIDs(ctx, dao.DB, []string{doc.ID}); delErr != nil {
if errors.Is(delErr, context.Canceled) || errors.Is(delErr, context.DeadlineExceeded) {
return common.CodeExceptionError, fmt.Errorf("delete ingestion tasks: %w", delErr)
}
common.Error(fmt.Sprintf("go side, doc %s, DeleteIngestionTasksByDocIDs failed", doc.ID), delErr)
}

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.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Do not continue after ingestion-task deletion fails.

Non-cancellation errors are only logged, so the method can delete chunks and return success while stale ingestion-task rows remain. Return an error for every delErr (and consider moving this cleanup before the document update to reduce partial-state risk).

Proposed fix
 			if _, delErr := s.taskDAO.DeleteIngestionTasksByDocIDs(ctx, dao.DB, []string{doc.ID}); delErr != nil {
 				if errors.Is(delErr, context.Canceled) || errors.Is(delErr, context.DeadlineExceeded) {
 					return common.CodeExceptionError, fmt.Errorf("delete ingestion tasks: %w", delErr)
 				}
 				common.Error(fmt.Sprintf("go side, doc %s, DeleteIngestionTasksByDocIDs failed", doc.ID), delErr)
+				return common.CodeExceptionError, fmt.Errorf("delete ingestion tasks: %w", delErr)
 			}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if _, delErr := s.taskDAO.DeleteIngestionTasksByDocIDs(ctx, dao.DB, []string{doc.ID}); delErr != nil {
if errors.Is(delErr, context.Canceled) || errors.Is(delErr, context.DeadlineExceeded) {
return common.CodeExceptionError, fmt.Errorf("delete ingestion tasks: %w", delErr)
}
common.Error(fmt.Sprintf("go side, doc %s, DeleteIngestionTasksByDocIDs failed", doc.ID), delErr)
}
if _, delErr := s.taskDAO.DeleteIngestionTasksByDocIDs(ctx, dao.DB, []string{doc.ID}); delErr != nil {
if errors.Is(delErr, context.Canceled) || errors.Is(delErr, context.DeadlineExceeded) {
return common.CodeExceptionError, fmt.Errorf("delete ingestion tasks: %w", delErr)
}
common.Error(fmt.Sprintf("go side, doc %s, DeleteIngestionTasksByDocIDs failed", doc.ID), delErr)
return common.CodeExceptionError, fmt.Errorf("delete ingestion tasks: %w", delErr)
}
🤖 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/document/document_ingest.go` around lines 131 - 136, Update
the DeleteIngestionTasksByDocIDs error handling in the document ingestion flow
so every non-nil delErr immediately returns an error instead of only logging and
continuing. Preserve the existing cancellation/deadline wrapping behavior, and
consider performing this cleanup before the document update to reduce
partial-state risk.

@codecov

codecov Bot commented Jul 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.65%. Comparing base (cd846cc) to head (aef70bd).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #17426   +/-   ##
=======================================
  Coverage   90.65%   90.65%           
=======================================
  Files          10       10           
  Lines         717      717           
  Branches      118      118           
=======================================
  Hits          650      650           
  Misses         39       39           
  Partials       28       28           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JinHai-CN
JinHai-CN merged commit 19d861b into infiniflow:main Jul 27, 2026
8 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant