Skip to content

fix(tracking): say how the first run is going: answers saved, time left, no stale copy - #1774

Merged
gkhngyk merged 9 commits into
ansvisor:mainfrom
cihan-gyk:fix/first-tracking-progress
Oct 29, 2026
Merged

gkhngyk merged 9 commits into
ansvisor:mainfrom
cihan-gyk:fix/first-tracking-progress

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

What the tracking progress UI says during and after a run, especially the first one.

  1. "Analysis complete — 0 results saved." On the cloud, Cloro's answers arrive through /cloro/callback and never reached the worker's insertedCount, so the count was always 0.
    • settleTrackingRun now returns resultCount read from the table (or null), and the job result carries resultCount and stillArriving.
    • The toast reads "Analysis complete — N answers saved.", or "Almost done — N answers saved so far, the rest still arriving.", or just "Analysis complete." when the count is unknown.
  2. Progress kept 150 min, not 60 (TRACKING_JOB_KEEP_MS, the worker's longest first-answer wait plus the queue tail). On a first run the ledger banner says "First tracking in progress — your results appear here as soon as it finishes. You can leave this page." The "latest completed results" copy shows only when there is a previous run.
  3. Time left (lib/tracking-eta.ts, pure): from the pace of finished checks over the last 10 minutes.
    • It needs at least 1 minute and 5 checks, and it hides after 10 minutes without progress.
    • Shown as "About N min left at the current pace…" in the banner and "· about N min left" in the first-run note. Without enough data, today's copy stays.
  4. "checks", not "answers" in the Action Center's first-run note: the counter includes tasks that ended without an answer.
  5. First-run note refreshes every 12 s instead of 30 s.
  6. Copy in en.json (insights.tracking): banners, Stop, queued and active bodies, ETA bodies, the ledger banner and the toasts.

Related issue

None.

Stacked on #1773 (first-run speed), which touches the same run-settlement.js. The diff against it holds only this change.

Type of change

  • fix — Bug fix

How to test

  1. Brand Visibility › Run All: the banner, then "About N min left…" after about a minute, then a toast with the right count (or none).
  2. A new brand's first run: the Action Center note reads "N of M checks · about N min left".
  3. Lose the job in the browser during a first run: the ledger banner reads "First tracking in progress…".
  4. Unit tests:
    • tracking-eta.test.ts
    • tracking-job-store.test.ts
    • first-run-note.test.tsx
    • run-settlement.test.js

Checklist

  • Branch follows the naming convention
  • Commits follow Conventional Commits
  • Server: format, lint, 283 test files / 3,948 tests (3 skipped) pass
  • Web: lint (0 errors, 7 warnings), typecheck and build pass. Tests: 557 of 558 files; _before-publish.test.tsx failed on the focus race that test(content): wait for the dialog's first focus before opening the JSON-LD code #1753 fixes (untouched here).
  • Browser check, light and dark at 1024 px: in the next batched local test

🤖 Generated with Claude Code

cihan-gyk and others added 9 commits October 29, 2026 14:24
The first run after a payment only started when the Stripe return page
loaded. A person who closed the tab before it did had the prompts saved in
onboarding wait for the nightly run, up to a day.

The return page and the checkout.session.completed webhook now share one
helper (web/src/lib/billing/first-run.ts) that starts the first run for
the organization's first brand, after the plan alignment, and only for an
active or trialing subscription. The API keeps it to one run per checkout
(server/src/lib/first-run.js): calls for a brand are taken one at a time,
and one that finds a full run already waiting or running, or one started
since the checkout began, gets that run's id back with created: false.
The return page carries that id to the dashboard as before, and only the
caller that started the run also starts the volume analysis. A failure in
the webhook is logged and Stripe still gets its 200.

Deploy the API before the web app: an older API starts a run for every
call, so the two callers would start two.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ne run per purchase

Review follow-ups to the first run after a payment:

- A delayed payment (SEPA, for one) leaves the checkout's subscription
  incomplete, so nothing started the first run. The webhook now starts it
  on customer.subscription.updated when the status was incomplete, since
  the subscription's creation; never on renewals or other changes.
- The volume analysis starts in the API, with the run it creates
  (routes/internal-trigger-tracking.js, moved out of server.js and
  tested), not from the web app, so a caller that gives up waiting still
  gets it. The analyze-volumes endpoint had no other caller and is gone.
- The jobs read for an existing run go back to the purchase when it is
  older than 20 hours, so a return page opened again a day later finds the
  finished run instead of starting a second one.
- The first brand is the first active one: a paused brand is skipped.
- The job's flag is afterPayment, not firstRun.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The first run after a payment is the customer's first look at the
product, and three things kept it slow:

- The job queue had no order. A first run started during the nightly
  cycle waited for a free slot like any other job, and each nightly run
  holds its slot through a Cloro drain that can last an hour. The first
  run (firstRun in the job's data) now goes ahead: it may take one slot
  beyond TRACKING_CONCURRENCY (TRACKING_PRIORITY_SLOTS, default 1), checks
  for a slot every second, and regular jobs step aside while one waits.
  The recovery sweep keeps that place.
- The daily rollups take a run's days only once it stamps, so until then
  Citations, Mentions and Visibility's 7/30/90-day ranges showed nothing
  for a brand whose first run it is. A brand's first full run now
  refreshes its days as answers land, at most every 2 minutes and one
  refresh at a time, then once more before the stamp, which waits for it.
  Later runs are unchanged: their mid-run counts still never show.
- A first run that ends short of complete checked for its stamp every
  2 minutes; the stamp is what fills the Action Center. It now checks
  every 30 seconds.

No change to what is sent to Cloro or how often.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e answers

Review follow-ups to the first run's progressive rollups and queue place:

- A first run's refreshes are at least max(2 min, 5 × the last refresh's
  duration) apart, so a brand whose refresh is slow does not refresh back
  to back.
- The stamp now waits for a refresh still running itself
  (run-settlement.js, given the refresher). A run that stamps at once
  needs no refresh of its own, as the stamp's covers it; one that has to
  wait for late answers refreshes once when the wait starts, then on the
  late polls as answers land, so they show before the stamp.
- The comment on why refreshes go one at a time: the SQL functions
  already take a per-brand advisory lock; starting them one at a time
  keeps refreshes from sitting on connections while they wait for it.
- The job flag that orders the queue is afterPayment; the worker's
  firstRun (no run of the brand ever stamped) says how it differs.
- Tests: the run after a payment keeps its extra slot on a retry, the
  trigger endpoint asks for priority, the stamp waits for the refresher,
  and the worker hands a first run's refresher and 30 s poll to the stamp
  (tracking-worker.first-run.test.js).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ft, and no stale copy

Found in the first-tracking review.

- "Analysis complete — 0 results saved": on the cloud, Cloro's answers are
  stored by its webhook, never counted by the worker. The run's settlement
  now hands back the answers it counted in the table, and the job reports
  them, with whether late ones are still arriving. The toast says the
  count, "so far" while answers still arrive, or no number at all.
- The saved job was dropped after 60 minutes while the worker may wait 150
  (90 for a first answer, 60 for the rest), so a long first run lost its
  progress banner. It is kept for 150 minutes now.
- The ledger banner said "showing the latest completed results" on a first
  run, which has none; it says the results appear when it finishes.
- A rough "about N min left" from the pace the checks finish at while the
  page watches, once there is enough to go on; the general range before.
- The Action Center's first-run note counts checks, not answers (a task can
  end without one), reads again every 12 seconds instead of 30, and shows
  the time left too.
