Skip to content

Sonny: bound the shared MCP host and pin a T3 thread to its bot's identity - #474

Merged
lydakis merged 5 commits into
mainfrom
claude/project-thread-p6odw4
Oct 31, 2026
Merged

lydakis merged 5 commits into
mainfrom
claude/project-thread-p6odw4

Conversation

@lydakis

@lydakis lydakis commented Oct 31, 2026 •

Copy link
Copy Markdown
Owner

From the external review's priority list ("memory bounds in the shared MCP host"). Sonny only, no daemon change. Closes #347 and #332, and closes items 2 and 3 of #335. Item 1 of #335, the macOS allocator footprint, stays parked.

The precedents

  • rmcp already caps each message at 16 MiB. That covers a stdio line (DEFAULT_MAX_LINE_LENGTH) and an HTTP event-stream event (DEFAULT_MAX_SSE_EVENT_SIZE). Sonny uses the same 16 MiB as its per-result cap. What rmcp does not bound is two things: how many results a single script holds at once, and an HTTP server that answers with a plain JSON body.
  • Codex's head/tail output buffer. Codex keeps a command's output as its first half and its latest half, within 1 MiB. Sonny now does the same while collecting text(), instead of applying the budget only after the run ends.

What changes

exec (sonny/src/exec.rs)

  • Output. A script's output is kept within 1 MB as it runs: the first half, then the latest. The saved "whole output" file holds what was kept, with the dropped byte count marked between the halves.
  • Calls in flight. A script can have at most 8 calls in flight (Promise.all over thousands queues). Together with the 16 MB result cap and the four running scripts, results held outside QuickJS are at most about 512 MB in the worst case. Before this change there was no limit.
  • Result format. A result now reaches the script as a single JSON string, not as a serde_json::Value tree plus a string.
  • One deadline. The deadline is set at the start of the call. Waiting for a place and listing servers' tools both count against it, so timeout_ms: 300 against a server that takes 5 s to start ends in about 300 ms with "ran out of time before it started". Servers now list their tools concurrently.
  • Tool-name collisions. When two tools normalize to the same identifier (my-server and my_server both give mcp__my_server__search), neither one is put on tools or in ALL_TOOLS. The description and the call error both explain why.

