Skip to content

feat(swarm): standalone task-contract validator for group plans - #1189

Open
razi-exo wants to merge 1 commit into
feat/swarm-workspace-preflightfrom
feat/swarm-task-contract
Open

razi-exo wants to merge 1 commit into
feat/swarm-workspace-preflightfrom
feat/swarm-task-contract

Conversation

@razi-exo

@razi-exo razi-exo commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

What this adds

A standalone checker for Swarm task plans. It takes a plan written by a model and the permissions the host allows, and either returns a validated plan or refuses it with an error. Nothing calls it yet.

Stacked on #1039. The base is feat/swarm-workspace-preflight, not main.

Files

File Lines
src/exo/core/group_task_contract.py 496
tests/test_group_task_contract.py 418
docs/SWARM-TASK-CONTRACT.md 201

What the checker decides

  • The plan shape, task order and dependencies. Cycles are refused.
  • Every profile in the plan belongs to the group and is covered by the host grants.
  • Capabilities a task asks for must be granted by the host. A fixed list of 19 elevated names is also refused by name. The host grant is the real gate.
  • Write scopes must sit inside a host-approved root.
  • Model routes must be named routes the host configured.
  • A reviewer cannot review its own task or share a profile with the task it reviews.

What it does not do

  • It is not a sandbox. Scopes are compared as text. It does not resolve symlinks or real paths, so a runtime would have to check them again.
  • It is not wired into execution. GroupHost.start takes no plan or grants today.
  • It does not route or run anything, grant read access, or detect secrets.
  • plan_id identifies the plan only. It is not a signature.
  • Importing it also loads sqlite3, httpx and some other exo modules, through its existing imports.

Verification

  • 25 tests in tests/test_group_task_contract.py pass, checked independently by a second reviewer. They use fake: routes and make no network calls.
  • That reviewer disabled four refusals one at a time (group membership, write-scope containment, elevated capability, self-review). Each made at least one test fail.
  • The Python example in the doc runs unchanged.
  • The doc passes the prose checker, including the duplicate check.
  • The full test suite was not run.

Refs #975. This does not close it.

Automated posting by agentic team with human oversight.

Add a checker that takes a model-written task plan and the permissions
the host grants, and accepts or refuses the plan. It is not called from
any runtime path yet.

- src/exo/core/group_task_contract.py: the validator
- tests/test_group_task_contract.py: 25 tests
- docs/SWARM-TASK-CONTRACT.md: what it decides and what it does not

Scopes are checked as text only. This is not a sandbox.

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.

What I verified by hand:

  • The validator logic reads fail-closed throughout: unknown keys refused, cycles named (I5), reviewer cannot share a profile with its builder and must depend_on the reviewed task, elevation capabilities refused even when granted (I11a), write scopes must sit inside a host root (I12), output paths must sit inside the task's write scopes (I8). Topo order is deterministic Kahn with ties broken by task_id.
  • The doc example matches the real types at this head: SavedGroup(id, owner, mode, conductor, members, created) and GroupMember(profile, session).
  • The 25 tests in tests/test_group_task_contract.py are focused, use fake:fast routes, and make no network or I/O calls.
  • Lint is green.

