Skip to content

feat(agent-org): flatten team capabilities - #786

Closed
ShiboSheng wants to merge 9 commits into
fix/issue-756-authoritative-team-lifecyclefrom
fix/issue-757-flat-team-capabilities
Closed

feat(agent-org): flatten team capabilities#786
ShiboSheng wants to merge 9 commits into
fix/issue-756-authoritative-team-lifecyclefrom
fix/issue-757-flat-team-capabilities

Conversation

@ShiboSheng

Copy link
Copy Markdown
Collaborator

Problem

Fixes #757.

PR1 establishes the authoritative long-lived Team lifecycle, but the persisted Team definition still models a recursive hierarchy and does not provide trusted, independently configurable Writer grants and Member communication links. Later TaskGraphWriter and peer-messaging work needs stable flat Member identities and immutable launch-time capability facts; it must not infer authority from role, hierarchy, UI state, or a mutable template.

The rollout also exposed two upgrade-boundary failures that prevented the PR1+PR2 product from being exercised safely on existing installations:

  • the published v1.2.3-v1.2.5 15-column agent_org_runs schema cannot serve the new lifecycle columns;
  • after the accepted old Agent Org runtime reset, retained historical Team Sessions still carry org_member_id and could consume standalone SDE page capacity, producing an empty filtered page with hasMore=true and a visible Retry state.

Solution

This stacked PR targets fix/issue-756-authoritative-team-lifecycle and delivers the PR2 definition/capability boundary:

  • Replace recursive hierarchy with one Coordinator plus 1..=50 flat Members carrying stable member_id values. role is display/expertise only.
  • Persist additional TaskGraphWriter Member IDs independently from canonical undirected Member communication links. Writer grants never imply links and links never imply Writer authority.
  • Materialize every new Team's default full connectivity as explicit canonical pair edges. The Coordinator is excluded from pair rows and remains bidirectionally reachable with every Member by invariant.
  • Preserve surviving IDs and policy during model-driven roster edits, connect new Members to existing Members by default, and remove dangling grants/links when a Member is deleted.
  • Route trusted settings through a dedicated full-replace command whose actor is constructed inside Rust. Model tools cannot submit grants or links, and disk success precedes the in-memory replacement.
  • Freeze flat roster, Writer allowlist, and canonical links into AgentOrgLaunchSnapshot; runtime capability indexes compile to HashSet membership checks. Running Teams never reread mutable templates.
  • Replace the communication matrix with per-Member connection summaries and a right-side peer panel. The panel edits the main Team draft, renders at most 49 peers, synchronizes both views of one canonical pair, and has no independent Save action.
  • Keep Writer activation and peer messaging closed until PR7 and PR9 respectively.

For the upgrade boundary, schema initialization recognizes only the exact published 15-column legacy run fingerprint. A match resets exactly agent_org_initial_inputs, agent_org_member_materializations, agent_org_run_progress, and agent_org_runs in one transaction, then recreates the single canonical schema. Current schemas remain idempotent; unknown or locally modified layouts fail closed and are never destructively reset. Ordinary Rust/CLI Sessions and other data are untouched.

Standalone SDE pagination now excludes any Session with org_member_id in SQL before LIMIT. This preserves page capacity and keyset cursor semantics without deleting or modifying retained historical Sessions; valid current Team roots continue to use the Agent Org stream.

Potential risks

  • The exact official legacy-schema match intentionally abandons old Agent Org run envelopes. The four runtime tables are rebuilt without backup, and that runtime state cannot be restored by reverting the code. This product decision preserves ordinary Sessions but may leave historical Coordinator/Member Sessions, messages, Tasks, Inbox rows, usage, WorkItem/Routine references, and other artifacts as retained history.
  • Unknown legacy/internal schemas are deliberately not guessed or reset. They remain available for diagnosis and may continue to fail canonical reads until handled explicitly.
  • Old recursive Team definitions are not heuristically converted. The persistence path backs up the old bytes and resets to validated flat defaults rather than inventing Member identity or capability policy.
  • This is a stacked PR and must be reviewed/merged after PR feat(agent-org): add authoritative team lifecycle #781. Its base should be retargeted to develop only after PR1 lands and the resulting diff is reverified.
  • The redesign remains fail-closed behind ORGII_AGENT_ORG_REDESIGN=1; enabling the incomplete stack early exposes configured/frozen Writer and communication facts but intentionally does not activate PR7 graph-write or PR9 peer-send behavior.
  • The packaged application and user acceptance passed, but the full WDIO rendered E2E suite was not rerun on the final follow-up commit. The relevant specs were updated and reviewed, and the final packaged real-data pagination path was exercised directly. UI screenshots are not attached yet, so the PR remains Draft.
  • Rollback before enabling the gate is to disable the flag and revert the PR. After an exact legacy runtime reset, rollback cannot recover the abandoned four-table data; retained ordinary Session data remains available.

