Repository navigation
fix(schedule): run jobs that fire late instead of silently skipping them - #4271
Conversation
A schedule due while the laptop slept or the daemon was busy for more than one second was dropped, because the daemon inherited APScheduler's 1-second misfire grace. Late runs now fire if they are within an hour of the due time, several missed runs collapse into one, and every skipped run (too late, or overlapping the previous run) is logged with its schedule name. Fixes amd#4207
Approve with suggestions — one doc sentence needs narrowingScheduled runs that came due a moment late used to vanish; this makes them fire for up to an hour and logs the ones it still has to skip, by schedule name. I ran the daemon in this environment and the behaviour holds: 30 minutes late fires, two hours late is skipped with a named WARNING, and a burst of missed minutes collapses to one run. The one thing to fix before merge is the new CLI doc sentence. It promises that a run due while the machine was asleep fires "once the daemon catches up" — true when the process was merely suspended, but not when the daemon itself was stopped or the machine was off. In that case the missed run is dropped and no warning is logged, which is the opposite of what the paragraph tells the user to expect. Narrowing the wording (or saying plainly that a restart doesn't replay) is enough; actually replaying across downtime would be a bigger change and belongs in a follow-up. Real-world evidenceNo Full Live daemon probe (real A–C confirm the fix end to end, including that the named WARNING really reaches the listener through a genuine misfire. D is the gap behind the doc finding: a daily 00:00 schedule armed at 00:49 — 49 minutes inside the one-hour grace — skips straight to tomorrow with no run and no warning. 🔍 Technical details🟡 ImportantDoc claim doesn't hold when the daemon itself restarts (
Worth noting for the follow-up: the store already records 🟢 MinorTests hardcode the grace value ( Logging tests drive a private APScheduler method ( Overlap message says "due at" but formats a list ( Strengths
|
The doc promised a run due while the machine slept "fires once the daemon catches up" without qualifying that the daemon process itself has to have stayed up -- a run that came due while the daemon wasn't running is dropped silently, the opposite of what the paragraph told users to expect. Also stops the grace-time test asserting against a duplicated literal instead of the constant it's actually pinning.
…amd#4370) `main` has been red since 2026-09-25 18:29, so nothing can leave the merge queue. Three separate regressions landed within minutes of each other; this clears all three. The worst is a literal `SyntaxError` — `ChatAgentConfig(...)` was passed `device=` twice, so the Agent UI backend and everything importing it failed at module load, taking out the Linux, Windows and macOS unit-test jobs. Nobody wrote that duplicate: amd#3666 and amd#4275 each added the same kwarg a few lines apart, neither diff conflicted textually, and the merge queue merged both cleanly into a file that does not parse. The other two are one-liners: amd#3402 re-imported `tool_cancelled` over a name the module already imports (failing the pylint gate) and shipped `wait_for_condition` with no UI label, and amd#4271 landed an over-long assertion (failing the black gate). **Worth knowing:** the ~13 "new pylint errors" that appear in the failing job's log are not pylint errors. They are the first 20 lines of the **non-blocking MyPy** output (1224 warnings, truncated for display) and have never gated anything. Only one pylint hit was real. No dependency or tool-version drift was involved — pylint 4.0.9 and black 26.5.1 both predate the last green run. ## Test plan - [ ] `python util/lint.py --black` — clean (1180 files unchanged) - [ ] `uvx pylint src/gaia --rcfile .pylintrc --disable C0103,C0301,W0246,W0221,E1102,R0401,E0401,W0718,W0212` — clean on Linux - [ ] `python -m compileall -q src/gaia tests` — no syntax errors - [ ] `python -m pytest tests/unit/test_schedule_daemon.py -q` — 28 passed - [ ] `python -m pytest tests/unit/chat/ui -q` — 1040 passed (was 17 collection errors) <details> <summary>🔍 Technical details</summary> **`src/gaia/ui/agent_loop.py`** — the two `device=session.get("device")` lines were textually identical, so deleting the later one restores exactly the intended call. `git blame` attributes line 461 to `1caad2ade5` (amd#4275) and line 465 to `7a8fea58b1` (amd#3666); amd#3666 is an ancestor of the last green commit `69f76ab57`, so amd#4275 is the one that created the duplicate. **`src/gaia/agents/tools/shell_tools.py`** — `gaia.agents.base.tools.tool_cancelled` is a pure re-export of `gaia.tool_cancellation.tool_cancelled`, which the module already imports at line 31. Verified the bindings are the same object, so dropping the function-local import is a no-op rather than a behaviour change. **Follow-up worth a maintainer's eye, deliberately not bundled here:** `wait_for_condition` executes arbitrary commands against the same allowlist as `run_shell_command`, but unlike `run_shell_command` it is not in `_GAIA_MUTATING_TOOLS`. By that set's own stated criterion ("or execute code") it looks like it belongs there, and omitting it means the tool skips the confirmation gating its sibling gets. That is a behaviour change, not a CI fix, so it should be reviewed on its own rather than smuggled into an unblock PR. **Also noted:** `.pylintrc` uses `disable = all` plus an explicit `enable` list that does not include `syntax-error`, which is why the pylint gate walked past a file it could not parse. Enabling `E0001` would have caught this at PR time. </details>
…tes (amd#4272) Stacked on amd#4271. Merge that first. With two `gaia schedule daemon` processes running (for example a login item plus a manual start), every schedule ran twice: two LLM runs and two Telegram messages. Separately, a `gaia schedule add` that raced the daemon's run bookkeeping could silently drop the new schedule. Now the daemon holds `~/.gaia/schedules.lock` (next to whichever store it uses) for its whole lifetime, so a second daemon exits at once with an error that names the running pid. Each store read-modify-write also takes a short lock, so concurrent changes are all kept. The flock/msvcrt calls in `gaia.daemon.lock` became shared `try_lock`/`unlock` helpers rather than a second copy. ## Test plan - [x] `~/.cache/gaia-dev/venv/bin/python -m pytest tests/unit/test_schedule_lock.py -q`: without the wiring, the second-daemon and concurrent `add` + `mark_run` tests fail (2 failed, and the race test loses schedule `b`). With the fix, 6 pass. - [x] `gaia schedule daemon` twice against one `HOME`: the second exits 1 with `another gaia schedule daemon (pid N) is already running … Stop the other daemon first`, and the first keeps running - [x] `~/.cache/gaia-dev/venv/bin/python -m pytest tests/unit/test_schedule_lock.py tests/unit/test_schedule_daemon.py tests/unit/test_schedule_store.py tests/unit/test_schedule_sinks.py tests/unit/cli/test_cli_schedule.py tests/unit/test_scheduler.py tests/unit/test_daemon_client.py tests/unit/test_daemon_scheduler.py tests/unit/test_daemon_cli_dev_anchor.py -q`: all pass - [x] black, isort, and pylint (errors-only, CI flags) are clean on the changed files - [ ] Windows: a second daemon is refused (the pid is omitted there, because Windows blocks reads of the locked byte) Fixes amd#4208 --------- Co-authored-by: Kalin Ovtcharov <[email protected]> Co-authored-by: Kalin Ovtcharov <[email protected]>
…md#4273) Stacked on amd#4272 (itself stacked on amd#4271). Merge those first. `gaia schedule add` used to accept sinks that could never deliver: a misspelled sink name, `telegram` without `--to`, a bare `file` with no path, or `notification` on Windows. Each of those schedules then failed on every run, only after spending a full LLM call. Now `add` rejects them with an actionable message and stores nothing. Each run also checks its sink before calling the agent, so schedules stored before this change fail fast too. The Telegram token is still checked only at delivery, because the daemon reads it from its own environment, not the shell that ran `add`. ## Test plan - [x] `~/.cache/gaia-dev/venv/bin/python -m pytest tests/unit/test_schedule_sinks.py tests/unit/cli/test_cli_schedule.py tests/unit/test_schedule_daemon.py -q`: 18 failed before the fix, 86 pass after - [x] `gaia schedule add --name t --cron "0 7 * * *" --prompt hi --sink telegram` exits 1 with `telegram sink needs a recipient: pass --to`. `--sink telegarm` and `--sink file` are rejected the same way, `--sink telegram --to 123` is added, and `gaia schedule list` shows only that schedule. - [x] `~/.cache/gaia-dev/venv/bin/python -m pytest tests/unit/cli/ -q`: all pass except the 4 `test_gaia_binary_on_path` cases, which fail locally because the dev venv's binaries aren't on PATH (unrelated) - [x] black, isort, and pylint (errors-only, CI flags) are clean on the changed files Fixes amd#4228 --------- Co-authored-by: Kalin Ovtcharov <[email protected]> Co-authored-by: Kalin Ovtcharov <[email protected]>
A schedule that came due while the laptop was asleep or the daemon was busy for more than one second never ran. The daemon inherited APScheduler's 1-second misfire grace, and the skip only showed up as a generic APScheduler warning. Now a run that is up to an hour late still fires, several missed runs collapse into one, and every skipped run is logged at WARNING with the schedule name. That covers runs more than an hour late and runs that overlap the schedule's previous run, which is now an explicit
max_instances=1rather than an inherited default.Test plan
~/.cache/gaia-dev/venv/bin/python -m pytest tests/unit/test_schedule_daemon.py -q -k Misfire: 5 failed onorigin/main, 5 pass with the fix. This includes an end-to-end check that a run due 60 s ago still fires.~/.cache/gaia-dev/venv/bin/python -m pytest tests/unit/test_schedule_daemon.py tests/unit/test_schedule_store.py tests/unit/test_schedule_sinks.py tests/unit/cli/test_cli_schedule.py -q: 106 passedFixes #4207