Skip to content

fix(systems): an exported manifest applies back clean; unobserved fields never read as drift (#4132) - #4153

Merged
vybe merged 29 commits into
devfrom
feature/4132-export-round-trip
Nov 1, 2026
Merged

vybe merged 29 commits into
devfrom
feature/4132-export-round-trip

Conversation

@vybe

@vybe vybe commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Fixes #4132. A manifest exported from a live system and applied back (dry run) reports nothing to create, nothing to update and no drift for every field the export writes; where the export cannot see a field it writes the # unobserved: header and the dry run reads it as unobserved, never as drift. Stacked on #4152 — base is feature/4130-apply-result-truth; the stack merges together in order. Draft until validated.

What

  • Seats: a seat the assignment provider does not answer is unobserved on export (header) and on apply (a seat_unobserved report, no write, no drift).
  • Held values: a skill, skill set, grant or gate the member already holds is in sync and is never blocked on a library, catalog or validator verdict; a value the member does not hold still gets the verdict. A declared gate is in sync only against a stored explicit row with an equal approver and an omitted or equal deadline; a library-default row is still a write.
  • Deterministic export: members, tags, schedules and resource keys sorted, so two exports are byte-identical. One existing naming test's order pin moved from roster order to name order for that reason.
  • Person seats are named in their own # unobserved: line on every export that names the members, whoever the viewer is.
  • tests/unit/test_4132_export_round_trip.py: one round trip per field group (naming, skills, sets, grants, gates, seat, person seats, deploy false, edges and mesh, folders, tags, resources, template, schedules) through the real exporter and the real apply route on the real database facade, plus the unobserved proof. Flow doc, requirements and user doc updated; registry entry added.

Rulings carried (plan file)

  • Person seats in the header only (the provider answers per seat and never lists them). Keep the naming inference from the manifest extension (any prefixed member keeps prefixed; the header names omitted members; ?naming=bare gives a complete export). Explicit stored gate rows only.

Review + security

/review (report-only, one pass): MERGEABLE, 0 critical. Fixed in 8b1bad57f: the person-seats line was appended only inside the viewer's seat-read gate. Noted, not changed: the library is still consulted for a held name with the verdict discarded (a raising library read still blocks retryably). /cso --diff: 0 findings. Fix mutation: 10 red with the five source files reverted.

Tests

Targeted: 273 passed on the new file and six guard suites, 160 on the ent#1030 seats, skills, gates and grants suites, 67 after the fix on the four touched suites. MCP suite 1,113 pass. Not run here: the full unit island (CI runs it once the stack is retargeted to dev).

Before merge

Merge #4145, #4146, #4150 and #4152 first. No migration, no image rebuild.

Handoffs

The last branch of the stack (a gate-write failure report) stacks on this one; #4134 owns the service refactor.

🤖 Generated with Claude Code

Trinity Agent (trinity) and others added 24 commits November 1, 2026 01:15
…rough real facade methods (#4128)

GET /api/systems/{name} called db.get_agent_permissions and
db.get_agent_folder_config, neither of which exists on DatabaseManager,
inside one try: permissions, folders AND schedules were absent for every
member. The exporter's folder read had the same missing name and
subscripted the pydantic row as a dict, so `folders` was never exported;
its permission block probed agents[0] only, so a system whose first
member had no outgoing edge exported no edges.

- get_system: one try per key; edges via get_permitted_agents narrowed
  to the caller's accessible roster (what the direct permissions route
  shows); folders via get_shared_folder_config by attribute.
- export_manifest: folders via get_shared_folder_config, a failed read
  named in `# unobserved:`; permission block computed in one pass over
  every member, filtered to members, full-mesh only over >= 2 keyed
  members (tag-only members are outside the universe).
- KNOWN_FACADE_GAPS loses get_agent_folder_config and
  get_agent_permissions; the 2373 raising=False stub and the 1759
  MagicMock stub that supplied the missing method now name the real one.

Mutation: with routers/systems.py and services/system_service.py
reverted to the base, 11 of 13 tests in test_4128_system_detail_export.py
and test_every_db_call_resolves_on_databasemanager go red; restored
byte-identical (sha256 checked).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
GET /api/systems split every accessible agent's name at its last hyphen
and called the left part a system: a naming: bare member was dropped,
content-writer invented a `content` system, and acme-api-worker landed
in `acme-api`. The list now reads the system tag deploy and apply write
(one batched get_tags_for_agents read over the caller's roster), lists
the roster agents that carry it, and lists a tag only with evidence it
is a system: the auto-created system view for it, a system_apply audit
row naming it, or a carrier named `<tag>-*`. A plain tag is not listed.
Unreadable tags (or evidence) are a named 503, kept a 503 past the outer
handler. created_at is filled from the roster's `created` field, so the
newest-first sort works.

Mutation: with list_systems reverted, tests 1-6 and 8 of
test_4129_systems_list_bare.py go red (7 is a ruling pin, green on the
old code); dropping `except HTTPException: raise` reds test 6; listing
every tag reds test 7.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…4129)

The MCP list_systems description stated the removed rule (group by the
part before a hyphen); it now says the list names systems deployed or
applied from a manifest, by their tag, and that a plain tag is not one.
The teardown_system warning is kept and reworded to match. The flow doc's
GET /api/systems line and the teardown-panel sentence follow, and name the
accepted gap: a bare-named system created by POST /deploy with no
system_view and never applied leaves no evidence, so it is not listed
until deploy records that its tag is a system.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e allowlist entry (#4128)

The GET /api/systems/{system_name} section of the system-manifest flow
still named db.get_agent_permissions/get_agent_folder_config/
get_agent_schedules, none of which the handler calls; it now names
get_permitted_agents (narrowed to the caller's accessible set),
get_shared_folder_config, list_agent_schedules and the per-key try.
get_agent_schedules has no caller left, so it leaves KNOWN_FACADE_GAPS.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The flow doc's detailed GET /api/systems section and its System Grouping
section still described the old last-hyphen split; both now state the tag
evidence rule (roster tag read, three evidence kinds, members from the
roster, the two named 503s, created_at). The gap sentence also names audit
retention pruning a bare system's only evidence.

Test 9 makes the system-view read and the audit read raise and asserts the
named 503. Red with the inner 503 replaced by a bare re-raise (both cases
fell through to the outer 500); green with the route restored byte-identical.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The assertion message still said GET /api/systems groups by the last hyphen.
Message text only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-only out of the evidence gate (#4131)

Case 1: a manifest key accepts the create route's charset ([a-z0-9_.-],
chained `_N` suffixes included) in both naming modes, so an exported
`writer_2` / `acme-writer_2` member parses again; every other bad key keeps
the named 400. The drift note recognises chained copies.

Case 2: `system_membership(naming=)`. Apply passes the manifest's naming;
under `bare` membership is the tag (the tag read still runs, so an outage
still refuses). With no naming (restart, get, export) bare is inferred as
export infers it: tags readable and every tagged member unprefixed. A
prefixed system keeps the #2373 union. A declared untagged bare name is
adopted whatever its shape; an undeclared untagged `<system>-x` is neither
member, drift nor blocker.

`deploy: false` names are excluded from the evidence gate in both modes.

test_2373: the renamed-member case now carries a tagged prefixed member
(the union property), and the accepted residual is pinned beside it.

Mutation: with the service change reverted, 21 tests in
test_4131_bare_naming_edges.py / test_2373 go red; restored, all green.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t, restart route tests, docs (#4131)

Case 3: `deploy: false` governs apply only. When a declared-only name is a
roster member by tag, apply adds the report `declared_only_member_tagged`
naming restart and teardown and the hand untag remedy; nothing is written.

The adoption warning names the explicit `?naming=bare` export when an
adopted name starts with `<system>-` (a default export infers prefixed).

Restart and get route tests run the real routes over the real db facade:
a bare member is handled, an untagged prefix lookalike and another
system's tagged member are not; a prefixed system still restarts its
untagged member; the tagged declared-only member is restarted, as the
report says.

Docs: the requirements sentence that pinned the refusal now states the
adopt rule; declared-only and the tag; flow-doc paragraphs with the one
accepted residual; user doc; MCP restart/export text for the inferred-bare
rule.

Mutation: with this checkpoint's service change reverted, the case-3
report test and the warning test go red; restored, all green.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Engine truth for apply (CP1 of #4130):

- `adopted[]` and the adoption line: a dry run (valid or invalid) shows the
  plan; a refused run lists nobody and drops the line; a real run lists only
  members whose system tag landed (per (name, tag), so a default tag that
  landed is not an adoption) and says it in the past tense.
- `summary.<group>.write` on a real run counts only landed writes
  (`ApplyOutcome.landed`, `summary.build(landed=)`); a refused run counts
  none. `report` / `unobserved` stay plan counts.
- A declared-only member is not re-read after the writes (no spurious
  "could not be re-read" warning) and its `applied` is None.

Mutation: with the system_service/summary changes reverted, 10 tests in
tests/unit/test_4130_apply_result_truth.py go red (refused/partial/default-tag
/past-tense adoption, raised-writer/held-skill/refused summary, absent and
live declared-only re-read, applied None).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Delivery and deploy truth (CP2 of #4130, code and tests):

- Deploy of a manifest whose every member is `deploy: false` is a named
  400 `nothing_to_deploy` on the dry run and the real run, raised after
  name resolution (validate_manifest is unchanged; apply still reports).
- `SystemDeployResponse.agents_declared_only` (additive, default []) on
  all three return sites; the warnings line stays. The create-mode golden
  is regenerated once under #4130 for the new key only.
- Apply's `skill_delivery` note lists every per-skill failed/conflict
  entry (e.g. `deploy: marker_not_written: ...`); a set whose skills were
  all held already records `current="unchanged"` instead of nothing.
- `set_gate`'s `marker_not_written` is a `gate_marker_not_written` report
  on apply and a warning line on deploy; deploy also warns when a skill
  assignment's delivery report names a failed skill. For a member deploy
  creates, both deploy lines are unreachable today (members start after
  the skills and gates phases); they read a return value already held.

Mutation: with these service changes reverted, 9 tests in
tests/unit/test_4130_apply_result_truth.py go red (nothing_to_deploy x2,
agents_declared_only x2, marker note, unchanged set, deploy delivery
warning, gate marker on apply and deploy).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…agent test (#4131)

- In a prefixed system an untagged `<system>-x` declared-only member is a
  member by name, so restart and teardown reach it. Apply now says so with
  the report `declared_only_member_prefixed` (no write). Mutation: with the
  new branch disabled, TestPrefixedDeclaredOnlyUntagged goes red.
- The adoption warning names the other-direction residual: a bare system
  with a prefix-shaped tagged member is read as prefixed by restart,
  teardown, get and export, so an untagged lookalike is reached by name.
  The flow doc says the same.
- Plan test 13: a tagged declared-only agent that is only shared with the
  caller gets no apply report, and restart still reaches it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes CP2 of #4130: the deploy_system description names
`agents_declared_only[]` and the `nothing_to_deploy` 400; apply_system's
says a real run's `summary.write` and `adopted[]` name only what landed
(kept under the 2,048-character description cap). Flow doc, roadmap
(one added line) and user doc updated to match.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…port and apply (#4132)

A provider whose `seat_for` answers nothing (`no_answer`) cannot say which
seat an agent holds. The export read that as "holds none" (no `seat:`, no
header), and the apply snapshot read it as case `none`, so a manifest with
`seat:` planned a `seat_missing` write. Both sides now read it as
unobserved: the export names `seat of <name>` in the `# unobserved:` header
and the dry run reports `seat_unobserved`, writing nothing.

Mutation: with seats.py reverted, test_export_names_a_seat_the_provider_
did_not_answer and test_dry_run_reads_no_answer_as_unobserved_never_a_write
go red.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ked on a verdict (#4132)

The skills, sets, grants and gates planners ran the library, catalog or
gate-validator verdict on every declared value, including one the member
already holds and apply would never write. An export of a member holding a
skill that has since left the library, a set gone from its catalog, a
retired capability or a gate whose approver this install can no longer
resolve therefore dry-ran as a blocker. A held value is now in sync; the
verdict still runs on every value apply would write. A declared gate is in
sync only against a stored explicit row with an equal approver and an
omitted or equal deadline; a library-default row is still a write.

Mutation: reverting skills.py turns the held-skill and held-set round
trips red; grants.py the retired-capability round trip; gates.py both
unresolvable-approver round trips.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-result-truth

# Conflicts:
#	src/backend/services/system_service.py
…roup round trips (#4132)

The exporter sorts members by name (edges and every header list follow),
tags, schedules by name and resource keys, so two exports of one system
are byte-identical whatever order the roster read returned. Every export
now carries an `# unobserved: person seats are not exported` line naming
its members: the assignment seam answers per seat and never lists them.

Round-trip tests through the real exporter and the real apply route for
folders, tags, resources, schedules, the full-mesh preset, explicit edges,
template, naming (inferred and bare) and deploy: false. The ent#1030
naming test's member-order pin moves to name order.

Mutation: with system_service.py reverted, the byte-identical and the
person-seats tests go red.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… headroom (#4130)

- The `failed` (500) deploy branch is now driven through the real
  POST /api/systems/deploy route with a declared-only member; it asserts
  `agents_declared_only` in the 500 body. Went red with the field removed
  from that branch (test_the_failed_branch_carries_the_declared_only_names).
- The `nothing_to_deploy` 400 is pinned through the route on both dry and
  real runs, not only on the service.
- apply_system MCP description trimmed from 2,043 to 1,984 characters
  (cap 2,048) with no fact dropped.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…egistry (#4132)

Two round trips the per-group set lacked: a member whose only exported
field is its template (the label verbatim, compared against the same
label, so no template_differs; an edited template is still reported),
and person_seats declared in an export, which read back as
seat_unobserved through the "person seats are not exported" header line.

Mutation: dropping the person-seats header append in export_manifest
turns the person-seats round trip red (StopIteration on the header).

Docs beside #4130's lines: the roadmap "Export round-trips naming" and
"Seats" bullets, the export section of the system-manifest flow, the
user-doc Export bullet; and the tests/registry.json entry.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…r and field (#4130)

`ApplyOutcome.landed` was a (member, step) set, so two writes of one kind on
one member with one failure still counted 2 in `summary.<group>.write`. The
executor's `attempt()` now records (member, step, key) — the skill(s), set,
gate's skill, capability, seat role, edge target or tag the write wrote — and
`summary.build(landed=)` counts a write change only when a write of its own
key landed. Dry-run, `report` and `unobserved` counts are unchanged, and a
run where everything landed still reports the plan counts.

`SystemApplyFailure` gains an additive `key` (None for a member-wide write)
so `failed[]` names which of two same-kind writes did not land.

Regression tests (real apply route handler, real db facade):
- two skill sets on one member, one held for its unwritten gate -> skills.write == 1,
  failed[] = (lead, skill_sets, ops-core)
- two gates on one member, one set_gate raising -> gates.write == 1,
  failed[] = (lead, gates, deploy)
Mutation: with the summary predicate reverted to per-(member, field) both
tests go red (assert 2 == 1); restored byte-identical (sha256 OK).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ers (#4132)

The `# unobserved: person seats are not exported` line was appended only
inside the caller's seat-read gate, so a non-owner viewer's export left it
out although the reason (the assignment seam never lists who fills a seat)
holds for every caller. The append now sits after the gate.

TestPersonSeatsHeader gains a non-owner export assertion; with the fix
reverted it goes red (the line is missing for the shared viewer).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@trinity-ability trinity-ability 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.

PR Validation Report

PR: #4153 - fix(systems): an exported manifest applies back clean; unobserved fields never read as drift (#4132)
Author: vybe
Branch: feature/4132-export-round-trip (8b1bad5) → feature/4130-apply-result-truth (42fbe35, stacked on #4152)
Files Changed: 11 (+477/-21), validated against the stacked base, not dev
Lane: B (the only Lane C/schema paths are absent; tests/unit/test_ent1030_naming.py changes one order pin, so Lane A is withheld)

Summary

Category Status Notes
Commit Messages ✅ conventional fix(systems): … headlines; two merges of the stacked base
Base Branch ✅ stacked on #4152 by design; the stack retargets to dev in order
PR Size ✅ 11 files
Status Auto-Promotion ✅ Fixes #4132 in body (same-repo)
Roadmap ⚠️ #4132 is priority-p3 type-bug, still labelled status-ready, not status-in-progress
Requirements ✅ docs/memory/requirements/roadmap.md: export round-trip and seats entries extended
Architecture ➖ no endpoint, schema or component change
Feature Flows ✅ feature-flows/system-manifest.md: new Round trip (#4132) paragraph
Feature Flow Format ➖ paragraph added to an existing flow
Security Check ✅ §4.1–4.3 clean (one @pytest.fixture email-regex false positive); gitleaks pass
Infrastructure ➖ none
Build Packaging ➖ no new top-level backend directory
Config Packaging ➖ no new env var
File Modes / Host Paths ✅ no mode flips, symlinks or host paths
Structural Review ✅ /review ran on the branch (MERGEABLE, 0 critical; finding fixed in 8b1bad5); /cso --diff 0 findings
Merge Gate ⚠️ stacked PR: no pytest (head) / regression diff on this base. Required contexts present are green (schema-parity, verify-non-root, gitleaks, prod-image-smoke). dev-ci: success. Tier 1 must go green after the retarget to dev, before merge
Test Adequacy ✅ 20 tests in a new file, using the real exporter, the real apply route and the real DB facade; non-happy paths (unheld value still gets its verdict; library-default gate is still a write; non-owner viewer)
Code Quality ✅ small, focused edits in five modules; no unrelated refactor
Requirements Trace ✅ each of the four issue cases maps to a test group
Product Fit ✅ approved bug; scope matches; OSS core
Product Bar 7–11 ✅ flow, requirements and user doc updated; no config key

Documentation Checklist

  • Commit messages are descriptive
  • Roadmap updated (the issue's status label is not status-in-progress; minor)
  • Requirements updated
  • Architecture updated (n/a)
  • Feature flow updated
  • Feature flows index updated (n/a, no new flow)

Security Checklist

  • No API keys or tokens
  • No real email addresses
  • No IP addresses
  • No .env files
  • No hardcoded secrets
  • No credential files
  • Infrastructure changes justified (none)

Execution coverage (§5.4)

changed symbol / test file executed by live consumer verdict
system_apply/seats.py read_member / plan / export_member (no_answer → unobserved) TestSeatNoAnswer::* apply snapshot + system_service.export_manifest ✅
system_apply/skills.py plan (held skill/set gets no verdict) TestHeldValues::test_a_held_skill_…, …_held_set_…, …_skill_not_held_still_gets_the_library_verdict apply plan ✅
system_apply/grants.py plan (held capability not judged) TestHeldValues::test_a_held_grant_whose_capability_was_retired_round_trips apply plan ✅
system_apply/gates.py plan (stored explicit row equal → in sync) TestHeldValues::test_a_stored_gate_the_validator_cannot_resolve_round_trips[approver, role], …_library_default_is_still_a_write apply plan ✅
system_service.export_manifest (sorting, person-seats line) TestDeterministicText, TestPersonSeatsHeader (incl. a non-owner viewer), TestPersonSeatsRoundTrip GET /api/systems/{system}/manifest ✅
tests/unit/test_ent1030_naming.py order pin moved from roster order to name order (follows the sort) — ✅

Fix mutation (rerun by me, each source file reverted to the stacked base one at a time; test_4132_export_round_trip.py):
gates → 2 red · grants → 1 red · seats → 2 red · skills → 2 red · system_service → 3 red. Every changed module is pinned.
Full run of the new file + test_4130_apply_result_truth.py + all test_ent1030_*.py: 291 passed.

Product fit (Step 6.6)

check verdict evidence
Approved (not incubating) ✅ #4132: type-bug, priority-p3, status-ready
Scope ↔ issue ✅ (1) held skill that left the library: met, skills.py + TestHeldValues; (2) seat_for None means "cannot say": met, seats.py + TestSeatNoAnswer; (3) person seats stated: met, through the # unobserved: header per the ruling, system_service.py + TestPersonSeats*; (4) byte-identical exports: met, TestDeterministicText. "Reveals nothing the read routes withhold": met. The person-seats line names only members already keyed in the export, and the viewer rule is unchanged (non-owner viewer test; test_ent1030_export_access.py green)
Open-core tier ✅ OSS core (operator and agent export/apply contract)
Doctrine ✅ none
Bar 7–11 ✅ user doc, flow and requirements updated

Issues Found

Critical (Block Merge)

  • None.

Warnings (Review Required)

  • Tier 1 pytest (head) / regression diff have not run, because the base is a stacked branch. Merge only after the stack retargets to dev and those are green.
  • #4132 still carries status-ready. Move it to status-in-progress so the closing keyword promotes it cleanly.

Suggestions (Optional)

  • skills.plan still looks up the library verdict map for held names and discards the result. A library read that raises therefore still blocks retryably. The PR body notes this, and the refactor belongs to #4134.
  • The held-gate shortcut compares the raw manifest key and approver. A case-variant spelling falls through to the validator and then the normal write path. That is safe, but it would show as a write rather than in sync.

Recommendation

APPROVE

All four issue cases have round-trip tests through the real exporter and apply route. Each fixed module goes red when its fix is reverted, and the export's viewer rule is untouched. Before merging, Tier 1 must pass after the stack retargets to dev (#4145, #4146, #4150 and #4152 land first).

…into pr-4152

# Conflicts:
#	src/mcp-server/src/tools/systems.ts
… into pr-4153

# Conflicts:
#	tests/registry.json
@vybe
vybe changed the base branch from feature/4130-apply-result-truth to dev November 1, 2026 22:06
@vybe
vybe merged commit 40c57fc into dev Nov 1, 2026
26 checks passed
@vybe
vybe deleted the feature/4132-export-round-trip branch November 1, 2026 22:15
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