Skip to content

Lookout: stays light with thousands of bots - #398

Merged
lydakis merged 4 commits into
mainfrom
claude/project-thread-faied7
Oct 30, 2026
Merged

lydakis merged 4 commits into
mainfrom
claude/project-thread-faied7

Conversation

@lydakis

@lydakis lydakis commented Oct 30, 2026 •

Copy link
Copy Markdown
Owner

The lookout collapsed near 1,000 bots. Four costs multiplied each other:

  1. Every bot made, forked or deleted made every subscriber re-check every bot (Lookout::sync), which is leads × bots per new bot.
  2. Every connect replayed the whole log from cursor 0, so a start cost leads × bots².
  3. Every event, down to each text delta, went through every subscriber, and each subscriber kept its own copy of every bot.
  4. Notes and status checks were awaited one at a time inside the event loop. A slow moment filled the client's queue, the client dropped the session, and the lookout replayed from 0 and fell behind again.

This follows how Kubernetes controllers stay light on large clusters (list then watch from a version, a shared cache, handlers by key, a work queue):

  • One bot checked, not all. A bot made or deleted is checked alone (check). The full check runs only when a subscriber's subscriptions change, and only for that subscriber (resubscribe(all)).
  • Events go by bot. watchers indexes which lookouts hear each bot (its own, and those that watch it). An event reaches only those, and a bot made or deleted reaches all. Each subscriber seats only the bots it watches plus its own.
  • Follow from the cursor. A lookout with a cursor follows after it and never replays the whole log. Once at start it reads who asked for its subscribers' running turns (prompts) and what each subscriber's own turn waits on (turns), which the replay used to tell it. Only a lookout with no cursor reads the whole log, once. refresh_tools now runs once per lookout, not on every reconnect.
  • Notes beside the stream. wake, wake_sources and the "does it rest?" check run as spawned tasks whose answers come back on a channel (answered). One note is in flight per subscriber. A dropped connection makes what a note carried news again (reconnected).
  • The log now says disconnected and lagged, so a dropped session shows up.

No behavior change in what a subscriber hears or when.

Numbers

From bench/lookout_scale.py (added here): 4-core Linux container, every task streams 10 deltas a second, 4 s turns in rounds, each sent from its lead.

Bots / subscribers Lookout CPU under load, before → after Endings told, before → after Start CPU, before → after Peak memory, before → after
330 / 30 18% → 4% 1,200 → 2,100 of 2,100 0.5 s → 0.05 s 21 → 17 MiB
1,010 / 10 35% → 2% 2,248 → 0* of 6,000 1.3 s → 0.2 s 33 → 24 MiB
1,100 / 100 87% → 4% 0 → 0* of 7,000 13 s → 0.35 s 88 → 31 MiB
3,300 / 300 did not start in 10 min → 21% not reached → 0* of 15,000 over 600 s → 1.9 s 278 → 59 MiB

* Past about 1,000 busy bots, the daemon still drops the lookout's session. Each socket session queues at most 64 messages (src/output.rs:48) on top of its 2 MiB byte budget, and hundreds of streaming turns overflow it before the writer runs. With that limit raised locally to 4,096, 1,100 bots / 100 subscribers told all 3,000 of 3,000 endings (p95 2.9 s). That daemon change is waiting on George and isn't in this PR.

Tests

  • cargo test -p sonny lookout: 67 pass, including three new tests (an event reaches only the lookouts that hear its bot; a note goes beside the stream and one lost with the connection is news again; a turn running before the lookout started is told as whoever asked).
  • tests.test_lookout (live): all 7 pass, including both restart tests.
  • tests.test_served: 2 of 17 fail in this container because bubblewrap isn't installed (sandbox_unavailable when a task starts). They don't touch the lookout.
  • clippy is clean.

A streaming synthetic model in its own process, P projects of T tasks
whose leads are subscribed as Sonny subscribes them, and the companions
in a bot's path: the lookout's start, rest and load (CPU, memory, how
late and whether each lead hears a task's turn ended), its restart over
the whole log, and a burst of gated calls against a slow judge.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGEHSaQA9KQfmqTB4MM
Each event reaches only the subscribers that watch its bot (a bot made
or deleted, all of them), and each checks that one bot alone instead of
every bot listed. Each subscriber keeps only the bots it watches. A
lookout follows from its cursor rather than replaying the whole log,
reading who asked for its subscribers' running turns once when it starts.
Notes and status checks go to the daemon beside the stream, so no call
holds the events up; a dropped connection makes what a note carried news
again.

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

chatgpt-codex-connector Bot commented Oct 30, 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-30T01:48:18.123418Z ec58e6c New commits
🔒 Security Review ✅ Completed 2026-10-30T01:49:46.419798Z ec58e6c 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 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: 1cc2e6ec51

ℹ️ 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/lookout/mod.rs Resolved
Comment thread sonny/src/lookout/mod.rs Resolved
Comment thread sonny/src/lookout/mod.rs Resolved
…ers, read who asked for turns begun before it heard

- A note the daemon has not answered counts as untold, so a saved
  cursor never passes news a crash would lose.
- A status answer is let go when the subscriber's own events came after
  the question: it is older than what they said.
- A task's turn that ends without having begun in what the lookout
  heard (before its cursor, or before its bot was watched) is held while
  its prompt is read for who asked, instead of being told as the
  person's. This replaces the start-up read of running turns.

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

@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: 3f441150e8

ℹ️ 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/lookout/mod.rs Resolved
Comment thread sonny/src/lookout/mod.rs Resolved
Each piece of a turn's state the lookout learns from its events (who
asked, what the subscriber waits on, a task's resolving) began before
the cursor for a turn that spans it. Recovering each from listings one by
one missed some, so the cursor file now keeps two marks, as a consumer
commits its offset only up to its oldest record still in work: where the
news ended, and just before the oldest turn still under way among the
bots a lookout hears. The stream starts at the second; what comes before
the first is history, as before. This replaces the prompt reads for
turns begun before the cursor and the start-up read of what each
subscriber waits on, and covers a dropped connection too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGEHSaQA9KQfmqTB4MM
@lydakis
lydakis merged commit 0e2ef5a into main Oct 30, 2026
4 checks passed
lydakis added a commit that referenced this pull request Oct 30, 2026
* Sonny: a register of every feature it has had, and why (sonny/FEATURES.md)

Each Sonny feature added, changed or removed, with its pull requests,
status (experimental, shipped, removed), the reason, and a Used? column
for the person to fill in. AGENTS.md asks every pull request that
touches a Sonny feature to update its row.

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

* FEATURES.md: the commons (#392)

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

* FEATURES.md: /goal (#397)

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

* FEATURES.md: #398 and #399

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

---------

Co-authored-by: Claude <[email protected]>
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