Skip to content

feat(daemon): cascade archive/delete onto subagents - #568

Merged
edwin-zvs merged 1 commit into
mainfrom
cascade-subagent-delete-archive
Jun 28, 2026
Merged

edwin-zvs merged 1 commit into
mainfrom
cascade-subagent-delete-archive

Conversation

@edwin-zvs

Copy link
Copy Markdown
Contributor

What

Archiving or deleting a session now cascades onto the subagents it owns: archive archives them, delete deletes them, recursively down the ownership tree.

Previously neither operation touched subagents — they were left as orphaned rows pointing at a parent that no longer existed (list clutter, held worktrees/adapters, dangling @{session:<id>} refs with no owner to collect them). The only existing cascade was the optional delete_members flag on group delete; the tighter parent/subagent bond had nothing.

How

  • New SessionManager::child_subagent_ids(parent) collects direct children matched by parent_session_id and SessionKind::Subagent (so an unrelated top-level session is never swept).
  • SessionManager::archive and ::delete snapshot their child subagents, do their existing work, then cascade via Box::pin(self.archive/delete(child)) — recursing through each child's own removal so nested subagents follow. A failure on one child is logged and never aborts the siblings or the parent.
  • Routes through the daemon's single archive/delete entry points, so every client surface (TUI, CLI, MCP) inherits the cascade, including subagent-scoped removal (construct_subagent_archive / construct_subagent_delete).

Behavior matrix

Operation Before After
delete(parent) subagents orphaned subagents deleted (recursive)
archive(parent) subagents orphaned subagents archived (recursive)
delete/archive unrelated session n/a other sessions' subagents untouched

Archive's reversibility guarantee extends through the cascade: cascade-archived subagents keep transcript + worktree and can be restarted.

Tests

  • delete_cascades_to_subagents — parent + two subagents + a nested subagent all deleted; an unrelated user session survives.
  • archive_cascades_to_subagents — parent + nested subagent archived recursively; a subagent owned by a different parent is untouched.
  • Existing archive_marks_terminal_and_keeps_session / archive_and_delete_return_quickly_without_blocking_caller still pass.

Full session:: module: 46 passed. Clippy clean on the changed region.

Spec

Adds specs/0052-session-removal-cascades-to-subagents.md and cross-references it from 0047-archive-vs-delete-session-lifecycle.md.

Notes for reviewer

Daemon-only logic, no user-visible render surface → no recording (per AGENTS.md judgment call). The change lives entirely in crates/daemon → relevant binary is construct (the daemon is served by the same construct binary via construct daemon run).

Archiving or deleting a session left its subagents behind as orphaned
rows pointing at a parent that no longer existed — list clutter, held
worktrees/adapters, and dangling @{session:<id>} refs with no owner to
collect them.

SessionManager::archive and ::delete now sweep the session's child
subagents (matched by parent_session_id + SessionKind::Subagent),
recursing through each child's own archive/delete so nested subagents
follow. A failure on one child is logged and never aborts the rest or
the parent's removal. This routes through the daemon's single
archive/delete entry points, so every client surface (TUI, CLI, MCP)
and subagent-scoped removal inherits the cascade.

Adds spec 0052 and cross-references it from 0047.
@edwin-zvs
edwin-zvs merged commit a5a89f0 into main Jun 28, 2026
1 check passed
@edwin-zvs
edwin-zvs deleted the cascade-subagent-delete-archive branch June 28, 2026 19:09
edwin-zvs added a commit that referenced this pull request Jun 29, 2026
…053, break pending_block_signatures compat

main advanced with #569 (keep run shimmer alive past owning-session idle),
which reworked the same shimmer lifecycle and added agent_managed to
ProgramRunProgress, plus #563/#568 (specs 0051 custom-templates, 0052
session-removal-cascades).

Reconcile:
- protocol: keep pending_block_ids rename + the declared-shimmer types
  alongside #569's agent_managed field; DROP the pending_block_signatures
  serde alias (clean break, per request) and remove the legacy-compat test.
- daemon: fold #569's agent_managed + inactivity-backstop refresh into the
  declaration-based narrow_program_run and set_program_run_pending so a
  complete/partial declaration also marks the run agent-managed; #569's
  AwaitingInput/terminal stop-signal split is preserved. Adapt #569's two
  lifecycle tests to the id-based API.
- specs 0042/0048: combine #569's stop-signal model with the declared
  per-block-id model; my new spec collides with main's 0051/0052, renumbered
  to specs/0053-program-shimmer-block-addressing and all references updated.

cargo test --workspace green.
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