Skip to content

fix(tracking): stop making a watched run sit through the ghost thresholds - #761

Merged
gkhngyk merged 1 commit into
mainfrom
fix/cloro-drain-interactive-tail
Aug 21, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
fix/cloro-drain-interactive-tail

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Summary

A brand's first analysis is started from the UI, and its progress bar stays on screen for as long as the drain loop polls. A run measured in production delivered all 292 of its results in four and a half minutes, then held the bar at 292/294 for another forty — waiting on two google-aio tasks that were never going to call back, which is what that scraper does whenever the query has no AI Overview.

This is the normal case, not an outlier. Over ten days:

Completed runs measured 184
Average time actually receiving results 14.2 min
Average time waiting after the last result 19.4 min
Worst case 56.2 min
Runs that waited >15 min on nothing 116 of 184

Every task pending in the database right now is google-aio.

Give a watched run a short tail. Once the pending set has shrunk to a negligible remainder and has not moved for about two minutes, stop waiting. Cron runs have no audience and keep the patient thresholds, so a quiet gap mid-burst still cannot cost them results — the split is source, which job-runner already sets to manual or cron and which the drain loop simply never read.

Leaving early costs the run nothing but an undercounted result_count. /cloro/callback matches a late delivery by task id and inserts the result whether or not the loop is still watching for it. MIN_STAMP_RATIO is 0.5, so a run at 99% still stamps and the dashboard still anchors.

The remainder has a floor of three rather than being a pure percentage: a single-prompt refresh submits about seven tasks, and 5% of that rounds to one, so a lone ghost would still hold the run open.

A second problem found while verifying this

The measured run did not exit at the 25-minute stall cap or the 30-minute ghost age. It was still polling at 44 minutes with its pending set untouched since minute five.

Both exits sit below this guard:

if (firstResultAt === null) { await sleep; continue; }

When the "delivery started" probe never succeeds, execution never reaches either branch, and the 90-minute first-result budget becomes the only way out.

So this PR tracks whether the pending set moved above that guard, and the tail rule reads that counter instead of the probe. A pending set that has shrunk to a handful is evidence enough that nothing is left worth waiting for, whether those tasks resolved as results, failures or empty responses. stalledPolls keeps its original semantics exactly, so cron behaviour is unchanged.

Why the probe fails is unresolved. It is left alone here rather than guessed at. Cron runs still depend on it and can still wait the full 90 minutes; that wants its own investigation.

Related issue

None — reported directly.

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

Requires a server deploy.

  1. Add a brand and let its first analysis run. When the last few platform checks stop responding, the run now finishes about two minutes later instead of holding the bar for twenty-five to forty.
  2. While the tail drains, the banner reads "Finishing up — N platform check(s) haven't responded" rather than "N task(s) still processing".
  3. The drain's closing log line carries exitReason: 'tail' and pendingAtExit, at info level — 'tail' is an ordinary ending, not a warning.
  4. A nightly cron run is unaffected: same thresholds, same exit reasons as before.

Five tests cover the new helpers, including the measured case (2 of 294 outstanding, two minutes of quiet), the floor that keeps a seven-task run from being held open by one ghost, and the refusal to give up while a meaningful share of the run is still outstanding.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • yarn lint passes (run from server/)
  • yarn format:check passes (run from server/)
  • yarn test passes (run from server/) — 362 tests
  • Changes are focused — one concern per PR

…olds

A brand's first analysis is started from the UI and its progress bar stays on
screen for as long as the drain loop polls. One measured run delivered all 292
of its results in four and a half minutes, then held the bar two tasks short of
the total for another forty — waiting on two google-aio tasks that were never
going to call back, which is what that scraper does whenever the query has no
AI Overview. Across ten days, runs averaged 19 minutes waiting on ghosts
against 14 minutes actually receiving results, and 116 of 184 spent more than
15 minutes waiting on nothing.

Give a watched run a short tail: once the pending set has shrunk to a
negligible remainder and has not moved for about two minutes, stop waiting.
Cron runs have no audience and keep the patient thresholds, so a quiet gap
mid-burst still cannot cost them results.

Leaving early costs the run nothing but an undercounted result_count.
/cloro/callback matches a late delivery by task id and inserts the result
whether or not the loop is still watching for it.

The remainder has a floor of three rather than being a pure percentage: a
single-prompt refresh submits about seven tasks, and five per cent of that
rounds to one, so a lone ghost would still hold the run open.

Track whether the pending set moved above the first-result guard rather than
below it. That guard can hold a run indefinitely when the delivery probe never
succeeds — the measured run sat there past both the stall cap and the ghost
age, exiting on neither because execution never reached them, leaving the
90-minute first-result budget as its only way out. The tail must not depend on
that probe: a pending set that has shrunk to a handful is evidence enough that
nothing is left worth waiting for, whether those tasks resolved as results,
failures or empty responses. Why the probe fails is unresolved and still
affects cron runs.

Also say what is happening while the tail drains. "2 task(s) still processing"
on a bar that has not moved in minutes reads as a hang.
@gkhngyk
gkhngyk merged commit d8e6a95 into main Aug 21, 2026
6 checks passed
@gkhngyk gkhngyk mentioned this pull request Aug 24, 2026
7 of 12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant