Skip to content

fix(ui): scheduled tasks run on the installed GAIA agent and show their failures - #5539

Merged
kovtcharov-amd merged 4 commits into
amd:mainfrom
kovtcharov:kalin/scheduled-tasks-on-sidecar
Oct 23, 2026
Merged

kovtcharov-amd merged 4 commits into
amd:mainfrom
kovtcharov:kalin/scheduled-tasks-on-sidecar

Conversation

@kovtcharov

@kovtcharov kovtcharov commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

On a desktop install every scheduled task failed in under a second with a "not installed" error that named an install command that didn't work, and the failure showed nowhere in the app. Scheduled runs now use the installed GAIA agent the same way chats do, and a run that fails says why on its schedule card and as a notification.

  • A relayed scheduled run starts fresh each time (no history), keeps its step cap and memory setting, and an unattended tool confirmation is denied at once instead of hanging until timeout.
  • A genuinely missing agent says to run gaia init.

Test plan

  • pytest tests/unit/chat tests/unit/chat/ui/test_scheduled_run_agent_path.py: 2174 passed
  • npx vitest run in src/gaia/apps/webui: 1529 passed
  • Live on a desktop-style install (agent runs as the daemon sidecar): a schedule with the prompt "Reply with exactly PONG" ran and recorded PONG as its result
  • Unit: a run against a missing agent stores last_error, shows it on the card and raises an error notification
  • Live, isolated GAIA home with the model server unreachable: the failed run shows on GET /api/schedules with error_count: 1 and the reason in last_error (response below)
🔍 Technical details
  • The scheduler imported the in-process flagship package, which the desktop install doesn't ship; it now chooses relay vs in-process with the same check chats use.
  • last_error is stored on the schedule and exposed by the schedules API; the app polls schedules every 30 s to raise the notification.
  • A timeout closes the relayed stream so the run stops promptly.
Failing schedule: GET /api/schedules (trimmed to the relevant fields)
{
  "schedules": [
    {
      "name": "pong-check",
      "status": "active",
      "last_run_at": "2026-10-22T19:44:54.564767+00:00",
      "run_count": 1,
      "error_count": 1,
      "last_error": "The model call failed at step 1, so this request is unfinished. Lemonade on this machine: Couldn't reach the local LLM.\n\nNothing had run yet.\n\nIt may be loading or briefly busy — try sending the message again."
    }
  ],
  "total": 1
}

The garbled dash in the message is an existing encoding issue on the model-error path, not part of this change.

…lures

On a desktop install every scheduled task failed in under a second with a
"not installed" error naming an install command that did not work: the
scheduler imported the in-process flagship package, which a desktop install
does not ship, while chats relay to the daemon-supervised sidecar binary.

- Scheduled runs now pick the agent the way chats do: relay to the flagship
  sidecar when that is how it is installed, run in process for a wheel or
  source install. The relay stays fresh per run (no history, no sidecar
  session), keeps the 5-step cap and memory setting, and a timeout closes
  the relayed stream so the run stops promptly.
- An unattended relayed run denies a tool confirmation at once instead of
  parking the sidecar until it times out, matching in-process background runs.
- A genuinely missing flagship now says to run `gaia init`.
- The last run's error is stored on the schedule, exposed as `last_error`
  by the schedules API, shown on the schedule card, and raised as an error
  notification (the app polls schedules every 30 s for this).
@github-actions github-actions Bot added documentation Documentation changes tests Test changes electron Electron app changes labels Oct 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

On a desktop install, scheduled tasks always failed because they tried to load an agent package that only wheel installs ship. They now pick the agent the same way chats do, so they reach the daemon sidecar, and a failed run shows its error on the schedule card and as a notification. I found no correctness problems. The relay path fails loudly in every case I traced: agent error, model failure, no answer, and a stop before or during the run. An unattended tool prompt is denied at once instead of waiting for the timeout.

The one gap is the evidence. The PR says a live run on a desktop-style install returned PONG, but it doesn't show that output or a screenshot of the new error line and notification. Pasting the run's result (or the GET /api/schedules response showing last_error) and a before/after screenshot of a failed schedule card would close it.

Real-world evidence

N/A: no evidence bundle was produced for this run. The verdict rests on reading the code and the new unit and vitest tests. The relay path, the schedules API and the Agent UI card/notification were not exercised here.

🔍 Technical details

Issues

🟡 Missing surface evidence: The schedule card error and the Errors-tab notification are visible in the Agent UI, and last_error is a new field on GET /api/schedules. Per the rubric, this needs a before/after screenshot of a failed schedule card, or at least the API response showing last_error. The "PONG" live run in the test plan is claimed but not shown.

🟢 Error card border uses the accent colour (ScheduleManager.css:65): the background is tinted with --danger but the left border uses --accent, so the failure line looks like an ordinary highlight.

    border-left: 2px solid var(--danger);

🟢 Relay results are read only after the turn ends (server.py, _relay_scheduled_prompt): events are drained from event_queue after _dispatch_sidecar_query returns. That's fine because the queue is unbounded (sse_handler.py:524), but a one-line comment saying so would stop someone from later bounding the queue and deadlocking scheduled relays.

Checked and fine

  • close_active_relay_response() on timeout is harmless for an in-process run, since it does nothing without a live relay response.
  • Every relay agent_error is fatal (relay.py:315,340,595), so raising on any agent_error in the scheduled relay can't mistake a recoverable tool error for a failed run.
  • notifyNewFailures keys on error_count and skips the first load. Restarts and new schedules don't re-notify, and the 30 s poll can't post duplicates (id includes the count).
  • last_error is added through _add_column, so existing DBs migrate. It is cleared on success and survives a reload, and the new test pins both.

Strengths

  • The scheduler reuses the chat path's install-kind check (_should_relay_to_sidecar / _agent_type_unknown) instead of guessing from imports, so scheduled runs and chats can't disagree about which agent runs.
  • The missing-agent message now names gaia init, the fix that actually works. The ModuleNotFoundError split still reports a real import failure (version skew) through agent_wheel_failed_message.
  • The tests cover the real install shape: a binary .installed record, no wheel, and fake sidecar events, including the deny-on-prompt and stop-before-send cases.

A scheduled run on a wheel install that could not reach the model was
recorded as a success, so its card showed no error. It now fails like a
relayed run does, and last_error carries the message.

- The flagship-runs test pins an in-process registration instead of
  depending on gaia_agent being installed, which CI's core-only install
  lacks.
- The schedule error card's border uses --danger.
- Note that the relay drain relies on the unbounded event queue.
@kovtcharov

Copy link
Copy Markdown
Contributor Author

Addressed all three: the error card's border is now red, the relay drain notes it relies on the unbounded queue, and the PR body now shows a live GET /api/schedules response with last_error set. Capturing that evidence turned up a real gap, now fixed: on a wheel install, a scheduled run whose model call failed was recorded as a success.

🔍 Technical details

Review suggestions

  • .schedule-card-error uses border-left: 2px solid var(--danger).
  • A one-line comment above the drain loop in _relay_scheduled_prompt says it is safe only because event_queue is unbounded.
  • Evidence: an Agent UI backend from this branch, with an isolated GAIA home and LEMONADE_BASE_URL pointed at a dead port, plus an every 1m schedule. The response is in the PR body.

Found while gathering evidence

  • The first live run returned error_count: 0, last_error: null, because the in-process process_query hands back a model_failed result instead of raising. _run_scheduled_prompt now raises on model_failed, which is the rule the relay path already applied through answer.failed. It is pinned by test_an_in_process_run_whose_model_failed_is_a_failed_run.

CI

  • Unit (all three OSes): test_scheduled_runs_use_the_flagship relied on the registry discovering gaia, which works on a dev box where gaia_agent is installed. CI installs only core, so the new registry check raised "not installed". The test now pins an in-process registration. I reproduced the failure locally by hiding gaia from discovery; it passes with the fix.
  • Linux Full Integration: Launchpad returned 503 Service Unavailable for ppa:lemonade-team/stable. Main's runs of the same workflow failed the same way from 18:34 to 22:36 UTC and went green at 23:06. The new push re-runs it.

Tests run locally

  • tests/unit/chat -n 4: 2174 passed. The one other test, test_issue_841_custom_python_agent_model_id_respected, patches Path.home and so fails under a GAIA_HOME override; it passes on its own without one.
  • Scheduler, schedule and flagship-run tests: 184 passed
  • webui: tsc --noEmit clean, vitest run 1529 passed
  • util/lint.py --black --isort clean

@kovtcharov

Copy link
Copy Markdown
Contributor Author

Merge note: #5538, #5539 and #5569 all touch the schedule form, so the second and third to merge need two small test updates (no product-code conflict beyond one message).

🔍 Technical details

Found while building all three together:

@kovtcharov

Copy link
Copy Markdown
Contributor Author

Ran this branch (2dabfdf) live on a v0.25.1-rc5 desktop install on a 16 GB Mac, chats on DeepSeek V4.1 Flash (Fireworks). The relay part works: a schedule created through the UI API now reaches the installed sidecar agent instead of failing with "not installed".

