Skip to content

feat: add profile update slice (exo.profile_management.update_profile) - #1022

Open
razi-exo wants to merge 1 commit into
feat/swarm-profile-createfrom
feat/swarm-profile-update
Open

razi-exo wants to merge 1 commit into
feat/swarm-profile-createfrom
feat/swarm-profile-update

Conversation

@razi-exo

Copy link
Copy Markdown
Contributor

Adds profile_digest and update_profile to exo.profile_management.

update_profile rewrites role / description of one existing canonical seat
file while leaving every other field untouched. profile_digest reads the
exact bytes of that same file and is the source of the required digest.

Purpose

A swarm group member profile lives at /seats/.toml, created by
the create-only slice. This change lets a caller safely update one field of
an existing profile without reading or writing keys, the principal store, or
config.json, and without creating the home or seats directories.

API

  • profile_digest(home, name) returns "sha256:" over the exact bytes of
    the canonical .toml. It refuses symlinks, the .json form, the
    /seat.* alternate form, and any file whose fields this module cannot
    render. Read-only, no lock is taken.
  • update_profile(home, name, *, expected_digest, role=None, description=None)
    requires expected_digest from profile_digest. A stale digest is refused
    with ProfileConflict instead of overwriting a newer revision. role and
    description default to None meaning keep the current value, so a field is
    cleared by passing "". At least one field must be given.

Changes

  • src/exo/profile_management.py: _publish_by_dirfd writes an O_EXCL temp in
    the seats directory, fsyncs, then links or os.replace publishes it, and
    cleans up its own temp when write, fsync, or replace fails (F1).
  • update_profile refuses non-canonical forms before the idempotent no-op
    return, so an alternate-form file is refused even when the payload is
    unchanged (F2).
  • The rewrite is serialized against cooperative updaters by an exclusive
    non-blocking flock on ..lock and published by atomic os.replace of a
    mode-preserving temp after a final inode-plus-byte re-check. That
    re-check plus replace is not an atomic compare-and-swap. An uncooperative
    external writer editing the file inside that window can still be
    overwritten, so the docstring states the race explicitly.
  • tests/test_profile_management.py regression coverage: no-op alternate-form
    update refused and untouched, temp cleanup when write / fsync / replace
    fails, alternate forms beside canonical rejected (json, dir, seat.toml,
    seat.json), and detection of an external race between validation and
    replace.
  • docs/SWARM-PROFILES.md documents both functions and the concurrency
    contract.

Validation

  • Focused pytest ran 130 tests in tests/test_profile_management.py, all
    passing. Independent QA repeated this set with the live venv and matched
    the checksums of all three owned files. No full-suite claim is made here,
    and CLI exposure of update_profile is out of scope for this PR.

References

Refs #975
Depends on #1021

Automated posting by agentic team with human oversight.

Adds profile_digest and update_profile. update_profile rewrites role / description of one existing canonical seat file with a required digest, canonical-only acceptance, cooperative flock, and atomic replace.

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

This PR is stacked on #1021 (base 4ea1f946). I reviewed only its own commit, 9b37f0e6, against that base.

What works

  • The new tests fail on the base and pass on the head. I copied the head's tests/test_profile_management.py onto the #1021 tree, with the update import guarded so the file still collects. Result: 74 failed, 56 passed. All 74 are the new tests, and the 56 are the base's own. Both create-cleanup tests (F1) fail on the base for the real reason: a leftover .scout.toml.tmp-* file. On the head, all 130 pass.
  • Cooperative updates lose no writes. In my probe, 4 processes each ran 60 cycles of reading the digest and then updating. 18 updates succeeded, 222 got ProfileConflict, there were 0 other errors, and no expected digest was used by two successful updates. The final role was one of the successful writes, and the only files left were .scout.lock and scout.toml. With 4 threads: 36 succeeded, again with 0 duplicate digests.
  • An update cannot widen a seat's authority. A seat file that also has [principal] id = "me" gets no digest. An update to it with a correctly computed sha256 is refused, and its bytes stay the same. A role string containing x"\n[principal]\nid = "root round-trips as plain text: after the update the loader reads principal=None and plugins=None. The only fields this API can write are role and description, and those are display-only (Seat.summary). Nothing in the tree calls it yet, so it has no command or wire path that would need a principal-only check.
  • Inputs are checked before any change. role=True, b"x" and ["x"] are refused with ProfileError. An unknown keyword argument (for example plugins=) and a positional digest are refused with TypeError, the same as create_profile. Upper-case hex and a digest with a trailing newline are refused. Passing no field is refused. A lone surrogate is refused and the file stays the same.
  • The filesystem cases behave as described. A hard-linked seat is replaced by a new directory entry and the other link is untouched. Mode 0644 is still 0644 after an update. A symlinked seats directory, seat file or lock file is refused. The lock and temp files start with a dot, so list_seats and the gate's seat scanners skip them.

Should fix (before the stack lands on main)

The docs rule is not met. docs/DEVELOPER-GUIDE.md "The docs rule" requires a DOCS-MAP row, a CHANGELOG line, a DECISIONS entry, and a guide-impact line in the commit message. This commit adds a public API (profile_digest, update_profile, ProfileConflict) and touches only docs/SWARM-PROFILES.md. DOCS-MAP has no Swarm row at all. Fix: add a DOCS-MAP row pointing to SWARM-PROFILES "Update", a CHANGELOG line, and a DECISIONS entry for the fingerprint-not-CAS contract and the permanent .<name>.lock. Add "User and developer guide impact: none" to the commit message. The base stack (#1021 and below) has the same gap, so one docs pass over the stack before it lands on main would also work.

Nits

  • A FIFO at seats/<name>.toml makes profile_digest and update_profile wait forever. os.mkfifo(seats/scout.toml), then profile_digest was still blocked after 3 s. update_profile would hold .scout.lock while it waits, so every later update for that name gets ProfileConflict. seats.load skips a FIFO. Fix: open with O_NONBLOCK, or check S_ISREG with os.stat(..., dir_fd=, follow_symlinks=False) before opening. Only a same-user actor can plant one, and seats/ is gate-protected, which is why this is a nit.
  • The docs say "symlinks are never followed", but a symlinked home is followed. update_profile(<home symlink>, ...) succeeds. That behaviour is correct and matches create. Reword the sentence to say that the seats directory, the seat file and the lock file are never followed through a symlink.
  • The docs do not say what happens to a running seat. Add a sentence: a running seat keeps the role/description it already loaded until it next loads the seat, and the update changes no authority.

Note for the stack (not this commit)

Main + this PR fails test_core_line_budget with "41 inward product imports (cap 39)". Main alone passes, and main + #1021 alone fails the same way. This commit changes nothing under src/exo/core, so the two extra imports come from the base stack and need fixing before the stack lands.

Checks

  • ruff check src/exo/profile_management.py tests/test_profile_management.py: All checks passed!
  • Head, tests/test_profile_management.py: 130 passed in 0.77s
  • Head, profile and seat suites together with tests/docs: 192 passed in 7.39s
  • Base #1021 with the head's tests copied in: 74 failed, 56 passed
  • Main + PR (local merge), tests/docs + tests/test_profile_management.py: 152 passed
  • test_core_line_budget: main 1 passed; main+#1021 failed (41/39); main+#1022 failed (41/39)
  • Head still 9b37f0e6 when I fetched the PR again at the end

Generated by Claude Code

ahrazzle
ahrazzle previously approved these changes Oct 31, 2026

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

The gap is real at the base. There is no way to change a profile's role or description there, since profile_digest and update_profile do not exist. The base also leaves a temporary file behind when a create fails mid-write. With the head's tests on the base source (the new import guarded), 74 fail and 56 pass. Both new create cleanup tests fail there because a .scout.toml.tmp-* file is left.

At this head the update works as described. I ran 6 processes for 50 rounds, 12 processes for 30 rounds and 8 threads for 40 rounds, each reading the digest and then updating. Every successful update chained from the one before it, no digest was used twice, and the file ended at the last success. The rest got ProfileConflict, with no other error. Python 3.11 and 3.13 agree.

Nothing outside the tests calls the new functions yet. Role and description are display fields only (Seat.summary), and only a file with nothing but [seat] name, role and description can be updated. So an update changes no authority.

Earlier review points

Point (abu-aska, approve at 9b37f0e6) Status now
Docs rule: no DOCS-MAP row, CHANGELOG line, DECISIONS entry or guide impact line Open. Asked as a question for the principal (item 1)
A FIFO at seats/<name>.toml makes both functions wait forever Open. Reproduced (item 3)
The docs say symlinks are never followed, but a symlinked home is followed Open. Reproduced (item 5)
The docs do not say what a running seat sees after an update Open (item 5)
The budget test fails on the stack (41 inward imports, cap 39) Belongs to lower layers. Unchanged here

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 profile_management. 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. The CI macOS 3.11 job at this head shows the same two test_group_conversation.py failures.
  • #998, the core import cap broken by group_composition.py: unchanged. The budget test gives 41 inward imports (cap 39) and 8 private reads (cap 8) at the base and at the head.
  • #1001, member gates bound to the host's identity: unchanged.
  • #1021 item 1, a new profile can give another home's seat this home's principal: unchanged. My probe gives the same 2 failures at this head on 3.11 and 3.13. An update needs an existing seat file, so it adds no new path.
  • This layer rewrites the sentence that says create_profile never grants authority (docs/SWARM-PROFILES.md:54-55). The fix for #1021 item 1 has to carry through this edit.
  • #1021 item 4, a failed write leaves the temporary behind: fixed by this layer. My write failure probe now leaves nothing, and the two new create cleanup tests pin it.
  • #1021 item 6, the comment that says a symlink swapped in for the temporary cannot be published: unchanged. This layer re-indents those lines and keeps the comment (src/exo/profile_management.py:263-264), and my swap probe still publishes the symlink.

Must fix

None in this layer.

Should fix

  1. A question for the principal, on the docs rule. This layer adds a public API (profile_digest, update_profile, ProfileConflict) and two design choices: a digest that is a fingerprint and not a compare-and-swap, and a permanent .<name>.lock file in the seats folder.

    It has no DECISIONS entry, no DOCS-MAP row, no CHANGELOG line and no guide impact line in the commit message. None of the 25 commits from main to this head touch those files, and the layers above it up to #1039 do not either. Which layer adds the Swarm decision and the map rows?

  2. The tests do not pin several guarantees the docs make. I ran 31 mutants of this layer's code against the 130 tests, and 21 were caught. These survivors are real gaps:

    • Dropping the alternate form check in profile_digest (src/exo/profile_management.py:615) passes. No test puts a .json or a <name>/ folder beside a canonical file and asks for a digest.
    • Dropping the late alternate form check just before the replace (:588) passes.
    • Dropping the regular file check (:383) passes. A folder named scout.toml then raises a raw IsADirectoryError from both functions, where the head raises ProfileError.
    • Dropping the no-op return (:691) passes. The idempotent test compares bytes and mode only, so a rewrite that swaps the file passes too.
    • Accepting upper-case hex passes. So does DIGEST_RE.search in place of fullmatch, which lets a digest with a trailing newline through. test_bad_expected_digest_refused_before_allocation (tests/test_profile_management.py:507-512) matches "expected_digest", and the stale digest error has that word too.
    • Its _snapshot helper skips .lock files (:400), so the test cannot see a lock created before the refusal.

    Fix: add a test for each. The other survivors are harmless: dropping the inode half of the final re-check (same bytes in a new file), the extra key check that the byte compare repeats, the read race check, and fsync.

Nits

  1. A FIFO at seats/scout.toml makes profile_digest block. update_profile blocks the same way while it holds the lock, so a second update gets ProfileConflict. The docs say there is no blocking (docs/SWARM-PROFILES.md:78). Repro: os.mkfifo that path, then call profile_digest. It is still blocked after 3 seconds. Fix: open with O_NONBLOCK, or check S_ISREG with a stat before the open.

  2. For a long name, profile_digest returns a digest but update_profile raises a raw OSError (errno 36) and leaves .<name>.lock. With a 5-digit process id, 226 characters work and 227 fail. The temporary name .<name>.toml.tmp-<pid>-<hex> (built at :568) is about 30 characters longer than the name.

    create_profile fails the same way for these names, so only a hand-written seat reaches this. Fix: use a short temporary name, or raise ProfileError.

  3. Docs:

    • The module docstring still says "the create-only foundation", "create_profile is the one entry point" and "it never updates" (lines 1, 3 and 13).
    • docs/SWARM-PROFILES.md:84 says symlinks are never followed. An update through a symlinked home works, which is fine, so say that the seats folder, the seat file and the lock are never followed.
    • Say that a running seat keeps the role and description it loaded until it next loads the seat.
    • The comment at src/exo/profile_management.py:271 says the link consumed the temporary. A hard link leaves the temporary's name in place, and the unlink above it removes it every time.

Checks

  • New tests at the head: 130 passed on Python 3.13, 130 on 3.11, and 130 in random order. On the base source with the import guarded: 74 failed, 56 passed.
  • Seat suites: 13 passed at the head and at the base.
  • Group, launch, core, integration and docs suites plus the new and seat tests: head 5 failed, 1709 passed, 2 skipped. Base 5 failed, 1635 passed, 2 skipped. The same 5 fail on both (steer x2, scheduler, import direction, budget). The 74 extra passes are the new tests.
  • Peer and gate_diff tests: the same 15 failures at the head and the base on 3.13 (237 passed), and the same 13 peer failures on 3.11 (110 passed).
  • 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 this module, and none are RESOLVED.
  • Mutants: 31 of this layer's code, 21 caught (item 2).
  • Probes on 3.11 and 3.13: the update chain under load, the FIFO, long names, a folder at the seat path, alternate forms beside the seat, the symlinked home, a FIFO lock (refused), and the #1021 probes. An update of a missing seat is refused and leaves only .ghost.lock, which the seat list skips and which does not block a later create.
  • CI at this head: lint passes. The macOS jobs show 20 failures on 3.13 and 22 on 3.11, none in the new tests or in a file this layer touches.
  • gate_diff: not needed, no gate file changed.
  • Merge: the head is a fast forward of its base. git merge-tree onto main b9dbadec is clean for this head and for the top of the stack (#1039). With main merged in, the new, seat and docs tests pass (183 on 3.13, and the 130 new tests on 3.11).
  • Overlap: the upper layers #1024 to #1039 contain this head and do not change these three files. No open PR outside the stack touches them, and this layer does not touch CHANGELOG.md.

Generated by Claude Code

@orda-aska
orda-aska force-pushed the feat/swarm-profile-update branch from 9b37f0e to 7d83e50 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 9b37f0e6 no longer covers the head. This review is for 7d83e502.

  • Same content as the tree I approved. I compared the approved commit 9b37f0e6 with the rewritten head 7d83e502. 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 25 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

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