- The progress banner's and the toasts' strings move to en.json
  (insights.tracking).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Stripe doesn't order its events, so the subscription's incomplete to
active update can come before the checkout's, whose alignment then hasn't
run. Align here too before the first run starts, so it tracks only the
plan's engines.

@gkhngyk gkhngyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good. Branch take-1774 (bb2c27b) is this PR's head 2ee2366 merged with take-1773, carrying #1772's fix. It merges on main 3b7611c without conflicts.

Checked

  • Result count: resultCount now comes from the settlement's table count (webhook answers included) and falls back to insertedCount. doneMessage handles an older server (no count means "Analysis complete.").
  • ETA: a pure function with reasonable guards (1 min, 5 checks, hidden after 10 min of no progress). Hooks run before the early return.
  • Copy: every key the code uses exists in insights.tracking and actionCenter.firstRun. There is no duplicate tracking key; en.json is the only locale.
  • Keep time: 150 min matches the worker's longest first-answer wait plus the tail.
  • Embeds: none. Read-only gate: no new action or route. Migrations: none.

Follow-up (not blocking): the settlement count is every answer for the brand since the run started, so a single-prompt run that overlaps it adds to the toast's number.

Deploy: API before web is best, though the web works with either.

Tests: at the tip merged with main: tracking-eta, tracking-job-store, first-run-note, the insights page, stripe and billing (137 tests) pass; tsc is clean; eslint and prettier are clean on the touched files. Server results as in #1773.

