Skip to content

Triggers: one stable scheduler job per HOME, so the Mac stops announcing background items - #529

Merged
lydakis merged 9 commits into
mainfrom
claude/project-thread-c6ojqm
Oct 31, 2026
Merged

lydakis merged 9 commits into
mainfrom
claude/project-thread-c6ojqm

Conversation

@lydakis

@lydakis lydakis commented Oct 31, 2026 •

Copy link
Copy Markdown
Owner

Why

macOS lists every LaunchAgent as a background item. It sends a notification each time one is added or changed. Every trigger was its own LaunchAgent (or systemd unit), and every lead resets its NAME.next trigger with replace on each look. every() computes the calendar from now, so each replace wrote a new plist and the Mac announced it again. The #512 relabel and the separate backup and boot jobs added a few more.

What

This follows the cron pattern: the system gets one job per HOME, me.lydakis.agent.scheduler.TAG. It is written once and never rewritten while Sonny stays at the same path, so add, replace, rm and fires never touch it.

  • The job
    • On a Mac it is a LaunchAgent with RunAtLoad, KeepAlive on a failed exit and AbandonProcessGroup.
    • On Linux it is a systemd user service: default.target, Restart=on-failure, KillMode=process.
    • It runs sonny scheduler.
  • sonny scheduler (new sonny/src/scheduler.rs)
    • Reads trigger definitions from ~/.agent/triggers/jobs/NAME.json. Each holds the program, environment, calendar entries and an optional watched path.
    • Fires a trigger when one of its calendar times comes.
      • It catches up once after sleep or downtime, using the checkpoint in .scheduler/looked.
      • A time is kept only once its fire starts.
      • Repeated and skipped DST hours are handled.
    • Fires when a watched path changes (stat-polled every 2 s), and while the trigger's asks queue is non-empty.
    • Runs one fire per trigger at a time. A fire holds a lock on ~/.agent/triggers/.scheduler/NAME.lock.
    • Runs at most max(4 × cores, 8) fires at once. Freed places go to the trigger that has waited longest.
    • A start that fails stays due and backs off, doubling up to 5 minutes.
    • Allows one scheduler per HOME.
    • Sleeps until the next time, at most a minute. A FIFO doorbell (.ring) and fire ends wake it early.
    • Re-execs when the Sonny binary is replaced or the time zone changes.
    • Lets its own job go when its HOME is deleted.
    • Also runs sonny boot at start when start_at_boot is on, and sonny home sync every ten minutes once backup setup has run its first sync. So the old me.lydakis.agent.backup and me.lydakis.agent.boot jobs go away.
  • Triggers (trigger.rs)
    • Add, replace and rm write or delete the JSON definition and ring the scheduler.
    • A ring that finds no scheduler writes and starts the job when it is missing or names another Sonny.
    • All per-trigger launchctl/systemctl code is removed.
  • Migration at Sonny's start: a one-time upgrade::once step named "scheduler-job", which retires at 0.10.0.
    • Each old per-trigger plist or unit becomes a JSON definition with the same times, and the old job is then let go.
    • The old backup and boot jobs are retired the same way.

Checks

  • cargo test -p sonny: 742 pass. Tests include:
    • next-time calculation, including 29 February and both DST cases
    • 10,000 due triggers with failing starts
    • fair turns in the fleet
    • checkpoint timing
    • a lock held by a fire from before a restart
    • migration
  • cargo clippy -D warnings and cargo fmt --check are clean.
  • AGENT_TEST_RUNTIME=1 python -m unittest tests.test_trigger: 26 pass, 1 skipped (the opt-in real-system test). These tests run the real sonny scheduler against a real daemon under a scratch HOME.
  • Codex found issues in six review rounds. All were fixed, and the seventh pass was clean.

Not verified yet

  • launchd bootstrap/kickstart of the scheduler job on a real Mac.
  • That macOS shows one background item and no further alerts.

Both need a run on George's own Mac, with his OK.

A Mac lists each LaunchAgent as a background item and notifies the person
whenever one is added or changed. Every trigger was its own LaunchAgent
(or systemd unit), and leads rewrite their next-look trigger on every
look, so the alerts kept coming.

Now the system keeps one job per HOME, me.lydakis.agent.scheduler.TAG,
written once and left alone while Sonny stays where it is. It runs
`sonny scheduler`, a cron for triggers: it reads definitions from
~/.agent/triggers/jobs/NAME.json and fires on calendar times (catching up
once after sleep), watched paths and queued asks, one fire per trigger at a
time. The backup sync and start_at_boot run from it too, so their own jobs
go. Sonny's start moves older per-trigger, backup and boot jobs over once.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGEcjSFCKYRSW92srAS
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 31, 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-10-31T17:46:26.120819Z 5502184 New commits
🔒 Security Review ⚠️ Failed 2026-10-31T16:57:15.584794Z
We couldn’t complete this review. Comment @codex security review to try again.
a894f70 New commits
ℹ️ 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

Copy link
Copy Markdown

The account paying for this security review has reached its Codex usage limits. The payer can check the Codex usage dashboard. For personal accounts, using credits requires enabling “Use credits for security reviews” in Code review settings. If you do not manage the paying account, contact this repository's admins.

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

