feat(cron): cron jobs leave the core for the cron-jobs plugin #37

Closed
gabrielvidal wants to merge 0 commits from cron-jobs-plugin into main
pull from: cron-jobs-plugin
Owner

Summary

Cron jobs — the owner's and every guest's own « Tâches planifiées » — leave the core for the new cron-jobs live plugin (ai-agent-plugins PR, linked below). The core keeps only thin contracts: a guest's job run as that guest, confined by the core (runs.guest), the meta.cron stamp, the delivery of a guest job's result, « Discuter », and the runs.cron provider readers (budget, auto-archive, agents). Decisions from Gabriel's forms move-ai-agent-cron-jobs-into-a-plugin_u0wa6b and cron-scheduled-in-the-cli-and-mcp_x4nk83.

Key changes

  • Removed: backend/cron/ (scheduler, service, routes, guests, guest_routes), schemas/cron.py, deps.cron_store / cron_scheduler, /api/cron*, /api/me/cron*, guestDefaults.cronLimits, cli/skills/scheduled-jobs, MCP run_cron_job / set_cron_job / browse kind=cron; ai-agent cron now only points at ai-agent plugin cron-jobs … (exit 2). Frontend: Settings → Cron (CronJobs.tsx), business/jobs/*, GuestJobs.tsx, the cron limits in GuestDefaults.tsx, the cron SSE event, /api/cron mocks.
  • runs.guest bridge (plugins/hubruns.py → new runs/guestjob.py): POST …/hub/runs/guest {guest, prompt, model, job, project, email, mailHtml, allow, effort, probe}. Owner-only, operator capability. The core builds the scope, the lean allowlist, the budget and the EVOX2 probe / Sonnet fallback from the guest's record; a body's scope / cwd / lean is ignored. It stamps meta.cron {id, name, guest, firedAt, project, email, mailHtml, plugin, fallback?}.
  • runs.start takes cron: {id, name} and stamps meta.cron (owner jobs).
  • Delivery (runs/guestjob.deliver_sweep, a push and an optional mail rendered from a mailHtml page) reads the stamp, not a store.
  • « Discuter » is now POST /api/cron-runs/discuss {sessionId, prompt} (cron.own, guests only). DiscussBar moved to business/conversations/components/. The Discuter scope and access.can_send are read off meta.cronChat / meta.cron.
  • plugins/cron_bridge.py: the runs.cron provider's index / list / get / create ops, cached 30 s and refreshed off-thread. It feeds usage/budget.py, conversations/autoarchive.py, agents/runs.py, conversations/catalog.py, the agents page's "its cron job", and hubcatalog's Schedule.
  • Neutral modules: core/cronexpr.py (the matcher: plugin scheduler, manifest, budget) and agents/runconfig.py (agent frontmatter: Run now, runs.start's lean).
  • Platform:
    • ui.pages[].unless: a page hidden from whoever holds a permission.
    • context.write create: true, which only makes a new .claude/agents/<name>.md.
    • provides: runs.cron.
    • A Settings plugin page's setRoute stays under /settings/p/…. This was a bug: it remounted under /plugins/… in the wrong section.
  • Carry-over (carryover.cron_jobs): /data/cron-jobs.json → the plugin's jobs.json (history unchanged), guestDefaults.cronLimits → limits.json, guests' qwen jobs → sonnet. It runs once, needs no install, and leaves the legacy file as .migrated.
  • Redirects /settings/cron → /settings/p/cron-jobs/jobs and /settings/jobs → /settings/p/cron-jobs/mine, keeping the query string and hash. Saved drawer and panel layouts are renamed in place.
  • authz: route table + matrix.golden.txt, telemetry features.json, i18n, mocks, openapi.json + src/generated, CLAUDE.md, docs/plugins.md / mcp.md / settings.md.

Key decisions

  • Delivery stays core (allowed as "your call"): it needs to read a guest's project files (mailHtml page and inline images, realpath-contained) and to mail them. No plugin bridge gives either power, and adding one would be broader than keeping ~300 lines. It needs nothing from the plugin because everything it reads rides on the run's meta.cron stamp. A run fired before the move (no email on its stamp) asks the plugin's get once.
  • Discuss stays core for the same reason: it is about a conversation, not a job. The job's name and project now ride on the stamps (cronChat.project, else the run's project tag for old runs).
  • Probing without blocking the tick: the plugin scheduler starts a thread per schedule run. A job that waits on the EVOX2 fires from a detached jobs/fire.py (its own session, no inherited pipes), so one sleeping box never holds the minute. The probe itself is the bridge's (runs.start's fallback, runs.guest's probe).
  • Double-fire guard: the plugin's tick claims each job's minute in its own store (flock + compare-and-set), as the core store did. The scheduler's in-memory _fired set can't protect the blue-green window.
  • Limits = grant field → plugin setting → carried limits.json → 5 / sonnet. The settings fields have no default, so the carried values aren't hidden behind one.
  • cron.own is kept, but only for « Discuter ». Access to the jobs themselves is the managed grant (defaultForGuests: true) plus plugins.use. A worker-bound connection has no plugins.use, so no cron there, as decided.
  • ai-agent cron prints where the commands went (exit 2), like services. It is not an alias.
  • PR #23 (guest-jobs-sonnet) is superseded: its decision (guest jobs default to Sonnet, existing qwen ones move once) is carried by runs/guestjob.DEFAULT_MODEL and the carry-over, which skips the move if #23's own marker shows it already ran.

For the hub-mcp-plugin branches when they rebase

  • ~/worktrees/ai-agent-hub-mcp-plugin: cli/ai_agent.py (the old cmd_cron, cron_expr, _guest_job_fields, the cron parser and its GUEST_COMMANDS entry) and cli/test_ai_agent.py CronMailHtml must take this branch's version.
  • ~/worktrees/ai-agent-plugins-hub-mcp (plugins/hub-mcp) has to drop:
    • in handlers/hubmcp_tools.py: run_cron_job and set_cron_job, "cron" in BROWSE_KINDS, and the kind == "cron" branch of _rows. The browse description must also stop saying "cron jobs".
    • in handlers/hubmcp_server.py: "cron jobs" in the instructions.
    • in README.md: the agents row's cron tools.
    • in the tests: test_hub_mcp_tools.py (agents group set, the GET /api/cron guest test) and test_hub_mcp_endpoint.py (run_cron_job, set_cron_job, browse kind=cron).
  • The parallel scheduled-doors branch also touches cli/mcp_tools.py / BROWSE_KINDS; after either rebase, regenerate frontend/openapi.json, src/generated and authz/matrix.golden.txt.

Changelog

  • Changed: cron jobs are now the Cron jobs plugin — Settings → Cron jobs (owner) and Settings → Scheduled jobs (guests) look and work as before
  • Added: every cron command is an MCP tool (plugin_cron-jobs_ls, _run, _pause…) and a CLI command (ai-agent plugin cron-jobs …), for guests on their own jobs too
  • Changed: guests' scheduled jobs start on Sonnet; jobs still on the local model move to Sonnet once
  • Removed: ai-agent cron, /api/cron, /api/me/cron and the run_cron_job / set_cron_job MCP tools
  • Fixed: a plugin's Settings page that updates its own address no longer jumps to another section

Install order

Merge and deploy this PR first, then the ai-agent-plugins PR. The plugin is seed: true: the hub installs it from the seed dir at the next start, and its carry-over has already put jobs.json and limits.json in its shared dir. Until the plugin is installed and approved, no cron job fires, so keep the two deploys close together. Then the homelab PR: its agents pause themselves with ai-agent plugin cron-jobs pause ….

Test notes

  • Backend, every module under bwrap, one process each, compared with main at the base commit: 2,141 passed. Two modules fail:
    • test_mcp (number matching) fails on main too.
    • test_typed_plugins (test_records_carry_kind) fails only because the worktree path is under ~/worktrees, which the store remaps; it passes from /tmp and on main.
  • New and ported tests: test_guest_jobs.py (24: confinement, runs.guest and its gate, the runs.start cron stamp, Discuss, delivery, mailHtml) and test_cron_bridge.py (11: readers, carry-over, context.write create, unless). Also updated: test_worker_routing, test_usage_budget, test_autoarchive, test_plugin_catalog, test_guests, test_authz, test_i18n, test_cron_lean, cli/test_mcp_tools, cli/test_ai_agent.
  • Frontend: tsc clean; vitest 1103/1104 (FreshContext CacheExpiredNotice fails on main too).
  • A live local hub on port 8131 (bwrap, a seeded /data/cron-jobs.json with an owner job and a guest's qwen job, the plugin seeded from the plugins worktree):
    • The carry-over ran: the legacy file became .migrated, the guest job moved to sonnet, and limits.json holds {maxJobs: 3, defaultModel: sonnet}.
    • On the CLI: ai-agent plugin cron-jobs ls|show|run|pause|resume work, and ai-agent cron prints the pointer.
    • Run now went through runs.start; there is no sidecar here, so the refusal was recorded as lastStatus.
    • As the guest: list returns their own jobs, and a */15 schedule is refused.
    • /api/plugins/ui: the owner sees jobs only, the guest mine only.
    • /settings/cron redirects. The screenshots below were taken after the last fix.
  • Never deployed from the EVOX2: deploy from the Homelab after review (ai-agent-deploy).

