Skip to content

fix(agent-org): delete workers when deleting an Agent Org session - #573

Closed
Harry19081 wants to merge 2 commits into
developfrom
fix/issue-556-delete-agent-org-workers
Closed

fix(agent-org): delete workers when deleting an Agent Org session#573
Harry19081 wants to merge 2 commits into
developfrom
fix/issue-556-delete-agent-org-workers

Conversation

@Harry19081

Copy link
Copy Markdown
Member

Summary

Fixes #556

Before this change, deleting an Agent Org session removed only the root/coordinator session. Its Rust worker sessions could remain in the database with a parent that no longer existed.

After this change, deleting the Agent Org root from the sidebar stops the active Rust run when needed, then removes the root, all Rust workers, and the run-owned coordination data together. The sidebar also removes every deleted session immediately.

What changed

  • Build the complete Rust worker hierarchy from agent_sessions.parent_session_id and delete it leaf-first.
  • Allow running and paused Agent Org runs to be stopped and deleted through the same user action.
  • Recheck the hierarchy and session states inside one SQLite transaction so the database cannot keep only half of the hierarchy.
  • Fail without deleting anything when the structure is unsafe, including nested Agent Org roots, cycles, excessive depth/size, concurrent topology changes, or a runtime that does not stop in time.
  • Evict the deleted sessions from the Rust runtime registry and EventStore retained state after the database commit.
  • Return all deleted session IDs to the frontend so the sidebar clears the root and workers together and navigates only once.

Scope

  • Rust Agent Org sessions only.
  • No code_sessions queries or CLI lifecycle/cleanup changes.
  • No database migration and no automatic cleanup of historical orphan rows.
  • Ordinary SDE/non-Agent Org deletion still uses the existing single-session path; only its successful result is wrapped in the new receipt shape.

Known limitation

This PR stops the active Rust runtime and clears queued work before deletion, but it does not add a new global drain/tombstone protocol for every detached background writer. Hardening extremely late asynchronous writes can be handled separately without expanding #556.

Verification

  • cargo test -p agent_core — 3151 passed, 2 ignored
  • cargo test -p project_management — 521 passed
  • cargo test -p agent_core session_hierarchy_delete — 11 passed
  • cargo test -p agent_core direct_agent_org_turn_refuses_cancelled_delete_fence — 1 passed
  • pnpm test — 770 files, 6823 tests passed
  • pnpm run typecheck
  • pnpm run lint
  • pnpm run check:circular — no circular dependencies
  • Isolated rendered Tauri E2E — 3 scenarios passed through the real sidebar menu: completed, running, and paused runs
  • Changed Rust files passed rustfmt --check; changed frontend/E2E files passed Prettier
  • git diff --check
  • Husky pre-commit and commitlint hooks passed without bypass

Repository baseline notes

Deleting an Agent Org root previously removed only its own row, leaving Rust worker sessions and run-owned data behind.

Build a leaf-first Rust hierarchy deletion plan, stop active runs, revalidate the topology in one transaction, clean canonical and run-owned state atomically, evict retained runtime state, and return all deleted IDs so the sidebar stays in sync. Ordinary SDE deletion keeps its existing single-session behavior, and CLI sessions remain out of scope.

Verification:
- cargo test -p agent_core (3151 passed, 2 ignored)
- cargo test -p project_management (521 passed)
- pnpm test (770 files, 6823 tests passed)
- pnpm run typecheck
- pnpm run lint
- pnpm run check:circular
- isolated rendered E2E (3 passed)
- changed Rust and frontend formatting checks
- git diff --check

Pre-commit hook ran. Total eslint: 2, total circular: 0
Pre-commit hook ran. Total eslint: 0, total circular: 0
@ShiboSheng ShiboSheng closed this Jul 30, 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.

fix(agent-org): delete workers when deleting an Agent Org session

2 participants