ℹ️ 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/scheduler.rs Resolved
Comment thread sonny/src/scheduler.rs Resolved
Comment thread sonny/src/home.rs Resolved
Comment thread sonny/src/scheduler.rs Resolved
Comment thread sonny/src/trigger.rs Resolved
Comment thread sonny/src/scheduler.rs Resolved
- Backup syncs only once setup ran its first sync: a clone put in
  ~/agent-home by hand would otherwise push this machine's home over it.
- Moving the old jobs is an upgrade::once migration (scheduler-job,
  retires at 0.10.0), with the backup's and boot's old jobs in it.
- Sonny's start rewrites the job when it runs another Sonny, even while the
  old scheduler answers its doorbell (installs that keep each version in
  its own folder).
- next_after searches eight years and a day, so 29 February crons fire.
- A trigger new to the scheduler fires once for a write to its watched path
  after its definition was written, so a write before the first read is
  not lost; every followed trigger is kept in the checkpoint.
- The scheduler's locks and checkpoint live in ~/.agent/triggers/.scheduler,
  which Sonny's start-up cleanup leaves, so a checkpoint write under way is
  never taken from it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGEcjSFCKYRSW92srAS
@chatgpt-codex-connector

Copy link
Copy Markdown

The account paying for this security review has reached its Codex usage limits. The payer can check the Codex usage dashboard. For personal accounts, using credits requires enabling “Use credits for security reviews” in Code review settings. If you do not manage the paying account, contact this repository's admins.

@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: 51b76eea38

ℹ️ 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/scheduler.rs Resolved
From the performance review of #529:
- Fires the scheduler runs are indexed by trigger (no scan of running
  processes per trigger per wake); the trigger loop no longer clones and
  sorts names, and ended fires are a set.
- At most four fires per core (eight at least) run at once: a burst of due
  triggers waits for room, woken by a fire's end.
- A start that fails keeps its trigger due and retries after a wait that
  doubles from a second up to five minutes, instead of losing that run.
- Watched paths are looked at every two seconds however often it wakes.

New test: 10,000 due triggers with every third start failing once all fire
exactly once, never more than the cap at a time.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGEcjSFCKYRSW92srAS
@chatgpt-codex-connector

Copy link
Copy Markdown

The account paying for this security review has reached its Codex usage limits. The payer can check the Codex usage dashboard. For personal accounts, using credits requires enabling “Use credits for security reviews” in Code review settings. If you do not manage the paying account, contact this repository's admins.

next_after took one moment for each local time, so in the repeated hour
an every-minute trigger skipped to 02:00. A local time now names every
moment it can (epochs_of tries both DST readings): an entry with a set hour
comes at the first, as cron runs a set-time job once; one with any hour
comes at both, as time goes. The test runs itself in America/New_York as a
child, so its TZ is no other test's.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGEcjSFCKYRSW92srAS
@chatgpt-codex-connector

Copy link
Copy Markdown

The account paying for this security review has reached its Codex usage limits. The payer can check the Codex usage dashboard. For personal accounts, using credits requires enabling “Use credits for security reviews” in Code review settings. If you do not manage the paying account, contact this repository's admins.

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

ℹ️ 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/scheduler.rs Resolved
Comment thread sonny/src/scheduler.rs Resolved

lydakis commented Oct 31, 2026

Copy link
Copy Markdown
Owner Author

@codex security review

This PR's automatic security review failed on the usage limit; it is one of the riskier rows in #531 (a login job that runs trigger fires outside the sandbox from ~/.agent/triggers/jobs).


Generated by Claude Code

… time

- A calendar time that came is checkpointed when its fire starts (or at
  once when a running fire skips it), so a scheduler that restarts while
  the time waits for room or after a failed start still finds it due.
- ensure() is serialized within the process: Sonny's start reaches it from
  the trigger, backup and start-at-login threads, whose writes of the job
  shared one temporary file.

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

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

ℹ️ 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/scheduler.rs Resolved

@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: 60079ee58b

ℹ️ 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/scheduler.rs Resolved

@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: 8c0e59ad99

ℹ️ 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/scheduler.rs Resolved
Comment thread sonny/src/scheduler.rs Resolved
Comment thread sonny/src/scheduler.rs Resolved
@lydakis
lydakis merged commit 36c6f49 into main Oct 31, 2026
4 checks passed
lydakis pushed a commit that referenced this pull request Nov 1, 2026
…p clone is not set up

A scheduler the system started after its HOME was deleted made HOME
again opening its doorbell, so never saw it gone and ran on idle; it now
checks before making anything. And backup counted as set up once
~/agent-home had a remote, though a clone made by hand has had no
restore or first sync and the scheduler never syncs it; setup now needs
that first sync too. (Codex code review on review-only #607, for #529.)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGCrVNEpqFFEqPCMbC2
lydakis added a commit that referenced this pull request Nov 1, 2026
…sitory (#603)

Fixes #597. Adds `agent sandbox [--writable PATH]... -- COMMAND` (network always off, client protections, hold released before exit). Sonny runs the tree's status, the seed's listings and the task worktree's checkout through it. The worktree is made with a plain --no-checkout add, then checked out confined. Removal keeps git's submodule guard, and a kept agent/NAME branch is never deleted. Also fixes #607's findings for #529: a scheduler started after its HOME is gone, and a backup clone made by hand counted as set up.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGCrVNEpqFFEqPCMbC2
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