← Back to Pull requests

Sonny: an automation does one job; the nightly cleanup is memory's own #1461

Open
unknown opened this pull request with 512 lines diff across 6 files
View on GitHub
unknown unknown commented on Nov 29, 2026 04:39 UTC
Author

<!-- claude-projects-attribution: {"github_login":"lydakis"} -->
_Requested by George · project thread_

What

An automation now does one job, as a cron line or a scheduled message does: it puts its message into an agent that is there already. Sonny only, no daemon change (src/ untouched).

Cut from automations

  • start / --fresh (the tool's start, Target::Start, run numbering, adopt/unconfine, cleanup-fresh): an agent for a job is made with start_task, then named with agent.

  • The done-lead pause: a message reopens a closed agent, as any message does.

  • live (--live): live templates stay for memory facts.

  • turn_budget_tokens / budget_counts: the daemon still offers turn budgets; Sonny uses none.
  • Changed

  • runs N counts every time the schedule came (iCalendar COUNT), whatever each did: sent, its if said no, or its agent was busy. Before, it counted messages sent. Rows and /background say ran T of N.

  • Every automation records who added it, by name and id. An agent's tool lists, reads and removes the ones it added and the ones that wake it.

  • News of a broken if goes to the agent it wakes.

  • A definition that still has a removed flag never fires: {"error":"invalid_automation","detail":"--turn-budget-tokens"}. It shows as a problem row in /background and in its agent's or adder's tool list. There is no migration.
  • Nightly memory cleanup becomes memory's own job (@memory-cleanup on Sonny's scheduler, sonny memory cleanup run), with no budget.

  • sonny memory schedule [--model M [--effort E] [--speed S]] [--cron …] writes it, and sonny memory unschedule turns it off. It stays off until the person schedules it again.

  • Each night with work, it starts a new agent memory-cleanup-N in ~/.agents/memory, as start_task makes one, then sends the cleanup ask, waits for its turn, and deletes the night before's agent.

  • At start, the old memory-cleanup automation moves to the job once, keeping its time, model, effort, speed and daemon (upgrade step cleanup-job, retires at 0.12.0).

  • /background shows it when its last night failed. Its page says when it runs next, on what model, and links last night's agent. x turns it off.
  • Text: the tool description and the automation skill now give the setup as "start the job's agent with start_task, then add with agent". docs/SONNY.md, REFERENCE.md, USAGE and FEATURES.md are updated, and the docs pictures are redrawn.

    Screenshots (synthetic data)

    /background, before (main) and after:

    <img src="https://raw.githubusercontent.com/lydakis/agent/19d7562ffa1860550925cdbbfd1f83098780b4dc/docs/sonny/background-failed.png" width="420"> <img src="https://raw.githubusercontent.com/lydakis/agent/cacd8fc9bcd239342ca95441bc0ad1e99e8cccd6/docs/sonny/background-failed.png" width="420">

    Pages, before (main) and after: the automation page has no budget line, and the cleanup has its own page.

    <img src="https://raw.githubusercontent.com/lydakis/agent/19d7562ffa1860550925cdbbfd1f83098780b4dc/docs/sonny/automation-page-60.png" width="600">
    <img src="https://raw.githubusercontent.com/lydakis/agent/cacd8fc9bcd239342ca95441bc0ad1e99e8cccd6/docs/sonny/automation-page-60.png" width="420">

    Tests

  • cargo fmt --check, cargo clippy --workspace --all-targets -D warnings, cargo test -p sonny -p agent-client: all pass.

  • AGENT_TEST_RUNTIME=1 python -m unittest tests.test_trigger: 29 run, 2 skipped, all pass.

  • - New: a trigger ends once its time came runs times, whatever each did.
    - New: a definition with a removed flag never fires.
    - Removed: the start, fresh, live and turn-cap tests.
  • New unit tests cover:

  • - the cleanup's schedule, its definition (no budget, a generation of its own), the move from the old automation, and a night's create/submit/wait/delete;
    - runs counting ticks, and old definitions as problem rows;
    - the cleanup's page.

    ---
    _Generated by Claude Code_

    Diff: 512 lines (+384 / -128) across 6 files Reviewer: chatgpt-codex-connector[bot] Review duration: 5m
    All Vouch review confidence checks passed
    Residual risk 0.40 = Change Risk (0.53) × (1 − Review Confidence (0.25)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.53 · 512 lines diff across 6 files
    0.53
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 45% · Reviewer familiarity: 35%
    24%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.373
    Shallow Review Depth shallow_review_depth
    0.344
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #1461"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: medium confidence: 24.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52.6% (MEDIUM) · Higher = larger blast radius
    52.6%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 24.8% · Lower = rushed or shallow review
    24.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 39.6% · Moderate risk
    39.6%
    Repository