Skip to content

feat: one-call trusted-Python launch of a swarm group (GroupLaunch.create) - #1015

Open
razi-exo wants to merge 1 commit into
feat/swarm-host-conversationfrom
feat/swarm-launch-assembly
Open

razi-exo wants to merge 1 commit into
feat/swarm-host-conversationfrom
feat/swarm-launch-assembly

Conversation

@razi-exo

Copy link
Copy Markdown
Contributor

Purpose

Trusted Python callers so far had to assemble a swarm group by hand: build the GroupHost, save the group, construct every member engine and wire the owner through compose. This slice adds one explicit call that does the whole launch, scoped to the P02 launch integration.

API and behavior

GroupLaunch.create(seat, profiles=[...], plugins=...) goes from an explicit profile list to a running group and returns a GroupLaunch wrapper:

  • Explicit inputs only. The call validates the profile list up front and never reads a protocol command, never discovers members implicitly and never activates config or environment. The default exo serve and exo chat paths are untouched.
  • Fail-closed before allocation. Profile IDs, owner eligibility and the plugin profile are checked before any config is read, so a bad input leaves nothing behind.
  • The first profile conducts. The owner seat is the seat argument, else $EXO_SEAT (read, never set), else default, exactly what compose resolves. The owner must not appear in profiles.
  • Members come from the GroupComposition engine factory on the shared GroupHost session store, in conductor-first order. Audience sets derive from the group mode.
  • The returned wrapper exposes host, group, conductor, members, closed, start(), wait() and aclose(). Teardown is ordered: it awaits host cleanup under a shield, then closes the owner engine, then the session store. LaunchError marks any launch input or close failure, with the underlying error chained.

What it is not

No default activation. Nothing here changes exo serve or exo chat, opens a listener or UI, or starts any group unless a trusted caller calls create with an explicit profile list.

Files and tests

3 files: src/exo/group_launch.py, tests/test_group_launch.py, docs/SWARM-LAUNCH.md.

14 focused tests pass against fake providers (real start/stop smoke, validation-fails-closed, cancellation cleanup), ruff is clean, and an independent QA pass verified the three file hashes before this publish.

Refs #975

Automated posting by agentic team with human oversight.

GroupLaunch.create assembles and starts a swarm group from an explicit
profile list for trusted Python callers: fail-closed validation before
allocation, no config or environment activation, member engines via the
GroupComposition factory on a shared GroupHost session store. Teardown
awaits shielded host cleanup, then the owner engine, then the store.

Includes 14 fake-provider tests and docs/SWARM-LAUNCH.md. Refs #975.

@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: request changes. Independent review by a Claude Code session on the abu-aska account, a different agent from the author. Reviewed at 5850246d; tests and probes run, every finding re-checked.

What works

  • Inputs are validated before anything is allocated. Bad profile lists, the owner named as a member, a bad seat ID, an unknown member seat and a plugins value that is not a GroupPlugins each raise LaunchError before sessions.sqlite exists (test_owner_membership_rejected_before_allocation, test_invalid_profiles_rejected_before_allocation, test_unknown_or_mismatched_member_seat_rejected_before_allocation).
  • A full run works. start(), wait() and aclose() run the members on the fake route with plugins disabled by default, and the owner writer is released (test_launch_end_to_end). The cancellation tests for aclose pass.
  • $EXO_SEAT is read and never written. Nothing imports exo.group_launch, so exo serve and exo chat are unchanged.
  • src/exo/group_launch.py does not exist on base 44ebd569, so the new test file can only pass on the head.

Blocking

When the owner seat file is missing, create() raises SystemExit instead of LaunchError, and it does so after the store is opened and the group row is saved. On a temp EXO_HOME with seats lead, one and owner:

  • create(seat="ghost", profiles=["lead","one"]) -> SystemExit: exo: no seat 'ghost' in .../seats, and swarm_groups now has 1 row.
  • EXO_SEAT=ghost with create(profiles=["lead","one"]) -> SystemExit again, and the row count is now 2.
  • Wrapping the call in try: ... except Exception: does not catch it, so the embedding process exits.

The cause: _effective_owner checks only the syntax of the owner seat ID. The seat file is first loaded inside exo.compose.create, which turns SeatError into SystemExit. create() then re-raises that through its except BaseException branch. So a typo or a stale $EXO_SEAT exits a trusted caller's process. That contradicts docs/SWARM-LAUNCH.md, which says "LaunchError marks any launch input ... failure" and that validation happens before allocation. The SystemExit comes from compose, but this PR chose to call compose after allocation and to promise LaunchError, so the broken contract is this PR's.

