Skip to content

fix(scheduler): count a run only when it ends - #7659

Merged
kovtcharov-amd merged 2 commits into
amd:mainfrom
tylerbea:fix/7613-run-count-at-end
Nov 13, 2026
Merged

kovtcharov-amd merged 2 commits into
amd:mainfrom
tylerbea:fix/7613-run-count-at-end

Conversation

@tylerbea

@tylerbea tylerbea commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Right after Run now, a scheduled task's card showed "Runs: 1, Last: just now" while it also said "Running…" and "No executions yet", and a run that then failed had already been counted. Now the run count and "Last" change when the run ends, together with its result.

Closes #7613

Before (counted while still running) After (counted once it finishes)

Test plan

  • New test_run_is_not_counted_until_it_ends in tests/unit/test_scheduler.py (fails on main with 1 == 0), and the in-flight test now checks the count after the run
  • 231 scheduler and related unit tests; black and isort
  • Built app with a real model: Run now, and the card shows "Runs: 0" until the run ends, then "Runs: 1, Last: just now"
🔍 Technical details
  • _execute_task_once in scheduler.py used to bump run_count and last_run_at before the turn ran. They now update after it, with the other result fields; the history divider and log lines use a local run_number.
  • If the app is killed mid-run, the run is not counted. Before, it was counted in memory but never saved, so stored data is the same.
  • No after screenshot: the mid-run state needs a run that lasts long enough to capture, and the frontend is unchanged.

A task card showed 'Runs: 1, Last: just now' while the run was still going, and a run that then failed was already counted. The count and last-run time now change when the run finishes.

Closes amd#7613
@github-actions github-actions Bot added the tests Test changes label Nov 12, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Request changes

The fix is right: a schedule's run count and "Last" time no longer change at the moment a run starts. They now change when the run finishes, and a run killed mid-way isn't counted. One gap remains. The card publishes the time at the end of the run but still stamps it with the time the run started, so for any real model run it looks stale the moment it lands:

  • The "just ran" highlight never shows for a run longer than 5 seconds. That covers almost every LLM run. Before this PR the highlight showed when a run started, so a finished run now gets no highlight at all.
  • "Last" doesn't say "just now" after a run that took more than a minute. It says "2 min ago" the instant the run finishes, which isn't the outcome the PR description promises.

Stamping the finish time instead is a one-line change (suggestion below).

Real-world evidence

N/A: no evidence bundle was produced for this run. The PR shows a "before" screenshot. Its own real-app test-plan item ("Runs: 0 until the run ends, then Runs: 1, Last: just now") is still unchecked, and that is the step that would have caught the issue above. Apart from that screenshot, this verdict rests on reading the code.

🔍 Technical details

🟡 last_run_at is published at the end but still holds the start time (src/gaia/ui/scheduler.py:1657)

now is captured at the top of _execute_task_once, before the executor call. The Agent UI reads last_run_at in two places that now misfire:

  • ScheduleManager.tsx:198: justRan = Date.now() - last_run_at < 5000. For a run that takes ≥5 s, the value first appears already more than 5 s old, so just-ran never applies. Its comment says "Flash effect when a run just completed", so the intent is the finish time.
  • ScheduleManager.tsx:45 (formatTime): "just now" only when under 60 s, so the card reads "N min ago" right after a long run finishes.

Keep now for the history divider and _db_store_result, which are per-run start records, and stamp the card field with the finish time:

        task.last_run_at = datetime.now(timezone.utc).isoformat()

A test that runs the fake executor past a patched clock (or asserts last_run_at >= a timestamp taken after release.set()) would pin this.

Checked, no issue:

  • No await falls between the error_count += 1 and the new run_count assignment, so a poll can't see error_count > run_count.
  • CancelledError on shutdown leaves the run uncounted. That matches the PR's stated intent and what was persisted before.
  • No other reader of run_count/last_run_at exists in the TUI or the daemon scheduler, which has its own store. The auto-refresh effect at ScheduleManager.tsx:189 now fires once per completed run, which is an improvement.
  • Docs: no doc describes when the counter increments.

Strengths

  • The new test is genuinely red-on-main and checks the in-flight state (running, run_count == 0, last_run_at is None) as well as the settled one, including the failure path's error_count.
  • The history divider and the log lines now agree with the stored count, because both use the local run_number.

kovtcharov-amd pushed a commit to kovtcharov/gaia that referenced this pull request Nov 12, 2026
Scheduled tasks run while the user is away, but when one finished
nothing told them; only failures reached the bell. Now a run that
finishes cleanly adds an unread "Scheduled task "<name>" finished"
notification with the start of the answer. Runs that were already done
when the app opened stay quiet, and a failed run still raises only its
error.

Closes amd#7596

| Before | After |
| --- | --- |
| <img
src="https://raw.githubusercontent.com/tylerbea/gaia/pr-shots/7596/before.jpg"
width="420"> | <img
src="https://raw.githubusercontent.com/tylerbea/gaia/pr-shots/7596/after.png"
width="420"> |

## Test plan

- [x] New `stores/__tests__/scheduleStore.finished.test.ts` (3 of 5
cases fail on main), plus all store and i18n tests (192) and `npm run
build`
- [x] Built app with the schedule list stubbed to a finished run: the
bell shows 1 unread with the finished notice
- [ ] With a real model: Run now on a task, close the dialog, and see
the notice arrive when it ends

<details>
<summary>🔍 Technical details</summary>

- `scheduleStore.ts` keeps finished-run counts per schedule (`run_count`
minus a run in flight, since the backend counts a run when it starts)
and compares them on each load, the same way it already compared error
counts.
- New string `schedules.finished` in English and Arabic.
- Not in this change: clicking a bell item doesn't open its chat for any
notification type. The notice carries the chat id, so that can follow in
`NotificationCenter`.
- The after shot stubs the schedule list and setup check, because the
empty scratch home can't complete a real run.
</details>

Note: amd#7643 is the auto-fix bot's draft for the same issue. This one
adds tests and before/after shots; keep whichever you prefer. amd#7659
changes when `run_count` goes up, so whichever merges second should
recheck the finished-run count here.
@kovtcharov-amd kovtcharov-amd added bug Something isn't working agent-ui Agent UI changes labels Nov 12, 2026
The card publishes the count at the end of a run, so the time it shows
must be the finish time too. With the start time, the just-ran highlight
never showed for runs over 5 seconds and Last read minutes ago right
after a long run finished.
@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Nov 13, 2026
Merged via the queue into amd:main with commit 6bcf3b4 Nov 13, 2026
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-ui Agent UI changes bug Something isn't working tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: A scheduled run counts as done the moment it starts

2 participants