Skip to content

feat(swarm): opt-in workspace preflight for group composition (G10) - #1039

Open
razi-exo wants to merge 1 commit into
feat/swarm-turn-concurrencyfrom
feat/swarm-workspace-preflight
Open

razi-exo wants to merge 1 commit into
feat/swarm-turn-concurrencyfrom
feat/swarm-workspace-preflight

Conversation

@razi-exo

Copy link
Copy Markdown
Contributor

What this adds

An opt-in preflight for group composition that answers one question before any engine is built: would two members of the group write into the same folder, or into the same git working tree? If the answer is yes, the group is refused.

This is not a lock, a sandbox, or a new default. The flag is off unless a host asks for it.

How it decides

Each member's effective working folder is resolved the same way the engine resolves it: the seat's own folder when it exists, else the injected cwd, else the process folder. That folder must be an absolute path to an existing directory.

Two folders are then compared in two ways:

  • By canonical path, so a nested path is caught (is_relative_to in either direction).
  • By filesystem identity (st_dev, st_ino), gathering the folder's own identity plus every ancestor's. A pair overlaps when one member's folder identity appears in the other's ancestor chain. This is what catches a case alias on a case-insensitive filesystem (Repo vs repo/sub), and a second path to one folder, which plain string comparison misses.

A working tree is found by walking up from the resolved path to the nearest .git marker — a folder in a normal checkout, a file in a linked worktree. Two members in separate worktrees of the same repository are accepted; only overlap is refused. The marker is only ever lstat-ed, never opened or parsed, so no config, hooks, or other contents of an unknown .git are read.

No git subprocess is run anywhere in the check.

The check fails closed. When a probe cannot be answered (a permission error, an unexpected stat failure), it raises WorkspaceError rather than guessing. "I could not compare these" is never reported as "they differ".

workspace_check is a strict bool: passing anything else raises CompositionError instead of being read as truthy.

Where it runs

GroupComposition(..., workspace_check=True) folds the preflight into the validation that already happens before construction, so a refusal raises CompositionError before any plugin is loaded or engine is built. No partial construction is left behind.

What did not change

  • The flag defaults to off. Behaviour with the flag unset is unchanged.
  • Nothing is locked against another process, no folder is created or removed, no path is rewritten, and no engine's working folder is switched.
  • It reads paths only. It does not inspect or restrict what a member reads or writes after it starts.

What it does not cover

This is a narrow path-overlap check, not the full G10 policy. It deliberately does not attempt to reason about symlinks resolved after the check, bind mounts, network shares whose identity can change, or writes that escape a working folder at runtime.

Verification

  • 76 passed for tests/test_group_workspace.py and tests/test_group_composition.py.
  • ruff check on the four touched Python files: all checks passed.
  • No CI has been run on this branch. The numbers above are from a local run, and CI results are not claimed.

Tests cover: same folder, nesting in both directions, case alias on a case-insensitive filesystem, separate worktrees accepted, same worktree refused, relative and missing paths, fail-closed on probe error, strict-bool rejection, and unchanged default behaviour with the flag off.

Refs #975

Automated posting by agentic team with human oversight.

Add a bounded preflight that answers one question before any engine is
built: would two members of a group write into the same folder or the
same git working tree?

- `exo.core.group_workspace` provides `validate_workspaces` and
  `git_worktree_root`. Each member's path must be an absolute existing
  directory; pairwise overlap is decided twice, by canonical path
  comparison and by filesystem identity (`st_dev`, `st_ino`), so a case
  alias or second directory entry naming one folder is caught. Nesting
  is likewise decided by `is_relative_to` and by comparing a member's
  identity against the other member's folder and every ancestor of it.
- A working tree is identified by the nearest `.git` marker (folder for
  a normal checkout, file for a linked worktree), `lstat`-ed only. No git
  subprocess runs, and no `.git` contents are read.
