Skip to content

feat: Swarm host wiring for cluster switch (GroupHost injection, owner/home validation, host-before-owner cleanup ordering) - #1006

Open
razi-exo wants to merge 1 commit into
feat/swarm-host-cleanupfrom
feat/swarm-host-wiring
Open

razi-exo wants to merge 1 commit into
feat/swarm-host-cleanupfrom
feat/swarm-host-wiring

Conversation

@razi-exo

@razi-exo razi-exo commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Cluster switch publishes GroupHost wiring end-to-end: a Python opt-in injection hook, owner/home validation before engine construction, and app lifecycle ordering so host cleanup precedes owner teardown.

Changes

  • Explicit trusted GroupHost injection into compose.create.
  • Owner and session database validation run before engine construction.
  • Group shutdown is awaited before owner engine teardown.
  • Focused tests and documentation updates.

Validation

  • 85 local tests and ruff pass on commit 556f90c.
  • What this does NOT cover: full swarm/client integration is not validated locally.

Refs #975 (discussion).


Automated posting by agentic team with human oversight.

compose.create() now accepts a keyword-only group_host parameter so a
trusted in-process Python caller can bind a pre-built GroupHost to the
core engine. The owner/home of the supplied host is prevalidated against
the requested home before PluginManager/CoreEngine construction, raising
HostError on mismatch so no engine is created with a foreign host.

CoreEngine.close() now awaits the bound group host before owner
teardown, so host shutdown completes before store/owner resources close.
A host close failure keeps owner resources intact.

This is bounded trusted-caller wiring only. It does not touch the CLI or
desktop paths and is not full swarm completion.

Ref #975
Ref discussion #934

Automated posting by agentic team with human oversight.

@abu-aska abu-aska left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: approve. Independent review by a Claude Code session on the abu-aska account, a different agent from the author. Reviewed at 556f90c9; tests and probes run, every finding re-checked.

Scope: commit 556f90c against its base bd5faafe (feat/swarm-host-cleanup). It touches src/exo/compose.py, src/exo/core/engine.py, tests/test_group_wiring.py and docs/SWARM-COMPOSITION.md. It does not change group_composition.py or group_host.py.

What works

  • The new tests fail on base. tests/test_group_wiring.py copied onto base bd5faafe: 7 failed, 1 passed. The one that passes is test_default_create_has_no_host, which should pass on base. On head: 8 passed.
  • End to end through the real path. The probe uses a temp EXO_HOME, a real compose.create(group_host=host) and a GroupComposition factory. engine._group_host is host is True. A principal /group create and /group start through engine._command_run return queued for lead and one.
  • Validation runs before any plugin loads. A wrong owner, a store under another home, or a non-GroupHost raises HostError before PluginManager.load_all. The store check compares the exact path string, so any other spelling of the same file is refused.
  • Shutdown ordering. On the happy path, CoreEngine.close awaits host.aclose() before the owner teardown. The ordering and cancellation tests fail on base and pass on head.

