Skip to content

Refactor: message processing - #16852

Merged
yingfeng merged 1 commit into
infiniflow:mainfrom
xugangqiang:feat/ingestion-refactor
Jul 13, 2026
Merged

yingfeng merged 1 commit into
infiniflow:mainfrom
xugangqiang:feat/ingestion-refactor

Conversation

@xugangqiang

@xugangqiang xugangqiang commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  1. refactor message processing
  2. delete un-used componentIndexMap
  3. unfold (delete) internal/ingestion/task/task_handler.go

@coderabbitai

coderabbitai Bot commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The ingestion refactor updates consumer redelivery and shutdown handling, terminal task settlement, direct pipeline execution, progress event persistence, tokenizer timeout configuration, and related tests.

Changes

Ingestion execution and progress refactor

Layer / File(s) Summary
Consumer lifecycle and task settlement
cmd/ragflow_server.go, internal/ingestion/service/ingestion_service.go, internal/ingestion/service/*_test.go
Ingestor processing now handles redelivery, worker tracking, terminal settlement, and context-bounded shutdown.
Progress event and persistence contract
internal/entity/ingestion_task.go, internal/ingestion/pipeline/*, internal/ingestion/service/progress_*, internal/service/ingestion_task_service*
Component indexes were removed from progress events and log rows, while cached totals drive concurrent progress aggregation.
Direct pipeline executor path
internal/ingestion/task/task_handler.go, internal/ingestion/task/*test.go, internal/ingestion/service/*test.go
Pipeline execution tests and integration simulations now invoke PipelineExecutor directly instead of TaskHandler.
Component runtime configuration and executor behavior
internal/ingestion/component/tokenizer*, internal/ingestion/task/embedder.go, internal/ingestion/task/pipeline_executor*
Tokenizer timeouts are environment-configurable, nil embedding models are rejected, and empty output handling and timing instrumentation were updated.

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related PRs

Suggested labels: ☯️ refactor

Poem

I’m a rabbit guarding the queue,
With workers that know when they’re through.
Progress hops clean,
Timeouts turn green,
And pipelines run straight as they chew.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 21.43% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 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.
Title check ✅ Passed The title is concise and matches the PR's main refactor around message processing.
Description check ✅ Passed The description includes the required Summary section and covers the main refactor points, though it is brief and light on background context.

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.

@xugangqiang xugangqiang added the ci Continue Integration label Jul 13, 2026
@xugangqiang
xugangqiang marked this pull request as ready for review July 13, 2026 06:48
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jul 13, 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 (2)
internal/ingestion/service/ingestion_service.go (1)

213-222: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Do 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 RUNNING without 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 win

Replace 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 for newProgressSink instead 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 win

Do 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 owning Ingestor path or rename this as a PipelineExecutor integration test and remove the Mirrors 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

📥 Commits

Reviewing files that changed from the base of the PR and between 2b9569f and 99a1d72.

📒 Files selected for processing (24)
  • cmd/ragflow_server.go
  • internal/entity/ingestion_task.go
  • internal/ingestion/component/tokenizer.go
  • internal/ingestion/component/tokenizer_test.go
  • internal/ingestion/pipeline/pipeline.go
  • internal/ingestion/pipeline/pipeline_test.go
  • internal/ingestion/service/execute_task_test.go
  • internal/ingestion/service/ingestion_service.go
  • internal/ingestion/service/ingestor_lifecycle_test.go
  • internal/ingestion/service/process_message_test.go
  • internal/ingestion/service/progress_sink.go
  • internal/ingestion/service/progress_sink_test.go
  • internal/ingestion/service/real_consumer_pipeline_test.go
  • internal/ingestion/service/run_task_test.go
  • internal/ingestion/task/embedder.go
  • internal/ingestion/task/pipeline_e2e_test.go
  • internal/ingestion/task/pipeline_executor.go
  • internal/ingestion/task/pipeline_executor_test.go
  • internal/ingestion/task/real_consumer_test.go
  • internal/ingestion/task/task_context_test.go
  • internal/ingestion/task/task_handler.go
  • internal/ingestion/task/task_handler_test.go
  • internal/service/ingestion_task_service.go
  • internal/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())

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.

🩺 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.

Suggested change
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.

@xugangqiang
xugangqiang marked this pull request as draft July 13, 2026 07:08
@xugangqiang
xugangqiang marked this pull request as ready for review July 13, 2026 07:08
@xugangqiang

Copy link
Copy Markdown
Contributor Author

@JinHai-CN @yingfeng @yuzhichang Please help to review.

@yingfeng
yingfeng merged commit cfacacc into infiniflow:main Jul 13, 2026
12 of 15 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Jul 15, 2026
@xugangqiang
xugangqiang deleted the feat/ingestion-refactor branch August 7, 2026 12:26
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.

2 participants