🤖 Generated with Claude Code

Screenshots

owner-job-open.png
owner-guests-mobile.png
guest-desktop.png
guest-mobile.png

## Summary Cron jobs — the owner's and every guest's own « Tâches planifiées » — leave the core for the new **`cron-jobs`** live plugin (ai-agent-plugins PR, linked below). The core keeps only thin contracts: a guest's job run *as that guest*, confined by the core (`runs.guest`), the `meta.cron` stamp, the delivery of a guest job's result, « Discuter », and the `runs.cron` provider readers (budget, auto-archive, agents). Decisions from Gabriel's forms `move-ai-agent-cron-jobs-into-a-plugin_u0wa6b` and `cron-scheduled-in-the-cli-and-mcp_x4nk83`. ## Key changes - **Removed**: `backend/cron/` (scheduler, service, routes, guests, guest_routes), `schemas/cron.py`, `deps.cron_store` / `cron_scheduler`, `/api/cron*`, `/api/me/cron*`, `guestDefaults.cronLimits`, `cli/skills/scheduled-jobs`, MCP `run_cron_job` / `set_cron_job` / `browse kind=cron`; `ai-agent cron` now only points at `ai-agent plugin cron-jobs …` (exit 2). Frontend: Settings → Cron (`CronJobs.tsx`), `business/jobs/*`, `GuestJobs.tsx`, the cron limits in `GuestDefaults.tsx`, the `cron` SSE event, `/api/cron` mocks. - **`runs.guest`** bridge (`plugins/hubruns.py` → new `runs/guestjob.py`): `POST …/hub/runs/guest {guest, prompt, model, job, project, email, mailHtml, allow, effort, probe}`. Owner-only, operator capability. The core builds the scope, the lean allowlist, the budget and the EVOX2 probe / Sonnet fallback from the guest's record; a body's `scope` / `cwd` / `lean` is ignored. It stamps `meta.cron {id, name, guest, firedAt, project, email, mailHtml, plugin, fallback?}`. - **`runs.start`** takes `cron: {id, name}` and stamps `meta.cron` (owner jobs). - **Delivery** (`runs/guestjob.deliver_sweep`, a push and an optional mail rendered from a `mailHtml` page) reads the stamp, not a store. - **« Discuter »** is now `POST /api/cron-runs/discuss {sessionId, prompt}` (`cron.own`, guests only). `DiscussBar` moved to `business/conversations/components/`. The *Discuter* scope and `access.can_send` are read off `meta.cronChat` / `meta.cron`. - **`plugins/cron_bridge.py`**: the `runs.cron` provider's `index` / `list` / `get` / `create` ops, cached 30 s and refreshed off-thread. It feeds `usage/budget.py`, `conversations/autoarchive.py`, `agents/runs.py`, `conversations/catalog.py`, the agents page's "its cron job", and `hubcatalog`'s *Schedule*. - Neutral modules: `core/cronexpr.py` (the matcher: plugin scheduler, manifest, budget) and `agents/runconfig.py` (agent frontmatter: *Run now*, `runs.start`'s `lean`). - Platform: - `ui.pages[].unless`: a page hidden from whoever holds a permission. - `context.write` `create: true`, which only makes a new `.claude/agents/<name>.md`. - `provides: runs.cron`. - A Settings plugin page's `setRoute` stays under `/settings/p/…`. This was a bug: it remounted under `/plugins/…` in the wrong section. - **Carry-over** (`carryover.cron_jobs`): `/data/cron-jobs.json` → the plugin's `jobs.json` (history unchanged), `guestDefaults.cronLimits` → `limits.json`, guests' `qwen` jobs → `sonnet`. It runs once, needs no install, and leaves the legacy file as `.migrated`. - Redirects `/settings/cron` → `/settings/p/cron-jobs/jobs` and `/settings/jobs` → `/settings/p/cron-jobs/mine`, keeping the query string and hash. Saved drawer and panel layouts are renamed in place. - authz: route table + `matrix.golden.txt`, telemetry `features.json`, i18n, mocks, `openapi.json` + `src/generated`, CLAUDE.md, docs/plugins.md / mcp.md / settings.md. ## Key decisions - **Delivery stays core** (allowed as "your call"): it needs to read a guest's project files (`mailHtml` page and inline images, realpath-contained) and to mail them. No plugin bridge gives either power, and adding one would be broader than keeping ~300 lines. It needs nothing from the plugin because everything it reads rides on the run's `meta.cron` stamp. A run fired before the move (no `email` on its stamp) asks the plugin's `get` once. - **Discuss stays core** for the same reason: it is about a conversation, not a job. The job's name and project now ride on the stamps (`cronChat.project`, else the run's project tag for old runs). - **Probing without blocking the tick**: the plugin scheduler starts a thread per schedule run. A job that waits on the EVOX2 fires from a detached `jobs/fire.py` (its own session, no inherited pipes), so one sleeping box never holds the minute. The probe itself is the bridge's (`runs.start`'s `fallback`, `runs.guest`'s `probe`). - **Double-fire guard**: the plugin's tick claims each job's minute in its own store (`flock` + compare-and-set), as the core store did. The scheduler's in-memory `_fired` set can't protect the blue-green window. - **Limits** = grant field → plugin setting → carried `limits.json` → 5 / sonnet. The settings fields have no default, so the carried values aren't hidden behind one. - `cron.own` is kept, but only for « Discuter ». Access to the jobs themselves is the managed grant (`defaultForGuests: true`) plus `plugins.use`. A worker-bound connection has no `plugins.use`, so no cron there, as decided. - `ai-agent cron` prints where the commands went (exit 2), like `services`. It is not an alias. - **PR #23 (`guest-jobs-sonnet`) is superseded**: its decision (guest jobs default to Sonnet, existing `qwen` ones move once) is carried by `runs/guestjob.DEFAULT_MODEL` and the carry-over, which skips the move if #23's own marker shows it already ran. ## For the `hub-mcp-plugin` branches when they rebase - `~/worktrees/ai-agent-hub-mcp-plugin`: `cli/ai_agent.py` (the old `cmd_cron`, `cron_expr`, `_guest_job_fields`, the `cron` parser and its `GUEST_COMMANDS` entry) and `cli/test_ai_agent.py` `CronMailHtml` must take this branch's version. - `~/worktrees/ai-agent-plugins-hub-mcp` (`plugins/hub-mcp`) has to drop: - in `handlers/hubmcp_tools.py`: `run_cron_job` and `set_cron_job`, `"cron"` in `BROWSE_KINDS`, and the `kind == "cron"` branch of `_rows`. The `browse` description must also stop saying "cron jobs". - in `handlers/hubmcp_server.py`: "cron jobs" in the instructions. - in `README.md`: the agents row's cron tools. - in the tests: `test_hub_mcp_tools.py` (agents group set, the `GET /api/cron` guest test) and `test_hub_mcp_endpoint.py` (`run_cron_job`, `set_cron_job`, `browse kind=cron`). - The parallel `scheduled-doors` branch also touches `cli/mcp_tools.py` / `BROWSE_KINDS`; after either rebase, regenerate `frontend/openapi.json`, `src/generated` and `authz/matrix.golden.txt`. ## Changelog - Changed: cron jobs are now the Cron jobs plugin — Settings → Cron jobs (owner) and Settings → Scheduled jobs (guests) look and work as before - Added: every cron command is an MCP tool (`plugin_cron-jobs_ls`, `_run`, `_pause`…) and a CLI command (`ai-agent plugin cron-jobs …`), for guests on their own jobs too - Changed: guests' scheduled jobs start on Sonnet; jobs still on the local model move to Sonnet once - Removed: `ai-agent cron`, `/api/cron`, `/api/me/cron` and the `run_cron_job` / `set_cron_job` MCP tools - Fixed: a plugin's Settings page that updates its own address no longer jumps to another section ## Install order Merge and deploy this PR **first**, then the ai-agent-plugins PR. The plugin is `seed: true`: the hub installs it from the seed dir at the next start, and its carry-over has already put `jobs.json` and `limits.json` in its shared dir. Until the plugin is installed and approved, **no cron job fires**, so keep the two deploys close together. Then the homelab PR: its agents pause themselves with `ai-agent plugin cron-jobs pause …`. ## Test notes - Backend, every module under bwrap, one process each, compared with main at the base commit: **2,141 passed**. Two modules fail: - `test_mcp` (number matching) fails on main too. - `test_typed_plugins` (`test_records_carry_kind`) fails only because the worktree path is under `~/worktrees`, which the store remaps; it passes from `/tmp` and on main. - New and ported tests: `test_guest_jobs.py` (24: confinement, `runs.guest` and its gate, the `runs.start` cron stamp, Discuss, delivery, `mailHtml`) and `test_cron_bridge.py` (11: readers, carry-over, `context.write` create, `unless`). Also updated: `test_worker_routing`, `test_usage_budget`, `test_autoarchive`, `test_plugin_catalog`, `test_guests`, `test_authz`, `test_i18n`, `test_cron_lean`, `cli/test_mcp_tools`, `cli/test_ai_agent`. - Frontend: `tsc` clean; vitest **1103/1104** (FreshContext `CacheExpiredNotice` fails on main too). - A live local hub on port 8131 (bwrap, a seeded `/data/cron-jobs.json` with an owner job and a guest's `qwen` job, the plugin seeded from the plugins worktree): - The carry-over ran: the legacy file became `.migrated`, the guest job moved to sonnet, and `limits.json` holds `{maxJobs: 3, defaultModel: sonnet}`. - On the CLI: `ai-agent plugin cron-jobs ls|show|run|pause|resume` work, and `ai-agent cron` prints the pointer. - Run now went through `runs.start`; there is no sidecar here, so the refusal was recorded as `lastStatus`. - As the guest: `list` returns their own jobs, and a `*/15` schedule is refused. - `/api/plugins/ui`: the owner sees `jobs` only, the guest `mine` only. - `/settings/cron` redirects. The screenshots below were taken after the last fix. - **Never deployed from the EVOX2**: deploy from the Homelab after review (`ai-agent-deploy`). 🤖 Generated with [Claude Code](https://claude.com/claude-code) ## Screenshots ![owner-job-open.png](https://git.gabvdl.xyz/attachments/6c5bef90-3c85-4fd6-89d2-297a95fa1b51) ![owner-guests-mobile.png](https://git.gabvdl.xyz/attachments/0c27fea0-c1bd-4eb7-a8d3-bc1b193ea079) ![guest-desktop.png](https://git.gabvdl.xyz/attachments/d2ee7c47-feff-46f9-9042-e586d4be903e) ![guest-mobile.png](https://git.gabvdl.xyz/attachments/c3c412c0-3200-4374-9f2c-30828fc88843)
gabrielvidal self-assigned this 2026-11-28 17:58:33 +01:00
gabrielvidal added 1 commit 2026-11-28 17:58:33 +01:00
Owner jobs and guests' own scheduled jobs are the cron-jobs live plugin's
(forms move-ai-agent-cron-jobs-into-a-plugin_u0wa6b,
cron-scheduled-in-the-cli-and-mcp_x4nk83). Gone: backend/cron/,
schemas/cron.py, /api/cron*, /api/me/cron*, the cron scheduler thread,
Settings → Cron and the guests' Tâches planifiées pages, `ai-agent cron`
(now a pointer), MCP run_cron_job / set_cron_job / browse cron, the
scheduled-jobs core skill, guestDefaults.cronLimits.

The core keeps thin contracts:
- runs.guest bridge (runs/guestjob.py): a guest's job run as that guest,
  confined by the core from their record; the plugin only names it.
- runs.start's cron stamp → meta.cron.
- delivery of a guest job's result (push, mail, mailHtml) off the stamp.
- « Discuter »: POST /api/cron-runs/discuss.
- runs.cron provider readers (plugins/cron_bridge.py): budget,
  auto-archive, agents catalog, the agents page's Schedule.
- core/cronexpr.py, agents/runconfig.py; context.write create for a new
  agent definition; ui.pages[].unless; setRoute keeps a Settings page
  under /settings/p/.
- carryover.cron_jobs: /data/cron-jobs.json → the plugin's jobs.json,
  cronLimits → limits.json, guests' qwen jobs → sonnet (PR #23's
  decision, superseded).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
Owner
Merged into `main` as 16e3b2e9 by the auto-ship batch https://ai-agent.lab.gabvdl.xyz/conversation/01a22324-ffa9-78f0-999d-dff18a148ad0.
gabrielvidal closed this pull request 2026-11-28 18:26:03 +01:00

Pull request closed

Please reopen this pull request to perform a merge.
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: gabrielvidal/ai-agent#37