Skip to content

Sonny: triggers tell when their check breaks, survive a restore, and can run as a read-only shadow - #623

Merged
lydakis merged 8 commits into
mainfrom
claude/project-thread-fhknyi
Nov 1, 2026
Merged

lydakis merged 8 commits into
mainfrom
claude/project-thread-fhknyi

Conversation

@lydakis

@lydakis lydakis commented Nov 1, 2026 •

Copy link
Copy Markdown
Owner

Three changes to Sonny's triggers, all Sonny only (no daemon, protocol or schema change).

1. A broken --if is told once, and once when it works again

Before: a gate that could not run (an error, or past GATE_TIMEOUT = 60 s) settled the fire as failed and told nobody; only /background showed it. A skipped or failed send already called missed(), a gate failure never did.

Now (sonny/src/trigger.rs, fire()): GateNews::of(before, said) compares what the gate said with what the row's checked kept. The first break tells; a break already told does not; the first yes or no after a told break says it works again. That is edge-triggered alerting, as monitoring tools alert on a change of state rather than every check, so a gate that fails every minute is one note, not one a minute. The row's checked.told means a break was told and no "works again" has gone since; a break note or a recovery note that did not go is tried again on the next check. While the daemon is paused, a gated fire waits for the resume before it runs its --if (found in the Monday rehearsal), as the turn a fire sends then waits.

Who hears: --reply-to, else the agent that added a --start trigger, else the agent it messages (gate_told). The note is attached (no turn), under the existing missed. request ids, which fire_generation already never counts as a fire's own. missed() now shares note() with it.

The automation skill's line "a gate that runs past its minute is a failed fire with no turn, which nothing below hears of" now says the job hears of it once.

2. Triggers survive a restore

Before: ~/.agent/triggers/jobs was not in the backup. Copying it alone would not help, since each trigger is pinned to an agent id of the old store, which the backup leaves out on purpose.