It still fails, though, because the scheduled run uses the local default model rather than the one the user picked: The model call failed at step 1 … Not enough free memory to load Gemma-4-E4B-it-GGUF with a 32,768-token window: it needs about 7.8 GB and only 5.0 GB is free. On any machine where the user chose a cloud model because the local default doesn't fit, every scheduled task fails this way.

Next step: run scheduled prompts on the chat's active model (the one /api/providers/active reports), the second half of #5583.

kovtcharov-amd pushed a commit that referenced this pull request Oct 23, 2026
…5610)

Four timing-sensitive unit tests failed 8 unrelated PRs this week
(#5537, #5539, #5562, #5563, #5564, #5565, #5566, #5568) and one of
main's last 11 completed runs. Each still guards the same bug, but no
longer races the clock on a busy runner. Every rewritten test was
checked by breaking the code: it fails on the real bug and passes 50/50
runs, including under full CPU load. The PR also keeps three tests out
of the developer's real `~/.gaia`.

## Test plan
- [x] `pytest tests/unit/mcp/client/test_stdio_hung_server.py
tests/unit/test_file_lock.py tests/unit/test_mcp_bridge_concurrency.py
tests/unit/chat/ui/test_agent_model_override.py
tests/integration/test_folder_indexing.py -n 4`: 316 passed, 3 skipped
- [x] The four de-flaked tests, run 50x each: 250/250 serial, and
250/250 under xdist (32 workers) with all 32 cores also running busy
loops. Main's versions in that same loaded run: redaction failed 10/50.
- [x] Each test fails when its bug is put back in the code (see details)
- [x] `tests/integration/test_folder_indexing.py -n 4`, 5 runs: all
pass. Main's version fails 7 to 9 tests per run.
- [x] Test 841 passes with `GAIA_HOME` set to a temp dir. Main's version
fails.
- [x] Electron `npx jest`: 1098 passed. The one failure,
`test_electron_chat_installer.js` (component size 103,725 > 102,400),
also fails on main and is unrelated.
- [ ] CI green on Linux, macOS and Windows unit lanes

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

**`test_redaction_stays_fast_on_dense_escapes`** (Linux, 2.01 to 2.03 s
against a 2 s limit)
- Cause: an absolute 2 s bound. Locally the worst text takes 0.19 s. On
a 4-worker, coverage-traced runner it took about 10x that.
- Fix: time one 1M-char text against eight 125K texts with the same
total length, on the same machine. Linear code scores about 1.0 and a
quadratic scan scores 8, so the test asserts < 3. It takes the best of
up to three paired runs, and uses the lower of the wall-clock and CPU
(`thread_time`) ratios. Contention inflates wall time, and Windows
samples CPU time on ticks. The test also fails if the 1M text takes more
than 15 s of CPU, which catches a per-position rescan: that is linear
but takes minutes.
- Break checks: a quadratic prefix copy in `_candidate_windows`
(`len(text[:start].rstrip("\\"))`) gives a ratio of 5.9x and the test
fails. Main's 2 s test passed that same regression locally (1.57 s). A
per-anchor rescan without merging takes 56 s and hits the 15 s ceiling.

**`test_children_of_an_exited_server_are_still_stopped`** (Linux)
- Cause: the test slept a fixed 2 s for the child watcher. The watcher
backs off (0.5, 1, 2, 4 s…), so on a slow start its next scan came after
the launcher had exited and the child was never recorded.
- Fix: poll until `child_pid in transport._children`, with a deadline of
3 × `_CHILD_SCAN_MAX_S`.
- Break checks: never recording children fails with "never recorded".
Clearing `_children` before stopping fails with "kept running". Delaying
the watcher's first scan by 2.5 s reproduces the CI failure on main's
test, and the new test passes.
- Note for the product side: a launcher that spawns a child and exits
inside a backoff window still orphans that child. Real `npx`/`uvx`
launchers outlive the window.

**`test_the_next_waiter_takes_the_lock_within_milliseconds`** (macOS,
median 6.5 to 8.1 ms against 5 ms)
- Cause: macOS stretches `sleep(0.001)` under load, and the 5 ms median
left no headroom.
- Fix: the test wraps `_poll_interval`, which records each interval and
signals the moment the waiter starts a poll's sleep. The lock is
released right then, so the whole interval stands between the waiter and
the lock.
- Assertions: every interval the front waiter asks for is ≤ 2 ms, and
the median hand-off is < 15 ms. A 20 ms poll always waits at least 20
ms, so it fails the median even with the bound widened.
- Break checks: `_NEXT_POLL_SECONDS = 0.02` or `0.1` fails the interval
assertion. Sleeping `_POLL_SECONDS` directly, so `_poll_interval` is
bypassed, fails the median (20.8 ms).

**`test_a_dropped_idle_connection_is_logged[True]`** (Linux)
- Cause: the test asserted that `"Traceback"` was absent from the stderr
captured by `capsys`. The traceback in that run came from a fake
Lemonade server that `test_lemonade_shared_server.py` left running on
the same xdist worker (`BrokenPipeError`).
- Fix: the `serve` fixture records the bridge server's own
`handle_error` calls, and the test asserts that list is empty.
socketserver calls `handle_error` before it closes the connection, so
the check doesn't race. A plugin that writes a traceback to stderr
during the test fails main's version and passes the new one.
- Break check: making `log_error` also call the base `log_error`, and
reverting `str(args[0])`, raises `TypeError` in the handler, and the
test fails.

**Isolation fixes**
- `test_folder_indexing.py`: `temp_folder` now lives in
`isolated_gaia_home`, a per-test fake home, so `ensure_within_home`
still admits it. Parallel workers no longer share or delete
`~/.gaia/test_temp`.
- `test_issue_841…`: the test now sets `GAIA_HOME` itself, so an
inherited value can't override the patched `Path.home`.
- `tests/electron/setup.js`: `os.homedir()` points at a per-file temp
dir. It is assigned rather than spied, so `jest.restoreAllMocks()` can't
undo it. Setting `HOME` would not work, because Jest's sandboxed
`process.env` never reaches `os.homedir()`.
- The "Ignoring invalid agents section in …\.gaia\tray-config.json" log
came from `crash-loop-notification.test.cjs`, which mocks `fs` with a
config the validator rejects. The real file was never read, but the path
now names the temp home.
</details>
…-on-sidecar

# Conflicts:
#	src/gaia/ui/_chat_helpers.py
A scheduled run built the agent with no model, so it ran the local
default even when the user had chosen another model, typically a cloud
one because the local default does not fit. On a 16 GB Mac every
scheduled task then failed with "not enough free memory to load
Gemma-4-E4B". Both the relayed and the in-process run now use the
user's chosen model (the custom_model setting new chats run), and fall
back to the agent's default only when none is chosen.
@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

Scheduled runs now use the model the user picked, the same one a new chat starts on, instead of the local default. That fixes the "not enough free memory to load Gemma-4-E4B" failure from the rc5 desktop run above. With no model picked they still use the agent's default.

🔍 Technical details
  • _run_scheduled_prompt and _relay_scheduled_prompt pass the custom_model setting (what /api/providers/active reports as the user's pick) as the model; a cloud id goes through the relay's existing cloud-key replay.
  • New tests pin the relayed /query body's model and the in-process config's model_id. The existing test still checks that no model is sent when the user has not picked one.
  • Merged main (one conflict in _dispatch_sidecar_query: kept both main's recording and this branch's max_steps).
  • Checks: tests/unit/chat plus the relay tests: 2260 passed. Scheduler tests: 276 passed. webui tsc --noEmit is clean, and vitest run gives 1529 passed.
  • Not re-checked live on the desktop install; worth one PONG run on a cloud model before merge.

@kovtcharov-amd
kovtcharov-amd merged commit b8b03af into amd:main Oct 23, 2026
42 checks passed
kovtcharov added a commit to kovtcharov/gaia that referenced this pull request Oct 23, 2026
amd#5634 reworded the relay's crash message to "GAIA stopped unexpectedly";
amd#5539's scheduled-run test still matched the old "ended unexpectedly".
kovtcharov-amd added a commit that referenced this pull request Oct 23, 2026
#5539 made Schedule.last_error required and #5569's fixture predates it, so
the frontend typecheck failed once both were on main.
kovtcharov-amd added a commit that referenced this pull request Oct 23, 2026
Main failed its unit tests on every OS and its frontend typecheck after
two PRs landed together: #5539 and #5634 each passed on their own. The
scheduled-run test expected "ended unexpectedly" where #5634 now says
"GAIA stopped unexpectedly while answering", and the schedule-form test
fixture lacked the `last_error` field #5539 made required. Both tests
now match the code.

## Test plan
- [x] `pytest tests/unit/chat/ui/test_scheduled_run_agent_path.py`: 15
passed (was 1 failed)
- [x] `npx tsc --noEmit` in `src/gaia/apps/webui`: clean (was 1 error)
- [x] `npx vitest run`: 156 files, 1611 tests pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Documentation changes electron Electron app changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants