Skip to content

Sonny: the sky, its replay and the lookout stay light at 10,000 agents - #655

Merged
lydakis merged 1 commit into
mainfrom
claude/project-thread-55z6gs
Nov 2, 2026
Merged

lydakis merged 1 commit into
mainfrom
claude/project-thread-55z6gs

Conversation

@lydakis

@lydakis lydakis commented Nov 2, 2026 •

Copy link
Copy Markdown
Owner

One data-oriented pass over Sonny's in-memory structures at fleet scale. I measured first at 1,000 and 10,000 agents and changed only what the numbers pointed at. No daemon change, no protocol or schema change, and nothing visible changes, so there's no FEATURES.md row.

What changed, and why

Structure Problem found Change 10,000 agents before → after
Sky replay tape (Replay.tape) Every event was kept as a parsed serde_json::Value. Each object is a BTreeMap node, so a slim event cost about 1.9 KB. Each event is kept as its JSON text (Taped). written_ms, and whether the event made an agent, sit beside the text so seek and played_to can read them without parsing. An event is parsed when it plays. 95,000 events: 178 MB → 22 MB
Sky frame (card) hues() ran models::named for every agent on every frame, even with m off. shown() sorted every agent to pick the top room. An agent's model name is worked out once, when its model changes (Agent::set_model). Model colours are computed only on m. select_nth_unstable_by replaces the full sort; the order is total, so the stars chosen are the same. p50 5.5 → 2.3 ms, p95 9.0 → 2.6 ms
Busiest-agent window (haiku::Title) Each note kept an owned String, and crown rebuilt a count map over the whole window every second. Each agent has a running count, updated as notes enter and leave the window. A note holds a u32 place for its agent, and places are reused once their count is zero. crown goes through the agents, not the notes. Same rules and tie-breaks. 1.2M notes (2,000/s for 10 min): 86 → 31 MB, weighing 16 ms → 0.2 ms/s
Lookout lineages (grow/roots) For every subscriber, every generation scanned every record: lineage, others, theirs, globbed, and then sync over every name. Made is an index of who made whom (by maker, plus the leads listed), kept as bots are created and deleted. Lineages are walked through it. globbed is computed only when a subscription has --bot globs, and sync checks only the names that could be watched. start CPU 1.9–2.1 s → 0.7–0.9 s, seated 1.1–1.2 s → 0.5 s
Lookout start listing watch() kept the whole bots listing alive for the life of the connection, next to its copy in records. drop(bots) after its last use. steady heap (massif) ~79 → ~44 MB. Peak RSS is unchanged (~103 MB): that comes from parsing the listing at start, and glibc keeps the pages it frees.

At 1,000 agents nothing got worse. Lookout start: 0.04 s → 0.05 s CPU (noise), 27 MB both. The sky frame is 1.1 → 0.8 ms.

What I kept and left alone

  • Caches: none added, none removed. The provider prompt cache and SQLite's statement cache are not touched.
  • Out of scope, owned by the reliability thread: the sky's unbounded feed channel and its drain budget (Capacity: sky replay's start reads all retained history #598 item 2), the lookout's heard/kept overflow and its durable backlog, held pagination, and the status projection (Capacity: sky replay's start reads all retained history #598 item 3, which needs a daemon change). I checked with that thread before starting; it reported no overlap.
  • Not changed: when a bot is created or deleted, every lookout still hears it (hearing). During a first start's full replay that costs about 25% of start CPU, but in steady state it is O(subscribers) per event. The lookout's records map holds full listing values, about 30 MB at 10k. Making it compact would mean changing every place that reads it, so I've left it as a follow-up if it ever matters.

How it was measured

  • sky::scale::fleet_profile (ignored test, new): SKY_AGENTS=10000 cargo test -p sonny --release fleet_profile -- --ignored --nocapture. It seats the agents and a past, drains 200k live events in batches, runs 200 frames with count/20 events per frame, and fills a replay tape. RSS is read after malloc_trim on Linux.
  • haiku::scale::the_window_at_fleet_scale (ignored test, new). It uses only the public API, so I ran the same test against base cefecb8.
  • bench/lookout_scale.py --projects 100 --tasks 100 --phases idle,restart (and 10×100 for 1k), with the agent binary fixed at base, swapping only sonny. Base was run 2×, new 4×. massif and callgrind were run on the lookout at 10k.
  • All runs are on the 4-CPU Linux container, release build with LTO off. Sky numbers compare base and branch in the same harness.

Checks

  • cargo fmt --all --check, cargo clippy --locked -p sonny --all-targets -- -D warnings: clean.
  • cargo test --release --locked -p sonny: 996 passed, plus the integration tests.
  • docs/LOOKOUT.md says how a subscriber works out what it watches, with the start numbers.

Measured first at 1,000 and 10,000 agents, then changed only what the
numbers named:

- A replay's tape keeps each event as its text, with when it was
  written and whether it made an agent beside it, rather than parsed:
  95,000 events took 178 MB, now 22 MB.
- The sky works out an agent's model name once, when its model changes,
  and only on `m` colours by it; it picks the stars it has room for
  rather than sorting every agent. A 10,000-agent frame: 5.5 ms p50,
  9.0 ms p95 before; 2.3 ms and 2.6 ms after.
- The busiest agent's window keeps a count for each agent as notes come
  and go, and each note names its agent by a place: 1.2 million notes
  in a ten-minute window took 86 MB and 16 ms to weigh each second, now
  31 MB and 0.2 ms.
- The lookout works out what each subscriber watches from one index of
  who made whom, rather than every bot listed for each subscriber and
  each generation; and lets go of the start's listing once it is in
  `records`. 10,000 bots, 100 leads: start CPU 1.9 s to 0.8 s,
  seated 1.1 s to 0.5 s.

Harnesses: sky::scale::fleet_profile, haiku::scale (ignored tests),
bench/lookout_scale.py.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGGG6mPjP8vkAvVqVgk
@lydakis lydakis self-assigned this Nov 2, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 2, 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-02T04:14:11.247059Z 19ab2f4 PR opened
🔒 Security Review ✅ Completed 2026-11-02T04:16:00.947969Z 19ab2f4 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
lydakis merged commit 79570c4 into main Nov 2, 2026
10 checks passed
@lydakis
lydakis deleted the claude/project-thread-55z6gs branch November 2, 2026 04:40
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