Three things to fix before this can land:

  1. Three NEW mypy diagnostics in the new file itself (types job 127523485623, run 42106758148). All three trace to _fail being annotated -> None although it always raises:

    • src/exo/core/group_task_contract.py: Argument 1 to "frozenset" has incompatible type "set[Any | None]"; expected "Iterable[str]" [arg-type]
    • Incompatible return value type (got "tuple[Any | None, Any | None, Any | None, frozenset[str]]", expected "tuple[str, str, str, frozenset[str]]") [return-value]
    • Item "None" of "Any | None" has no attribute "__iter__" (not iterable) [union-attr]
      The one-line fix is def _fail(rule: str, target: str, reason: str) -> NoReturn: (import NoReturn from typing). That lets the guards in _group_facts narrow group_id/owner/mode to str and the member profiles to str. The other 15 NEW diagnostics in that job are in stack-base files (group_commands, group_composition, group_conversation, group_engine_adapter, group_host, group_runner, group_launch), not this delta.
  2. The root test suite never ran this PR's tests. All five test jobs fail at collection with the same error, from the job log of 127523485654:
    tests/agents/test_delegate_routes.py:10: ModuleNotFoundError: No module named 'test_tiers'
    That failure is pre-existing on the stack base, not this delta: #1039's head 9837200 fails the same five jobs, while main (012b1b4) is green on all 17 checks. So the "25 tests pass" claim in the PR body has no CI evidence here. The collection error needs fixing on the stack (or a focused local run shown as evidence) before this lands with green CI.

  3. Landing-rule gaps in the change itself: no CHANGELOG entry under Unreleased, and the new doc is not registered — docs/DOCS-MAP.md at this head has zero mentions of SWARM-TASK-CONTRACT. This is a new public surface (a validator other slices will build on, refs #975), so it needs the CHANGELOG entry and the docs-map row in the same change.

Not blocking, but noted: the PR body says importing the module loads sqlite3, httpx and other exo modules through RouteConfig; that matches the module docstring's own caveat, so no surprise there. Also _walk accepts tuples although its error message says "strings, mappings and lists only" — harmless, but the message is slightly wrong.

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

This reviews only this PR's own commit on its base feat/swarm-workspace-preflight (9837200).

What works

I probed validate_plan and HostGrants with plain data. Every path refusal below fails closed.

  • Write scopes under root /srv/w: ../, ./, //, a trailing /, a relative path, an empty string, /, a backslash and the sibling /srv/w2 are all refused. /srv/w/... and /srv/w/..x are accepted, which is correct because they are plain names inside the root.
  • Case and Unicode spellings only cause false refusals, never escapes. /srv/W/x, /SRV/w/x and an NFD scope under an NFC root are refused. A U+2215 division slash stays one component inside the root.
  • Roots /, //, /srv/, srv, an empty string, /srv/../etc and a bare string are refused when HostGrants is built.
  • Ids are ASCII only. büild, a fullwidth build and build with a trailing newline are refused. Duplicate task ids and a duplicate artifact (in two tasks or twice in one) are refused. Profile Builder is refused against grant builder.
  • Cycles: self-dependency (I4), a 2-cycle, mutual review and a 2,000-task ring are refused (I5). A 50-deep nested value is refused by the depth cap.
  • Routes: only configured names pass. Cheap, cheap (trailing space), fast, main and fake:fast are refused. The default backend refuses every name.
  • Elevation names: Approve, approve, APPROVE and a fullwidth approve fail CAPABILITY_RE. approve plus a newline fails the control check. So case, whitespace and lookalike spellings of a listed name cannot reach the grant check.
  • Owner scoping holds. Grants for alice against a group owned by Alice are refused (I10a).
  • Doc claims hold. The files have 496, 418 and 201 lines with 25 tests. A grep finds no use of the module outside its own file, its test and the doc. The doc's example is byte-identical to the code I ran, and it prints 64 socratic ['build_report', 'check_report'] on 3.13 and 3.11.

Must fix

  1. The types job fails on three new mypy errors in this file. scripts/check_types.py with Python 3.11 and mypy 2.4.0 lists three NEW diagnostics in src/exo/core/group_task_contract.py at the head. Base 9837200 lists the other 15 NEW lines and none in this file. The earlier review names the errors and the fix, so I only confirm them. They come from this commit, so I cannot approve yet.

Should fix

  1. A goal with a newline or a tab is refused, against the module's own comment. Line 60 says "a goal may contain newlines and tabs". But _text (line 100) refuses any _CTRL match first, and _CTRL covers \n and \t. A goal "line one\nline two" returns I1 build: control character in goal.

    The _GOAL_BAD check at line 312 can never fire. Model-written goals are often multi-line, so a real plan would be refused.

  2. The elevation list misses exo's own authority-bearing tools. src/exo/core/agents/delegate.py lines 43-46 already keep delegate, memory, send_message, bus_post, cronjob_manage, peers, peer_send and jobs from children, plus the toolsets memory, bus, delegation, kanban and skills.

    None of these is in ELEVATION_CAPABILITIES. When the host grants them, these permits pass: delegate, delegation, peers, bus, jobs, shell, push, sudo, secrets, credentials, env_allow.

    Dotted and suffixed forms of listed names also pass: net.fetch, network-raw, git.commit, commit_push, merge-pr, spawn.child, approve.tool. The doc is honest that the host allowlist is the real gate. Still, a list that blocks spawn but not delegate reads as more than it is. Either add exo's own names and refuse any permit whose first . or - segment is listed, or drop the list.

  3. Reviewer independence is checked on the direct pair only. Three plans are accepted. In the first, checker writes a prep task under role worker, build consumes its artifact, and then check (also checker) reviews build.

    In the second, with builder also a reviewer profile, check2 (builder) reviews check, which reviewed builder's own task. In the third, a reviewer requests shell and write_scope and passes when the host grants them to checker.

    The doc's reviewer section says "distinct identity" and "Reviewers are read-only". Please say in the doc that the rule compares profile names on the direct pair only, and that I15 does not limit permits. Or refuse a reviewer whose profile appears upstream of the task it reviews.

  4. Two tasks with no order between them may write the same path. Artifact names must be unique plan-wide (line 388), but path outputs have no such rule. Tasks a and b with no dependency, each with scope /srv/w and output /srv/w/report.md, are accepted. This holds when they use different profiles too. Nothing orders them, so a runtime that runs independent tasks at once would race on that file.

    Refuse a path output declared by two tasks, as artifacts already are. Or say in the doc that the runtime must serialize tasks whose write scopes overlap.

  5. No bounds on input size. A 100,007-character write scope is accepted. Nothing caps task count, list lengths or path length. _check_references scans depends_on for every artifact input. A fan-in of 3,000 producers (589,733 bytes of compact JSON) took 2.43 s. At 6,000 producers (1,183,733 bytes) it took 9.51 s.

    A 2,000-task ring gives a 12,918-character error message. A task-count cap, list caps and an artifact-to-producer index would bound this.

  6. Nine refusals have no test. Removing any one of them leaves all 25 tests green. No test sends a non-empty route, so the whole route allowlist can go (M9). The mode check, control characters in paths, the schema check, the depth cap, duplicate artifacts and the reviewer subset check are also unpinned. So are one-task-per-reviewer (M7) and membership-covered-by-grants (M8). See the mutant table below.

Nits

  • _CTRL covers ASCII controls only. U+0085 and U+202E pass in a write scope and in a goal. Containment still holds, but U+202E can mislead a person reading the plan. Refusing Unicode categories Cc and Cf would close it.
  • Names compare case-sensitively. Two tasks may output artifacts report.md and Report.md, and task ids build and Build may coexist. On a case-insensitive filesystem a runtime that stores either as a file name would collide.
  • ValidatedPlan(...) can be built directly with any plan_id, and nothing marks a value as validated. Its docstring says it is "the only thing a runtime is ever handed". The doc could say the runtime must call validate_plan itself.
  • REVIEWER_ROLES makes verifier and critic read-only but not scout. delegate.py line 39 makes scout and critic read-only for children. A task with role scout and scope /srv/w is accepted here. The doc could say the two role lists differ.

Checks

  • tests/test_group_task_contract.py: 25 passed on 3.13 and 3.11, at the head and at refs/pull/1189/merge (b598746).
  • Every tests/test_group_*.py, tests/test_saved_groups.py and test_core_line_budget: 364 passed, 1 skipped, 1 failed on 3.13. On 3.11 it was 362 passed, 1 skipped, 3 failed. Head and merge ref gave the same counts.
  • The budget failure is 41 inward product imports (cap 39). Base 9837200 shows the same 41, and main 012b1b4 passes at 39. This commit leaves the count at 41 and adds 496 counted lines (19,140 to 19,636).
  • The two extra 3.11 failures are test_interleave_during_turn_and_idle_stop and test_stop_cancels_and_records_receipt in tests/test_group_conversation.py. They fail the same way on base 9837200 under 3.11, so they do not come from this commit.
  • Mutants, each run against the new test file on 3.13:
Mutant Result
M1 drop group-membership refusal (I10) killed by test_non_member_profile_rejected
M2 _within as a plain prefix test killed by test_output_outside_write_scope_rejected
M3 drop elevation refusal (I11a) killed by test_elevation_capability_refused_despite_grant
M4 drop same-profile self-review refusal (I14) killed by test_self_review_rejected
M5 cycle stops silently instead of refusing (I5) killed by test_cycle_rejected_names_member
M6 drop duplicate task_id refusal (I3) killed by test_duplicate_task_id_rejected
M7 drop one-task-per-reviewer refusal (I14) survived, 25 passed
M8 drop membership-covered-by-grants refusal (I10) survived, 25 passed
M9 drop the route allowlist, names and resolve (I1) survived, 25 passed
M10 drop the group mode check (I17) survived, 25 passed
M11 drop the control-character check in paths survived, 25 passed
M12 drop the schema check (I1) survived, 25 passed
M13 drop the depth cap survived, 25 passed
M14 drop the duplicate-artifact refusal (I8) survived, 25 passed
M15 drop the reviewer_profiles subset check survived, 25 passed
  • ruff check on both Python files: all checks passed. git diff --check is clean. No gate-sensitive file changed, so scripts/gate_diff.py does not apply.
  • merge-tree with the base is clean (rc 0). With main 012b1b4 it gives rc 1, with conflicts in docs/SEATS.md, src/exo/compose.py, src/exo/core/engine.py, src/exo/core/models/router.py and src/exo/server/engine.py. The base alone has the same five conflicts with main, and none of them is a file of this commit.
  • CI on this head: lint passed and types failed (see Must fix). The four test jobs stop at collection in tests/agents/test_delegate_routes.py with No module named 'test_tiers'. I got the same error on the merge ref. This commit does not touch that file, and the earlier review covers it.

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.

2 participants