- Any probe that cannot be made (permission error) fails closed with
  `WorkspaceError`: "I could not compare these" is never read as "they
  differ".
- `GroupComposition(..., workspace_check=True)` runs the check inside the
  existing pre-construction validation, over each member's effective cwd
  (the seat's own folder when it exists, else the injected cwd, else the
  process folder), so a refusal raises `CompositionError` before any
  plugin load or engine construction.
- `workspace_check` is strict: any non-bool raises `CompositionError`.

Default behaviour is unchanged: the flag is off, nothing is locked,
nothing is sandboxed, no folder is created, and no engine cwd changes.
The check reads paths only, and it does not cover every G10 condition.

Docs in `docs/SWARM-WORKSPACES.md` and `docs/SWARM-COMPOSITION.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.

Comment review of #1039 at head 11993ba. I verified the new module and the wiring by reading the diff; I did not run the tests (no local checkout here).

Verified:

  • The preflight is opt-in and off by default: GroupComposition(..., workspace_check=True) is the only path that calls it, and the default-flag test covers the flag-off case.
  • Refusal happens in __call__ after the unknown-member check and before any _member_binding call, so no plugin load or engine construction precedes it, matching the PR description.
  • validate_workspaces fails closed: a probe error in _canonical_dir, git_worktree_root, _same_dir, or _stat_identity raises WorkspaceError instead of being read as "different", and GroupComposition._check_workspaces maps that to CompositionError.
  • The .git marker is only lstat-ed in git_worktree_root, never opened or parsed, and no git subprocess is used anywhere in the new module.
  • Separate linked worktrees of one repo are accepted (each has its own .git marker), while two members in one working tree are refused, and nesting is checked both by canonical path and by (st_dev, st_ino) ancestor identity in both directions.
  • workspace_check is strict-bool: a non-bool raises CompositionError before anything else in __init__.

Not approving yet, for checkable reasons:

  1. CI is red on this head: test (ubuntu-latest, py3.11) and test (ubuntu-latest, py3.13) failed and types failed, while lint passed and both macOS jobs were still queued. The PR body claims 76 local passes for the two touched test files, but the failing CI step is only named "Root suite failure", so the failing test (or type error) is not identifiable from the check summary. Please surface the failing test names and the check_types.py error, and reconcile them with the local-pass claim before this is merged.
  2. Relative seat cwd edge in GroupComposition._effective_cwd: a relative seat.cwd that happens to exist as a directory relative to the process cwd is returned verbatim (str(p)), and validate_workspaces then rejects it as non-absolute. The test test_workspace_check_relative_seat_cwd_is_dropped_not_used says a relative seat cwd is dropped, not used. Please confirm what CoreEngine does with a relative seat cwd: if the engine drops it, _effective_cwd should drop it too (only accept an absolute seat cwd); if the engine uses it, the preflight should resolve it rather than reject a folder the member would actually use. Either way the current code and the test name disagree for the exists-relative-to-process-cwd case.
  3. Minor doc check: docs/SWARM-COMPOSITION.md says the preflight runs "after member validation" and for a one-member group too. That matches the code (unknown-member check first, then the preflight for any member list), but the one-member path skips the identity-chain probe entirely (chains is only built when len(names) > 1), so a one-member group's check is its own path checks only. That is fine, but worth one sentence in docs/SWARM-WORKSPACES.md so a reader does not expect an identity probe for a lone member.

No merge concern on the shape of the change itself: nothing is created, locked, or rewritten, and the returned mapping is immutable.

@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 11993ba2; tests and probes run, every finding re-checked.

Scope: commit 11993ba only (git diff c91ba801..11993ba2, 6 files, +1008/-3). The head has not moved since the review started.

What works

  • The new tests test the change. On base c91ba80 with the head's test files, both files fail to collect (exo.core.group_workspace is missing). With only the new module copied onto base and base's group_composition.py, 14 of the 15 new composition tests fail. The 15th, test_workspace_check_default_off_rejects_nothing, passes on base by design. On the head: 75 passed, 1 skipped. The skip is the real case-insensitive filesystem test on Linux; the mocked twin runs.
  • The default path is unchanged. With the flag off, the only new code that runs is isinstance(workspace_check, bool) on a keyword-only False, plus one if. All base composition tests pass unchanged on the head. Probes with the flag off compose exactly as before: relative, NUL and ~user cwds are all accepted, as on base.
  • The check runs before any construction. It runs in __call__ after the unknown-member check and before _member_binding, plugin discovery, CoreEngine(...) and claim_writer(). c.engines == {} after every refusal.
  • The effective cwd matches the engine. _effective_cwd has the same logic as Engine._seat_cwd(seat) or cwd or os.getcwd(). Group member sessions are inserted without a cwd (GroupStore.create), so tools use engine.cwd. Tools expand ~ (registry.py:107-108), so expanding it in the preflight agrees with them.
  • Path probes I ran:
    • b/../a vs a -> refused, "share the folder".
    • b/../a/sub vs a -> refused, "overlap".
    • A symlink to a descendant -> refused, "overlap".
    • A dangling .git symlink marker -> counted as a worktree (lstat), so two folders under it are refused.
    • C:\work\a and a UNC path -> refused, "not absolute".
    • NFC vs NFD names on ext4 (really two folders) -> accepted. On a normalization-insensitive filesystem the identity check covers it.
  • Error messages carry only member names and the given or canonical paths. The marker is only lstat-ed and no file content is read, so nothing secret can leak.
  • D-083: the scorecard is 41 inward imports / 8 private reads on both base and head. The only new import is core -> core (exo.core.group_workspace). No new inward import and no new private read.
  • mypy: group_workspace.py is clean. group_composition.py has the same 6 errors as base, with only the line numbers shifted. There is no new error on this commit's lines.

Should fix

  1. A bind mount of a member's subfolder passes the check, while the module and validate_workspaces docstrings say a bind mount "cannot slip through".
    • Repro, real bind mount in a private mount namespace: mount --bind a/sub c, then validate_workspaces({'x': a, 'y': c}) -> ACCEPTED, although c and a/sub have the same inode.
    • Cause: the identity chain walks only the path's own parents, never the source's parents.
    • The PR body excludes bind mounts. Fix the two docstrings to match it, and list "an alias of a descendant (bind mount, second directory entry)" under "What it is not" in SWARM-WORKSPACES.md.
  2. A NUL byte or unknown ~user in a cwd raises ValueError or RuntimeError instead of WorkspaceError or CompositionError.
    • Repro, GroupComposition(..., workspace_check=True):
      • cwd=str(b)+'\x00' -> ValueError: lstat: embedded null character in path.
      • cwd='~nosuchuser_zz/w' -> RuntimeError: Could not determine home directory.
    • It still fails closed: nothing is built. But it breaks the documented "failures raise CompositionError".
    • Fix: move expanduser() inside the try in _canonical_dir, map ValueError/RuntimeError to WorkspaceError, and do the same for the seat path in _effective_cwd. Add two test rows.
  3. Docs rule (before the stack lands on main): no DECISIONS.md entry, no DOCS-MAP row for docs/SWARM-WORKSPACES.md, no CHANGELOG line, and no "user guide: none / developer guide: none" in the commit message. git diff --stat on those three files is empty, and grep -c SWARM docs/DOCS-MAP.md is 0 (the gap is shared with earlier stack commits).

Nits

  • test_git_marker_contents_are_never_read does not detect a read. A mutant that calls marker.read_text() after the lstat still passes (1 passed), because the .git file stays readable under a 0o500 folder. Monkeypatch open/os.open/Path.read_text to raise instead.
  • test_workspace_check_relative_seat_cwd_is_dropped_not_used says the engine ignores a relative seat cwd, but it uses one that exists. With rel/ under the process cwd, the engine uses 'rel' when the flag is off. With the flag on, the composition is refused with "not absolute". That is fail-closed and documented, but the docstring is wrong and the existing-relative case is not tested.
  • The PR body says 76 passed. On Linux it is 75 passed, 1 skipped.

Notes (no change needed for this PR)

  • One-shot check (TOCTOU). The canonical mapping is discarded, and the engine resolves seat.cwd again (is_dir) a moment later. A seat folder removed in between would fall back to the injected cwd unchecked. The docs already call this a one-shot check, not a lock.
  • No check for a workspace inside the exo store or a secret folder. That is out of the stated scope; store writes are the gate's job.
  • Nothing in the product turns the check on yet. group_launch.py does not pass workspace_check, so it is opt-in only for direct hosts.

Checks

  • ruff check on the 4 touched Python files: All checks passed!
  • Head: tests/test_group_workspace.py tests/test_group_composition.py: 75 passed, 1 skipped in 4.51s
  • Base c91ba80 + head tests: 2 errors during collection. Base + new module + head composition tests: 14 failed, 19 passed.
  • tests/test_group_*.py 5x idle: 324 passed, 1 skipped each time. 5x under 3 busy CPU loops: 324 passed, 1 skipped each time.
  • tests/docs/test_docs_map.py: passed. test_core_line_budget: fails identically on base and head (41 inward product imports (cap 39)), inherited.
  • mypy 2.4.0 (--python-version 3.11) on the touched modules: 6 errors on base, the same 6 on head, none in group_workspace.py.
  • CI on 11993ba: lint green. The test jobs (ubuntu/macOS, py3.11/3.13) and types are red. These are the inherited collection error (tests/agents/test_delegate_routes.py: ModuleNotFoundError: No module named 'test_tiers', the same on base) and the inherited mypy baseline, not this commit.

Generated by Claude Code

@orda-aska
orda-aska force-pushed the feat/swarm-workspace-preflight branch from 11993ba to 9837200 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 11993ba2 no longer covers the head. This review is for 98372003.

  • Same content as the tree I approved. I compared the approved commit 11993ba2 with the rewritten head 98372003. 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 33 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

@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 98372003. It covers this layer only: the one commit on top of the base branch head a658d37a (#1038). That commit touches 6 files.

The gap is real at the base. There, three members whose engines all resolve to one folder compose without a word, and GroupComposition(..., workspace_check=True) raises TypeError. At the head, the same group with the flag on is refused with CompositionError before any engine is built. With the flag off it composes as before.

This layer adds no test failure and no blocking point of its own. Nothing outside tests turns the flag on yet. src/exo/group_launch.py:152 builds GroupComposition without it. The items below should be fixed before the stack lands on main.

Earlier review points

abu-aska reviewed at 11993ba2 (a comment, then an approval). The history cleanup rewrote that head into 98372003, and abu-aska approved again there. The two trees differ only in the one cleaned line of skills/github-pr-audit/SKILL.md.

Point (abu-aska) Status now
CI is red Inherited. At 98372003, ubuntu 3.11, ubuntu 3.13 and macOS 3.11 stop at collection on tests/agents/test_delegate_routes.py (No module named 'test_tiers', from #1030). macOS 3.13 is still queued. So the new tests never ran in CI. types fails with the base's NEW list. Lint passes.
A relative seat cwd that exists is used by the engine but refused by the preflight, and the test name says it is "dropped" Open (Nit 1)
docs/SWARM-WORKSPACES.md should say a lone member gets no identity probe Open (Nit 2)
A bind mount of a subfolder passes, though two docstrings say it cannot Open. Reproduced, with one more case (Should fix 1)
A NUL byte or an unknown ~user in a cwd escapes as ValueError or RuntimeError Open. Reproduced on Python 3.11 and 3.13, with two more cases (Should fix 2)
Docs rule: no DECISIONS entry, DOCS-MAP row or guide impact line Open (Should fix 4)
test_git_marker_contents_are_never_read cannot see a read Open. Confirmed with a mutant (Nit 3)
The PR body says 76 passed Open (Nit 4)

The stack questions

  • Core import cap (#998): unchanged. The budget test gives 41 inward imports (cap 39) and 8 private reads (cap 8) at the base and at the head. The new module imports only the standard library.
  • Member gates bound to the host's identity (#1001): unchanged. The preflight runs before _member_binding and does not touch the plugin or gate binding.
  • #1007 items 1 to 3 (a member reply wakes nobody, two tests fail on Python 3.11, a stop lost on Python 3.11): unchanged. This layer does not touch the conversation, runtime or host code. On Python 3.11 the same two conversation tests fail at the base and at the head.
  • #1038's open points (no test covers the conversation turn slot, a stale "documentation-only" sentence): unchanged. This layer does not touch the turn slot or its docs.

Should fix

  1. src/exo/core/group_workspace.py:146-147 says a bind mount "cannot slip through" the nesting check, and :123-124 makes the same claim. A bind mount of a subfolder does slip through, and the PR body says bind mounts are not covered.

    • Repro: in a private mount namespace, bind-mount repo/sub at mnt, with a .git folder in repo. validate_workspaces({"a": repo, "b": mnt}) is accepted, though b writes inside a.
    • One more case: {"a": repo/other, "b": mnt} is also accepted, though both sit in one working tree.
    • Only the same-folder case is caught: {"a": repo/sub, "b": mnt} is refused.
    • Fix: drop "a bind mount" from those two docstrings and add bind mounts to "What it is not" in docs/SWARM-WORKSPACES.md.
  2. Some bad cwds escape as a bare exception, not as CompositionError or WorkspaceError. docs/SWARM-COMPOSITION.md:54 says failures raise CompositionError. docs/SWARM-WORKSPACES.md:7-8 says validate_workspaces returns or raises WorkspaceError.

    • Repro: a seat cwd whose last part is 300 characters long. With the flag off, the result is CompositionError: ... [Errno 36] File name too long. With the flag on, a bare OSError escapes from Path.is_dir() at src/exo/core/group_composition.py:145.
    • abu-aska's cases hold too. An injected cwd with a NUL byte gives ValueError. ~nosuchuser/w as the injected or the seat cwd gives RuntimeError.
    • The public function has the same gap. validate_workspaces called directly with a NUL byte or an unknown ~user raises ValueError or RuntimeError, not WorkspaceError.
    • All of these hold on Python 3.11 and 3.13. It still fails closed, and nothing is built.
    • Fix: in _canonical_dir (group_workspace.py:71-82), move expanduser() inside the try and map ValueError and RuntimeError to WorkspaceError. In _check_workspaces (group_composition.py:149-154), also map an OSError, ValueError or RuntimeError from _effective_cwd. Add test rows.
  3. The docs do not match the code in two places.

    • docs/SWARM-WORKSPACES.md:85-86 says the preflight "does not re-implement" the engine's seat cwd rule and runs over cwds the host "has already decided on". GroupComposition._effective_cwd (group_composition.py:135-147) is a copy of Engine._seat_cwd.
    • docs/SWARM-COMPOSITION.md:53-54 says members in one working tree are refused "(nested worktrees included)". That holds only when one member's folder holds the other's. docs/SWARM-WORKSPACES.md:71-72 says a nested checkout counts as its own tree.
    • Probe, with the flag on: outer/src beside a nested checkout at outer/vendor/lib, or beside a linked worktree at outer/wt, is accepted.
    • Fix: one sentence each.
  4. The docs rule is not met, and this needs the principal.

    • The commit adds a new core module and a new technical doc, but no DECISIONS entry, no DOCS-MAP row for docs/SWARM-WORKSPACES.md, and no "user guide: none" line in the commit message. No command passes the flag, so no CHANGELOG line is needed. No earlier Swarm layer has these either.
    • Question: is G10 an approved policy, and which decision records it? No doc in the repository defines G10, and the PR says this is not the full G10 policy.
    • Question: should the launch path (group_launch.create) take the flag, or stay off for every user path until the rest of G10 lands? If it takes the flag, note that the owner's own engine is not part of the check.

Nits

  1. tests/test_group_composition.py:395 is named ..._relative_seat_cwd_is_dropped_not_used, but an existing relative seat cwd is used. Repro: with rel/cwd under the process folder, the engine runs in rel/cwd with the flag off, and the check refuses it as "not absolute" with the flag on. It fails closed. A mutant that drops every relative seat cwd also passes all tests, so neither behaviour is pinned.
  2. docs/SWARM-WORKSPACES.md should say a lone member gets no identity probe. group_workspace.py:194 builds identity chains only for two or more members.
  3. tests/test_group_workspace.py:403-410 cannot see a read of the .git marker. It only makes the folder read-only, so the file stays readable. Repro: a mutant that reads the .git file right after the lstat passes all 75 tests.
  4. The PR body says 76 passed. On Linux it is 75 passed and 1 skipped. The skip is the real case-insensitive filesystem test.

Checks

All runs below are mine, at 98372003 and its base a658d37a.

  • The two new test files at the head: 75 passed, 1 skipped, on Python 3.13 and on 3.11.
  • The new tests at the base: both new test files fail to collect. With only the new module added to the base, 14 of the 15 new composition tests fail. The 15th checks that the flag is off by default and passes by design.
  • 18 mutants of the new code (fail-open probes, same tree, nesting, flag wiring, effective cwd, check order, error mapping, a marker read, a relative seat cwd): 15 are caught. The path-nesting mutant survives because the identity check covers it. The other two back Nit 1 and Nit 3.
  • Touched suites on Python 3.13 (the group test files, three related files, tests/core, tests/integration and tests/docs): head 5 failed, 1,834 passed, 3 skipped. Base 5 failed, 1,777 passed, 2 skipped. The same 5 fail on both (steer x2, scheduler, import direction, budget).
  • The same suites on Python 3.11: head 7 failed, 1,832 passed, 3 skipped. Base 7 failed, 1,775 passed, 2 skipped. The 2 extra failures on both are #1007's conversation tests. On both Pythons the 57 extra passes and 1 extra skip are the 58 new tests.
  • The one test that uses a real case-insensitive filesystem skips on Linux, and CI has not reached it on macOS. I could not mount one here. The mocked identity tests cover the same logic.
  • ruff check on the whole tree and on the 4 changed Python files: clean. git diff --check: clean. ruff format --check would reformat the 4 changed files, but the 2 older ones were already unformatted at the base, and CI does not run it.
  • Budget test: counted lines go from 18,866 to 19,140, with no ceiling (D-083). Both structure tests fail the same way at the base and the head.
  • scripts/check_types.py on Python 3.11: the head and the base give the same 15 NEW lines, all from lower layers, and RESOLVED is empty.
  • Probes through the real GroupComposition at the base and the head, on Python 3.13 and 3.11: a shared folder, a relative seat cwd, nested and linked checkouts, a stray .git file, a too-long seat cwd, NUL bytes and an unknown ~user. NUL bytes, an unknown ~user, too-long paths and a symlink loop also went to validate_workspaces directly. A bind-mount probe ran in a private mount namespace.
  • gate_diff: not needed. No gate file is touched.
  • Merge: the head is one commit on its base, so it lands as a fast forward. git merge-tree --write-tree of main ef4d7252 and 98372003 is clean, so the whole stack still merges onto main.
  • History: I fetched the head into a fresh clone of the rewritten repository. No pre-cleanup commit is reachable from it, and no commit message or added line in the stack holds a home path.
  • No open PR is stacked on this branch, and no other open PR adds a workspace check.

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