Repository navigation
Feature: user select pipeline support - #16788
Conversation
1. e2e - execute pipeline to parse pdf file and save chunks to ES 2. chunks can be retrieved for using in chat
📝 WalkthroughWalkthroughThe PR migrates document ingestion toward ChangesIngestionTask/MQ migration
Hybrid proxy routing
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant DocumentService
participant IngestionTaskDAO
participant MQEngine
participant TaskHandler
Client->>DocumentService: Ingest document
DocumentService->>IngestionTaskDAO: CheckAndCreate ingestion task
DocumentService->>MQEngine: Publish tasks.RAGFLOW message
MQEngine->>TaskHandler: Deliver ingestion task
TaskHandler->>TaskHandler: Execute pipeline and process output
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ 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 |
b2af266 to
a8fa139
Compare
There was a problem hiding this comment.
Actionable comments posted: 4
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
internal/dao/ingestion.go (1)
260-283: 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick winDelete orphaned
IngestionTaskLogrows when deleting anIngestionTask.The method queries
IngestionTaskLogrows to collect files but never deletes them within the transaction. After the parentIngestionTaskis deleted, these log rows become orphaned with a danglingtask_idforeign key. TheIngestionTaskLogentity has no cascade-delete GORM tag, so logs accumulate indefinitely.🛡️ Proposed fix
err = tx.Model(&entity.IngestionTask{}).Where("id = ?", taskID).Delete(&entity.IngestionTask{}).Error if err != nil { return nil, err } + if err = tx.Where("task_id = ?", taskID).Delete(&entity.IngestionTaskLog{}).Error; err != nil { + return nil, err + } + taskInfo := &TaskInfo{🤖 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/dao/ingestion.go` around lines 260 - 283, The delete flow in the IngestionTask cleanup path collects `IngestionTaskLog` records but never removes them, leaving orphaned logs after `IngestionTask` deletion. Update the transaction in the same method that queries `taskLogs` and deletes `entity.IngestionTask` to also delete matching `IngestionTaskLog` rows for the same `taskID` before or alongside the parent delete, ensuring the cleanup stays atomic and no dangling `task_id` rows remain.
🧹 Nitpick comments (3)
internal/service/document.go (2)
1446-1451: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winRemove or improve debug-style log statements.
The dash-prefixed messages (
"-----------------go side, before/after insert document") look like temporary development artifacts. They lack structured context (e.g.,docID) and add noise to every ingest request. Either remove them or include the document ID for production usefulness.♻️ Proposed fix
- common.Info("-----------------go side, before insert document") if _, err := s.IngestDocuments(doc.KbID, userID, []string{doc.ID}); err != nil { common.Error(fmt.Sprintf("go side, doc %s, IngestDocuments", docID), err) return common.CodeExceptionError, err } - common.Info("-----------------go side, after insert document")🤖 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.go` around lines 1446 - 1451, Remove the temporary dash-prefixed debug logs around the document ingest flow in the document insert path, or replace them with production-appropriate structured logs that include useful context like docID. Update the logging in the insert/ingest block near s.IngestDocuments so it no longer emits noisy “before/after insert document” messages without identifiers, and keep the error path logging as the primary signal.
729-730: 🗄️ Data Integrity & Integration | 🔵 TrivialAddress the FIXME: files from
taskInfoare not deleted.The
DeleteDAO method returnsTaskInfo.FilesToDelete, butdeleteDocumentFullonly logs a warning and skips actual file cleanup. This can lead to orphaned storage objects. Would you like me to generate an implementation that deletes these files from storage?🤖 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.go` around lines 729 - 730, The Delete flow is only logging a warning and never removing the files listed in taskInfo.FilesToDelete. Update deleteDocumentFull in document.go to actually iterate over TaskInfo.FilesToDelete and delete each referenced storage object, using the same storage cleanup path used elsewhere in the document service. Keep the existing Delete DAO behavior intact, and replace the FIXME/Warn-only handling with real cleanup tied to the taskInfo result.internal/handler/document.go (1)
1274-1275: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winRemove or improve debug-style log statements.
The dash-prefixed messages (
"---------- go side ingest request") look like temporary development artifacts. They lack structured context (e.g., userID, doc count) and fire on every ingest request. Either remove them or include meaningful fields.♻️ Proposed fix
func (h *DocumentHandler) Ingest(c *gin.Context) { - common.Info("---------- go side ingest request") - user, errorCode, errorMessage := GetUser(c)if code, err := h.documentService.Ingest(userID, &req); err != nil { common.ErrorWithCode(c, int(code), err.Error()) return } - common.Info("---------- go side ingest request completed") - common.SuccessWithData(c, true, "success")Also applies to: 1299-1300
🤖 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/handler/document.go` around lines 1274 - 1275, The debug-style log in the ingest flow is a temporary artifact and should not be emitted as a dash-prefixed message on every request. Update the logging in the ingest handler around the request entry and related ingest path to either remove these `common.Info` calls or replace them with structured logs that include meaningful context such as userID and document count, using the ingest request handling logic in `document.go` as the location reference.
🤖 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/ingestion_service.go`:
- Around line 291-298: defaultRunDocumentTask is losing cancellation/deadline
propagation because the incoming ctx is never attached to the TaskContext
returned by LoadFromIngestionTask. In ingestion_service.go, update
defaultRunDocumentTask to assign the passed-in ctx onto docTaskCtx.Ctx before
the TaskHandler uses it, so pipeline execution does not fall back to
context.Background(). Keep the fix localized to defaultRunDocumentTask and the
TaskContext setup.
In `@internal/ingestion/task/real_consumer_test.go`:
- Around line 151-154: Set a PipelineID on the seeded Knowledgebase or Document
used by LoadFromIngestionTask so TaskHandler.Handle does not pass an empty
dataflow ID into NewDataflowService. Update the test setup around the
LoadFromIngestionTask/Handle flow in real_consumer_test.go to populate
PipelineID on the task’s underlying Knowledgebase or Document, matching the
field that LoadFromIngestionTask copies.
In `@internal/service/document.go`:
- Around line 1576-1588: The ingestion flow in `CheckAndCreate`/`publishTask`
leaves an `IngestionTask` stuck in `CREATED` if `json.Marshal` or
`s.publishTask("tasks.RAGFLOW", payload)` fails, which blocks retries. Update
the task-creation path in `Document` service to clean up or roll back the newly
created task on any failure after `CheckAndCreate` succeeds, so a later retry
can create a fresh task. Use the `task` returned from `CheckAndCreate` and
ensure failures after that point do not leave an orphaned `CREATED` record.
- Around line 718-724: The document deletion flow in the code path using
GetByDocumentID is treating “no ingestion task” as a hard error, so the nil
check is never reached. Update the deletion logic around GetByDocumentID to
explicitly handle gorm.ErrRecordNotFound as a non-fatal case (or use a lookup
that returns nil without error), while still returning real DAO errors. Keep the
behavior aligned with the old taskDAO.DeleteByDocIDs path so documents without
ingestion tasks can still be deleted.
---
Outside diff comments:
In `@internal/dao/ingestion.go`:
- Around line 260-283: The delete flow in the IngestionTask cleanup path
collects `IngestionTaskLog` records but never removes them, leaving orphaned
logs after `IngestionTask` deletion. Update the transaction in the same method
that queries `taskLogs` and deletes `entity.IngestionTask` to also delete
matching `IngestionTaskLog` rows for the same `taskID` before or alongside the
parent delete, ensuring the cleanup stays atomic and no dangling `task_id` rows
remain.
---
Nitpick comments:
In `@internal/handler/document.go`:
- Around line 1274-1275: The debug-style log in the ingest flow is a temporary
artifact and should not be emitted as a dash-prefixed message on every request.
Update the logging in the ingest handler around the request entry and related
ingest path to either remove these `common.Info` calls or replace them with
structured logs that include meaningful context such as userID and document
count, using the ingest request handling logic in `document.go` as the location
reference.
In `@internal/service/document.go`:
- Around line 1446-1451: Remove the temporary dash-prefixed debug logs around
the document ingest flow in the document insert path, or replace them with
production-appropriate structured logs that include useful context like docID.
Update the logging in the insert/ingest block near s.IngestDocuments so it no
longer emits noisy “before/after insert document” messages without identifiers,
and keep the error path logging as the primary signal.
- Around line 729-730: The Delete flow is only logging a warning and never
removing the files listed in taskInfo.FilesToDelete. Update deleteDocumentFull
in document.go to actually iterate over TaskInfo.FilesToDelete and delete each
referenced storage object, using the same storage cleanup path used elsewhere in
the document service. Keep the existing Delete DAO behavior intact, and replace
the FIXME/Warn-only handling with real cleanup tied to the taskInfo result.
🪄 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: 5c1fe55e-0e7e-4159-b9c0-5e9dd5e4c04c
📒 Files selected for processing (17)
internal/admin/service.gointernal/dao/ingestion.gointernal/handler/document.gointernal/ingestion/service/execute_task_test.gointernal/ingestion/service/ingestion_service.gointernal/ingestion/service/real_consumer_dataflow_test.gointernal/ingestion/task/dataflow_e2e_test.gointernal/ingestion/task/dataflow_real_pipeline_integration_test.gointernal/ingestion/task/dataflow_service.gointernal/ingestion/task/dataflow_service_test.gointernal/ingestion/task/real_consumer_test.gointernal/ingestion/task/task_context.gointernal/ingestion/task/task_context_test.gointernal/ingestion/task/task_handler.gointernal/ingestion/task/task_handler_test.gointernal/service/document.gointernal/service/document_test.go
| tc, err := LoadFromIngestionTask(task) | ||
| if err != nil { | ||
| t.Fatalf("LoadTaskContext: %v", err) | ||
| t.Fatalf("LoadFromIngestionTask: %v", err) | ||
| } |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Check how TaskHandler.Handle uses PipelineID / dataflowID
ast-grep outline internal/ingestion/task/task_handler.go --match 'Handle|handleDataflow' --view expanded
# Search for PipelineID usage in the handler and dataflow service
rg -nC3 'PipelineID|dataflowID' internal/ingestion/task/task_handler.go internal/ingestion/task/dataflow_service.go --type=goRepository: infiniflow/ragflow
Length of output: 10361
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Inspect the test and task-loading code around the relevant lines.
ast-grep outline internal/ingestion/task/real_consumer_test.go --view expanded
ast-grep outline internal/ingestion/task/task_context.go --view expanded
ast-grep outline internal/ingestion/task/task_loader.go --view expanded
printf '\n--- real_consumer_test.go (selected lines) ---\n'
sed -n '1,220p' internal/ingestion/task/real_consumer_test.go
printf '\n--- task_context.go (selected lines) ---\n'
sed -n '1,240p' internal/ingestion/task/task_context.go
printf '\n--- task_loader.go (selected lines) ---\n'
sed -n '1,240p' internal/ingestion/task/task_loader.goRepository: infiniflow/ragflow
Length of output: 9420
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '%s\n' '--- task_handler.go ---'
cat -n internal/ingestion/task/task_handler.go
printf '\n%s\n' '--- search for task type / parser based dispatch ---'
rg -nC3 'handleDataflow|handleStandard|ParserID|TaskType|ParserType|PipelineID' internal/ingestion/task internal/entity internal/dao --type=goRepository: infiniflow/ragflow
Length of output: 42346
Set a PipelineID on the seeded KB or Document.
LoadFromIngestionTask only copies PipelineID from Document or Knowledgebase; with both empty here, TaskHandler.Handle() passes an empty dataflow ID into NewDataflowService and fails with empty dataflow id.
🤖 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 151 - 154, Set a
PipelineID on the seeded Knowledgebase or Document used by LoadFromIngestionTask
so TaskHandler.Handle does not pass an empty dataflow ID into
NewDataflowService. Update the test setup around the
LoadFromIngestionTask/Handle flow in real_consumer_test.go to populate
PipelineID on the task’s underlying Knowledgebase or Document, matching the
field that LoadFromIngestionTask copies.
| ingestionTask, err := s.ingestionTaskDAO.GetByDocumentID(docID) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if ingestionTask == nil { | ||
| return nil | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
GetByDocumentID returns an error (not nil) when no task exists — the nil check is dead code and blocks document deletion.
GetByDocumentID uses First(), which returns gorm.ErrRecordNotFound when no record is found. The if err != nil { return err } guard catches this before the if ingestionTask == nil check is ever reached. Documents without ingestion tasks (e.g., those using the legacy non-pipeline path) will fail to delete entirely. The old taskDAO.DeleteByDocIDs was a no-op when no tasks existed, so this is a regression.
🐛 Proposed fix
// Delete tasks from DB
ingestionTask, err := s.ingestionTaskDAO.GetByDocumentID(docID)
if err != nil {
- return err
- }
- if ingestionTask == nil {
- return nil
- }
- taskInfo, err := s.ingestionTaskDAO.Delete(ingestionTask.ID, &ingestionTask.UserID)
- if err != nil {
- return err
+ if !dao.IsNotFoundErr(err) {
+ return err
+ }
+ // No ingestion task for this document; proceed with deletion
+ } else {
+ taskInfo, delErr := s.ingestionTaskDAO.Delete(ingestionTask.ID, &ingestionTask.UserID)
+ if delErr != nil {
+ return delErr
+ }
+ // FIXME: need to add logic to delete files in taskInfo
+ common.Warn(fmt.Sprintf("need to delete files from taskInfo: %v", taskInfo))
}
- // FIXME: need to add logic to delete files in taskInfo
- common.Warn(fmt.Sprintf("need to delete files from taskInfo: %v", taskInfo))📝 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.
| ingestionTask, err := s.ingestionTaskDAO.GetByDocumentID(docID) | |
| if err != nil { | |
| return err | |
| } | |
| if ingestionTask == nil { | |
| return nil | |
| } | |
| ingestionTask, err := s.ingestionTaskDAO.GetByDocumentID(docID) | |
| if err != nil { | |
| if !dao.IsNotFoundErr(err) { | |
| return err | |
| } | |
| // No ingestion task for this document; proceed with deletion | |
| } else { | |
| taskInfo, delErr := s.ingestionTaskDAO.Delete(ingestionTask.ID, &ingestionTask.UserID) | |
| if delErr != nil { | |
| return delErr | |
| } | |
| // FIXME: need to add logic to delete files in taskInfo | |
| common.Warn(fmt.Sprintf("need to delete files from taskInfo: %v", taskInfo)) | |
| } |
🤖 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.go` around lines 718 - 724, The document deletion
flow in the code path using GetByDocumentID is treating “no ingestion task” as a
hard error, so the nil check is never reached. Update the deletion logic around
GetByDocumentID to explicitly handle gorm.ErrRecordNotFound as a non-fatal case
(or use a lookup that returns nil without error), while still returning real DAO
errors. Keep the behavior aligned with the old taskDAO.DeleteByDocIDs path so
documents without ingestion tasks can still be deleted.
| task, err := s.ingestionTaskDAO.CheckAndCreate(task) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| message := documentTaskMessage(task) | ||
| message["task_type"] = task.TaskType | ||
| message["kb_id"] = doc.KbID | ||
| message["tenant_id"] = kb.TenantID | ||
| message["dataflow_id"] = flowID | ||
| message["file"] = nil | ||
| if redisClient := redis.Get(); redisClient == nil || !redisClient.QueueProduct(documentParseQueueName(doc, priority), message) { | ||
| return fmt.Errorf("Can't access Redis. Please check the Redis' status.") | ||
| taskMessage := common.TaskMessage{ | ||
| TaskID: task.ID, | ||
| TaskType: common.TaskTypeIngestionTask, | ||
| } | ||
| return nil | ||
| payload, err := json.Marshal(taskMessage) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| return s.publishTask("tasks.RAGFLOW", payload) |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Orphaned IngestionTask on publish failure blocks retries.
If publishTask (or json.Marshal) fails after CheckAndCreate succeeds, the task remains in CREATED status with no message published. CheckAndCreate rejects documents with an existing CREATED task, so the user cannot retry — the document is permanently stuck.
🔒 Proposed fix: clean up task on failure
task, err := s.ingestionTaskDAO.CheckAndCreate(task)
if err != nil {
return err
}
taskMessage := common.TaskMessage{
TaskID: task.ID,
TaskType: common.TaskTypeIngestionTask,
}
payload, err := json.Marshal(taskMessage)
if err != nil {
+ _, _ = s.ingestionTaskDAO.Delete(task.ID, &task.UserID)
return err
}
- return s.publishTask("tasks.RAGFLOW", payload)
+ if err := s.publishTask("tasks.RAGFLOW", payload); err != nil {
+ _, _ = s.ingestionTaskDAO.Delete(task.ID, &task.UserID)
+ return err
+ }
+ return nil
}📝 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.
| task, err := s.ingestionTaskDAO.CheckAndCreate(task) | |
| if err != nil { | |
| return err | |
| } | |
| message := documentTaskMessage(task) | |
| message["task_type"] = task.TaskType | |
| message["kb_id"] = doc.KbID | |
| message["tenant_id"] = kb.TenantID | |
| message["dataflow_id"] = flowID | |
| message["file"] = nil | |
| if redisClient := redis.Get(); redisClient == nil || !redisClient.QueueProduct(documentParseQueueName(doc, priority), message) { | |
| return fmt.Errorf("Can't access Redis. Please check the Redis' status.") | |
| taskMessage := common.TaskMessage{ | |
| TaskID: task.ID, | |
| TaskType: common.TaskTypeIngestionTask, | |
| } | |
| return nil | |
| payload, err := json.Marshal(taskMessage) | |
| if err != nil { | |
| return err | |
| } | |
| return s.publishTask("tasks.RAGFLOW", payload) | |
| task, err := s.ingestionTaskDAO.CheckAndCreate(task) | |
| if err != nil { | |
| return err | |
| } | |
| taskMessage := common.TaskMessage{ | |
| TaskID: task.ID, | |
| TaskType: common.TaskTypeIngestionTask, | |
| } | |
| payload, err := json.Marshal(taskMessage) | |
| if err != nil { | |
| _, _ = s.ingestionTaskDAO.Delete(task.ID, &task.UserID) | |
| return err | |
| } | |
| if err := s.publishTask("tasks.RAGFLOW", payload); err != nil { | |
| _, _ = s.ingestionTaskDAO.Delete(task.ID, &task.UserID) | |
| return err | |
| } | |
| return nil |
🤖 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.go` around lines 1576 - 1588, The ingestion flow in
`CheckAndCreate`/`publishTask` leaves an `IngestionTask` stuck in `CREATED` if
`json.Marshal` or `s.publishTask("tasks.RAGFLOW", payload)` fails, which blocks
retries. Update the task-creation path in `Document` service to clean up or roll
back the newly created task on any failure after `CheckAndCreate` succeeds, so a
later retry can create a fresh task. Use the `task` returned from
`CheckAndCreate` and ensure failures after that point do not leave an orphaned
`CREATED` record.
3736514 to
df3c310
Compare
|
LGTM |
Summary
Feature: user select pipeline support