Repository navigation
Go: add context, part11 - #17426
Go: add context, part11#17426
Conversation
Signed-off-by: Jin Hai <[email protected]>
📝 WalkthroughWalkthroughTask 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. ChangesTask access and error contracts
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ 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.
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
📒 Files selected for processing (28)
api/apps/restful_apis/chunk_api.pyapi/apps/restful_apis/document_api.pydocs/references/http_api_reference.mdinternal/agent/sandbox/manager_test.gointernal/dao/task.gointernal/dao/task_test.gointernal/service/chunk/chunk.gointernal/service/chunk_types.gointernal/service/dataset/index.gointernal/service/document/document_crud.gointernal/service/document/document_ingest.gointernal/service/document/document_test.gointernal/service/memory_message_service.gotest/testcases/restful_api/test_chunks.pytest/testcases/restful_api/test_documents.pytest/testcases/test_http_api/test_chunk_management_within_dataset/test_add_chunk.pytest/testcases/test_http_api/test_chunk_management_within_dataset/test_delete_chunks.pytest/testcases/test_http_api/test_chunk_management_within_dataset/test_list_chunks.pytest/testcases/test_http_api/test_chunk_management_within_dataset/test_update_chunk.pytest/testcases/test_http_api/test_file_management_within_dataset/test_list_documents.pytest/testcases/test_http_api/test_file_management_within_dataset/test_stop_parse_documents.pytest/testcases/test_sdk_api/test_chunk_management_within_dataset/test_add_chunk.pytest/testcases/test_sdk_api/test_chunk_management_within_dataset/test_update_chunk.pytest/testcases/test_sdk_api/test_file_management_within_dataset/test_list_documents.pytest/testcases/test_web_api/test_chunk_app/test_chunk_routes_unit.pytest/testcases/test_web_api/test_chunk_app/test_create_chunk.pytest/testcases/test_web_api/test_chunk_app/test_update_chunk.pytest/testcases/test_web_api/test_document_app/test_list_documents.py
| 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)) | ||
| } |
There was a problem hiding this comment.
🗄️ 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.
| 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 |
There was a problem hiding this comment.
🎯 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.
Signed-off-by: Jin Hai <[email protected]>
There was a problem hiding this comment.
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
📒 Files selected for processing (3)
internal/service/document/document_crud.gointernal/service/document/document_ingest.gotest/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
| 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) | ||
| } |
There was a problem hiding this comment.
🗄️ 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.
| 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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
No description provided.