Skip to content

feat(agent-org): track exact run session ownership - #652

Draft
ShiboSheng wants to merge 1 commit into
developfrom
fix/issue-642-exact-run-session-ownership
Draft

feat(agent-org): track exact run session ownership#652
ShiboSheng wants to merge 1 commit into
developfrom
fix/issue-642-exact-run-session-ownership

Conversation

@ShiboSheng

Copy link
Copy Markdown
Collaborator

Problem

Agent Org currently infers a Session's Run from the Root Session or the newest Run under that Root. That assumption is safe only while one Root owns one Run. Once sequential Runs are introduced, an old Rust Worker can be misidentified as belonging to a newer Run, affecting Run View, Inbox, Wake, Recovery, Watchdog, Finality, and deletion behavior.

Legacy data also needs a safe upgrade path: unambiguous ownership should be restored automatically, while duplicate live Runs, conflicting Turn Intents, and unsupported historical CLI records must never be silently reassigned or activated.

Solution

  • Add lineage and idempotency fields to agent_org_runs and canonical Coordinator/Rust Worker ownership in agent_org_run_sessions.
  • Enforce one live Run per Root, unique originating messages, one-Run ownership for Rust Workers, and Coordinator/Worker role separation at the database layer.
  • Add an idempotent migration that backfills Coordinator mappings and only unambiguous Rust Worker mappings, with bounded diagnostics for conflicts and unsupported legacy CLI code_sessions.
  • Resolve Run ownership in a fixed order: active Turn Intent, exact Session mapping, explicit or unique Root Run, then a bounded legacy parent walk.
  • Create Coordinator/Run mappings and Rust Worker Session/mappings transactionally so mapping failures cannot leave orphan Sessions.
  • Update Run View, Inbox/tasks, Wake, Recovery, Watchdog, Finality, initialization, lifecycle events, and Rust Worker lookup to use exact ownership.
  • Add a bounded keyset-paged Timeline backend for later UI work.
  • Reject multi-Run deletion without changing durable state; the complete deletion workflow remains PR 2.
  • Preserve save-time and pre-launch rejection for all CLI Agent Org participants. This PR does not add CLI materialization, mapping, Wake, Recovery, or cleanup support.

Refs #642

Part of #635

Potential risks

  • Databases containing more than one live Run for a Root now fail migration explicitly. This preserves user data but requires manual diagnosis instead of choosing a winner automatically.
  • Ambiguous legacy Rust Workers remain unmapped and return an explicit ambiguity rather than being guessed into the wrong Run.
  • The migration and schema are additive. Rolling application code back leaves the new columns and mapping table in place; older code ignores them, and no downgrade deletes ownership data.
  • Multi-Run deletion is intentionally unavailable until PR 2. Attempts fail before deleting Runs, Sessions, mappings, or tasks.
  • Agent Org CLI participants remain unsupported and are still rejected before Root Session or Run creation.
  • This PR has no frontend changes. The inactive-member/Group Chat clarity and pinned-header overlap found during manual validation are tracked separately in Agent Org member views can show ambiguous Group Chat content and overlapping pinned headers #651.
  • On the rebased develop, strict package-wide Clippy is currently blocked by pre-existing warnings in unchanged orgtrack_core and agent_core lines. The commit hook passed its scoped changed-file Clippy, and every diagnostic from the post-rebase package command was checked against this PR's diff.

Verification

Passed on the implemented diff:

  • cargo test -p agent_core --lib agent_org_runs — 50 passed.
  • cargo test -p agent_core --lib validation_rejects_cli — 3 passed.
  • cargo test -p agent_core --lib launch_validation_rejects_cli — 1 passed.
  • cargo test -p agent_core --lib agent_org_wake — 1 passed.
  • Resolver-focused Agent Org suite — 20 passed.
  • cargo test -p agent_core --lib agent_org_watchdog — 7 passed.
  • cargo test -p agent_core --lib agent_org_plan_approvals — 18 passed.
  • cargo test -p session_persistence --lib turn_intents — 12 passed.
  • Session persistence suite — 33 passed.
  • Multi-Run deletion protection test — 1 passed.
  • HTTP E2E scenario agent-org-app-restart-transitions-running-runs-to-paused — 15 assertions passed through production Run View, restart/recovery, resume, and deletion-guard paths.
  • pnpm run typecheck — passed.
  • pnpm run check:circular — passed; 6,207 files processed, no circular dependency.
  • git diff --check — passed.
  • pnpm run tauri:build:fast — passed in 360.6 seconds.
  • Computer Use smoke test — application startup, Command+5 reload, full quit/restart, and Coordinator/Rust Worker reopen passed.
  • User manual acceptance — passed.

Integration with the latest develop (2c02a4127):

  • Rebased without conflicts.
  • cargo test -p agent_core --lib agent_org_runs — 50 passed.
  • cargo test -p session_persistence --lib turn_intents — 12 passed.
  • pnpm run typecheck — passed.
  • pnpm run check:circular — passed.
  • Commit hooks ran without bypass: lint-staged passed; scoped Cargo Clippy passed; hook trailer recorded eslint: 0, circular: 0.

Known repository-baseline checks:

  • Post-rebase cargo clippy -p agent_core -p session_persistence -p e2e-test -p org2 --all-targets -- -D warnings reaches unchanged orgtrack_core warnings and fails on seven existing diagnostics outside this PR.
  • The corresponding --no-deps package check also reports existing warnings in unchanged Agent Core provider/tool files. One reported function in launch_helpers.rs is an unchanged pre-existing function; this PR only reorders validation later in that file.
  • Full-workspace formatting has unrelated baseline differences; all changed Rust files were formatted and the final diff passes git diff --check.

Audit

  • Architecture audit covered domain types, state machines, ownership/authority, persistence, concurrency, Rust lifecycle, wire/API shape, initialization parity, resolver symmetry, compatibility, and tests. No P0/P1 findings remain.
  • Performance guard confirmed no new polling, timers, subscriptions, workers, or unbounded caches. Timeline reads have a hard limit and indexed keyset pagination; migration diagnostics and legacy scans are bounded.
  • CLI rejection remains at save and launch boundaries, with launch rejection before Root Session and Run creation.
  • Final scope is 30 files, 3,281 insertions, and 704 deletions. All files map directly to exact Run–Session ownership, migration, lifecycle consumers, deletion protection, or their test/E2E wiring.
  • No UI screenshots are included because this PR changes no TypeScript, TSX, or CSS.

Persist canonical Coordinator and Rust worker ownership so historical workers cannot resolve to a newer Run under the same Root Session. Add transactional mapping creation, safe legacy backfill, exact resolver precedence, lifecycle integration, a bounded Timeline backend, and a multi-Run deletion guard while preserving CLI rejection.

Verification:
- cargo test -p agent_core --lib agent_org_runs (50 passed)
- cargo test -p session_persistence --lib turn_intents (12 passed)
- cargo clippy -p agent_core -p session_persistence -p org2 --all-targets -- -D warnings
- pnpm run typecheck
- pnpm run check:circular
- Agent Org HTTP E2E (15 assertions passed)
- pnpm run tauri:build:fast
- Computer Use and user manual acceptance passed

Pre-commit hook ran. Total eslint: 0, total circular: 0
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.

1 participant