fix(tasks): resolve files stuck in Pending status despite completed processing

The status calculation required ALL steps to be explicitly marked as
success/skipped before a file could be "completed". This failed for
dynamic pipelines where:

1. check_for_duplicates was logged before the file record existed (no
   file_id), so its FileProcessingStep was never updated from "pending"
2. extract_text was not marked as "skipped" for non-PDF files that go
   through PDF conversion first

Fix:
- Move check_for_duplicates success log to after initialize_file_steps()
  with the correct file_id so the step actually gets updated
- Mark extract_text as "skipped" for non-PDF files
- Add terminal-step fallback: if send_to_all_destinations is "success",
  the file is "completed" even if intermediate steps remain "pending"
  (handles any other dynamic pipeline edge cases)

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-02-27 16:38:10 +00:00
parent f641264dd2
commit 2c55f076be
5 changed files with 159 additions and 17 deletions
+19 -7
View File
@@ -183,13 +183,6 @@ def process_document(
# Not a duplicate (or deduplication disabled) -> insert a new record
logger.info(f"[{task_id}] Creating new file record in database")
if settings.enable_deduplication and settings.show_deduplication_step:
log_task_progress(
task_id,
"check_for_duplicates",
"success",
"New file - no duplicates found",
)
log_task_progress(task_id, "create_file_record", "in_progress", "Creating file record")
new_record = FileRecord(
filehash=filehash,
@@ -213,6 +206,17 @@ def process_document(
f"File record ID: {new_record.id}",
file_id=new_record.id,
)
# Update the check_for_duplicates step now that file_id is available.
# This must happen after initialize_file_steps() which creates the
# step as "pending". The dedup check already passed at this point.
if settings.enable_deduplication:
log_task_progress(
task_id,
"check_for_duplicates",
"success",
"New file - no duplicates found",
file_id=new_record.id,
)
# 1. Generate a UUID-based filename for storage
file_ext = os.path.splitext(original_local_file)[1]
@@ -330,6 +334,14 @@ def process_document(
"Non-PDF file detected, converting to PDF",
file_id=file_id,
)
# Mark local text extraction as skipped since the file needs PDF conversion first
log_task_progress(
task_id,
"extract_text",
"skipped",
"Non-PDF file, text extraction deferred to OCR after conversion",
file_id=file_id,
)
log_task_progress(
task_id,
"process_document",