Skip to content

Sonny: triggers are automations, for the person and for agents; turn caps say what they count - #632

Merged
lydakis merged 11 commits into
mainfrom
claude/project-thread-29yeal
Nov 1, 2026
Merged

lydakis merged 11 commits into
mainfrom
claude/project-thread-29yeal

Conversation

@lydakis

@lydakis lydakis commented Nov 1, 2026 •

Copy link
Copy Markdown
Owner

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

Where Before After
Agents' tool (sonny/src/served.rs) triggers, verb fire, answer "fired": true, list key triggers automations, verb run, "ran": true, list key automations
Script (sonny/src/skills.rs) ~/.agent/trigger (fire) ~/.agent/automation (run); Sonny removes its own old script
CLI sonny trigger …, /triggers sonny automation …, /automations
State (sonny/src/trigger.rs Places) ~/.agent/triggers ~/.agent/automations, moved once
Message header and origin [trigger NAME · …], origin: "trigger" [automation NAME · …], origin: "automation"
when and why words fire, fired on demand, run now
Errors invalid_trigger, trigger_exists, trigger_not_found, trigger_failed, triggers_unsupported automation_* / automations_unsupported
Restore restored-triggers.json, "set up again with the triggers tool" restored-automations.json, "automations tool"
Memory cleanup (client/src/memory.rs) schedules through ~/.agent/trigger through ~/.agent/automation
Approver policy (client/src/approver.rs) "managing the agent's own triggers" "own automations"
lead.md, automation and zen skills, README, docs trigger(s) automation(s)

Kept, since no agent or person reads them: the module trigger.rs and its types, request ids trigger_…, --trigger-fire, the old per-trigger launchd label (only for the scheduler-job migration), AGENT_TRIGGER_LOCK_FD.

Upgrade

  • trigger::Places::home moves ~/.agent/triggers to ~/.agent/automations when 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 migration automations-folder, retired in 0.10.0.
  • skills::install_own removes ~/.agent/trigger only when it is Sonny's own script (its usage line and exec … trigger "$@").
  • History stays readable: trigger::sent_it takes automation and the old trigger origin everywhere an origin is read (relays, lookout by, sky, /usage, transcript), and drawn history still names old triggers tool calls and ~/.agent/trigger script calls as automations.

Turn caps say what they count

In the eval (below), agents set their own jobs turn_budget_tokens of 4k to 12k unasked, and every first run failed with turn_budget_exhausted on 29k to 42k of the agent's history (the cap counts input plus output of every request). Changed:

  • served.rs description: "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."
  • The automation skill and docs/SONNY.md say the same.

Eval

The role eval gains an automation day (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

🤖 Generated with Claude Code

@lydakis lydakis self-assigned this Nov 1, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-01T22:07:41.710101Z a001a9c New commits
🔒 Security Review ✅ Completed 2026-11-01T20:12:46.417579Z 8f4eb03 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

lydakis commented Nov 1, 2026

Copy link
Copy Markdown
Owner Author

Eval: python3 -m bench.role_eval all --day automation --runs 3, gpt-6.1-sol, A = 09ae110 (triggers/fire), B = cdaf930 (this rename before the rebase onto #623's merge). Day: set up a weekday-9 branch check, list what's scheduled, run it now, remove it.

run steps right scheduled via ended clean "trigger" / "automation" said to the person turns output tokens
A1 4/4 tool yes 0 / 0 13 13.9k
A2 4/4 tool yes 0 / 1 29 29.1k
A3 4/4 tool yes 0 / 0 13* 1.8k*
B1 4/4 tool yes 0 / 0 11 9.3k
B2 4/4 tool yes 0 / 0 16 15.5k
B3 2/4 tool yes 0 / 1 8* 1.7k*

* 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 approval_denied from the eval's allowlist, not a naming mix-up (which rule refused it isn't recoverable, since the task was discarded).

Unrelated finding, in both arms: all 5 first manual runs failed with turn_budget_exhausted, because the agent that set the job up capped it at 4k-12k tokens, while a run on that same agent reads its 29k-42k of history first. Left for a follow-up.


Generated by Claude Code

@lydakis lydakis changed the title Sonny: triggers are automations, for the person and for agents Sonny: triggers are automations, for the person and for agents; turn caps say what they count Nov 1, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread sonny/src/trigger.rs Outdated
Comment on lines +135 to +136
if !self.state.exists() && old.is_dir() {
let _ = std::fs::rename(&old, &self.state);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@lydakis
lydakis force-pushed the claude/project-thread-29yeal branch from 925d3e1 to 1659e4d Compare November 1, 2026 21:08

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread sonny/src/trigger.rs Outdated
Comment on lines +140 to +142
match old.quiet(scheduling) {
Some(_held) if std::fs::rename(&old.state, &places.state).is_ok() => places,
_ => old,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread sonny/src/trigger.rs
/// 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")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread sonny/src/home.rs
Comment on lines +378 to +379
let held = places.repo.join(AUTOMATIONS);
match std::fs::remove_file(places.repo.join(TRIGGERS)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread sonny/src/upgrade.rs Outdated
Comment on lines +83 to +86
// `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).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread sonny/src/trigger.rs
Comment on lines +150 to +152
let Some(_held) = old.quiet(scheduling) else {
return false;
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

claude added 11 commits November 1, 2026 22:03
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
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
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
@lydakis
lydakis force-pushed the claude/project-thread-29yeal branch from 8bb8561 to a001a9c Compare November 1, 2026 22:06
@lydakis
lydakis merged commit 59133c9 into main Nov 1, 2026
10 checks passed
@lydakis
lydakis deleted the claude/project-thread-29yeal branch November 1, 2026 22:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants