Repository navigation
fix(ingestor): dedup memory-task redelivery to prevent duplicate extraction - #8
Closed
xugangqiang wants to merge 1 commit into
Closed
xugangqiang wants to merge 1 commit into
xugangqiang wants to merge 1 commit into
Conversation
processMessage now applies the same claim-based dedup guard to memory tasks that it already applies to ingestion tasks. A redelivered memory message (same TaskID) is ack-skipped instead of being dispatched to the worker a second time, which previously duplicated the extraction. The claim is released by executeMemoryTask on settle, mirroring executeTask. Tests: - TestProcessMessage_DuplicateIngestionDeliveryAckSkips drives the redelivery/claim path the burst test cannot reach (its simulated broker only redelivers on Nack, and the fixed code never Nacks). It injects a second delivery of the same taskID while the first is in flight and asserts the duplicate is ack-skipped and the task executes exactly once. - TestProcessMessage_DuplicateMemoryDeliveryAckSkips verifies the new memory-branch dedup claim.
Owner
Author
|
Superseded by the upstream PR on infiniflow/ragflow (head xugangqiang:fix/memory-task-redelivery-dedup, base main). |
xugangqiang
added a commit
that referenced
this pull request
Oct 30, 2026
- prefer worker-claim time (doc.ProcessBeginAt) for wait duration (#2) - omit zero-value times from the JSON log line instead of emitting 0001-01-01, and guard the logger with atomic.Pointer for a safe swap (#8, #7) - populate DurationMS from ParseDurationS so consumers need not recompute (#11) - drop the unused IngestLog.Code field (#Nit) - thread the failure reason through MarkFailed into the emitted event's ErrorInfo, so failed runs are no longer logged with an empty reason (#4) - persist process_end_at idempotently (WHERE process_end_at IS NULL) so overlapping terminal events cannot rewrite the recorded completion instant (#12) All changes covered by unit tests in internal/common, internal/observability and internal/service.
xugangqiang
added a commit
that referenced
this pull request
Nov 2, 2026
- prefer worker-claim time (doc.ProcessBeginAt) for wait duration (#2) - omit zero-value times from the JSON log line instead of emitting 0001-01-01, and guard the logger with atomic.Pointer for a safe swap (#8, #7) - populate DurationMS from ParseDurationS so consumers need not recompute (#11) - drop the unused IngestLog.Code field (#Nit) - thread the failure reason through MarkFailed into the emitted event's ErrorInfo, so failed runs are no longer logged with an empty reason (#4) - persist process_end_at idempotently (WHERE process_end_at IS NULL) so overlapping terminal events cannot rewrite the recorded completion instant (#12) - emit the running lifecycle event from PrepareValidatedRun AFTER the worker-claim time is stamped, so BeginTime and wait_duration_s reflect this run instead of a zero or previous-run value (#A) - only emit user_name when set, so the always-empty key is not logged and the JSON field uses omitempty (#C) - correct the ingestor.log sink docs: it always writes to stdout; ingestor.log.path only adds an optional rotated file on top (#B) - drop the redundant SetIngestLog/SyncIngestLog calls from admin and syncer, which never emit ingestion events (#D) All changes covered by unit tests in internal/common, internal/observability and internal/service.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Memory-extraction tasks share the
tasks.RAGFLOWNATS consumer and the ingestor worker pool with ingestion tasks, but they do not use the ingestion state machine (noingestion_taskrow).processMessage's memory branch therefore lacked theclaimTaskdedup guard that the ingestion branch has.Under a NATS redelivery — an
AckWaittimeout while a slow LLM extraction is running, or an ingestor restart — a redelivered memory message was dispatched to the worker again, because nothing rejected the second transition. This double-executed the extraction:extractByLLMcall (extra LLM token cost), andembedAndSaveMessages→InsertChunks, producing duplicate extracted memory entries in the store.The blocking send introduced by the backpressure fix (PR infiniflow#18369) made this race reachable: a redelivery arriving while the first run is still in flight has no guard and is scheduled a second time.
Correct behavior
A redelivered memory task that is already being processed must be
ack-skipped, never re-executed. The in-flight claim must be released when the worker settles the task (so a later genuine redelivery can retry) and on shutdown (so the broker redelivers after restart).Fix
In
processMessage's memory branch:claimTask(taskID)guard before enqueuing; on conflictack-skip the duplicate;ctx.Done()(shutdown) path so the broker redelivers the task after restart instead of blocking the consume loop;executeMemoryTaskviadefer e.releaseTask(taskID)once the worker settles, mirroringexecuteTask.This makes the memory branch symmetric with the ingestion branch's dedup handling.
Tests
TestProcessMessage_DuplicateMemoryDeliveryAckSkips: delivers the same memoryTaskIDtwice (worker pool not started, so the claim is held in the channel) and asserts the second delivery isack-skipped with no second enqueue.TestProcessMessage_DuplicateIngestionDeliveryAckSkips: asserts the same guarantee for the ingestion branch (injected duplicate delivery →ack-skip, exactly one execution, exactly oneCOMPLETEDrow).Dependency
Stacks on infiniflow#18369 (ingestion backpressure fix), which converted the memory branch to a blocking send and established the in-flight
claimTask/releaseTaskpattern this PR reuses. Merge infiniflow#18369 first.