Skip to content

bug: tracking run is discarded when the scraper's first delivery lands after the 60-minute drain deadline #702

Closed

Description

@gkhngyk

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.js does 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

  1. Run a daily tracking job for a brand large enough that the provider's first callback arrives more than 60 minutes after submission.
  2. Watch the worker exit at drainDeadline with pending == expectedSubmitted.
  3. Observe that tracking_runs has no row for the run, while prompt_results fills 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:

  1. 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.
  2. 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 with CLORO_STALL_POLL_LIMIT / CLORO_GHOST_STALL_POLLS.
  3. 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:

Related: #687, #690, #649.

Activity

  1. added
    bug
    on Aug 11, 2026
  2. self-assigned this
    on Aug 11, 2026
  3. added a commit that references this issue on Aug 12, 2026
    e502569
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions