Skip to content

Auto-refresh cost panels every 2s - #47

Merged
aakri0 merged 1 commit into
mainfrom
fix/cost-auto-refresh
May 1, 2026
Merged

Auto-refresh cost panels every 2s#47
aakri0 merged 1 commit into
mainfrom
fix/cost-auto-refresh

Conversation

@aakri0

@aakri0 aakri0 commented May 1, 2026

Copy link
Copy Markdown
Owner

Why

The 2-second refreshAll() ticked stats and the Invocations table but not the cost strip. Burst submissions especially: the user watched 50 rows appear in the table while Last 30 days stayed frozen at the pre-burst value until they reloaded. Single submits had the same issue if focus drifted before pollResult's terminal hook fired.

Fix

  • refreshAll() now also calls refreshUsageTotal() every tick, so the strip's Last 30 days + jobs-counted always reflect the current state.
  • When the #cost tab is the active view, refreshAll() also calls refreshCostPage() so the rate table + by-status breakdown stays in sync.
  • The immediate calls in onSubmit / onBurst / clearFinishedJobs stay — they give a snappy 0-latency update on user action; the periodic tick handles everything afterwards.

Verified

  • API: ran a 2s sleep job. /usage/cost returned 4 jobs → 5 jobs ($5.118e-5 → $7.918e-5) within seconds of completion. With the new JS, the strip picks that up on the next 2s tick.

app.js?v=18.

The 2-second periodic refreshAll() ticked stats and the jobs table but
not the cost strip. Burst submissions, in particular, finished in the
background and the user watched 50 rows appear in the table while the
'Last 30 days' total stayed frozen at the pre-submit value until they
reloaded. Single submits had the same issue if focus drifted before
pollResult's terminal hook fired.

Hook refreshUsageTotal() into refreshAll() so the cost strip ticks on
the same 2s cadence as everything else. When the dedicated #cost tab is
visible, also refresh the rate table + by-status breakdown so the
deeper view stays in sync.

Verified live: total grew 4 -> 5 jobs ($5.118e-5 -> $7.918e-5) within
seconds of a single submit completing, with no manual refresh.

Bumped app.js?v=18.
@aakri0
aakri0 merged commit 5aa6413 into main May 1, 2026
3 checks passed
@aakri0
aakri0 deleted the fix/cost-auto-refresh branch May 1, 2026 23:00
aakri0 added a commit that referenced this pull request May 2, 2026
…resh (#48)

Two related cost-strip gaps from #47:

1. Invoke ×50 (load test) updated 'Last 30 days' (because refreshAll
   ticks /usage/cost) but Estimated max and Actual stayed at —. onBurst
   skipped renderEstimate and pollResult — the strip's first two cells
   were single-submit-only.

2. After a hard refresh the JS state was empty, so all cells started at
   '—'. The Last 30 days panel filled in within 2s, but Estimated and
   Actual had no source until the user submitted again.

Fixes:

onBurst now:
  - calls fetchEstimate(body) -> renderEstimate so Estimated max
    populates immediately with the per-job number (the aggregate lives
    in Last 30 days where it belongs);
  - clears the actual cell, then awaits all 50 submits, picks the first
    job_id and pollResult()s it so Actual ticks live for one
    representative — same UX as a single submit.

New hydrateCostStripFromJobs() + computeEstimateLocal():
  - On every refreshAll tick, if the strip is empty AND the user hasn't
    just submitted (lastInvokeAt < 30s), pick the most recent terminal
    job from /jobs and:
      * render its cost as Actual,
      * reconstruct its worst-case estimate locally using the rates we
        cache from /usage/cost.pricing.
  - Active flows take priority via state.lastInvokeAt set in onSubmit
    and onBurst, so an in-flight pollResult never gets clobbered.

The estimate reconstruction matches api/pricing.estimate_max_cost
exactly (same formula, same per-attempt accounting, same network
treatment) and uses the rate card already on /usage/cost so a single
source of truth stays.

Bumped app.js?v=19.
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