fix(knowledge): unstick summary and isolate manual re-index trace attempts
Manually uploaded text documents could get stuck showing "generating summary" forever, and editing/re-saving a document mixed its trace into the previous attempt. Three related fixes: 1. finalizeIndexedKnowledgeState no longer marks a text document completed the moment chunks are indexed. Doing so made KnowledgePostProcess hit its non-processing guard and skip the summary/question/graph fan-out, stranding summary_status on "pending". The row now stays "processing" (still retrievable via enable_status=enabled) and post-process remains the sole authority that drives processing -> finalizing -> completed. 2. ProcessManualUpdate now allocates a fresh span-tracking attempt via OpenAttempt. Previously it ran with attempt 0, so processChunks dropped every stage span and KnowledgePostProcess fell back to LatestAttempt, piling the new run's summary/wiki subspans onto the prior attempt's trace. 3. Enrichment workers (summary, question, graph extract) skip when a newer attempt has superseded theirs. A stale subtask from a previous upload/edit/reparse must not read deleted chunks or decrement the new attempt's pending_subtasks_count, which would race-promote the row to completed before the new attempt finishes. Updated TestFinalizeIndexedKnowledgeState to expect the deferred completion for text documents.
This commit is contained in:
@@ -169,6 +169,20 @@ func attemptFromCtx(ctx context.Context) int {
|
||||
return 0
|
||||
}
|
||||
|
||||
// attemptSuperseded reports whether a newer parse attempt has started for the
|
||||
// knowledge since this enrichment subtask was enqueued. Stale subtasks from a
|
||||
// previous upload/edit/reparse that is still draining must NOT touch the new
|
||||
// attempt's chunks or decrement its pending_subtasks_count — doing so would
|
||||
// race-promote the row to completed before the new attempt finishes. An attempt
|
||||
// of 0 predates attempt tracking (or tracking is disabled) and is never treated
|
||||
// as superseded.
|
||||
func attemptSuperseded(ctx context.Context, tracker SpanTracker, knowledgeID string, attempt int) bool {
|
||||
if attempt <= 0 || knowledgeID == "" {
|
||||
return false
|
||||
}
|
||||
return tracker.LatestAttempt(ctx, knowledgeID) > attempt
|
||||
}
|
||||
|
||||
// beginStage / endStage / failStage / skipStage are the by-name shims
|
||||
// the pipeline uses so call sites don't have to thread *Span values
|
||||
// through the existing function signatures. Each helper looks up the
|
||||
|
||||
Reference in New Issue
Block a user