Repository navigation
Conversation
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
left a comment
There was a problem hiding this comment.
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:fastroutes, and make no network or I/O calls. - Lint is green.
Three things to fix before this can land:
-
Three NEW mypy diagnostics in the new file itself (types job 127523485623, run 42106758148). All three trace to
_failbeing annotated-> Nonealthough 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 isdef _fail(rule: str, target: str, reason: str) -> NoReturn:(import NoReturn from typing). That lets the guards in_group_factsnarrowgroup_id/owner/modetostrand the member profiles tostr. 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.
-
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. -
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
left a comment
There was a problem hiding this comment.
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/w2are all refused./srv/w/...and/srv/w/..xare 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/xand 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/../etcand a bare string are refused whenHostGrantsis built. - Ids are ASCII only.
büild, a fullwidthbuildandbuildwith a trailing newline are refused. Duplicate task ids and a duplicate artifact (in two tasks or twice in one) are refused. ProfileBuilderis refused against grantbuilder. - 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,mainandfake:fastare refused. The default backend refuses every name. - Elevation names:
Approve,approve,APPROVEand a fullwidthapprovefailCAPABILITY_RE.approveplus 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
aliceagainst a group owned byAliceare 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
- The types job fails on three new mypy errors in this file.
scripts/check_types.pywith Python 3.11 and mypy 2.4.0 lists three NEW diagnostics insrc/exo/core/group_task_contract.pyat 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
-
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_CTRLmatch first, and_CTRLcovers\nand\t. A goal"line one\nline two"returnsI1 build: control character in goal.The
_GOAL_BADcheck at line 312 can never fire. Model-written goals are often multi-line, so a real plan would be refused. -
The elevation list misses exo's own authority-bearing tools.
src/exo/core/agents/delegate.pylines 43-46 already keepdelegate,memory,send_message,bus_post,cronjob_manage,peers,peer_sendandjobsfrom children, plus the toolsetsmemory,bus,delegation,kanbanandskills.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 blocksspawnbut notdelegatereads 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. -
Reviewer independence is checked on the direct pair only. Three plans are accepted. In the first,
checkerwrites apreptask under roleworker,buildconsumes its artifact, and thencheck(alsochecker) reviewsbuild.In the second, with
builderalso a reviewer profile,check2(builder) reviewscheck, which reviewed builder's own task. In the third, a reviewer requestsshellandwrite_scopeand passes when the host grants them tochecker.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.
-
Two tasks with no order between them may write the same path. Artifact names must be unique plan-wide (line 388), but
pathoutputs have no such rule. Tasksaandbwith no dependency, each with scope/srv/wand 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
pathoutput declared by two tasks, as artifacts already are. Or say in the doc that the runtime must serialize tasks whose write scopes overlap. -
No bounds on input size. A 100,007-character write scope is accepted. Nothing caps task count, list lengths or path length.
_check_referencesscansdepends_onfor 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.
-
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
_CTRLcovers 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.mdandReport.md, and task idsbuildandBuildmay coexist. On a case-insensitive filesystem a runtime that stores either as a file name would collide. ValidatedPlan(...)can be built directly with anyplan_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 callvalidate_planitself.REVIEWER_ROLESmakesverifierandcriticread-only but notscout.delegate.pyline 39 makesscoutandcriticread-only for children. A task with rolescoutand scope/srv/wis 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 atrefs/pull/1189/merge(b598746).- Every
tests/test_group_*.py,tests/test_saved_groups.pyandtest_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_stopandtest_stop_cancels_and_records_receiptintests/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 checkon both Python files: all checks passed.git diff --checkis clean. No gate-sensitive file changed, soscripts/gate_diff.pydoes not apply.merge-treewith the base is clean (rc 0). With main 012b1b4 it gives rc 1, with conflicts indocs/SEATS.md,src/exo/compose.py,src/exo/core/engine.py,src/exo/core/models/router.pyandsrc/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.pywithNo 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
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, notmain.Files
src/exo/core/group_task_contract.pytests/test_group_task_contract.pydocs/SWARM-TASK-CONTRACT.mdWhat the checker decides
What it does not do
GroupHost.starttakes no plan or grants today.plan_ididentifies the plan only. It is not a signature.sqlite3,httpxand some other exo modules, through its existing imports.Verification
tests/test_group_task_contract.pypass, checked independently by a second reviewer. They usefake:routes and make no network calls.Refs #975. This does not close it.