@gkhngyk
gkhngyk merged commit 0225157 into ansvisor:main Oct 29, 2026
4 of 5 checks passed
gkhngyk added a commit that referenced this pull request Oct 30, 2026
…th Details (#1811)

The panel under the Action Center tabs took several lines while a new
brand's first tracking ran: a title, the count, a link and a paragraph.
People saw it on every section and asked for something simpler and
smaller.

- It is one line now, at most 36px: "First tracking running · 18 of 40
  checks · ~6 min left · Details". Details unfolds what was there before
  (what the run means, or that it waits for a slot, and the way to Brand
  Visibility) and folds it again. Still gone once the brand has a
  completed run.
- The run's reading moves to a hook (hooks/use-first-run.ts): one read
  loop per brand however many parts of the page show the run, so the
  Getting started steps can read the same in the next change. Same
  sources and 12 s pace as before; the time left is kept per brand.
- The count still says checks, not answers: a check can end without an
  answer (#1774).
- Help (action-center-overview) and the Action Center guide describe the
  line.

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Gökhan Geyik <[email protected]>
gkhngyk added a commit that referenced this pull request Oct 30, 2026
…ng run goes on (#1814)

* feat(action-center): show the first tracking run as one thin line, with Details

The panel under the Action Center tabs took several lines while a new
brand's first tracking ran: a title, the count, a link and a paragraph.
People saw it on every section and asked for something simpler and
smaller.

- It is one line now, at most 36px: "First tracking running · 18 of 40
  checks · ~6 min left · Details". Details unfolds what was there before
  (what the run means, or that it waits for a slot, and the way to Brand
  Visibility) and folds it again. Still gone once the brand has a
  completed run.
- The run's reading moves to a hook (hooks/use-first-run.ts): one read
  loop per brand however many parts of the page show the run, so the
  Getting started steps can read the same in the next change. Same
  sources and 12 s pace as before; the time left is kept per brand.
- The count still says checks, not answers: a check can end without an
  answer (#1774).
- Help (action-center-overview) and the Action Center guide describe the
  line.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* feat(action-center): put the steps that are ready now first while the first run goes on

A new brand's first tracking takes 30 to 65 minutes. Clicking a step or a
page that needs its data meanwhile showed an empty page or a 0, which
reads as a product that doesn't work; asking people to wait loses them.

- Getting started: while the first run goes on, the steps that need none
  of its data and aren't done (set-up steps: KPIs, competitors, topics,
  prompts, Search Console, Analytics, the snippet; and the high-value
  prompts once Search Console's suggestions are in) come first, marked
  "Ready now". The explore steps, whose pages show the first answers, say
  "Arriving now" and open their card, which says "Your first answers are
  arriving (18 of 40) · ~6 min. This fills in when tracking finishes."
  instead of opening an empty page. The act steps wait for the
  suggestions after the run, as before. Back to the usual order once
  it's done (steps.ts: needsFirstAnswers, needsTrackingData,
  firstRunOrder).
- The same message (FirstRunEmptyState, from useFirstRun) replaces
  Brand Visibility's empty state and "No results for the period" during
  the first run, and sits above the Tracked Prompts table.
- When the first run finishes: "Your first results are ready" as a
  toast, on whatever page (FirstRunReady in the dashboard layout reads
  the run there while this browser holds its job; the Action Center,
  Brand Visibility and Prompts read it anyway). The Actions page reads
  its list and steps again then, and once more 90 s later for the first
  signal pass's actions.
- Help: getting-started-steps and first-results-after-setup.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(prompts): one first-run message on Brand Visibility, ~1h, and "Arriving now" in Tracked Prompts

From the first look at the Ready now change:

- Brand Visibility said it twice during the first run: its own "First
  tracking in progress" band, and the new arriving card under it. The
  band stays alone: no empty state under it while the first run goes on
  ("Or test a single prompt" stays). Tracked Prompts keeps the card, as
  it has no band.
- Getting started's explore steps said "First answers · ~3h"; a first
  run usually takes 30 to 65 minutes, so ~1h.
- Tracked Prompts' rows said "Within 24h" under the card's "~6 min".
  While the brand's first run goes on, a new prompt's row (and a
  location column) says "Arriving now", with why on hover; without a
  first run, "Within 24h" as before.
- Help: getting-started-steps, first-results-after-setup,
  tracked-prompts and prompt-locations; the guides too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(action-center): read the first run less often with nothing going on, and not in a hidden tab

The first run's read loop now runs on Brand Visibility, Prompts and the
Action Center, which stay open for long. After five reads in a row with no
run going, read every minute instead of every 12 seconds; a run showing up
brings back the usual pace. A hidden tab reads nothing and reads at once
when it is shown again.

---------

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Gökhan Geyik <[email protected]>
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.

2 participants