Repository navigation
Description
Description
The scraper drain loop in server/src/workers/tracking-worker.js has a hard 60-minute drainDeadline. When the provider's first delivery lands later than that, the run is abandoned with zero results: the tracking_runs row is deleted by the partial-run guard, the results arrive minutes later with no run to belong to, and the dashboard's 24h window stays anchored to the previous day.
Observed in production this morning for one large brand (~1.8k tasks):
| event | time (local) |
|---|---|
| tracking job created | 05:02 |
| drain deadline reached, job completed | 06:04 |
| first scraper result inserted | 06:09 |
| last scraper result inserted | 06:42 |
1778 results landed — all of them after the worker had given up. At stamp time the run's result count was 0, so tracking_runs dropped the row entirely ("tracking run produced no results — row removed"). The day therefore has no stamped run for that brand even though the data is in prompt_results.
Knock-on effects:
- The Insights 24h window still resolves to the previous day's run, so the dashboard shows yesterday's numbers.
- The end-of-run pulse still fires (
job-runner.jsdoes not check whether the run was stamped), and it computes from the stale anchor — see the duplicate-pulse issue.
The 60-minute cap was sized when the queue drained faster. Delivery latency for the largest brands is now at or past it, so the cap fires on healthy runs rather than on stuck ones — the exact failure mode CLORO_STALL_POLL_LIMIT and the ghost-task exit from #690 were added to avoid.
Steps to reproduce
- Run a daily tracking job for a brand large enough that the provider's first callback arrives more than 60 minutes after submission.
- Watch the worker exit at
drainDeadlinewithpending == expectedSubmitted. - Observe that
tracking_runshas no row for the run, whileprompt_resultsfills up shortly afterwards.
Expected behavior
A run whose results are merely slow should still be stamped once they land, and the deadline should protect against a genuinely stuck queue, not against normal latency.
Actual behavior
The run is discarded before its first result arrives; the results become orphaned relative to the run ledger and the dashboard/pulse window does not advance.
Deployment mode
Cloud (ansvisor.com)
Environment
Server (Node), production daily cycle.
Proposed fix
Options, roughly in order of preference:
- Make the deadline start counting from first delivery, not from submission. The stall/ghost exits already cover "nothing is coming"; the absolute cap only needs to bound the tail. A brand that has received nothing yet should be governed by the stall and ghost-age exits, which have their own bounds.
- Raise the cap and make it configurable (e.g.
CLORO_DRAIN_DEADLINE_MIN, default 90) so it can be tuned per deployment without a code change — consistent withCLORO_STALL_POLL_LIMIT/CLORO_GHOST_STALL_POLLS. - Log the exit reason explicitly (deadline / stall / ghost / drained) so a run that ends on the deadline is distinguishable in the logs without reconstructing timings from the database.
Worth deciding separately: should the end-of-run pulse fire at all when the run was not stamped? Today it does, and it necessarily reports a stale window.
Relevant code:
- https://github.com/ansvisor/ansvisor/blob/main/server/src/workers/tracking-worker.js
- https://github.com/ansvisor/ansvisor/blob/main/server/src/lib/job-runner.js
- https://github.com/ansvisor/ansvisor/blob/main/server/.env.example
Activity
fix(tracking): stop discarding runs whose first result lands late (#710)