Verification

  • cargo test -p agent_core agent_org -- --nocapture — 227 passed.
  • cargo test -p agent_core core::session::persistence -- --nocapture — 34 passed.
  • cargo test -p org2 agent_sessions::session_directory::aggregation::tests -- --nocapture — 13 passed.
  • npm test -- --run src/scaffold/WizardSystem/variants/AgentOrg/MemberCommunicationPanel.test.ts src/scaffold/WizardSystem/variants/AgentOrg/orgTree.test.ts src/api/tauri/rpc/schemas/agentOrgs.test.ts — 16 passed.
  • npm test -- --run src/store/session/sessionAtom/__tests__/sidebarLoaders.test.ts src/api/tauri/rpc/__tests__/sessionAggregateSchemas.test.ts — 28 passed.
  • cargo check -p agent_core --all-targets && cargo check -p org2 --all-targets — passed.
  • cargo clippy -p agent_core -p org2 --all-targets -- -D warnings — passed.
  • npm run lint — passed.
  • npm run check:circular — no circular dependencies across 6,350 modules.
  • cargo fmt --all -- --check and git diff --check — passed.
  • ORGII_AGENT_ORG_REDESIGN=1 npm run tauri:build:fast — passed; produced the packaged ORG2.app from this worktree.
  • Packaged real-data verification against ~/.orgii: the standalone SDE stream advanced 10 -> 20 -> 21 rows, then exhausted normally with no Retry, empty page, cursor stall, or new pagination/schema error in the log. No historical Session was deleted or modified by the pagination fix.
  • User manually verified the latest packaged version and reported it passed.

Architecture review covered compilation, structure/dead code, naming, semantic ownership, default branches, domain leakage, developer clarity, wire shape, initialization parity, and resolver symmetry. No new wire or duplicate lifecycle owner was introduced by the follow-up.

Performance verdict: pass. Pagination remains one bounded keyset query using the existing ordered sidebar and root-membership indexes; no polling, cache, retained state, dependency, or frontend retry path was added.

frontend-ui-audit could not be rerun during final handoff because its referenced SKILL.md is absent from both the workspace and user skill directories. Existing UI unit/rendered specs and packaged manual acceptance are recorded above; the PR remains Draft for review evidence completion.

Replace recursive Agent Org hierarchies with stable flat Member rosters and
persist additional Writer grants independently from canonical undirected
Member communication links. Freeze the roster and both capability sets into
immutable launch snapshots while keeping PR7 Writer authority and PR9 peer
messaging fail closed.

Replace the communication matrix with per-Member connection summaries and a
right-side peer panel backed by one canonical draft pair set. Preserve trusted
full-replace validation, atomic persistence, stable Member identities, locale
parity, and the PR1 lifecycle contracts.

Verification:
- cargo test -p agent_core agent_org -- --nocapture (227 passed)
- npm test -- --run src/scaffold/WizardSystem/variants/AgentOrg/MemberCommunicationPanel.test.ts src/scaffold/WizardSystem/variants/AgentOrg/orgTree.test.ts src/api/tauri/rpc/schemas/agentOrgs.test.ts (16 passed)
- cargo check -p agent_core --all-targets && cargo check -p org2 --all-targets
- cargo clippy -p agent_core -p org2 --all-targets -- -D warnings
- npm run lint
- npm run check:circular
- ORGII_AGENT_ORG_REDESIGN=1 npm run tauri:build:fast
Reset only the exact published legacy Agent Org run schema while preserving ordinary sessions and unknown layouts. Keep retained Team member sessions out of standalone SDE pagination so orphan coordinators cannot consume page capacity or trigger Retry.

Verification:
- cargo test -p agent_core core::session::persistence -- --nocapture (34 passed)
- cargo test -p org2 agent_sessions::session_directory::aggregation::tests -- --nocapture (13 passed)
- npm test -- --run src/store/session/sessionAtom/__tests__/sidebarLoaders.test.ts src/api/tauri/rpc/__tests__/sessionAggregateSchemas.test.ts (28 passed)
- cargo check -p agent_core --all-targets && cargo check -p org2 --all-targets
- cargo clippy -p agent_core -p org2 --all-targets -- -D warnings
- npm run lint
- npm run check:circular
- ORGII_AGENT_ORG_REDESIGN=1 npm run tauri:build:fast
- Packaged real-data SDE pagination exhausted 10 -> 20 -> 21 without Retry

Pre-commit hook ran. Total eslint: 0, total circular: 0
@ShiboSheng
ShiboSheng force-pushed the fix/issue-757-flat-team-capabilities branch from 7f90f99 to 8aa187a Compare August 12, 2026 17:11
@ShiboSheng
ShiboSheng marked this pull request as ready for review August 12, 2026 17:13
@ShiboSheng
ShiboSheng requested a review from Neonforge98 August 12, 2026 17:13
@ShiboSheng

Copy link
Copy Markdown
Collaborator Author

orgii://cloud/session/ref?v=1&org=bfa7b134-2486-45fa-81ad-a369441fafb4&owner=776dbd69-ac1d-4f72-a0d4-69cb4f2667dd&session=codexapp-rollout-2026-08-12T00-30-58-019ff1a9-b497-7f60-9e6e-2086cceb7a6d

…formed members

parse_org_members silently dropped any member entry without a string
'name', which cascaded into Writer-grant and communication-link removal
on update — silent member deletion. Malformed entries are now hard,
structured errors naming the entry index and offending field.

update_org also replaced members wholesale with runtime_config: None,
destroying persisted per-member runtime configuration. Survivors now
keep the stored runtime_config, merged by member_id.
…ff order, ids, links

- Boot reconcile of default template teams now reconciles ONLY structural
  identity (canonical member ids exist, canonical agent ids restored,
  removed canonical members re-added and re-linked). User edits survive a
  boot: member name/role/runtime_config, user-added members, description,
  plan approval policy, Writer grants, deliberate link deletions.

- Per-org quarantine: one invalid on-disk definition no longer blocks the
  whole store until restart. Valid orgs load normally; invalid entries are
  quarantined (id/name + error), round-trip verbatim on every save, block
  only writes touching their id/name, and are listed via
  quarantined_definitions(). File-level corruption keeps full Blocked.
  Diagnostics document the fix-file-and-restart requirement.

- org_names_referencing_agent fails safe: quarantined raw entries and
  fully blocked files are scanned as raw text, so the agent-deletion
  guard still protects references the store could not interpret.

- Legacy sniff now runs only on version-less/array files. A valid
  schemaVersion:2 envelope can never be backup-reset by nested
  children/hierarchyMode keys inside field values.

- Both validators reject member ids with leading/trailing whitespace
  instead of validating the trimmed id while storing the raw one.

- validate_launch_snapshot is structural-only; the 256KB cap moved to
  serialize_launch_snapshot on the write path.

- save_trusted_settings materializes full connectivity when INSERTing a
  new multi-member team with empty links; updates keep caller links
  verbatim so deliberate deletions survive.
…tore

The run store's private serialize_launch_snapshot duplicated
validate + to_string without the size cap; it now imports the shared
definitions::orgs::serialize_launch_snapshot, which validates
structurally and enforces the 256KB cap exactly once at the write
boundary. Read/context/task-persist paths no longer serialize the
snapshot just to check its size.
…owner

Store commits fsync under the store mutex. The model tools
(create/update/remove_org in execute_text) and the launch path
(apply_member_launch_overrides) ran them directly on the async executor,
while the Tauri commands each hand-rolled their own offloading.

AgentOrgsStore now exposes async wrappers (insert/replace/remove/
apply_member_launch_overrides/save_trusted_settings _async) built on a
single run_blocking helper; the Tauri commands, model tool actions, and
launch all go through them. org_store plumbing switched from
&AgentOrgsStore to &Arc<AgentOrgsStore> so callers can share ownership
with the blocking task.
…opy, naming

- COORDINATOR_MEMBER_ID moves to core_types::agent_org as the single
  source of truth; the definitions store and the run coordination layer
  both import it (agent_org_runs keeps its public re-export).
- Frontend member cap now mirrors MAX_AGENT_ORG_MEMBERS via
  AgentOrgs/config/agentConstants.ts instead of hardcoding 50 in
  AgentTeamFormSections.isOrgDraftValid.
- Stale 'team hierarchy' empty-state copy replaced with flat-team
  wording in all 13 locales (agentOrgs.orgWizard.noMembers).
- OrgDefinition::member_count() renamed to participant_count() with a
  doc comment for the coordinator-inclusive semantics.
- Dropped the vestigial _org_store State params from
  debug_agent_org_execute_tool_as_agent and
  debug_agent_org_emit_member_idle.
…tion

A single-space member id now fails with the dedicated
leading/trailing-whitespace error instead of the generic
empty-or-reserved message; keep an actually-empty case for the
empty-id path and assert the new message for the untrimmed one.
# Conflicts:
#	src-tauri/crates/agent-core/src/core/coordination/agent_org_runs/store.rs
#	src-tauri/crates/agent-core/src/core/session/launch/launch_helpers.rs
@ShiboSheng

Copy link
Copy Markdown
Collaborator Author

Superseded by #825: #825. The replacement is a clean PR2 stack on the current PR #824 head and intentionally excludes commits 4ac8568 and ce3f5d3. The old branch is retained for history.

@ShiboSheng ShiboSheng closed this Aug 16, 2026
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.

feat(agent-org): [2/10] flatten Team definitions and persist trusted Writer settings

2 participants