Repository navigation
fix(ingestion): settle a terminal task's open run before deletion - #21798
Conversation
The worker closes the run ledger best-effort before flipping the task to COMPLETED/FAILED, so a lost terminal write leaves a run open with no worker left to settle it. Remove only repaired this for queued/STOPPED tasks, so deleting such a terminal task orphaned the ledger and the parse history kept showing the run as running. Settle COMPLETED/FAILED runs the same way before deleting the task row, matching PrepareDocumentTaskForCleanup.
|
@coderabbitai review |
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Map and settle terminal task runs internal/service/ingestion_task_service.go, internal/service/ingestion_task_service_test.go |
Remove maps STOPPED, COMPLETED, and FAILED tasks to their corresponding run-ledger status and message. It settles a run only when a pipeline-log ID is present and the run exists with a positive count. Missing runs are ignored; other lookup or settlement errors prevent deletion. Tests verify settlement for COMPLETED and FAILED tasks. |
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Possibly related PRs
- infiniflow/ragflow#21700: Changes ingestion-task deletion and cleanup behavior, including numbered pipeline run settlement.
- infiniflow/ragflow#21694: Adds document-task cleanup and terminal pipeline-run settlement.
- infiniflow/ragflow#21711: Changes terminal ingestion-event persistence, which is also involved in recording terminal run events.
Suggested labels: 🐞 bug, go, parsing, size:S
Suggested reviewers: jay77721
Merge Risk: 
Minimal · up to 9e5c3
-
No merge-blocking issue is established from the supplied evidence.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Title check
-
Explanation
The title names the main change: Remove now settles a terminal task's open run before deleting the task. It follows the fix(ingestion) convention and matches the raw summary, PR description, and objectives. It is specific and free of noise.
Full details: Description check
-
Explanation
The description covers the problem, the cause, the change, idempotency, and a test plan. It is detailed and matches the diff and the objectives. It does not use the repository template's heading exactly. It uses a '## Summary' heading, but the required '### Summary' section is present in substance, and the content explains purpose and background for reviewers.
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 2 functions across 2 files.
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
A rabbit checks the ledger at dawn.
Three terminal paths are neatly drawn.
The run receives its ending note.
Then task removal sets afloat.
Soft paws hop on, the work is done.
Comment @coderabbitai help to get the list of available commands.
|
|
Discussion: I verified the terminalRunSettlement mapping on a verbatim extraction: STOPPED, COMPLETED and FAILED settle to cancel, done and fail respectively, and non-terminal statuses (RUNNING, PENDING, empty) do not settle. The old branch in Remove only settled STOPPED, so a completed or failed task whose terminal write was lost kept an open ledger with no worker left to close it. That Remove now settles those cases end to end, including the idempotency and the no-commit-row-on-reject behavior, is covered by TestIngestionTaskServiceRemoveSettlesTerminalTaskRun, which I could not run on my host (package dependency tree does not build in my sandbox), so that part is read-only for me. Nothing blocking from what I can verify. |
|
{"body": "Thanks for the read-only verification \u2014 the mapping reading matches what the code does.\n\nI can cover the part you could not run. On head |
|
LGTM |
yuzhichang
left a comment
There was a problem hiding this comment.
Reviewed merge-base(main)..9e5c3fa — internal/service/ingestion_task_service.go, internal/service/ingestion_task_service_test.go.
What the diff does
Remove previously settled only a STOPPED task's open run ledger. The new terminalRunSettlement helper centralizes the terminal-status to run-status mapping (STOPPED→CANCEL, COMPLETED→DONE, FAILED→FAIL) and is applied to every terminal task before the row is deleted, so a lost best-effort terminal write no longer leaves a pipeline_operation_log row stuck in an open status with no worker left to close it. The RunCount > 0 gate, gorm.ErrRecordNotFound tolerance, and the idempotent settleTaskRun/ensureTerminalEvent path are unchanged.
Verification
STOPPEDmapping is identical to the base branch, so there is no behavior change for the previously covered case.COMPLETED/FAILEDreuse the sametaskTerminalMessageComplete/taskTerminalMessageFailedconstants andTaskStatusDone/TaskStatusFailvalues thatMarkCompleted/MarkFailedandPrepareDocumentTaskForCleanupalready use, so no second source of truth or dual path is introduced.settleTaskRunremains idempotent:advanceOpenLogIfOpenonly moves rows inOpenPipelineOperationStatuses(), andensureTerminalEventskips insertion when a terminal event already exists — so retrying after a failed settlement, or racing a late worker write, is safe.- Missing/deleted ledger rows are still tolerated for terminal tasks (
ErrRecordNotFoundignored), so the fix does not make a task undeletable when its run row is gone. - New test covers both
FAILEDandCOMPLETEDwith an open numbered run and asserts the run status plus the terminal event message. - No enterprise surface, build tags, or GORM
Takewith a bare string ID is touched. The new test is untagged and uses the existing in-memory SQLite service harness, so it stays in the unit tier.
No blocking findings.
Summary
IngestionTaskService.Removesettles a task's numbered run ledger before deleting the row, but only for queued (CREATED/SCHEDULED) andSTOPPEDtasks.COMPLETED/FAILEDtasks are deleted without that step.The worker closes the ledger before flipping the task to a terminal state, and that close is best-effort:
recordTerminalPipelineLogonly logs a warning whenRecordPipelineLog/RecordTerminalfail (internal/ingestion/service/ingestion_service.go), thenMarkCompleted/MarkFailedstill runs. A transient DB error therefore leaves aCOMPLETED/FAILEDtask whose run is still in an openoperation_status. Deleting the task removes the only reference that could settle that run — no worker remains — so the run shows as running in the parse history forever.PrepareDocumentTaskForCleanupalready settles the ledger forCOMPLETED/FAILEDtasks for the same reason;Removeis the missing sibling.Change
STOPPED→CANCEL,COMPLETED→DONE,FAILED→FAIL) and settle before deleting the task row.AdvanceOpenLogonly updates open states andensureTerminalEventskips when a terminal event already exists, so an already-closed run is a no-op.Test plan
TestIngestionTaskServiceRemoveSettlesTerminalTaskRunseeds aFAILEDand aCOMPLETEDtask bound to an open numbered run, callsRemove, and asserts the run reachesFAIL/DONEwith the matching terminal event. Red on the base commit (numbered run status = "0"), green with the change.go test -tags cgo,static ./internal/service/passes.