Skip to content

Release exp: cascade delegated subagent deletion (#5926) - #6073

Merged
nesquena-hermes merged 3 commits into
masterfrom
stage/5926
Jul 14, 2026
Merged

nesquena-hermes merged 3 commits into
masterfrom
stage/5926

Conversation

@nesquena-hermes

Copy link
Copy Markdown
Collaborator

Ships #5926 (relates #5307), @pxxD1998 — a destructive-path fix that converged over 6 rounds to a fully-verified SAFE state.

Deleting a parent session now cascades removal of its delegated/subagent sessions + on-disk transcript artifacts (incl Agent-migrated legacy delegates), while never over-deleting siblings, unrelated sessions, or any still-live child.

Codex authoritative gate SAFE (round 6): no over-delete of live/sibling/unrelated data (FK cascade scoped to removed IDs; unrelated usage/compression-lock/Telegram rows survive); the migrated-delegate under-delete is fixed without widening to non-delegates; the new cross-process file lock (POSIX flock / Windows msvcrt) was verified on a real two-process test — serialized recovery + cleanup, no overlap/deadlock, released, persistent lock file never unlinked; fail-closed on missing/unqueryable state.db, liveness-query failure, and absent lock primitive (20-call no-primitive probe preserved all rows + artifacts, no FD growth); recovery-from-prior-failed-run works; partial cleanup reported honestly not shown as success. 51 focused tests. Thanks @pxxD1998 for the careful multi-round hardening on a data-deletion path.

@greptile-apps

greptile-apps Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds cascading cleanup when a parent session is deleted. The main changes are:

  • Deletes delegated session rows and transcript artifacts.
  • Preserves branches, compression continuations, siblings, and live sessions.
  • Serializes cleanup across threads and processes.
  • Adds retry manifests for partial artifact cleanup.
  • Reports cleanup failures in the API and session UI.
  • Adds focused tests and architecture documentation.

Confidence Score: 4/5

The missing-state-database result needs correction before merging.

  • WebUI-only deletion can be reported as failed after it succeeds.
  • Swipe callers can restore a row for a session that no longer exists.
  • The destructive cascade itself has strong scope, locking, and recovery safeguards.

api/routes.py and the cleanup result contract in api/models.py

Important Files Changed

Filename Overview
api/models.py Adds locked, lineage-aware database deletion and retryable transcript cleanup.
api/routes.py Adds partial-cleanup reporting but classifies an absent CLI database as a failure.
static/sessions.js Shows cleanup errors for single and batch deletion and propagates single-delete failure.
tests/test_delete_cli_session_delegate_cascade.py Adds extensive tests for lineage, preservation, locking, recovery, and schema edge cases.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Delete session request] --> B[Delete WebUI sidecar and write tombstone]
    B --> C{Messaging session?}
    C -- Yes --> H[Return success]
    C -- No --> D[Acquire profile cleanup locks]
    D --> E[Recover stale manifests]
    E --> F[Delete parent and delegated rows in transaction]
    F --> G[Clean transcript artifacts]
    G --> H[Return success with cleanup status]
    H --> I[Update session UI]
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A[Delete session request] --> B[Delete WebUI sidecar and write tombstone]
    B --> C{Messaging session?}
    C -- Yes --> H[Return success]
    C -- No --> D[Acquire profile cleanup locks]
    D --> E[Recover stale manifests]
    E --> F[Delete parent and delegated rows in transaction]
    F --> G[Clean transcript artifacts]
    G --> H[Return success with cleanup status]
    H --> I[Update session UI]
Loading

Reviews (1): Last reviewed commit: "Release exp: cascade delegated subagent ..." | Re-trigger Greptile

Comment thread api/routes.py
from api.models import delete_cli_session

delete_cli_session(sid)
state_db_cleanup_failed = not delete_cli_session(sid)

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.

P1 Missing Database Becomes Failure

When a WebUI-only profile has no state.db, delete_cli_session() returns False and this line reports state_db_cleanup_failed=true. The WebUI session was already deleted and tombstoned, but the client shows “Delete failed” and swipe callers restore its row because deleteSession() returns false. Treat an absent, inapplicable CLI database separately from an operational cleanup failure.

@nesquena-hermes
nesquena-hermes merged commit a81872a into master Jul 14, 2026
18 checks passed
@nesquena-hermes
nesquena-hermes deleted the stage/5926 branch July 14, 2026 19:15
@cutter-sh

cutter-sh Bot commented Jul 14, 2026

Copy link
Copy Markdown

🎬 Cutter preview — PR #6073

Delete a session
Delete a session — Sidebar sessions list after cascade delete removes the delegated subagent session.

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