Repository navigation
Add persistent cyber loops schedules run by the service (M2.4 part B) - #160
Merged
Merged
Conversation
…oopIteration hook The model can now schedule prompts in its own Session with cron_create, cron_list and cron_delete. A task is a Loop of kind cron (cron_ ID) that reuses the loop events, sweep, overlap, budgets and restore, and shares the loops.max_per_session cap with /loop. Expressions are 5-field cron in local time (cyber-core::cron, DST-aware); one-shot tasks take an at time. The tools are offered only to root Sessions outside Workflow Runs, and cron_delete cannot stop a user's /loop. Restore applies the missed-run policy to cron tasks; a one-shot task whose time passed under skip ends expired. /loop gains --until-goal (stops with goal_ended when the recorded Goal ends) and --notify always|on_change|never. Iterations that report noop: false or fail, and failed or budget_exceeded stops, record a Session notification. LoopIteration hooks fire after loop.iteration.ended.1. /loop list rows show the kind, the next run and the stop conditions. Adds the OpenSpec change implement-m2-4-schedules (proposal, design, tasks, spec deltas) covering both this part and persistent schedules.
Schedules are their own event streams (schedule.created/updated/run), projected into new schedule and schedule_run tables. The served App runs a sweep that starts due runs through an unattended gate, creates a new unattended Session per run (or resumes a root Session switched to the schedule's Mode) and admits the prompt queued as schedi_<id>_<n>; the Drain's idle exit records the outcome. Transitions are decided inside the writer transaction so a run is never started or ended twice. The gate refuses missing or untrusted directories, refuses bypass unless loops.allow_bypass comes from user or managed config, and is re-checked before every run. Asks in scheduled runs are denied with 'Denied: no approver in unattended schedule'. cyber loops add/resume/run are refused inside agent subprocesses. Adds deterministic per-schedule jitter (loops.jitter_seconds), notify policies with Session and desktop notifications (osascript/notify-send, text passed as argv), budgets across runs, restore of interrupted and missed runs, schedule_wakeup noop reporting during scheduled runs, the ScheduleRun hook, and usage-limit waits for scheduled runs. Exposes /api/v1/schedules routes, regenerates the OpenAPI document, SDK and docs/cli.md, and updates the guide, features, README and roadmap.
Without it the production host fell back to the refusing default, so the service would refuse every schedule. Caught by app_host_forwards_every_tool_host_method.
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This is part B of the OpenSpec change
implement-m2-4-schedules, and it completes M2.4. It adds persistentcyber loopsschedules that the Cyber service runs with no client open. It also covers the unattended Mode rules, deterministic jitter, completion notifications, budgets across runs, theschedule.run.1record, theScheduleRunhook and usage-limit waits for scheduled runs.It builds on part A (#159), so this PR's diff includes part A's commit until #159 is merged.
Spec requirements implemented (
loops-scheduling)cyber loops add --cron "<expr>" [--name] [--dir] [--agent] [--mode] [--model] [--new-session|--session <id>] [--notify] [--missed] [--max-cost|--max-tokens|--max-turns|--timeout] "<prompt>", pluslist,show,pause,resume,runandrm. Each schedule is its own event stream (schedule.*), projected into the newscheduleandschedule_runtables (new migration). Only the served App runs the sweep: every 5 s, plus nudges. Each run creates a new unattended Session, or resumes the given root Session. The prompt is admitted queued asschedi_<id>_<n>, and the outcome is recorded when the Drain goes idle.addwarns when the service was not running.dont-ask.bypassneedsloops.allow_bypass: true, and the setting must come from aglobal:(user) ormanaged:layer; project, local, env, profile and CLI layers cannot enable it. The service's ownbypassgate still applies. Underdont-ask, and for any ask no approver can answer, the model receivesDenied: no approver in unattended scheduleand the run continues. The directory must exist and its checkout must be trusted. The directory, trust, Mode and target Session are checked ataddand again before every run. A failed check ends the runrefusedand notifies.loops.jitter_seconds(default 60, capped at 3600,0turns it off), derived from SHA-256 of its ID. The next run isnext_occurrence(now − jitter) + jitter, andlistandshowreport it.notifyisalways,on_change(default) ornever. A run reportsnoopthroughschedule_wakeup, which is now offered during scheduled runs; its delay is ignored there. Failed and refused runs notify, and so do budget stops. A notification goes to the run's Session (TUI, remote devices) and to the desktop through aDesktopNotifierport: macOS runsosascriptand Linuxnotify-send, with the text passed only as arguments.addflags, elsebudgets.loop, apply across runs. They are checked before and after each run. An exhausted schedule stops withbudget_exceededand notifies;resumerefuses it.schedule.run.1records each run in phases:started,reportedandended(with outcome, duration, cost, tokens and turns).ScheduleRunis an observational runtime lifecycle event.interrupted. Missed runs follow--missed skip(the default) orrun-once.Security (non-negotiable rules)
bypass: a schedule never runs inbypassunlessloops.allow_bypasscomes from user or managed config.cyber-core::loops::allow_bypasschecks the merged value and the label of the layer that set it, and fails closed on anything else. Tests cover the project, local, env, profile and CLI layers, and a real trusted checkout whosecyber.jsoncsets it.dont-ask: they are denied with feedback, and the run continues.cyber loops add,resumeandrunare refused whenCYBER_SESSION_IDis set;cron_tasks (part A) stay Session-scoped and capped.addand again before every run.ToolHost::schedule_policydefault andBuiltinHostwithouthook_config);n − 1runs; an end requires the run to still berunning.Design decisions that changed the spec
These are in
openspec/changes/implement-m2-4-schedules/specs/loops-scheduling/spec.md:cyber service installin this codebase, so the warning offerscyber service start;loops.allow_bypass;refusedoutcome;noopthroughschedule_wakeup.Other choices are in
design.md:--sessiontarget skips the run;max_wall_secondsis checked between runs, not during a usage-limit wait;Tests
cyber-server/tests/schedules.rs:dont-askSession, with its events and notifications;bypasswithout the opt-in, a missing directory, and trust lost afteradd→refusedwith a notification and no Session;resume;skipandrun-onceafter a restart.cyber-server/tests/usage_limit.rs: a scheduled run in an attended Session waits for the reset and completes.cyber-app/tests/schedules.rs(production App and tool host):dont-askgetsDenied: no approver in unattended schedule;schedule_wakeupwithnoop: truemakes a quiet run, and theScheduleRunhook payload is checked;bypass.cyber-cli/tests/loops_cli.rs(real binary and service):addwith the service warning,list,rununtil completed,pause,resume,rm, and the refusal inside an agent subprocess.cyber-core::loops:allow_bypassby layer, and the jitter settings;schedules: jitter, the next run, request validation, run IDs and the notify policy;cyber loopsbudget flags and ID checks.Docs
docs/local-core-guide.md: a new "Persistent schedules" section.docs/features.md,README.mdandROADMAP.md(the M2.4 status line).docs/cli.mdis regenerated, socyber help-markdownequals it.sdk/openapi.jsonand the TypeScript SDK are regenerated, withScheduleNotFoundError.