Repository navigation
fix(tracking): stop progress bar freezing on webhook-mode runs - #279
Merged
Merged
Conversation
The webhook-mode drain loop counted every cloro_pending_tasks row for the brand, not just the task_ids the current run submitted. Tasks Cloro never delivered a webhook for are never cleaned up, so they accumulate as orphan rows (observed: rows 9-28 days old). A brand-wide count is therefore poisoned by those orphans (and by concurrent runs): it never reaches zero, the loop runs to its 60-minute deadline, and the progress bar freezes partway even though real results keep landing via the callback — so a refresh shows the saved results while the banner looked stuck. Larger brands (~45-minute runs, more tasks) hit this most. - Drain loop now counts only this run's own task_ids (brand-scoped read intersected in memory, so no oversized .in(...) URL), and gives up early if delivery stalls for ~10 min instead of holding a worker for the full hour. - Add cleanupStalePendingTasks() to sweep orphan rows older than 2h; run it at startup and from runDailyTracking (covers both cloud and self-hosted). - Bump the client's saved-job TTL 10m -> 60m so the progress banner survives a refresh during a legitimately long run.
There was a problem hiding this comment.
Pull request overview
Fixes webhook-mode tracking runs where the insights progress banner could freeze due to counting brand-wide cloro_pending_tasks (including orphans / concurrent runs) instead of tasks submitted by the current job, and adds cleanup/TTL adjustments to make long runs more resilient.
Changes:
- Scope the webhook-mode drain loop to the current run’s submitted
task_ids and add a stall guard to stop holding a worker for up to an hour. - Add a periodic orphan sweep (
cleanupStalePendingTasks()) for oldcloro_pending_tasksrows (startup + daily tracking). - Extend the client-side stored tracking job TTL from 10 minutes to 60 minutes to survive refreshes during long runs.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| web/src/lib/tracking-job-store.ts | Extends localStorage TTL for restoring the progress banner during long runs. |
| server/src/workers/tracking-worker.js | Fixes drain-loop counting to be job-scoped and adds an early stall cutoff. |
| server/src/server.js | Invokes stale pending-task cleanup at startup and before daily tracking runs. |
| server/src/lib/job-manager.js | Adds cleanupStalePendingTasks() to delete orphaned pending-task rows. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…-only cleanup
- Drain loop: a transient cloro_pending_tasks read error no longer counts as
zero pending (which would end the run early and report it complete while
tasks are still in flight). Skip the tick and retry on the next poll.
- cleanupStalePendingTasks: use delete({ count: 'exact' }) instead of selecting
every deleted task_id just to log the total.
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.
Summary
The analysis progress bar (insights page loading banner) could freeze partway
on webhook-mode tracking runs while results kept arriving in the background —
refreshing the page then showed the saved results. Most visible on large brands
whose runs take ~45 minutes.
Root cause is in the webhook-mode drain loop in
tracking-worker.js. Whilewaiting for Cloro to push results, it counted every
cloro_pending_tasksrow for the brand:
Tasks Cloro never delivers a webhook for are never cleaned up, so they pile up
as orphan rows (found rows 9–28 days old in production). A brand-wide count is
poisoned by those orphans (and by concurrent runs): it never reaches zero, the
loop runs to its 60-minute deadline, and
processed = expected - pendingplateaus below the real value — the bar freezes. The
/cloro/callbackhandlerkeeps inserting the genuine results into
prompt_resultsindependently, whichis why a refresh shows them.
Changes
task_ids this run submitted.Brand-scoped read (a handful of rows) intersected in memory with the run's own
ids, avoiding an oversized
.in(...)URL. The loop now finishes as soon asthis run's results are in.
a worker (and a concurrency slot) for the full hour when Cloro drops tasks.
cleanupStalePendingTasks()deletes pending rows olderthan 2h (well past the 60-min drain deadline). Runs at startup and from
runDailyTracking, so it covers both cloud and self-hosted.tracking-job-store.tsfrom10 min to 60 min so the progress banner survives a refresh during a long run.
Related issue
None — production bug fix (frozen progress bar / orphaned pending tasks).
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
CLORO_WEBHOOK_URLset).cloro_pending_tasksolder than 2h; after a server restart / daily run it is swept and no longer affects future runs' counts.Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)