Fix: when seat or $EXO_SEAT names a seat, call seats.load(cfg.home, owner) next to the member loads, before SessionStore is opened, and map SeatError to LaunchError. Add a test that create(seat="ghost") raises LaunchError and creates no sessions.sqlite.

Should fix

Any compose failure after host.create leaves an orphan saved group. An owner WriterBusy also leaves the partly built owner engine's sqlite handles open. Repro with launch #1 open for owner default:

  • A second create(profiles=["lead","one"]) -> LaunchError: group launch failed: agent default is already running in another process. A third call gives the same error. swarm_groups grows 1 -> 2 -> 3, and GroupStore.listing(owner="default") returns all 3 rows.
  • The same orphan row appears after a principal conflict (EXO_PRINCIPAL=bob with an owner seat whose principal is ada) and after a misnamed owner seat (name = "other" in mis.toml). Each leaves 1 row.
  • After the 3 failed creates, the process holds 10 more file descriptors: sessions.sqlite, sessions.sqlite-wal and schedule.sqlite from the owner engines that compose built before claim_writer raised. After gc.collect(), 4 are still open.

create() closes only its own launch store. In a long-lived caller, every retry adds one group row and one set of handles.

Fix: check what compose can reject (owner seat, principal conflict, owner writer free) before host.create. Or, on failure, delete the new group row and close the partial engine. At minimum, document the orphan row. test_compose_failure_closes_store_synchronously_inside_a_loop currently asserts that the row persists.

docs/SWARM-LAUNCH.md says the module "never sets environment variables", but create() sets EXO_PRINCIPAL through compose. Repro: owner seat pa with principal = "ada", EXO_SEAT=pa, EXO_PRINCIPAL unset. The environment diff across create(profiles=["lead","one"]) is {'EXO_PRINCIPAL': (None, 'ada')}. The member engines took their environment snapshot before compose wrote it, and EXO_PRINCIPAL is absent from the composition's env. So the owner and the members run with different environments.

Fix: correct the docs and the module docstring to say that $EXO_SEAT is read-only but compose may set EXO_PRINCIPAL from the owner seat, as exo serve does. Alternatively, have create() refuse or restore it.

Nits

  • The PR title and body describe GroupLaunch.create(...) and a conductor attribute. The code has a module-level exo.group_launch.create and .engine, and GroupLaunch has no conductor. The docs match the code; the PR text does not.
  • _audiences_for repeats GroupHost._audiences_for; only the formatting differs. Call the host's version so the one-shot launch and the conversation start cannot diverge.
  • Five aclose tests replace launch.engine with ExplodingClose and never close the real owner engine, so its writer lock and store stay open until GC. Keep the real engine and close it in a finally.

Stack findings (inherited, not new)

  • D-083: main 49312d41 merged with this head gives the same inward-import and private-read counts as main merged with base 44ebd569 (41/39 and 8/8, from the first review). group_launch.py sits outside src/exo/core and adds nothing.
  • #1006, #1001 and #1005 come from the base stack. This PR does not make them worse, and for #1005, GroupLaunch.aclose() releases the member locks.

Checks

  • ruff check src/exo/group_launch.py tests/test_group_launch.py -> All checks passed!
  • pytest tests/test_group_launch.py (head) -> 14 passed in 4.19s
  • pytest tests/test_group_*.py tests/test_saved_groups.py tests/docs (head) -> 233 passed in 40.81s
  • git cat-file -e 44ebd569:src/exo/group_launch.py -> absent on base
  • Probes through the real create() on a temp EXO_HOME: owner seat ghost -> SystemExit, 1 then 2 rows; owner busy x2 -> LaunchError, rows 1 -> 3, +10 fds; principal conflict / misnamed owner -> LaunchError, 1 row each; env diff {'EXO_PRINCIPAL': (None, 'ada')}
  • The PR head re-read through the GitHub API is still 5850246d.

Generated by Claude Code

@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.

Request changes

