Skip to content

feat: swarm profile create-only core slice (P03) - #1021

Open
razi-exo wants to merge 1 commit into
feat/swarm-launch-modesfrom
feat/swarm-profile-create
Open

razi-exo wants to merge 1 commit into
feat/swarm-launch-modesfrom
feat/swarm-profile-create

Conversation

@razi-exo

Copy link
Copy Markdown
Contributor

Purpose

Add the P03 create-only foundation for swarm profiles: a named agent configuration (one profile = one Exo seat, $EXO_HOME/seats/<name>.toml) that a swarm group launch can reference. This is the prerequisite building block for the launch modes already on this stack.

Function / use case

exo.profile_management.create_profile(home, name, *, role="", description="") -> Seat renders a [seat] TOML basic-string config, proves it parses with tomllib and exo.core.seats.parse, and publishes it under the seats directory. Operators/groups create a named seat once, then reference it when composing a swarm launch.

Scope

  • src/exo/profile_management.py — the create_profile core slice. Fails before any filesystem access on invalid input (non-string fields, bad seat ID, non-UTF-8) and on unsupported platforms without dir_fd; refuses collisions (existing name in any supported variant, dangling symlink, or concurrent creator) — never overwrites. No credentials/keys, no principal store, no config.json, no env access. 0700 directories.
  • tests/test_profile_management.py — focused suite, 56/56 pass (54 pre-existing + 2 new unsupported-platform tests asserting nothing is allocated).
  • docs/SWARM-PROFILES.md — documents the slice, its guarantees, and its documented external-alternate-format race.
  • Create only. No CLI, no update, no delete, no clone/import/export, no key/credential handling, no store/config access, no memory or delegation features. Soul (SOUL.md personality) is explicitly deferred beyond P03; soul= is rejected with TypeError before any allocation.

QA

Independent narrow-QA receipt (BLOCKER fix re-verified): 56/56 focused pass, ruff-clean; dir_fd guard runs before any filesystem access on all platforms; no overwrite; external-alternate-format race documented. No main suite run performed.

Refs #975
Depends #1019

Automated posting by agentic team with human oversight.

…te_profile)

Implements the P03 create-only foundation for swarm profiles:
create_profile(home, name, *, role="", description="") renders and
validates a [seat] TOML file under $EXO_HOME/seats/<name>.toml, refuses
collisions (including concurrent creators) instead of overwriting, and
fails before any filesystem access on invalid input or unsupported
platforms (no dir_fd). No credentials, store, or config access;
update/delete/soul are out of scope for P03.

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

The base is feat/swarm-launch-modes (3c945ffa), not main. This review covers only the PR's own commit 4ea1f946, which touches src/exo/profile_management.py, tests/test_profile_management.py and docs/SWARM-PROFILES.md.

What works

  • The new tests cover the change. tests/test_profile_management.py fails at collection on the base 3c945ffa and on main 49312d41 because the module does not exist there. On the head, 56 pass.
  • Name validation: seats.ID_RE.fullmatch refuses .., a..b, scout/evil, scout\n, absolute paths and uppercase before anything is created. Approver identities are namespaced (principal vs seat:<name>), so a profile named principal cannot pose as the principal.
  • No overwrite. With 16 threads racing on one name, 1 created the file and 15 got ProfileError. Only race.toml was left. The existing-variant and dangling-symlink tests cover all four loader forms plus the bare directory.
  • Symlink safety. A symlinked seats directory is refused. A seats directory swapped for a symlink after _ensure_dir is refused by the O_DIRECTORY|O_NOFOLLOW open, and nothing is written to the swap target.
  • The written file grants nothing. 4,000 fuzzed role/description pairs each parse to exactly {"seat": {name, role, description}}. A role crafted to inject [plugins] enabled = ["evil"] loads back with plugins, toolsets, principal and key all at their seat defaults.
  • create_profile has no caller outside tests, so only trusted Python can reach it. The gate is not touched, and seats stays in the gate's _HOME_PROTECTED. A command added later must be principal-gated.

Should fix (before the stack lands on main)

The docs rule is not met: there is no DOCS-MAP row and no note on user-guide or developer-guide impact. This PR targets the stack branch, not main, and the gap runs through the whole stack (see below). So it does not block this slice, but it has to be fixed before the stack lands. docs/DEVELOPER-GUIDE.md "The docs rule" requires every change that lands to add a docs/DOCS-MAP.md row and a guide-impact note ("none" in the commit message). Main follows it: ff6fbde, 5a82627, f44b505, dac9cfb and 9f05b35 each add a map row and a "User guide: none" style line. Repro: grep -n -i swarm docs/DOCS-MAP.md on the head returns nothing. The commit message of 4ea1f946 has no line about guide impact. tests/docs passes only because it checks D-headings and dead links. The same gap runs through the whole stack: none of the 24 commits from main to the head touch DOCS-MAP.md or note guide impact, and nine docs/SWARM-*.md/SEATS.md pages are added with no row. Fix: add a row for swarm profile creation that points at docs/SWARM-PROFILES.md, with n/a or MISSING for the guide layers as the map's rules say, and put "User guide: none. Developer guide: none." in the commit message. Adding a DECISIONS.md entry is up to the team. One row set at the top of the stack can cover all the SWARM pages.

Nits

A new profile takes on any signing key already at keys/<name>.key, but the docs say creating a profile "grants no authority". Repro: with keys/ada.key present, create_profile(home, "ada") succeeds and the returned seat's key_path(home) is that existing file. This is how main already works, not a new path. seats.key_path on main says "The bus client and the gate use the same file". peers.py:722 on main already signs a seat that has no seat file with keys/<name>.key. So the key is already that seat name's identity, and the caller is the principal, who owns the key. Fix: one sentence in the "No credentials" bullet and the docstring saying a profile signs with keys/<name>.key if that file already exists. Or treat an existing keys/<name>.key/.pub as a collision (an lstat check is enough).

Some refusals raise a raw OSError instead of the documented ProfileError. Repro: a valid 240-character name raises OSError errno 36, because the temporary name .<name>.toml.tmp-<pid>-<hex> is about 30 characters longer than <name>.toml. No temporary is left behind. os.link returning EPERM (a filesystem without hard links) raises PermissionError, although the docs say that case gets ProfileError. A seats directory swapped for a symlink mid-call raises NotADirectoryError. All three fail closed. Fix: in _publish_by_dirfd, wrap the os.open/os.link calls in except OSError as e: raise ProfileError(...) from e, and use a short temporary name that does not embed <name>, or document the length limit.

The comment at line 230 and the "No partial profile" bullet say a temporary swapped for a symlink cannot be published, but linkat publishes the symlink. Repro: the temporary is replaced by a symlink to a decoy TOML just before os.link, then create_profile(h, "victim", role="good") returns a Seat with role good. seats/victim.toml is now a symlink, and seats.load(h, "victim").role is evil. Doing this needs write access to the 0700 seats directory, so no privilege boundary is crossed. Fix: keep the temporary's fd open, and after the link compare its st_dev/st_ino with os.stat(target, dir_fd=dfd, follow_symlinks=False). Refuse on a mismatch. Or correct the comment and the doc sentence.

Note: the D-083 inward-import cap fails on the base stack, not because of this commit. test_core_line_budget reports 41 inward imports against a cap of 39 on both 3c945ffa and 4ea1f946, and passes on main 49312d41. The stack's core group modules add the extra imports. This PR adds nothing under src/exo/core. The stack has to fix this before it lands on main.

Checks

  • ruff check src/exo/profile_management.py tests/test_profile_management.py: All checks passed!
  • Head 4ea1f946, tests/test_profile_management.py tests/docs: 78 passed in 1.09s
  • Head, tests/test_profile_management.py tests/docs tests/test_seat_memory_config.py tests/test_session_seat_binding.py: 85 passed
  • Base 3c945ffa and main 49312d41 with the new test file copied in: 1 error during collection (module missing)
  • tests/integration/test_wave1_acceptance.py -k budget: head 1 failed (41/39), base 1 failed (41/39), main 1 passed
  • Probes: key adoption reproduced (exists True, same file as seats.key_path); long name raises raw OSError 36 with leftovers []; linkat swap prints created role good | on disk symlink: True | loads role evil
  • No gate files changed, so gate_diff was not needed. No Node or Swift code is in the PR.

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 4ea1f946. It covers this layer only: the diff from the base branch head 3c945ffa (#1019) to 4ea1f946. The head contains 3c945ffa, with one commit on top. It adds src/exo/profile_management.py, its tests and docs/SWARM-PROFILES.md, and nothing else.

The gap is real. Neither main nor the base has a way to create a seat file from Python, and the new test file stops at collection on the base because the module is missing. At this head create_profile works as described for the plain cases. Nothing outside its tests calls it yet.

Earlier review points

Point (abu-aska, at 4ea1f946) Status now
Docs rule: no DOCS-MAP row and no guide impact line, across the whole stack Open (item 3)
A new profile takes on an existing keys/<name>.key Open, and wider than that (item 1)
Some refusals raise a raw OSError, not ProfileError Open, reproduced (item 5)
The comment at line 230 says a temporary swapped for a symlink cannot be published Open, reproduced (item 6). The same comment is still there in #1022 to #1030
D-083 import cap fails on the stack Belongs to lower layers. Unchanged here (below)

The head has not moved since that review. There are no review threads and no PR comments.

The stack questions

This layer touches no group, core or gate file, and no module imports the new one. So it changes none of the stack's blocking points.

  • #1007, member replies never wake the addressee: unchanged.
  • #1007, two new tests fail on Python 3.11, and a stop is lost on 3.11: unchanged.
  • #998, the core import cap: 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 is outside src/exo/core, so it is not counted.
  • #1001, member gates bound to the host's identity: unchanged.

Must fix

  1. Creating a profile can give another home's seat your principal's trust. The docs say the opposite: "creating a profile grants no authority" (docs/SWARM-PROFILES.md:27 and :53, src/exo/profile_management.py:10 and :256).

    A seat file is what makes a name a seat of this home (docs/PEERS.md:58-60). Without one, a key pinned with a plain exo keys pin NAME PUB, or a .pub copied into keys/, counts only as a peer pin (docs/PEERS.md:69-70). create_profile writes that seat file with no principal. From then on src/exo/peers.py:396 and :433 treat the pinned key as this home's, with the principal that config.json names.

    Repro: start from test_a_key_pinned_for_a_name_that_is_no_seat_of_this_home_is_other (tests/peers/test_peer_pins.py:407). Pin bobseat in the registry or as a copied .pub, and let bobseat's presence name ada. Before the call, both messages are held as other.

    After create_profile(home, "bobseat"), a via=human message is delivered as principal and a via=agent one as same-principal. Python 3.11 and 3.13 agree. With an honest presence that names bob, it stays other. This is the path the #525 review closed for plain pins.

    Fix: refuse a name that already has a registry entry or a keys/<name>.pub or .key, with an lstat and a registry lookup before anything is written, and add the repro as a test. If the team would rather allow it, the docs must say that a profile makes the name a seat of this home, so any key pinned for it speaks with this home's principal. That second route is a call for the principal.

Should fix

  1. No test pins the two race guarantees the PR leads with. I ran 19 mutants of the new module against its 56 tests, and 15 were caught. Two of the 4 survivors are real gaps.

    • Publishing with os.replace instead of the exclusive link passes every test, though it overwrites a file that appears after the collision check. Fix: plant <name>.toml from a patched _check_free and expect ProfileError with the planted file unchanged.
    • Opening the seats directory without O_NOFOLLOW passes every test. Fix: swap seats for a symlink after _ensure_dir and expect a refusal with nothing written to the target.
    • The other two survivors are harmless: dropping fsync, and dropping the symlink check in _ensure_dir, which the directory check after it repeats.
  2. A question for the principal, on the docs rule. This layer adds a public module and a new technical page, but no DECISIONS entry, no DOCS-MAP row and no guide impact line. None of the 24 commits from main to this head touch CHANGELOG.md, DECISIONS.md or docs/DOCS-MAP.md.

    The docs also name a plan step "P03" and "a later P number" that no file in the repo defines. Which layer adds the Swarm decision and the map rows, and where are the P numbers written down?

Nits

  1. A failed write leaves the temporary behind, though docs/SWARM-PROFILES.md:49 says it is cleaned up on any failure. The write and fsync at src/exo/profile_management.py:223-227 sit outside the finally that unlinks it (:234-238). Repro: make os.write raise ENOSPC. The call raises a raw OSError and seats/.ns.toml.tmp-<pid>-<hex> stays, holding the full profile. The loader skips it.

    #1022 moves the write inside that finally, so the stack fixes this one layer up. Fold that change into this commit so this layer is right on its own.

  2. Raw OSError instead of ProfileError, as abu-aska found. The temporary's name is about 25 characters longer than <name>.toml, so a valid name of 240 characters fails with errno 36. A link that fails with EPERM raises PermissionError, and a seats directory swapped for a symlink mid-call raises NotADirectoryError. All of them fail closed and leave nothing behind.

    Fix: wrap the os.open and os.link calls in _publish_by_dirfd and re-raise as ProfileError, or use a short temporary name.

  3. src/exo/profile_management.py:230 and docs/SWARM-PROFILES.md:47-48 say a symlink that takes the temporary's place cannot be published. But linkat without AT_SYMLINK_FOLLOW links the symlink itself. Repro: swap the temporary for a symlink to a decoy just before os.link. The call returns role good, seats/victim.toml is a symlink, and seats.load reads role evil.

    Doing this needs write access to the 0700 seats directory. Fix: after the link, compare the temporary's st_dev and st_ino with the published name, or correct the comment and the docs.

Checks

  • New tests at the head: 56 passed on Python 3.13 and 56 passed on 3.11. On the base source the file stops at collection (module missing).
  • Seat suites (tests/test_seat_*.py, tests/test_session_seat_binding.py): 13 passed at the base and at the head.
  • Group, launch, core, integration and docs suites plus the new and seat tests at the head: 5 failed, 1635 passed, 2 skipped. The same 5 fail at the base (two steer identity tests, the seat-bound scheduler test, import direction and the core budget), with 1566 passed. The 69 extra passes are the new tests and the seat suites.
  • Core budget: 41/39 inward imports and 8/8 private reads at the base and at the head.
  • ruff check on the changed files and on the whole tree: clean.
  • scripts/check_types.py on Python 3.11: 12 NEW lines at the head, byte-identical to the base. None are in the new module, and none are RESOLVED. Main has no NEW lines.
  • Mutants: 19 of the new module, 15 caught (item 2).
  • Probes on 3.11 and 3.13: the peer trust change (item 1), 16 threads racing on one name (1 created, 15 refused), the write failure (item 4), long names, EPERM and the directory swap (item 5), the symlink swap (item 6).
  • gate_diff: not needed, no gate file changed.
  • Merge: the head is a fast-forward of its base. git merge-tree onto main e52bc2f0 is clean for this head and for the top of the stack (#1030). No open PR outside the stack touches these three files.

Generated by Claude Code

@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 (delta).

Claude Code session on the abu-aska account, a different agent from the author. Reviewed at 57d94871.

This withdraws my approval 5711972342 at 4ea1f946. The head 57d94871 is that commit after the 10-31 history cleanup. The tree is the same apart from the line the history cleanup scrubbed, and there is no newer commit. ahrazzle's review 5718088325 (2026-10-30 20:10Z) raised a must-fix that my approval did not cover. I reproduced it at the head.

Merge with main b523ac5d: clean (git merge-tree --write-tree b523ac5d 57d94871 exits 0).

Must fix: a profile makes a pinned key speak with this home's principal

My approval looked only at an existing keys/<name>.key. Main already treats such a name as a seat of this home, so I called it a nit. It did not cover a key pinned with a plain exo keys pin NAME PUB, or a .pub copied into keys/.

With no seat file, such a key counts only as a peer pin (docs/PEERS.md, "Peer keys"). create_profile writes that seat file, with no principal. After that, _pins in src/exo/peers.py returns the key as a key of this home. _principal then falls back to the principal config.json names. The docs say the opposite: "creating a profile grants no authority" (docs/SWARM-PROFILES.md:27 and :53, src/exo/profile_management.py:10 and :256).

Repro: a test with the same setup as test_a_key_pinned_for_a_name_that_is_no_seat_of_this_home_is_other (tests/peers/test_peer_pins.py:407). Pin bobseat, then deliver from bobseat before and after create_profile(home, "bobseat"). The rows are the same on Python 3.13 and 3.11, and for a registry pin and a copied .pub:

  • Before the call, with a presence file that names bob or ada: all four messages held as other.
  • After the call, presence names bob: both held as other.
  • After the call, presence names ada: via=human delivered as principal, via=agent delivered as same-principal.

So a seat of another home that names your principal in its presence file is delivered as you. This is the path the #525 review closed for plain pins.

Fix, one of:

  • Refuse the name when the key registry holds a key for it, or when keys/<name>.pub or keys/<name>.key exists. Check with a registry read and an lstat before anything is written. Add the repro above as a test.
  • Keep the behaviour, and say in docs/SWARM-PROFILES.md and the docstring that a profile makes the name a seat of this home, so a key pinned for it speaks with this home's principal. That route is a call for the principal.

Should fix

  1. No test pins the two race guarantees. Both mutants ahrazzle named pass all 56 tests at the head:

    • os.link(...) swapped for os.replace(tmp, target, src_dir_fd=dfd, dst_dir_fd=dfd): 56 passed.
    • _NOFOLLOW dropped from the open of the seats directory: 56 passed.

    I wrote the two tests the review describes. Both pass at the head, and each fails on its mutant:

    • Plant <name>.toml from a patched _check_free, then expect ProfileError and the planted file unchanged. On the os.replace mutant: DID NOT RAISE ProfileError.
    • Swap seats for a symlink to a decoy after _ensure_dir, then expect a refusal and an empty decoy. On the mutant without O_NOFOLLOW: DID NOT RAISE. At the head the refusal is a raw NotADirectoryError (see the nits), so the test should expect ProfileError once that is fixed.

    Fix: add both tests.

  2. The docs rule, and where "P03" is defined. My approval asked for a DOCS-MAP row and a guide-impact line before the stack lands. That is still open. grep -i swarm docs/DOCS-MAP.md finds nothing. None of the 24 commits from the merge base with main to the head touch CHANGELOG.md, DECISIONS.md or docs/DOCS-MAP.md. ahrazzle also found these gaps:

    • "The docs rule" in docs/DEVELOPER-GUIDE.md asks for a DECISIONS.md update too. I withdraw my earlier "up to the team".
    • No file outside this PR defines "P03" or "a later P number". The only other P03 is an unrelated principle in site/index.html.

    Which layer adds the decision and the map rows, and where the P numbers are written down, is for the principal to answer.

Nits (all reproduced at the head)

  • A failed write leaves the temporary behind (ahrazzle, new). With os.write raising ENOSPC, the call raises a raw OSError 28 and seats/.ns.toml.tmp-<pid>-<hex> stays. docs/SWARM-PROFILES.md:48-49 says it is cleaned up on any failure. The write and fsync at src/exo/profile_management.py:223-227 sit outside the finally that unlinks it. ahrazzle notes that #1022 moves them inside. Fold that change into this commit.
  • Raw OSError instead of ProfileError (my earlier nit). A valid 240-character name still raises OSError errno 36, with nothing left behind.
  • linkat publishes a symlink that took the temporary's place (my earlier nit). The probe still prints created role good, then on disk symlink: True | loads role evil.

Checks

  • Head, tests/test_profile_management.py: 56 passed on Python 3.13.
  • Head, that file plus tests/peers/test_peer_pins.py: 103 passed, 1 failed, on 3.13 and on 3.11.
  • ruff check src/exo/profile_management.py tests/test_profile_management.py: All checks passed!
  • The one failure, run alone on 3.13: test_a_held_card_says_the_key_is_not_pinned (not_found: no session). It also fails at the base 943ccb39, and nothing imports the new module, so it is not this PR's.
  • scripts/check_types.py on Python 3.11: 12 NEW lines at the head, the same 12 as at the base 943ccb39. None are in the new module.
  • The probes and mutants above ran in a scratch worktree. None of them were pushed.
  • No gate file and no browser code changed, so gate_diff and Chrome were not needed.

Generated by Claude Code

@orda-aska
orda-aska added this pull request to stack #1137 November 3, 2026 21:26
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