Now:

  • home::sync writes triggers.json into the copy: every definition (trigger::backed_up), without what its fires did or its daemon's ids, written only when it changed and removed with the last trigger. Nothing is ever set up from it.
  • A restore (home::adopt) leaves that list at ~/.agent/sonny/restored-triggers.json (trigger::restore).
  • The first lead of each folder opened after it gets a queued note (origin sonny.restore, in parts of at most 128 KiB of definitions, under the daemon's 256 KiB message limit) with that folder's triggers (each row's folder is the longest folder its agent's name starts with, from the leads the list names, so shop and shop.web stay apart), asking it to set up again the ones the person asked for and leave out what ran its course. A lead's own LEAD.next look is left out, since each lead sets its own. ~/.agent/sonny/restored-told keeps which folders were told, so one lead per folder hears; until then the backup keeps a restored folder's rows, so a sync right after a restore does not drop them.

This follows memory over codified behaviour: which triggers the person still wants is a judgment, so it goes to the lead, as an upgrade step does.

3. --shadow: a dry run for moving a job onto a trigger

trigger add --shadow (the tool's shadow: true). Each fire forks the agent where it is now into BOT.shadow-HEX (a --start trigger whose agent is not made yet first makes that agent, sending it nothing, so every copy is a fork with its allow list and a day's idle expiry; a name past 114 bytes is cut so the copy's fits 128), then confines it before it runs:

  • the read-only sandbox, and no shell or write_stdin: a sandboxed agent's commands still reach its daemon socket, which takes a submit to another agent or a pause from a read-only agent (capped), so a copy reads with the daemon's file tools and read-only MCP tools only;
  • no gate a person or a model answers: the source's gates are replaced by one gate on exec alone, tagged shadow, which nobody serves and which lapses in 60 s, so anything that ever reached it is denied. Writes outside the sandbox are refused with no gate to ask (write_denied);
  • the person's command rules without their allow rules;
  • of Sonny's tools only exec (fork allow), and in exec a call of an MCP tool that does not say it only reads (readOnlyHint), or that its server's approval mode would ask about, is refused outright for a shadow (sonny/src/exec.rs);
  • no created_by, so its rules are its own and not its source's; the tool host keeps a shadow on the shadow rules (tool_host::configured) and declared::refresh leaves its tools and gates alone.

A copy that cannot be confined is deleted before it runs. Its answer goes as a report to --reply-to, which defaults for a shadow trigger to the agent that added it, else the --start adder, else the agent it copies, as [trigger NAME · TIME · shadow run of BOT STATUS: a read-only copy, so nothing past reading was done]. The copy is deleted once its report went, and expires after a day idle otherwise.

An asked-for shadow fire keeps its submit (and, once its report went, how it ended) before it goes, so a fire cut short goes on with the same copy or ends as it did. The outcome keeps how the copy's turn ended (ended), which /background and forget_done read once the copy is gone.

Why this shape: Codex's read-only sandbox with approvals never is the precedent (an escape is refused rather than asked). Following it fully means nothing asks the person; the trade-off Codex accepts is that a read that needs to leave the sandbox fails, which is right for a dry run whose job is to say what it would have done. Withholding the shell goes further than Codex, because Agent's socket is reachable from the sandbox.

Docs

  • sonny/FEATURES.md: Triggers and backup rows.
  • docs/SONNY.md: usage line, shadow runs, a broken --if, a gate during a pause.
  • sonny/skills/automation/SKILL.md: gate failures are told; moving a job onto a trigger with shadow first.

Tests

  • cargo test -p sonny (905 pass): gate news edges (including an owed recovery) and who hears; backup list contents and the restore note per folder (lead looks, other folders and a dotted folder's rows left out, told once, long lists in parts); a sync writes, keeps (while a restored folder is untold) and removes triggers.json; shadow names (a 128-byte agent name too), tools (no shell), rules and fields; a shadow fire's whole sequence against a stand-in daemon, and an asked fire cut short before and after its report; a copy that cannot be confined is deleted before it runs; exec in a shadow runs a read-only tool and refuses others without asking.
  • Runtime suite (AGENT_TEST_RUNTIME=1 python -m unittest tests.test_trigger, 30 tests): a shadow fire against a real daemon (fork, read-only configure, report, copy gone), a --start shadow that makes its agent and copies it, a broken --if told once, not again, then "works again", and a gate that waits out a pause.
  • cargo fmt --check, cargo clippy --workspace --all-targets -D warnings.

🤖 Generated with Claude Code

…store

A trigger whose --if could not run (an error, or past 60 s) settled the
fire as failed and told nobody. Now the agent that hears of the trigger
(its --reply-to, else the agent that added a --start trigger, else the
agent it messages) gets one attached note when the check breaks and one
when it works again, as alerts fire on a change of state. A note that
did not go is tried again on the next failure.

The backup now keeps a list of every trigger's definition
(triggers.json in the copy), without what its fires did or the ids of
its daemon. A trigger is tied to an agent of the old machine's store,
which the backup leaves out, so nothing is set up from the list: a
restore leaves it for the leads, and the first lead of each folder
opened after it gets a note with that folder's triggers to set up again
the ones the person asked for. A lead's own LEAD.next look is left out.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGF964FQkZib7N2tFwi
A dry run for moving a job from elsewhere onto a trigger. Each fire of a
shadow trigger forks its agent (or, for a --start trigger whose agent is
not made yet, makes one as its first fire would) into BOT.shadow-HEX and
confines it before it runs: the read-only sandbox, no gate a person or a
model answers (one unserved, lapsing gate on exec alone), the person's
command rules without their allow rules, and of Sonny's tools only
exec, where a call of an MCP tool that does not say it only reads, or
that its server would ask about, is refused. Everything past reading is
refused, never asked about. A copy that cannot be confined is deleted
before it runs.

The copy's answer goes as a report to --reply-to, which defaults for a
shadow trigger to the agent that added it, and the copy is deleted once
the report went. The tool host keeps a shadow on its rules and leaves
its tools and gates alone.

The runtime suite now checks a shadow fire against a real daemon, and
that a broken --if is told once and once when it works again.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGF964FQkZib7N2tFwi
@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-01T19:39:45.450106Z 4cb7459 New commits
🔒 Security Review ✅ Completed 2026-11-01T18:33:27.776522Z e1120c1 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.

@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: e1120c141a

ℹ️ 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 Resolved
Comment thread sonny/src/home.rs Resolved
Comment thread sonny/src/trigger.rs Resolved
Comment thread sonny/src/trigger.rs Resolved
Comment thread sonny/src/trigger.rs Resolved
…s kept

- A --start --shadow trigger whose agent no fire made yet makes that agent
  (sending it nothing) and forks the copy from it, so every copy has the
  fork's tool allow-list and day-idle expiry; start_shadow is gone.
- A shadow fire someone asked for keeps its submit before it goes, so a
  fire cut short goes on with the same copy and request instead of a new copy.
- The backup keeps a restored folder's trigger list until its lead was
  handed it, so a sync right after a restore does not drop it.
- A "works again" note that did not go stays owed (checked.told) and goes
  on the next check that works.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGF964FQkZib7N2tFwi

@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: 99dd93e8ea

ℹ️ 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 Resolved
Comment thread sonny/src/trigger.rs Resolved
…ts go by exact folder

- Once a shadow fire's report went, its ask keeps how it ended before the
  copy is deleted, so one cut short after that ends as it did instead of
  resubmitting to a copy that is gone.
- A restored row belongs to the longest folder name its agent starts with,
  from the leads the list names, so `shop` is not handed `shop.web`'s
  triggers and telling `shop` does not drop them from the backup.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGF964FQkZib7N2tFwi
The first machine's last sync was rejected on macOS once the restored
machine had pushed to the same remote (sync does not fetch), so the
second machine now backs up to a remote of its own.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGF964FQkZib7N2tFwi

@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: 740b6a6215

ℹ️ 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 Resolved
Comment thread sonny/src/trigger.rs Resolved
Comment thread sonny/src/trigger.rs Resolved
… notes in parts

- A shadow copy goes without `shell` and `write_stdin`: a sandboxed
  agent's commands still reach its daemon socket, which takes a submit to
  another agent or a pause from a read-only agent, so a dry run reads with
  the daemon's file tools and read-only MCP tools only.
- A shadow fire's outcome keeps how the copy's turn ended (`ended`), which
  `with_turn` and `forget_done` read once the copy and its handle are gone.
- A restored folder's list goes to its lead in parts of at most 128 KiB of
  definitions, each its own turn, under the daemon's 256 KiB message limit;
  the folder is told once every part went.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGF964FQkZib7N2tFwi
Found in the Monday rehearsal: a gate ran while the daemon was paused,
though the turn a fire sends then is held until the resume. A gated fire
now looks at the daemon's pause first and waits, looking every 5 s, until
it lifts; a daemon that does not answer is not taken as paused.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGF964FQkZib7N2tFwi

@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: 1ddee40dbf

ℹ️ 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 Resolved
An agent named in 115 to 128 bytes made a copy name past the daemon's
128 bytes, so its shadow fires all failed. The copy's name now keeps as
much of the agent's name as fits before `.shadow-` and its stamp.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGF964FQkZib7N2tFwi
@lydakis
lydakis merged commit 13b8999 into main Nov 1, 2026
10 checks passed
@lydakis
lydakis deleted the claude/project-thread-fhknyi branch November 1, 2026 20:03
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