Skip to content

fix(etl): flush remaining items before totalProcessed + use ORM for completion status#2413

Merged
andrew-bierman merged 1 commit into
mainfrom
fix/etl-completion-ordering
May 13, 2026
Merged

fix(etl): flush remaining items before totalProcessed + use ORM for completion status#2413
andrew-bierman merged 1 commit into
mainfrom
fix/etl-completion-ordering

Conversation

@andrew-bierman
Copy link
Copy Markdown
Collaborator

Summary

  • Remaining-items ordering bug: totalProcessed was incremented before flushing the final valid/invalid batches. If processValidItemsBatch or processLogsBatch threw, totalProcessed showed an inflated count while totalValid/totalInvalid stayed null — making job records misleading (e.g. the May 7 EMS job: 15,975 totalProcessed, null valid/invalid). Fixed by flushing remaining items first, then updating totalProcessed.

  • Silent completion failure: the final status = 'completed' update used raw SQL with an ::etl_job_status cast that silently failed in some Neon HTTP driver versions (the inner try-catch swallowed the error). This left jobs stuck in 'running', which the reset-stuck sweep then marked as 'failed' — even though all items were successfully ingested (the "phantom failure" pattern visible as 100% successRate + status=failed). Fixed by using the same db.update().set({ status: 'completed' }) ORM pattern that already works reliably for the 'failed' path in the outer catch.

Root cause

These two bugs together explain the patterns observed in the May 7–8 ETL run:

  • Many jobs showing status: failed with successRate: 100 → phantom failures from the completion update bug
  • Jobs with high totalProcessed but null totalValid/totalInvalid → ordering bug in the remaining-items flush

Test plan

  • Trigger an ETL run for a source with a small file — verify it completes with status: completed and non-null totalValid/totalInvalid
  • Verify the admin /catalog/etl endpoint no longer shows phantom failures after successful runs

Post-Deploy Monitoring & Validation

  • What to monitor: GET /api/admin/analytics/catalog/etl — watch for jobs completing with status: completed instead of status: failed after the fix ships
  • Expected healthy behavior: ETL jobs for files that process 100% valid items should show status: completed, successRate: 100, non-null totalValid/totalInvalid
  • Failure signal: jobs still showing phantom failures (100% successRate + status=failed) → the Drizzle ORM completion update is still failing; check Neon connection logs
  • Validation window: first ETL run after deploy
  • Owner: whoever monitors the admin dashboard

Compound Engineered 🤖 Generated with Claude Code

…ORM for completion

Two bugs caused phantom failures and inflated totalProcessed counts:

1. Remaining-items ordering: totalProcessed was incremented *before* the final
   valid/invalid flushes. If processValidItemsBatch or processLogsBatch threw,
   totalProcessed showed an inflated count while totalValid/totalInvalid stayed
   null — making job records misleading and harder to diagnose on retry.
   Fixed by flushing remaining items first, then updating totalProcessed.

2. Silent completion failure: the final status='completed' update used raw SQL
   with an ::etl_job_status cast that silently failed in some Neon HTTP driver
   versions. The inner try-catch swallowed the error, leaving the job in
   'running' state so the reset-stuck sweep would mark it 'failed' even though
   all items were successfully ingested.
   Fixed by using the same db.update().set({ status: 'completed' }) pattern
   that already works reliably for the 'failed' path in the outer catch.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 13, 2026 05:54
@github-actions github-actions Bot added the api label May 13, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 13, 2026

Warning

Rate limit exceeded

@andrew-bierman has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 23 minutes and 44 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 65c2ca3f-70fe-42fe-a1d9-e93667af9ef3

📥 Commits

Reviewing files that changed from the base of the PR and between 38bb663 and c45b9e7.

📒 Files selected for processing (1)
  • packages/api/src/services/etl/processCatalogEtl.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/etl-completion-ordering

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 and usage tips.

@github-actions
Copy link
Copy Markdown
Contributor

Coverage Report for API Unit Tests Coverage (./packages/api)

Status Category Percentage Covered / Total
🔵 Lines 76.17% 502 / 659
🔵 Statements 76.17% (🎯 65%) 502 / 659
🔵 Functions 95% 38 / 40
🔵 Branches 88.67% 227 / 256
File CoverageNo changed files found.
Generated in workflow #1177 for commit c45b9e7 by the Vitest Coverage Report Action

@github-actions
Copy link
Copy Markdown
Contributor

Coverage Report for Expo Unit Tests Coverage (./apps/expo)

Status Category Percentage Covered / Total
🔵 Lines 82.61% 480 / 581
🔵 Statements 82.61% (🎯 75%) 480 / 581
🔵 Functions 92.59% 50 / 54
🔵 Branches 90.9% 170 / 187
File CoverageNo changed files found.
Generated in workflow #1177 for commit c45b9e7 by the Vitest Coverage Report Action

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes two bugs in the catalog ETL processor: (1) totalProcessed was incremented before the final batch flush so a flush failure produced inflated counts with null valid/invalid totals, and (2) the final status='completed' update used a raw-SQL enum cast that silently failed under some Neon HTTP driver versions, leaving jobs stuck and later marked as failed by the stuck-job sweep.

Changes:

  • Reorder remaining-items handling so valid/invalid batches are flushed before totalProcessed is updated.
  • Replace the raw-SQL completion update with the same Drizzle ORM update().set({ status: 'completed' }) pattern used by the failure path.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@andrew-bierman andrew-bierman merged commit 44534b1 into main May 13, 2026
14 checks passed
@andrew-bierman andrew-bierman deleted the fix/etl-completion-ordering branch May 13, 2026 05:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants