Skip to content

feat: add principal-only shared knowledge commands for saved Swarm groups - #1024

Open
razi-exo wants to merge 2 commits into
feat/swarm-profile-updatefrom
feat/swarm-knowledge-commands
Open

razi-exo wants to merge 2 commits into
feat/swarm-profile-updatefrom
feat/swarm-knowledge-commands

Conversation

@razi-exo

Copy link
Copy Markdown
Contributor

Purpose

Adds the human control surface for the owner-published shared knowledge store (GroupKnowledge, see docs/SWARM-KNOWLEDGE.md) on the existing group command name, so a group owner can publish knowledge and its verified members can read it — with no autonomous retrieval.

Functions

Four principal-only subcommands, each behind principal.require_principal:

  • /group knowledge_publish {"id": …, "key": …, "text": …, "sources": […], "expected_revision": N} — owner-only publish with explicit revision compare-and-swap; the publisher is always this seat (eng.agent), never caller-supplied.
  • /group knowledge_read {"id": …, "member": …, "key": …} — member-scoped read, validated against the group's verified members.
  • /group knowledge_list {"id": …, "member": …, "limit": N} — keys visible to that member.
  • /group knowledge_history {"id": …, "member": …, "key": …, "limit": N} — revision history for a key visible to that member.

Use case

Principal-only ops (publish/read/list/history); explicit revision CAS; owner is always eng.agent; human_owner_view; verified members only; no autonomous retrieval remains — gap M02–M04 implementation is partial. Caveat: list/history currently materialize all rows before slicing.

Provenance and refs

Automated posting by agentic team with human oversight.

Explicit GroupKnowledge store: owner-only publishes with revision
compare-and-swap inside one transaction, immutable per-key revision
history, and fail-closed reads limited to the group's own members.
Nothing reads sessions, memories or messages, so no private content is
ingested automatically.
…oups

Expose GroupKnowledge via the "group" command name: knowledge_publish / knowledge_read / knowledge_list / knowledge_history. Publishing is owner-only (eng.agent) with explicit expected_revision compare-and-swap; reads are member-scoped and fail-closed. Imported verbatim from PR #974 (commit provenance retained).

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

Scope: this PR's own 2 commits, 9b37f0e6..d149ddce (base feat/swarm-profile-update, #1022). The store slice src/exo/core/group_knowledge.py, its tests and docs/SWARM-KNOWLEDGE.md came over from #974. Findings from the #974 review that still apply are marked as carried.

What works

  • Authority holds on the real path. All four ops were run through the Dispatcher:
    • principal:tui and principal succeed.
    • local, unknown, seat:helper, channel, principalx and "" all get forbidden and write no swarm_knowledge row.
  • The publisher is always eng.agent. Extra fields publisher, owner, by, seat, author and caller each give bad_request "unknown field(s): <name>" and write nothing.
  • Member scoping fails closed.
    • A non-member and a member of another group get unknown member.
    • Another seat's group and an unknown id get no group.
    • Through a second group of the same seat, the item is null and knowledge_list and knowledge_history both return [] (re-probed at head).
  • CAS holds.
    • Stale or missing expected_revision gives a revision-conflict bad_request and writes nothing.
    • Non-integer and negative values give expected_revision must be a nonnegative integer.
    • 16 racing publishers: 1 ok and 15 conflicts, with gapless history.
  • The new tests fail on the base and pass on the head.
    • On base 9b37f0e6 both new files fail at collection (ModuleNotFoundError: exo.core.group_knowledge).
    • On the head they give 44 passed.
    • With the four knowledge ops removed from _OPS on the head, the roundtrip, cross-group and stale-CAS tests fail (3 failed, 41 passed). The suite does test the change, but see the first item under "Should fix".
  • D-083 adds nothing. The scorecard hit lists on base and head are identical (41 inward imports, 8 private reads).

This slice is approved because it targets the stack branch, not main, and leaves the required types job as red as it found it. The two items in the next section must be fixed before the stack lands on main.

Should fix (before the stack lands on main)

  • _knowledge() stores the cache as eng._group_knowledge, which adds a mypy attr-defined diagnostic to the types baseline check.

    • Repro: mypy 2.4.0 --python-version 3.11 --platform linux over src/exo clients/tui/exo_tui, compared with .github/mypy-baseline.json through check_types.parse_output/differences.
    • Base gives 239 errors and 17 NEW; head gives 240 and 18 NEW.
    • The only addition is NEW 1x src/exo/core/group_commands.py: "CoreRuntime" has no attribute "_group_knowledge" [attr-defined].
    • Not blocking for this slice: the required job is already red on the base with the same pattern (_group_store, _group_messages, inherited from #978) plus the composition, host, runner and launch errors. This PR does not change the job's state, and there is no runtime effect.
    • Since the baseline never grows, the stack cannot land on main until all three are fixed.

    Fix: return GroupKnowledge(_groups(eng)) (the tables use CREATE TABLE IF NOT EXISTS), or one public lazy property on the engine that also fixes the two inherited errors. Trialled: mypy goes to 239 with no _group_knowledge line, and test_group_knowledge*.py plus test_group_commands.py give 67 passed.

  • The docs rule is not met.

    • DOCS-MAP.md "The rule" requires a map row, a DECISIONS.md entry and a user-guide/developer-guide impact note in the same commit. DEVELOPER-GUIDE step 3 puts the impact line in the commit message.
    • DOCS-MAP.md and DECISIONS.md have no Swarm rows at all; grep -rln SWARM-KNOWLEDGE docs hits only SWARM-COMMANDS.md.
    • Neither commit message has the impact line, and there is no CHANGELOG line.
    • COMMANDS.md has no group row (inherited from #978).
    • tests/docs passes (22 passed), so this is a written-rule gap. Under the stacked-PR policy it is should-fix, not blocking.

    Fix: add a DOCS-MAP row for SWARM-KNOWLEDGE.md and §Shared knowledge, a DECISIONS entry or an amendment, a CHANGELOG line and a group row listing the knowledge ops, and end the commit message with the impact line.

Should fix

  • Several regressions would not be caught by the tests. Each of these mutants leaves all 44 new tests green (re-run at head):

    • dropping the group_id filter from GroupKnowledge.keys(), so a list would show another group's key names;
    • dropping it from history(), so a history would show another group's revision text;
    • raising MAX_TEXT_LEN tenfold (carried from #974);
    • keys[:limit] -> keys in knowledge_list.

    The current code is correct: the second-group probe above returns []. The fixture's only other group belongs to another seat, so it fails with no group before any query runs. Fix:

    • publish to group A, then assert knowledge_list and knowledge_history for a member of a second group of the same seat return [];
    • add a 100,000 / 100,001-character text pair;
    • publish 3 keys and assert that limit=2 returns 2 keys with total 3.
  • 32 malformed-input cases pass without the feature. test_malformed_publish, test_malformed_read and test_malformed_list_and_history assert only code == "bad_request", and an unknown op returns the same code. With the knowledge ops removed from _OPS, all 32 still pass. Fix: add match= on each specific message (unknown field(s): publisher, sources must be, expected_revision must be, limit must be, and so on).

  • knowledge_history loads every revision body before slicing. It runs synchronously on the event loop under the store lock. Measured through group_commands.command:

    • 1,000 revisions of 100,000 characters, limit=1: 96 ms, tracemalloc peak 100.7 MB;
    • 3,000 revisions of 100 characters: 73 ms, 2.3 MB.

    Cost grows linearly, and history is never pruned. Only the principal can trigger this, and the data is the owner's own, so it is a resource issue, not a security one. Fix: ORDER BY revision DESC LIMIT ?, then reverse, plus a SELECT COUNT(*) for total.

Nits

  • A lone surrogate is accepted in sources (carried from #974). "sources": ["doc:\ud800"] -> ok, stored and read back, while the same character in text -> bad_request. Nothing crashes today. Fix: reject any source for which s.encode("utf-8") raises in _validate_sources.

Stack (inherited)

  • D-083 budget: 41/39 inward imports and 8/8 private reads. test_core_line_budget fails on base and head alike.
  • mypy: 17 NEW diagnostics already on the base (_group_store, _group_messages, group_composition, group_host, group_runner, group_launch).
  • The usage text suggests '<json>', but a quoted argument gets the usage error. The op split also accepts only a single space.

Checks

  • ruff check on the 4 changed Python files: All checks passed!
  • New tests: base 9b37f0e6 gives 2 collection errors (ModuleNotFoundError); head gives 44 passed; head with the knowledge ops removed gives 3 failed, 41 passed.
  • tests/test_group_*.py tests/test_saved_groups.py tests/docs tests/core/test_rename.py tests/test_store.py tests/test_session_owner_boundary.py: base 269 passed, head 313 passed.
  • mypy 2.4.0 (py3.11, linux) against the baseline: base 239 errors with 17 NEW, head 240 with 18 NEW. The one added line is group_commands.py _group_knowledge [attr-defined]. With the per-call fix it is 239.
  • Mutants: keys_no_group, history_no_group, text_cap_x10 and list_no_slice each give 44 passed; history_no_slice gives 1 failed.
  • Module path printed from the tree under test: .../wt/src/exo/core/group_knowledge.py.

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 d149ddce. It covers this layer only: the diff from the base branch head 9b37f0e6 (#1022) to d149ddce. The head contains 9b37f0e6, with two commits on top. They add src/exo/core/group_knowledge.py, four knowledge_* subcommands in src/exo/core/group_commands.py, two docs and two test files.

The gap is real at the base. There, /group knowledge_publish and /group knowledge_list both get the usage error, and exo.core.group_knowledge does not exist. The new test files fail to collect on the base source.

At this head the commands work through the real Dispatcher. As principal and principal:tui all four subcommands work. As local, channel, seat:helper, unknown, principalx or an empty caller all four get forbidden, and the knowledge tables are not even created.

The publisher is always this seat. A second group of the same seat with the same members sees nothing of the first group's knowledge. Another seat's group, or an unknown id, gets no group.

A publish with no expected_revision on an existing key gets a conflict, so it never overwrites by accident. 16 threads on two connections raced for revision 1 of one key: 1 won, 15 got a conflict, and history kept one row. Python 3.11 and 3.13 agree on every probe, and so does the head merged with the newest main.

Earlier review points

Point Status now
abu-aska (approve at d149ddce): _knowledge() caches on eng._group_knowledge, one new mypy line Open. Confirmed (item 2)
abu-aska: docs rule not met Open. Asked as a question for the principal (item 1)
abu-aska: group filter mutants in keys() and history(), text cap and list slice survive Open. Confirmed (item 4)
abu-aska: 32 malformed input cases pass without the feature Open. Confirmed (item 4)
abu-aska: knowledge_history loads every revision before slicing Open. Confirmed (item 5)
abu-aska: a lone surrogate is accepted in sources Open. Confirmed (item 7)
abu-aska: budget 41/39 and the mypy errors of lower layers Lower layers. Unchanged here
abu-aska: the usage text shows '<json>', but a quoted argument gets the usage error Inherited. This layer adds four names to the same usage line and keeps the quotes
abu-aska on #974 (same store files): the cross-owner publish test passes on the revision conflict, not the owner check The command test now catches a missing owner check. The store test alone still passes without it
abu-aska on #974: the source count cap is untested Open (item 4)
abu-aska on #974: the owner has no read path of its own Open (item 6)
abu-aska on #974: the doc should say knowledge reaches a member only as quoted data Open here, where nothing puts knowledge in a prompt yet. #1035 adds that rule with the first prompt path

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

The stack questions

This layer changes no group conversation, host, runner, composition, profile or gate file. So it changes none of the stack's blocking points.

  • #1007, member replies never wake the addressee: unchanged.
  • #1007, two tests fail on Python 3.11, and a stop is lost on 3.11: unchanged. The group suites on 3.11 give the same 2 failures in test_group_conversation.py at the base and at the head. On 3.13 they all pass.
  • #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. The import direction test fails with the same text on both. The new core module adds 384 counted lines, which D-083 allows.
  • #1001, member gates bound to the host's identity: unchanged.

Must fix

None in this layer.

Should fix

  1. A question for the principal, on the docs rule. This layer adds four user-facing subcommands of /group and a new store with two tables in the sessions database. It keeps every revision forever, and nothing can remove a key or a revision, even one published by mistake.

    It has no CHANGELOG line, no DECISIONS entry, no DOCS-MAP row, no group row in docs/COMMANDS.md and no guide impact line in either commit message. No commit from main to this head touches those files, and none of the six layers above it does either. The docs name plan steps "M02" to "M04" that no file defines. Which layer adds the Swarm decision, and is a store with no removal path the intended design?

  2. One new type error. src/exo/core/group_commands.py:56 sets eng._group_knowledge, and scripts/check_types.py reports it as a new attr-defined line. On Python 3.11 the head has 13 NEW lines (18 errors) and the base 12 lines (17 errors). This is the only added one, none are RESOLVED, and the CI types job shows the same line.

    Fix: build GroupKnowledge(_groups(eng)) per call, since its tables use CREATE TABLE IF NOT EXISTS, or give the engine one typed attribute. I tried the per-call form: the 67 tests of item 4 pass, and the check is back to the base's 12 lines.

  3. Two open PRs carry the same change. #974 is still open, and its group_knowledge.py, tests/test_group_knowledge.py and docs/SWARM-KNOWLEDGE.md are byte-identical to this layer's. Discussion #746 asks for one canonical PR per change. Fix: close #974 as superseded by this layer, or drop the store commit here and stack on #974.

  4. The tests do not pin several guarantees. I ran 34 mutants of this layer's code against the 67 tests in the two new files and tests/test_group_commands.py. 20 were caught. These survivors are real gaps:

    • A publish with no expected_revision that falls back to the current revision, so it overwrites blindly, passes (src/exo/core/group_commands.py:351). No test publishes twice to one key without expected_revision.
    • knowledge_history that checks the seat instead of the named member passes. The fixture's seat one is also a member, and no history test names a non-member.
    • Dropping the group filter from keys() or history() passes.
    • Raising the text cap tenfold, or the source count cap to 100, passes. The 51 sources case (tests/test_group_knowledge_commands.py:175) is 51 copies of "s". With the cap raised, the duplicate check still rejects it, and the test checks only the error code.
    • knowledge_list without its [:limit] slice passes. So does a total counted after the slice, in knowledge_list or knowledge_history.
    • Dropping the command's own list check on sources passes. A JSON object then gets through, and its keys become the sources.
    • Running the publish outside the store's transaction passes. No test races two publishes.
    • The 32 malformed cases check only the bad_request code, and an unknown op gets that code too. With group_commands.py reverted to the base, they all still pass, and so do the denial test and the protocol test: 34 of the 38 command tests.

    Fix: add a test for each, and a match= on each malformed case's message. Two survivors are harmless: the member padding check (the store then says unknown member) and the store's own negative revision check (the command rejects it first).

Nits

  1. knowledge_history reads every revision before it keeps the newest limit (src/exo/core/group_commands.py:427). With 300 revisions of 100,000 characters and limit 1, one call took about 15 ms and peaked at 30 MB of memory. The cost grows with every revision, and history is never pruned. The PR body names this caveat. Fix: ORDER BY revision DESC LIMIT ? and a COUNT(*) for total.

  2. Docs:

    • docs/SWARM-COMMANDS.md:92-95 says members learn of knowledge "only through their own explicit reads outside this slice". No member read exists at this head. #1035 adds a prompt snapshot later but does not edit this sentence. The PR body also says verified members "can read it".
    • The owner can read its own knowledge only by naming a member. knowledge_read with the seat's own name gives unknown member unless the seat is also a member. Say so, or let the owner read without a member.
  3. A lone surrogate is stored in sources and read back ("sources": ["doc:\ud800"]). The same character in text gives bad_request with the raw codec message "'utf-8' codec can't encode character". Responses use ASCII JSON, so nothing crashes today. Fix: reject it in _validate_sources and give both one plain message.

Checks

  • New tests: 44 passed on Python 3.13, 44 on 3.11, and 44 twice in random order. On the base source both files fail to collect (ModuleNotFoundError). With group_commands.py reverted to the base and the store kept: 4 failed, 40 passed.
  • Group suites with the new tests: on 3.11 the head gives 2 failed and 258 passed, the base 2 failed and 214 passed. The same 2 fail on both (#1007). On 3.13 the head gives 260 passed.
  • Group, profile, seat, core, integration and docs suites with the new tests: head 5 failed, 1753 passed, 2 skipped. Base 5 failed, 1709 passed, 2 skipped. The same 5 fail on both (steer x2, scheduler, import direction, budget). The 44 extra passes are the new tests.
  • Core budget: 41/39 inward imports and 8/8 private reads at the base and at the head. Counted lines go from 17,830 to 18,214.
  • ruff check on the changed files and on the whole tree: clean. ruff format --check flags only group_commands.py, as it does at the base.
  • scripts/check_types.py on Python 3.11: 13 NEW lines (18 errors) at the head, 12 lines (17 errors) at the base. The one added line is item 2. None RESOLVED.
  • Mutants: 34 of this layer's code, 20 caught (item 4).
  • Probes through the real Dispatcher on 3.11 and 3.13, with identical results: callers, cross group reads, the owner read path, the publish race, caps, surrogates and history cost.
  • The head merged with main b9dbadec (clean): 44 new tests pass on 3.13 and on 3.11. The group, store, session and docs suites give 316 passed, and the probes give the same results.
  • CI at this head: lint passes. The types job shows the one new line. The four test jobs fail only on lower-layer tests: 20 on Ubuntu 3.13 and macOS 3.13, 22 on Ubuntu 3.11 and macOS 3.11. None is a knowledge test.
  • 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). The upper layers #1025, #1028, #1030, #1035, #1038 and #1039 contain this head. From #1035 up they change group_knowledge.py and SWARM-KNOWLEDGE.md to add the prompt snapshot.
  • Overlap: outside the stack only #974 touches these files. The other 17 open PRs touch none of them. The stack does not touch CHANGELOG.md.

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: 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 d149ddce no longer covers the head. This review is for 7a00b7c8.

  • Same content as the tree I approved. I compared the approved commit d149ddce with the rewritten head 7a00b7c8. 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 27 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