Repository navigation
Sonny: triggers are automations, for the person and for agents; turn caps say what they count - #632
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Eval:
* the lead discarded its task, so usage covers the lead only. No difference from the rename: every call went through the tool in both arms, no script calls, and leads say "schedule", "job" or "report" to the person. B3's miss was its task's add returning Unrelated finding, in both arms: all 5 first manual runs failed with Generated by Claude Code |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9094cce3ff
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if !self.state.exists() && old.is_dir() { | ||
| let _ = std::fs::rename(&old, &self.state); |
There was a problem hiding this comment.
Quiesce running automation jobs before moving their state
When an upgrade moves this directory while an existing scheduler fire is still running (for example, waiting for a shadow report or executing its --if command), that process retains Places pointing at .agent/triggers. Its subsequent settle() finds no definition at the old path and takes the retirement branch instead of updating the moved state. The automation therefore loses its send count/result, and a one-shot or --runs-limited job can run again despite already delivering its message. The scheduler deliberately lets existing fires finish across upgrades, so migration needs to coordinate with those fires before relocating their files.
AGENTS.md reference: AGENTS.md:L40-L40
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Real, fixed in 925d3e1. Places::moved now moves ~/.agent/triggers only while it can take the folder's files lock (.lock), its scheduler's (.scheduler/scheduler, unless the caller is that scheduler) and every fire's (.scheduler/*.lock, which a fire holds to its end). While any is held, the caller works in the old folder, as the running fire does. The scheduler checks each minute: once its fires are done it moves the folder itself and re-execs from the new place, the same way it does after an upgrade. Test: the_triggers_folder_moves_to_automations_once holds a fire lock, then the scheduler lock, and checks who moves and when.
Generated by Claude Code
925d3e1 to
1659e4d
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1659e4d883
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| match old.quiet(scheduling) { | ||
| Some(_held) if std::fs::rename(&old.state, &places.state).is_ok() => places, | ||
| _ => old, |
There was a problem hiding this comment.
Coordinate migration with callers retaining the old Places
During an upgrade, automation add can receive the old Places because the scheduler holds its lock, then await daemon requests in add() before acquiring the files lock in install(). Meanwhile, the scheduler can call Places::moved(home, true) and rename the directory because that caller holds none of the locks checked here. When install() resumes, Lock::take() recreates .agent/triggers and writes the new automation there, but ring() and subsequent callers select .agent/automations, leaving an apparently successful addition permanently unscheduled and unlisted. The new fire-lock checks prevent the previously reported running-fire case, but the unlocked daemon-resolution phase in add() exposes this separate race. Revalidate the selected directory under migration coordination before writing, or retain coordination throughout the operation.
AGENTS.md reference: AGENTS.md:L40-L40
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Real, fixed in 2e04b97. The move now leaves ~/.agent/triggers as a symlink to automations, created while the folder's files lock is still held. An add that picked the old Places before the move takes that lock only after the link exists, so its writes land in the new folder. A writer that finds neither path, between the rename and the link, gets automations_moved instead of Lock::take creating the old folder again. The test now covers both: a write through the link after the move, and the error in the gap.
Generated by Claude Code
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2e04b97b20
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| /// projects' leads were handed theirs, a line each. | ||
| fn restored_list(home: &Path) -> PathBuf { | ||
| home.join(".agent/sonny/restored-triggers.json") | ||
| home.join(".agent/sonny/restored-automations.json") |
There was a problem hiding this comment.
Migrate the pending restoration list before renaming its path
If a home was restored before this upgrade and some project leads have not opened yet, their automation definitions still live in .agent/sonny/restored-triggers.json. Changing this path without moving that file makes restored_rows() silently return an empty list, so those leads never receive the instructions needed to recreate their automations, and pending_restored() no longer preserves them in subsequent backups. Repository-wide search found no migration of this file; the automations-folder migration only handles the jobs directory and script. Convert this Sonny-written state once during upgrade rather than abandoning pending restorations.
AGENTS.md reference: AGENTS.md:L31-L35
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Real, fixed in a682ab8. restored_list renames restored-triggers.json to restored-automations.json the first time it reads the list and finds only the old name. The same applied to the backup copy's list: adopt falls back to triggers.json when the copy has no automations.json, and keep_triggers deletes triggers.json at the next sync, which writes the new name. The backup test now pushes the old name and restores from it, and also renames the restored list back to its old name before the lead reads it.
Generated by Claude Code
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a682ab854c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let held = places.repo.join(AUTOMATIONS); | ||
| match std::fs::remove_file(places.repo.join(TRIGGERS)) { |
There was a problem hiding this comment.
Resolve the active automation directory before backing it up
If sonny home sync runs before the folder migration, or while a running fire prevents that migration, definitions still live under .agent/triggers. However, keep_triggers() reads them through trigger::Places::under(), which now unconditionally selects .agent/automations, rather than the migration-aware selector. The resulting empty list causes this sync to delete the existing triggers.json backup without writing its replacement, and sync_once() commits and pushes that deletion. Resolve the active directory before collecting definitions so automations remain backed up while migration is pending.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 21040f6: keep_triggers now reads trigger::Places::moved(&places.home, false), the same selector everything else uses, so a sync while the move waits backs up the old folder's automations instead of deleting triggers.json.
Generated by Claude Code
| // `automations.json`; run where they are read | ||
| // (`trigger::Places::moved`, `skills::install_own`) rather than through | ||
| // [`once`], since the script and the scheduler read the folder without | ||
| // Sonny's start (0.8.0). |
There was a problem hiding this comment.
Run the mechanical migration through upgrade::once
This explicitly bypasses the repository's required migration mechanism: root AGENTS.md says that mechanical rewrites of Sonny-written files are migrations run by upgrade::once. Registering automations-folder without invoking that mechanism leaves completion unrecorded and distributes the migration across ordinary readers instead of following the prescribed lifecycle. Call upgrade::once from the necessary CLI and scheduler entry points; its callback already supports returning false to retry when locks prevent completion.
AGENTS.md reference: AGENTS.md:L31-L35
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 21040f6: Places::moved now runs the folder move and the restored list's rename through upgrade::once (record ~/.agent/sonny/migrated), returning false to retry while a fire or another scheduler holds the folder. It is still called from every entry point (Places::home, the scheduler's re-exec check), since the script and the scheduler run without Sonny's start; a HOME with no ~/.agent gets no record, so the scheduler's gone-HOME guard still holds. The old ~/.agent/trigger script's removal is its own migration, automation-script, run through once at Sonny's start after its successor is written.
Generated by Claude Code
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 21040f67f5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let Some(_held) = old.quiet(scheduling) else { | ||
| return false; | ||
| }; |
There was a problem hiding this comment.
Rename the restoration list before waiting for folder locks
When a home has pending restorations in restored-triggers.json and an old scheduler or fire holds a lock, this return also postpones renaming the restoration list. The fresh evidence is that the combined migration now exits before reaching the list rename, while restored_list() unconditionally returns restored-automations.json. Consequently, pending_restored() returns no rows during that interval, and home::keep_triggers() omits those pending restorations from the backup that sync_once() commits and pushes; opening a lead during the interval also misses its restoration instructions. Perform the independent list rename before the folder-lock check so waiting for running jobs does not hide restoration state.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in the next push: the restored list's rename now runs first in the migration, before the folder-lock check, so it happens even while a fire or an old scheduler holds the folder. The test asserts the list is renamed while the fire's lock is still held.
Generated by Claude Code
The person's word for them is automation, so agents, who talk to the person, now read and say it too: the `automations` tool with `run`, the `~/.agent/automation` script, `sonny automation`, `/automations`, the `[automation NAME · ...]` headers, `origin: "automation"` and the automation_* error codes. Internal names (trigger.rs, request ids, --trigger-fire, scheduler labels) stay. Upgrade: the first 0.8.0 Sonny, scheduler or script to look moves ~/.agent/triggers to ~/.agent/automations, and Sonny's old ~/.agent/trigger script goes (migration automations-folder, retired in 0.10.0). History with origin "trigger" and old tool calls still read as an automation's. The memory cleanup schedules through the new script. The role eval gains an `automation` day (set up, list, run, remove) and accepts the old names so an arm of an older build compares. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013jkdGD7saFpzzSnMyV12Dg
…n script Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013jkdGD7saFpzzSnMyV12Dg
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013jkdGD7saFpzzSnMyV12Dg
Agents set their own jobs caps of 4k to 12k tokens, and every first run failed on 29k to 42k of the agent's history. The tool and the skill now say what the cap counts and to set one only when the person asks for a spending limit. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013jkdGD7saFpzzSnMyV12Dg
A fire of the old Sonny keeps its paths to its end, so moving the folder under it lost its result and could run a one-off again (Codex review). Places::moved takes the folder's files lock, its scheduler's and every fire's first; while any is held, everything works in the old folder, and the scheduler, which holds its own, moves it within a minute of the last fire ending and runs again from the new place. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013jkdGD7saFpzzSnMyV12Dg
…d tool Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013jkdGD7saFpzzSnMyV12Dg
An add that chose ~/.agent/triggers before the scheduler moved it wrote there after the move, where nothing reads (Codex review). The move now leaves ~/.agent/triggers as a link to automations, made while the files' lock is held, and a writer that finds neither between the move and the link gets automations_moved rather than making the old folder again. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013jkdGD7saFpzzSnMyV12Dg
…mes readable restored-triggers.json, left by a restore for leads not opened yet, becomes restored-automations.json when next read; a backup's triggers.json is read when the copy has no automations.json and goes at its next sync (Codex review). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013jkdGD7saFpzzSnMyV12Dg
…up during a pending move keeps the old folder's list The folder's move and the restored list's rename are one migration run by upgrade::once wherever the folder is found, so its completion is recorded in ~/.agent/sonny/migrated; a HOME without ~/.agent gets no record (the scheduler's gone-HOME guard). Sonny's old ~/.agent/trigger script is its own migration, automation-script, at Sonny's start. home sync reads the active folder, so a sync while the move waits keeps triggers.json's replacement instead of deleting it. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013jkdGD7saFpzzSnMyV12Dg
…s folder to move Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013jkdGD7saFpzzSnMyV12Dg
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013jkdGD7saFpzzSnMyV12Dg
8bb8561 to
a001a9c
Compare
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013jkdGG5PKzf3A9NDuvu9Xu
Sonny already calls them automations to the person ("↳ From an automation", the automation skill). Agents talk to the person, so they now read and say the same word. Sonny and the client only: no daemon, protocol or schema change.
What changes, from → to
sonny/src/served.rs)triggers, verbfire, answer"fired": true, list keytriggersautomations, verbrun,"ran": true, list keyautomationssonny/src/skills.rs)~/.agent/trigger(fire)~/.agent/automation(run); Sonny removes its own old scriptsonny trigger …,/triggerssonny automation …,/automationssonny/src/trigger.rsPlaces)~/.agent/triggers~/.agent/automations, moved once[trigger NAME · …],origin: "trigger"[automation NAME · …],origin: "automation"whenandwhywordsfire,firedon demand,run nowinvalid_trigger,trigger_exists,trigger_not_found,trigger_failed,triggers_unsupportedautomation_*/automations_unsupportedrestored-triggers.json, "set up again with the triggers tool"restored-automations.json, "automations tool"client/src/memory.rs)~/.agent/trigger~/.agent/automationclient/src/approver.rs)Kept, since no agent or person reads them: the module
trigger.rsand its types, request idstrigger_…,--trigger-fire, the old per-trigger launchd label (only for the scheduler-job migration),AGENT_TRIGGER_LOCK_FD.Upgrade
trigger::Places::homemoves~/.agent/triggersto~/.agent/automationswhen the new one is absent, so the first 0.8.0 Sonny, scheduler or script to look moves it (the scheduler re-execs the new Sonny within a minute of an upgrade). Recorded as upgrade migrationautomations-folder, retired in 0.10.0.skills::install_ownremoves~/.agent/triggeronly when it is Sonny's own script (its usage line andexec … trigger "$@").trigger::sent_ittakesautomationand the oldtriggerorigin everywhere an origin is read (relays, lookoutby, sky, /usage, transcript), and drawn history still names oldtriggerstool calls and~/.agent/triggerscript calls as automations.Turn caps say what they count
In the eval (below), agents set their own jobs
turn_budget_tokensof 4k to 12k unasked, and every first run failed withturn_budget_exhaustedon 29k to 42k of the agent's history (the cap counts input plus output of every request). Changed:served.rsdescription: "A cap on each turn a run starts." → "A cap on the tokens of each turn a run starts, counting every request's input with the agent's history, so a cap below that history fails every run before it starts. Set one only when the person asks for a spending limit."Eval
The role eval gains an
automationday (set up a weekday-9 check, list, run now, remove) and accepts the old names so an arm of an older build compares. Results in this comment: no difference from the rename.Tests
cargo fmt --check,cargo clippy --workspace --all-targets -D warnings,cargo test -p sonny -p agent-client(931 Sonny tests), including a folder-move test and an old-origin lookout test.AGENT_TEST_RUNTIME=1 python -m tests.run --jobs 4: 47 modules OK before the rebase onto Sonny: triggers tell when their check breaks, survive a restore, and can run as a read-only shadow #623's merge;tests.test_triggerandtests.test_served(56) OK after it.🤖 Generated with Claude Code