Repository navigation
Refactor: message processing - #16852
Conversation
📝 WalkthroughWalkthroughThe ingestion refactor updates consumer redelivery and shutdown handling, terminal task settlement, direct pipeline execution, progress event persistence, tokenizer timeout configuration, and related tests. ChangesIngestion execution and progress refactor
Estimated code review effort: 4 (Complex) | ~60 minutes Possibly related PRs
Suggested labels: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
internal/ingestion/service/ingestion_service.go (1)
213-222: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick winDo not acknowledge a redelivery while its worker is still running.
Acknowledging this delivery can permanently settle the broker message. If the active worker then crashes or shutdown times out, the task remains
RUNNINGwithout another redelivery. Extend the acknowledgment deadline instead, and add a regression test asserting the duplicate handle is not acknowledged.Proposed fix
if !e.claimTask(task.ID) { common.Warn(fmt.Sprintf("task %s redelivered while worker still processing, ack skip (task_id=%s doc_id=%s kb_id=%s)", taskMessage.TaskID, task.ID, task.DocumentID, task.DatasetID)) - if ackErr := handle.Ack(); ackErr != nil { - common.Error(fmt.Sprintf("error ack redelivered task %s", taskMessage.TaskID), ackErr) + if progressErr := handle.InProgress(); progressErr != nil { + common.Error(fmt.Sprintf("error extending redelivered task %s", taskMessage.TaskID), progressErr) } return }🤖 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/service/ingestion_service.go` around lines 213 - 222, The redelivery branch in the task-processing flow must not acknowledge a duplicate while the original worker is still active. Replace the handle.Ack call within the !e.claimTask(task.ID) path with logic that extends the message acknowledgment deadline, while preserving the warning and early return; add a regression test verifying the duplicate handle is not acknowledged.internal/ingestion/service/progress_sink_test.go (1)
67-96: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick winReplace this no-op race test with an eager-construction assertion.
All goroutines only read
sink.docSvc, so this cannot detect a race, and a nil dependency passes. Replace it with a focused non-nil assertion fornewProgressSinkinstead of retaining a misleading concurrency test.Proposed focused test
-func TestProgressSink_DocService_NoDataRace(t *testing.T) { - // concurrent read-only access +func TestNewProgressSinkEagerlyBuildsDocumentService(t *testing.T) { sink := newProgressSink(servicepkg.NewIngestionTaskService()) - - // wait-group goroutines reading sink.docSvc + if sink.docSvc == nil { + t.Fatal("newProgressSink must eagerly construct docSvc") + } }As per coding guidelines, remove dead tests and preserve the required behavior with focused coverage.
🤖 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/service/progress_sink_test.go` around lines 67 - 96, Replace TestProgressSink_DocService_NoDataRace with a focused assertion that newProgressSink constructs a non-nil sink.docSvc eagerly. Remove the goroutine, synchronization, database setup, and race-oriented comments, while preserving the use of newProgressSink and asserting its DocumentService dependency is non-nil.Source: Coding guidelines
🧹 Nitpick comments (1)
internal/ingestion/task/real_consumer_test.go (1)
104-162: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDo not present this manual simulation as production consumer coverage.
The test bypasses
Ingestor.processMessage, claiming,completeTask, and handle settlement, so it can pass while the refactored lifecycle fails. Either drive the owningIngestorpath or rename this as aPipelineExecutorintegration test and remove theMirrors Start()claims.As per coding guidelines, keep refactors centered on the owning abstraction and collapse duplicate ingestion paths.
🤖 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/task/real_consumer_test.go` around lines 104 - 162, Replace the manual lifecycle simulation in the test with coverage that drives the owning Ingestor processMessage path, including claim/complete handling and message settlement. If that path cannot be exercised here, rename the test to describe PipelineExecutor integration only, remove the “Mirrors Start()” and consumer lifecycle assertions, and keep the setup focused on PipelineExecutor.Execute.Source: Coding guidelines
🤖 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/ingestion/service/ingestor_lifecycle_test.go`:
- Line 75: Update the ingestor.Stop call in the lifecycle test to pass a
deadline-bearing context created with an appropriate timeout instead of
context.Background(). Ensure the context is canceled or otherwise cleaned up
after the test, while preserving the existing shutdown assertion flow.
---
Outside diff comments:
In `@internal/ingestion/service/ingestion_service.go`:
- Around line 213-222: The redelivery branch in the task-processing flow must
not acknowledge a duplicate while the original worker is still active. Replace
the handle.Ack call within the !e.claimTask(task.ID) path with logic that
extends the message acknowledgment deadline, while preserving the warning and
early return; add a regression test verifying the duplicate handle is not
acknowledged.
In `@internal/ingestion/service/progress_sink_test.go`:
- Around line 67-96: Replace TestProgressSink_DocService_NoDataRace with a
focused assertion that newProgressSink constructs a non-nil sink.docSvc eagerly.
Remove the goroutine, synchronization, database setup, and race-oriented
comments, while preserving the use of newProgressSink and asserting its
DocumentService dependency is non-nil.
---
Nitpick comments:
In `@internal/ingestion/task/real_consumer_test.go`:
- Around line 104-162: Replace the manual lifecycle simulation in the test with
coverage that drives the owning Ingestor processMessage path, including
claim/complete handling and message settlement. If that path cannot be exercised
here, rename the test to describe PipelineExecutor integration only, remove the
“Mirrors Start()” and consumer lifecycle assertions, and keep the setup focused
on PipelineExecutor.Execute.
🪄 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
Run ID: 908e1306-b487-46aa-9ae3-43f4d7fbbbce
📒 Files selected for processing (24)
cmd/ragflow_server.gointernal/entity/ingestion_task.gointernal/ingestion/component/tokenizer.gointernal/ingestion/component/tokenizer_test.gointernal/ingestion/pipeline/pipeline.gointernal/ingestion/pipeline/pipeline_test.gointernal/ingestion/service/execute_task_test.gointernal/ingestion/service/ingestion_service.gointernal/ingestion/service/ingestor_lifecycle_test.gointernal/ingestion/service/process_message_test.gointernal/ingestion/service/progress_sink.gointernal/ingestion/service/progress_sink_test.gointernal/ingestion/service/real_consumer_pipeline_test.gointernal/ingestion/service/run_task_test.gointernal/ingestion/task/embedder.gointernal/ingestion/task/pipeline_e2e_test.gointernal/ingestion/task/pipeline_executor.gointernal/ingestion/task/pipeline_executor_test.gointernal/ingestion/task/real_consumer_test.gointernal/ingestion/task/task_context_test.gointernal/ingestion/task/task_handler.gointernal/ingestion/task/task_handler_test.gointernal/service/ingestion_task_service.gointernal/service/ingestion_task_service_test.go
💤 Files with no reviewable changes (2)
- internal/ingestion/task/task_handler.go
- internal/ingestion/task/task_handler_test.go
| done := make(chan struct{}) | ||
| go func() { | ||
| ingestor.Stop() | ||
| ingestor.Stop(context.Background()) |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
Use a deadline-bearing context as required by Stop.
context.Background() violates the method’s documented caller contract. Give the context a timeout so this test also exercises the supported shutdown path and cannot leak Stop indefinitely.
go func() {
- ingestor.Stop(context.Background())
+ ctx, cancel := context.WithTimeout(context.Background(), 4*time.Second)
+ defer cancel()
+ ingestor.Stop(ctx)
close(done)
}()📝 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.
| ingestor.Stop(context.Background()) | |
| go func() { | |
| ctx, cancel := context.WithTimeout(context.Background(), 4*time.Second) | |
| defer cancel() | |
| ingestor.Stop(ctx) | |
| close(done) | |
| }() |
🤖 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/service/ingestor_lifecycle_test.go` at line 75, Update the
ingestor.Stop call in the lifecycle test to pass a deadline-bearing context
created with an appropriate timeout instead of context.Background(). Ensure the
context is canceled or otherwise cleaned up after the test, while preserving the
existing shutdown assertion flow.
|
@JinHai-CN @yingfeng @yuzhichang Please help to review. |
Summary