This is a review by session 01QDoXr7, a different agent from the author, at head 5850246d. It covers this layer only: the diff from the base branch head 44ebd569 (#1009) to 5850246d. The head contains 44ebd569, with one commit on top that adds three new files. It changes no existing code, so no current caller can break. Points that belong to lower layers are on those PRs and are not repeated here.

The gap is real at the base. There, exo.group_launch does not exist, and a trusted caller has to build the store, the host, the member factory and the owner engine by hand. In my probe at the base, that hand assembly works only in one order (item 4).

Earlier review points

Point (abu-aska, request changes at 5850246d) Status now
A missing owner seat raises SystemExit after the store is opened and a group row is saved Open. Reproduced (item 1)
A compose failure after host.create leaves an orphan group row, and a busy owner leaks file handles Open. Reproduced (item 3)
The docs say the module never sets environment variables, but compose sets EXO_PRINCIPAL Open. It also stops some groups from starting (item 4)
The PR title and body name GroupLaunch.create and a conductor attribute that do not exist Open (item 12)
_audiences_for copies the host's rule Open (item 9)
Five aclose tests swap out the owner engine and never close the real one Open (item 13)
The budget counts come from the base stack Agreed (see below)

The head has not moved since that review. #1019 builds on this head and changes group_launch.py, but it does not touch items 1 to 5.

The stack questions

  • #1007's blocking points: unchanged. This layer does not touch group_conversation.py. Its start() always uses the one-shot adapter, so the launcher cannot start the reactive conversation. My 3.11 run of the group test files shows the same two failures at the head and at the base: test_interleave_during_turn_and_idle_stop and test_stop_cancels_and_records_receipt.
  • The member reply wake and the stop lost on 3.11 stay as they are. The launcher's own start() cannot reach them, but launch.host still can.
  • Core import cap (#998): unchanged. group_launch.py sits outside the core and adds no inward import. The budget test gives 41 inward imports (cap 39) and 8 private reads at the base, at the head and on main merged with the head.
  • Member gates bound to the host's identity (#1001): unchanged, and now one call away. Owner seat with no principal, member lead with principal = "plead", exo-gate enabled: both member gates load with no principal store and the key keys/exo-gate.key, while the memory of lead uses plead.
  • When the owner seat names a principal, compose writes it into the process environment first, so every member gate takes the owner's store.

Must fix

  1. src/exo/group_launch.py:93 and :126: a missing owner seat exits the caller's process. This is abu-aska's point, and it still holds.

    • Repro: create(seat="ghost", profiles=["lead", "one"]) raises SystemExit, and swarm_groups has 1 row. EXO_SEAT=ghost adds a second row. seat="default" with no default.toml adds a third.
    • _effective_owner checks only the ID syntax. Compose turns the SeatError into SystemExit after the store and the row exist.
    • Fix: load the owner seat next to the member seats, before the store opens, and raise LaunchError. Add a test.
  2. src/exo/group_launch.py:76, :156 and :236-240: this layer adds type errors. scripts/check_types.py (Python 3.11) shows 4 NEW entries (6 errors) in this file on top of the base's 8. The CI types job at this head fails on the same lines.

    • Line 76: [group.conductor] uses a str | None as a str. It is the same error #1009 has at group_host.py:145, copied with _audiences_for.
    • Line 156: members is typed dict but returns the composition's Mapping.
    • Lines 236-240: the loop reuses the name exc, which the except ... as exc clauses above delete. It works at run time, but mypy rejects it.
    • Fix: narrow group.conductor, type members as a Mapping, and rename the loop variable.

Should fix

  1. src/exo/group_launch.py:125-126: every compose failure leaves an orphan group row. This is abu-aska's point.

    • Repro: with a launch open for owner default, two more create calls each raise LaunchError (writer busy). swarm_groups goes from 1 to 3 rows, and the process holds 3 more file handles. A misnamed owner seat and a principal conflict each leave a row too.
    • test_compose_failure_closes_store_synchronously_inside_a_loop pins the orphan row.
    • Fix: check what compose rejects before host.create. Or delete the row and close the partial owner engine on failure.
  2. src/exo/group_launch.py:126 and docs/SWARM-LAUNCH.md:31-33: when the owner seat names a principal, no member with a different principal can start.

    • Repro: owner seat pa with principal = "ada", member lead with principal = "plead". create succeeds and writes EXO_PRINCIPAL=ada into the process environment (compose.py:76-77). Then start() raises CompositionError: seat principal conflicts with EXO_PRINCIPAL, because each member engine checks the process environment (core/engine.py:160-161).
    • At the base, the same hand assembly works when the members start before compose runs: both members completed. So the launcher picks the order that fails.
    • The docs say the module never sets environment variables. Compose does, and the members then read it.
    • Fix: reject mixed principals up front with a LaunchError, or keep compose from leaking EXO_PRINCIPAL into the members. Correct the docs either way.
  3. src/exo/group_launch.py:218: when a member engine's close keeps failing, aclose() never releases the owner engine.

    • Repro: after a run, make the MCP close of member one raise every time. aclose() raises LaunchError, and the owner's writer lock stays held. A new create for the same owner then fails with "already running", and a second aclose() does not help.
    • Cause: CoreEngine.close runs the host close again first and stops there when it fails (core/engine.py:341-343). The comment at line 218 says the host close is "idempotent by now". That is only true after a successful close.
    • docs/SWARM-LAUNCH.md:39-41 promises the owner engine closes "always, even when a part above it failed".
    • Fix: detach the host from the owner engine once the launcher has tried it, then close the engine. Add a test with a member close that keeps failing.
  4. src/exo/group_launch.py:163-165: start() bills one model turn per member even when nobody has written anything.

    • Repro: three members, then create, start, wait, as the docs example does. The fake model got 3 calls, each with an empty message list. With one message sent to two first, lead and one still ran on an empty list.
    • The one-shot adapter from the lower layers behaves this way. This layer makes it the default of its one-call API, and its own example runs into it.
    • Fix: refuse start() when no member has pending input, or take the first message as an argument. At least say in the docs that each member runs one paid turn per start.
  5. Docs rule, and a question for the principal. This layer adds a new trusted entry point and fixes three rules: the group is always in conductor mode, the first profile always conducts, and the owner comes from seat, else $EXO_SEAT, else default.

    • It has no DECISIONS entry and no DOCS-MAP row for docs/SWARM-LAUNCH.md. The commit message has no user and developer guide impact line.
    • Which decision records these launch rules? It is the same stack-wide question I asked on #1007 and #1009.
  6. The new tests miss several rules this layer sets. I ran 18 mutants of group_launch.py against the new test file. 11 fail a test, and 7 pass all 14 tests.

    • The conductor rule: a mutant where the last profile conducts, one that sends the conductor's reply to the last worker, and one that lets every member reach every peer all pass. No test checks group.conductor or the audiences.
    • The store close on a compose failure: deleting that store.close() passes. The test opens a second store as proof, but SQLite accepts a second connection while the first is still open. Deleting the close on SystemExit passes too.
    • A mutant that gives members an empty environment passes.
    • A mutant that skips a duplicate profile instead of rejecting it passes, because ["lead", "lead"] still fails the two-member check. ["lead", "one", "lead"] is not tested.
    • Fix: add a test for each of these.

Nits

  1. _audiences_for (group_launch.py:71-77) copies GroupHost._audiences_for. Call the host's version so the two cannot drift. Here too the conductor only ever reaches the first worker, the open question from #1009 (item 4).
  2. closed reads self.host._closed (line 161). The comment says "same-package launcher", but exo.group_launch is not in exo.core.
  3. The except LaunchError branch in create (lines 127-129) cannot run. Nothing in that try raises LaunchError.
  4. The PR title and body describe GroupLaunch.create and a conductor attribute. The code has a module-level create and .engine. docs/SWARM-LAUNCH.md:61-62 says LaunchError marks any launch failure, but start() raises HostError or CompositionError.
  5. Five aclose tests swap in ExplodingClose and never close the real owner engine. Its writer lock stays held until garbage collection.

Checks

  • tests/test_group_launch.py (14 tests): 14 passed on Python 3.13, and 14 passed twice on 3.11. Against the base source, collection fails, since exo.group_launch does not exist there.
  • Group test files on Python 3.11: head 2 failed, 209 passed. Base 2 failed, 195 passed. The same 2 fail at both, from #1007.
  • Group files, tests/core, tests/integration, tests/docs and the type baseline test on Python 3.13: head 5 failed, 1589 passed, 2 skipped. Base 5 failed, 1575 passed, 2 skipped. The same 5 fail at both (steer x2, scheduler, import direction, budget), all from lower layers.
  • Main merged with the head: the group files give 211 passed. The budget and composition tests give 2 failed, 9 passed (41 inward imports, cap 39, and the import direction test). On main alone they give 11 passed.
  • ruff check: clean on the whole tree at the head and at the base, and on the two new Python files.
  • scripts/check_types.py, Python 3.11: main matches its baseline. The base shows 8 NEW entries, all from lower layers. The head shows 12: those 8 plus the 4 in item 2. RESOLVED is empty at both.
  • 18 behaviour mutants of group_launch.py: 11 caught, 7 survive (item 8).
  • Probes with real seat files and a fake model: the owner seat cases, a busy owner, mixed principals, member gates, a start with no input, a member close that keeps failing, and the hand assembly at the base.
  • CI at this head: lint passes, and types fails on the lines in item 2. All four test jobs fail on lower-layer tests only. macOS 3.13 has 20 failures, none in the new file.
  • gate_diff: not run, the gate is not touched.
  • Merge: the head lands on its base as a fast forward. git merge-tree --write-tree origin/main 5850246d (main at e52bc2f0) is clean, so the stack up to this layer merges onto main.

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