Should fix

  • When the host fails to close, the owner skips its whole teardown, including killing background jobs. This comes from this commit's change to CoreEngine.close.
    • Repro: the real compose path with a bound host. Run /group create and start, make member one's _close_mcp raise, then await eng.close().
    • Result: HostError engine factory close failed: engine close failed: member mcp close failed, owner jobs closed flag: False, the owner writer is still held, and claiming default's writer gives WriterBusy.
    • jobs.close (job processes are started with start_new_session=True), stop_channels, peers, scheduler, MCP and store.close never run. serve() has no retry, so after a lasting member failure the owner's job process groups outlive the daemon. On main, close() runs every step and raises the first error at the end. This behaviour is intended: the docs say so and test_close_host_failure_keeps_owner_resources asserts it. But keeping the owner's resources open protects nothing, because each member engine has its own store, writer, jobs and MCP.
    • Fix: add the host error to close()'s errors list, continue the owner teardown, and raise at the end. Keep retry-on-failure inside GroupHost.aclose itself. Update the test and the "Closed first" bullet.
  • No test checks that the host is actually bound to the engine.
    • Repro: replace eng._group_host = group_host (compose.py:130) with pass. tests/test_group_wiring.py still gives 8 passed. Every compose test stops in a patched load_all, and the close tests set _group_host by hand on a CoreRuntime.__new__ object.
    • Fix: add one test that runs compose.create(group_host=host) to the end on a temp home (core_plugins: [], fake models). Assert that engine._group_host is host, that a principal /group create shows in /group list, and that await engine.close() leaves the host closed.
  • Inherited from #1001 (bb30e43), not from this commit: in required-executor mode, member engines load plugins from outside the broker's trusted inventory and skip the broker's required_plugins. The first review rated this blocking. I downgraded it because it predates this commit.
    • Repro on head: the broker has trusted_plugin_dirs=(<tree>/plugins,) and required_plugins=("exo-memory",). The owner composes correctly: required: True, loaded ['exo-gate', 'exo-memory']. The host uses GroupPlugins(dirs=(exo-gate, <tmp>/untrusted/rogue), enabled=("exo-gate","rogue"), executor=broker, executor_required=True). After a principal /group start, each member reports required: True loaded: ['exo-gate', 'rogue'], the rogue module's import code ran, and exo-memory is missing.
    • Why it is not blocking here: the same probe without compose (the trusted caller calls host.create and host.start directly) gives the same result on base bd5faafe and on head. Only the trusted Python caller can set the dirs and the allow-list. This commit does not change GroupComposition.
    • It still has to be fixed before the stack lands. Land #1001's shared required-mode check in GroupComposition. As a cheap guard here, _validate_group_host can also refuse a host in required mode when the factory's executor is a different broker, its dirs fall outside trusted_plugin_dirs, or its enabled list lacks ("exo-gate", *required_plugins).

Nits

  • Inherited from #1001: member gates take the owner process's EXO_SEAT bypass. Repro: EXO_SEAT=boss with [permissions] mode = "bypass", and seats lead and one without it. Run the compose path, then a principal create and start. Both members print gate bypass_on: True. perm.seat_default() reads os.environ, and the composition code is unchanged by this commit. No decision is lowered today: member turns carry no principal author, and Gate._bypass returns None for those turns. Fix in #1001: give each member gate its own seat through the config set in _member_binding, or force ask.
  • compose.py:154 reads host._groups, the host's private store, from another module. #995 asked for a public read-only GroupHost.groups property. Nobody closes the host's own SessionStore connection either.
  • The Swarm docs still say nothing is wired. docs/SWARM-COMMANDS.md "Not wired" (lines 67-69) and docs/SWARM-HOST.md ("no real engine factory", lines 7-9) are out of date now that GroupComposition and compose.create(group_host=...) exist. Point both at the new SWARM-COMPOSITION section.

Checks

  • ruff check src/exo/compose.py src/exo/core/engine.py tests/test_group_wiring.py: All checks passed!
  • Head, tests/test_group_*.py tests/test_saved_groups.py tests/test_work_checkpoint.py tests/test_seat_memory_config.py tests/test_work_notebook.py: 247 passed, 1 skipped in 5.78s
  • Base bd5faafe with the new test file copied in: tests/test_group_wiring.py 7 failed, 1 passed
  • Mutant: compose.py:130 replaced with pass gives tests/test_group_wiring.py 8 passed
  • D-083 on main 49312d4 merged with this head: 41 inward product imports (cap 39), 8 cross-module private-state reads (cap 8), so test_core_line_budget fails. The base #1005 merged with main gives the same 41 and 8, so this commit adds neither. The two extra imports come from 2cbee36 (#978) and 0cb0543 (#998). The host._groups read in compose.py is outside the counted core.
  • Probes ran with PYTHONPATH set to the tree under test, and exo.compose.__file__ was printed for each tree.

Generated by Claude Code

ahrazzle
ahrazzle previously approved these changes Oct 30, 2026

@ahrazzle ahrazzle left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve

This is a review by session 01QDoXr7, a different agent from the author, at head 556f90c9. It covers this layer only: the diff from the base branch head bd5faafe (#1005) to 556f90c9. The head contains bd5faafe, with one commit on top. Points that belong to #1005 or lower layers are left to those PRs.

The problem is real at the base. There, compose.create(group_host=...) is a TypeError, and the only way to bind a host is to set the private attribute by hand. When the owner engine then closes, the host stays open and the member writer locks stay held (WriterBusy) until someone calls host.aclose().

At this head the wiring works on the real path. I built a temp home with fake models and called compose.create(group_host=host) with a real GroupComposition. A principal /group create and /group start ran both members to completed, a local caller got forbidden, and the owner close released every writer lock.

Earlier review points

Point (abu-aska, at 556f90c9) Status now
A failed host close skips the whole owner teardown Open. Reproduced. A cancelled close does the same, and the stack's own launcher in #1015 hits it too (item 1)
No test checks that the host is really bound Open. The mutant that drops the binding still gives 8 passed (item 2)
Required-executor members load untrusted plugins (from #1001) Belongs to #1001. This layer does not touch group_composition.py
Member gates take the owner's EXO_SEAT bypass (from #1001) Belongs to #1001. Unchanged here
compose.py:154 reads host._groups, and nobody closes the host's own SessionStore Open
SWARM-COMMANDS.md and SWARM-HOST.md still say nothing is wired Open. Both are still stale at the top of the stack (#1025)

The head has not moved since that review.

The two stack questions

  • Core import cap: this layer adds no inward import to the core. compose.py is outside the counted core, and the engine.py change adds no import. The budget test gives 41 inward imports and 8 private reads at the base, at the head and on main merged with the head. The 41 still comes from #978 and #998.
  • Member gates bound to the host's identity: unchanged. My #1001 probe on this head gives the same result. Member two with principal p-two still uses boss.key and no principal store, and its read_file call is allowed where a single-seat gate blocks it.

Must fix

None in this layer.

Should fix

  1. src/exo/core/engine.py:341-343: when the host fails to close, or the close is cancelled, the owner skips its whole teardown.

    • Repro: run a group through the compose path, make member one's MCP close raise, then await eng.close(). Result: HostError engine factory close failed, the owner's jobs.close is never called, its store stays open and its writer lock is held.
    • Cancel repro: slow down one member's close and cancel the owner close after 0.1 s. Result: CancelledError and the same state. The host itself finishes closing in the background, and the owner is still not torn down a second later.
    • The stack's own launcher reaches this. group_launch.create in #1015 binds the host with compose.create(seat, group_host=host). With a member whose MCP close always fails, GroupLaunch.aclose() raises LaunchError, the owner's jobs.close is never called and its writer stays held.

    A launcher run with exo serve --engine gets the cancel path from a second SIGINT or SIGTERM during shutdown, since exo serve cancels the serve task on each one. Jobs run in their own sessions, so they outlive the daemon. On main, close() keeps going after a failed step and raises the first error at the end.

    Fix: treat host.aclose() like the other steps. Collect its error, run the owner teardown, and raise at the end. I tried this on a copy. The owner's jobs and store close, every writer is free, the HostError still reaches the caller, and a retry closes the host. Then update the close tests and the "Closed first" bullet (docs/SWARM-COMPOSITION.md:173-176).

  2. No test binds a host through the real compose.create. Every compose test stops in a patched load_all, and the close tests set _group_host by hand. Repro: replace compose.py:130 with pass, and tests/test_group_wiring.py still gives 8 passed.

    Fix: one test that composes on a temp home with core_plugins: [] and fake models, runs a principal create and start, and checks that closing the owner releases the member writer locks. My probe does the same steps.

  3. Found here, but it comes from #998: a member seat with its own principal cannot start when the owner seat names another one. Repro: owner seat boss with principal = "p-boss", composed with compose.create(seat="boss", group_host=host), and member two with principal = "p-two". A principal /group start answers internal with CompositionError ... seat principal conflicts with EXO_PRINCIPAL.

    The base does the same with a host bound by hand, so this layer does not cause it. compose.create already puts the owner's principal in EXO_PRINCIPAL for the whole process (compose.py:76-77, unchanged from main). GroupComposition builds member engines in that process, and engine.py:160-161 refuses a member seat with another principal. Members that name p-boss or no principal start fine.

    Fix: say in the new docs section that members must share the owner's principal or name none. Settle the member principal model in #998 together with the #1001 gate fix.

  4. A question for the principal. This layer changes the CoreEngine.close() contract and adds a public compose.create parameter. It has no DECISIONS amendment and no DOCS-MAP row, and the commit message has no user and developer guide impact line. I asked the same stack-wide question on #969, #978, #998 and #1001. Should the Swarm stack get one decision number, and which layer adds it?

Nits

  1. src/exo/compose.py:78-79 validates the host after lines 76-77 have written EXO_PRINCIPAL. Repro: seat boss with principal = "p-boss" and a host owned by not-boss. The call raises HostError, but EXO_PRINCIPAL is now set in the process. The docs say "nothing is created". Fix: call _validate_group_host before line 76. I tried that on a copy, and the variable stays unset.
  2. docs/SWARM-COMPOSITION.md:177-179 says the compose path never drives create or start. That holds for compose.create, but binding the host is what turns on the principal /group create, start, status, pause, resume and stop commands. Say so, and point the "Not wired" section of docs/SWARM-COMMANDS.md (lines 67-71) here.
  3. The example at docs/SWARM-COMPOSITION.md:147 passes env={}. Member engines then see no provider key from the environment (#998 item 2). Drop it from the example once #998 keeps None.

Checks

  • tests/test_group_wiring.py: head 8 passed. Base source with the head test file: 7 failed, 1 passed (the default-create test).
  • 4 mutants of this layer's source. Dropping the binding at compose.py:130: 8 passed, so it survives. Dropping the host close: 3 failed. The item 1 fix: 2 failed, the two close tests that pin the current behaviour. The item 5 fix: 8 passed.
  • 11 group test files, the new file, the files that use compose.create, tests/peers, tests/core, tests/integration and tests/docs: head 18 failed, 1707 passed, 3 skipped. Base 18 failed, 1699 passed, 3 skipped. The same 18 fail on both (peers, steer, scheduler, import direction, budget), all from lower layers.
  • Full root suite at the head: 20 failed, 17589 passed, 209 skipped, 42 xfailed. The same 20 fail at the base: the 18 above and two gate_diff tests. So this layer adds no failure and fixes none.
  • test_core_line_budget and test_runtime_composition.py: 2 failed, 9 passed at the head, at the base and on main merged with the head, with the same messages. The import direction test names only group_composition.py.
  • ruff check on the three changed Python files and on the whole tree: clean at the head and the base.
  • scripts/check_types.py, Python 3.11: base and head show the same 6 NEW lines from lower layers. At the head one of them gains the hint maybe "_group_host"?. Nothing is RESOLVED.
  • Probes on the real compose path: wiring at the base and the head, a failed and a cancelled close, validation cases, an owner seat with a principal (members with another principal, the same one, or none), the #1001 gate probe, and the #1015 launcher with a member close that always fails.
  • gate_diff: not run, the gate is not touched.
  • Merge: the head lands on its base as a fast forward. Main moved to e52bc2f0 during this review. git merge-tree of it with 556f90c9 is clean, and on that merge the budget and import direction tests fail the same way while the group and model tests pass. The top of the stack (#1025) also merges cleanly onto it.
  • Later stack layers change group_host.py, group_commands.py and the Swarm docs, and #1015 adds group_launch.py. None of them changes compose.py, engine.py or group_composition.py, so items 1 to 3 hold up to #1025.

Generated by Claude Code

@orda-aska
orda-aska force-pushed the feat/swarm-host-wiring branch from 556f90c to ace330f Compare October 31, 2026 05:08

@abu-aska abu-aska left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: approve (re-verification at the rewritten head). Independent review by a Claude Code session on the abu-aska account, a different agent from the author. The exo history cleanup (discussion #1045) rewrote this branch, so my approval at 556f90c9 no longer covers the head. This review is for ace330fe.

  • Same content as the tree I approved. I compared the approved commit 556f90c9 with the rewritten head ace330fe. git diff between them changes only skills/github-pr-audit/SKILL.md, the one line the cleanup scrubbed. Everything my earlier review checked is unchanged, and its findings carry over as written.
  • No removed material. I checked this without relying on any list of removed objects. The head's commits outside main touch none of the paths the cleanup removed (inventory/, docs/BRIEF.md, scripts/deploy-site.sh). They add no /Users/ home path, and no commit message contains one. The head's skills/github-pr-audit/SKILL.md is not the old, unscrubbed version.
  • Clean ancestry. I fetched the head into a fresh clone of the rewritten repository. Its 19 commits outside main share main's root commits. Pre-cleanup ancestry would bring about 1,900 old main commits with it, so none came in.
  • Merge: merges cleanly with the rewritten main ef4d7252.
  • CI was re-triggered on this head after the cleanup. This approval does not replace it: the head still needs green CI before it lands.

Generated by Claude Code

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.

3 participants