MCP host (sonny/src/mcp.rs)

  • Cache file. The listing cache is now keyed by a SHA-256 of the config. Before, the key was the config's debug string, which contained env and http_headers values. The file is written 0600 inside a 0700 folder. sha2 is already in the lockfile through portable-pty, so no new crate is built.
  • Stderr. stderr is read in 8 KB chunks. Each kept line is cut at 1 KB, and the last 20 lines are kept.
  • Abandoned starts. A start that is given up (a script's deadline, or the start timeout) now stops the server's whole process group through a guard. Before, a wrapper's child (npx → node) could outlive it.

ACP (sonny/src/acp.rs, sonny/src/t3.rs)

  • What a thread stores. A T3 thread now stores its bot's bot_id and the store lineage, not just the bot's name. On resume or load, Sonny refuses a different store. It also refuses a bot that was removed and then created again under the same name: the daemon's inspect returns a bot_not_found error for a stale bot_id. Every submit now carries bot_id.
  • Old thread files. A thread file saved before this change holds only a name. It binds by that name once and is pinned from then on (a one-way conversion), so George's existing T3 threads keep working.

Docs: docs/SONNY.md (exec bounds, cache, stderr) and sonny/README.md (T3 identity) are updated, and FEATURES.md history now includes this PR.

Known gap

rmcp drops a stdio line over 16 MiB and leaves the connection open, so a call whose result is that large waits out its 60 s timeout instead of failing right away. rmcp also reads an HTTP server's non-streamed JSON body without a limit (response.bytes()). Both are upstream; I'll note them on #335.

Tests

  • cargo test -p sonny -- exec:: mcp:: t3::: 28 pass. New tests cover the deadline (a slow server), collisions, calls in flight and output bounding, the head/tail Output, the cache's secrets and file modes, stderr cutting, and the pinned thread record.
  • tests/test_acp.py::test_a_thread_comes_back_as_its_bot_and_not_another_made_under_its_name passes locally. The thread resumes, then the lead is deleted and created again under the same name, and the resume is refused with "calc.lead is gone".
  • Locally, the other ACP and served tests that start tasks need bubblewrap, which this container can't install, so CI is the check for those.

…ntity

The lookout's MCP host held what scripts and servers sent outside QuickJS's
cap without bound, and a resumed T3 Code thread bound by bot name alone.

- exec: a script's output is kept within 1 MB as it runs, its first half
  and its latest, as Codex keeps a command's; eight calls in flight per
  script; a result over 16 MB (rmcp's per-message cap) is refused; results
  reach the script as one JSON string, not a Value tree.
- exec: one deadline from the call, which waiting for a place and listing
  servers' tools spend; servers list concurrently, and a start given up
  stops its process group.
- exec: tools whose identifiers collide are refused, not replaced.
- mcp: the listing cache is keyed by a SHA-256 of the config, not the
  config's debug string with its env and headers, and written 0600 in a
  0700 folder; stderr is read in chunks, each line cut at 1 KB.
- acp: a thread remembers its bot's id and store lineage; resume refuses a
  bot made again under the name, or another store's, and submit carries
  bot_id. A thread kept by name only binds by name once and is pinned then.

Closes #347, closes #332; #335 keeps its macOS allocator item.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGF1uDHaNjs42Bgs9Uu
@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-31T02:46:48.137843Z 48c5aaa New commits
🔒 Security Review ✅ Completed 2026-10-31T02:47:42.699268Z 48c5aaa 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.

@lydakis lydakis self-assigned this Oct 31, 2026

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

ℹ️ 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 docs/SONNY.md Resolved
Comment thread sonny/src/exec.rs Resolved
@lydakis
lydakis merged commit 8236fd8 into main Oct 31, 2026
5 checks passed
lydakis added a commit that referenced this pull request Oct 31, 2026
* Sonny: bound the shared MCP host and pin a T3 thread to its bot's identity

The lookout's MCP host held what scripts and servers sent outside QuickJS's
cap without bound, and a resumed T3 Code thread bound by bot name alone.

- exec: a script's output is kept within 1 MB as it runs, its first half
  and its latest, as Codex keeps a command's; eight calls in flight per
  script; a result over 16 MB (rmcp's per-message cap) is refused; results
  reach the script as one JSON string, not a Value tree.
- exec: one deadline from the call, which waiting for a place and listing
  servers' tools spend; servers list concurrently, and a start given up
  stops its process group.
- exec: tools whose identifiers collide are refused, not replaced.
- mcp: the listing cache is keyed by a SHA-256 of the config, not the
  config's debug string with its env and headers, and written 0600 in a
  0700 folder; stderr is read in chunks, each line cut at 1 KB.
- acp: a thread remembers its bot's id and store lineage; resume refuses a
  bot made again under the name, or another store's, and submit carries
  bot_id. A thread kept by name only binds by name once and is pinned then.

Closes #347, closes #332; #335 keeps its macOS allocator item.

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

* FEATURES: MCP bounds and T3 identity pinning (#474)

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

* exec: one text past the output cap keeps its own start

Codex review on #474: a first text() over 1 MB kept only its end. The
head now fills from the text that overflows it.

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

* tests: a T3 thread's record holds its bot's identity and store

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

* Split Sonny's tool answering out of the lookout into its own companion

The lookout only watches and tells now. Sonny's tools (start_task, memory,
goal, commons, exec and its MCP servers) are answered by `sonny tool-host`,
the daemon's companion `sonny-tool-host`, kept beside the lookout by Sonny
and `sonny acp`, so a slow, crashing or memory-heavy tool never holds up a
lead's news. The host signals the lookout (SIGUSR1) when a call changes the
subscription or goal files it reads, follows only tool_started and
turn_finished from its own cursor, refreshes agents' declared tools on
start, and gives way to another build as the lookout does. /status says
"tools not answered" when no host runs.

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

* FEATURES: tool host rows for #481

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

* Lookout: reread on a subscriptions or goal call's end in the stream, not a signal

A SIGUSR1 from the tool host could be handled after the events that
follow the call's tool_result, so news right after a subscribe could be
read with the old subscriptions and lost. The lookout now follows those
calls by their tool_started and rereads on their tool_completed, which
the stream orders before every later event.

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

* cargo fmt

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

---------

Co-authored-by: Claude <[email protected]>
lydakis added a commit that referenced this pull request Oct 31, 2026
…text (#494)

* Sonny: bound the shared MCP host and pin a T3 thread to its bot's identity

The lookout's MCP host held what scripts and servers sent outside QuickJS's
cap without bound, and a resumed T3 Code thread bound by bot name alone.

- exec: a script's output is kept within 1 MB as it runs, its first half
  and its latest, as Codex keeps a command's; eight calls in flight per
  script; a result over 16 MB (rmcp's per-message cap) is refused; results
  reach the script as one JSON string, not a Value tree.
- exec: one deadline from the call, which waiting for a place and listing
  servers' tools spend; servers list concurrently, and a start given up
  stops its process group.
- exec: tools whose identifiers collide are refused, not replaced.
- mcp: the listing cache is keyed by a SHA-256 of the config, not the
  config's debug string with its env and headers, and written 0600 in a
  0700 folder; stderr is read in chunks, each line cut at 1 KB.
- acp: a thread remembers its bot's id and store lineage; resume refuses a
  bot made again under the name, or another store's, and submit carries
  bot_id. A thread kept by name only binds by name once and is pinned then.

Closes #347, closes #332; #335 keeps its macOS allocator item.

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

* FEATURES: MCP bounds and T3 identity pinning (#474)

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

* exec: one text past the output cap keeps its own start

Codex review on #474: a first text() over 1 MB kept only its end. The
head now fills from the text that overflows it.

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

* tests: a T3 thread's record holds its bot's identity and store

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

* Split Sonny's tool answering out of the lookout into its own companion

The lookout only watches and tells now. Sonny's tools (start_task, memory,
goal, commons, exec and its MCP servers) are answered by `sonny tool-host`,
the daemon's companion `sonny-tool-host`, kept beside the lookout by Sonny
and `sonny acp`, so a slow, crashing or memory-heavy tool never holds up a
lead's news. The host signals the lookout (SIGUSR1) when a call changes the
subscription or goal files it reads, follows only tool_started and
turn_finished from its own cursor, refreshes agents' declared tools on
start, and gives way to another build as the lookout does. /status says
"tools not answered" when no host runs.

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

* FEATURES: tool host rows for #481

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

* Lookout: reread on a subscriptions or goal call's end in the stream, not a signal

A SIGUSR1 from the tool host could be handled after the events that
follow the call's tool_result, so news right after a subscribe could be
read with the old subscriptions and lost. The lookout now follows those
calls by their tool_started and rereads on their tool_completed, which
the stream orders before every later event.

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

* cargo fmt

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

* Sonny: exec's image() shows the model the picture, in order with the text

With the daemon's tool_result parts (#482), an exec script's text() and
image() come back as ordered text and image parts, as Codex's code mode
returns them, rather than a saved file's path. A picture is a PNG, JPEG,
GIF or WebP by its own bytes, scaled to 1568 on its longest side as the
daemon's read scales one; a result holds up to 20, 5 MB together, and
image() throws past that. Pictures are marked in the output by a private
use character that text() strips, so the budget's cut drops a picture
with its place; the tool host holds the parts' text to its 60 KiB.

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

* FEATURES: #494

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

* exec: a picture's mark opens and closes with its own characters

A mark the output budget cut in half shifted the split's alternation, so
later whole marks named no picture. A mark now opens with U+E000 and
closes with U+E001: a half one is dropped and every whole one after it
still shows its picture.

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

---------

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.

Codex findings on main's MCP code mode and ACP resume (raised on #329)

2 participants