Skip to content

fix(session-ipc): refuse to delete a session with a running turn - #2292

Merged
vastsa merged 3 commits into
vastsa:mainfrom
SeanLiu326:fix/session-delete-running-guard
Nov 15, 2026
Merged

vastsa merged 3 commits into
vastsa:mainfrom
SeanLiu326:fix/session-delete-running-guard

Conversation

@SeanLiu326

Copy link
Copy Markdown
Contributor

Fixes #2291.

What

sessionDelete had no running guard and held no session operation, so deleting a live session cascaded away the rows its turn was still streaming into: every later outbox append failed its foreign key, terminal events landed on deleted rows, and the renderer kept receiving events for a session that no longer existed.

The change

  • activeTurns.has(id) now refuses with AGENT_BUSY, matching session.fork's existing guard for the same situation.
  • The deletion then runs under acquireSessionOperation, closing the check-to-host-call window for a turn that starts in between.

Behavior is unchanged for idle sessions.

@aiuo-codepilot aiuo-codepilot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AIUO CodePilot · Preliminary review

Diff-only preliminary review. The change adds a running-turn guard plus session-operation serialization to `sessionDelete` and also refactors `agentCompact` to hold a session operation. The claimed window-closing effect depends on `acquireSessionOperation` and `activeTurns` correctly sharing state with the turn-start path; the diff does not include that definition, so I could not verify the invariant. No concrete evidenced defect found in the added lines themselves.

No evidenced findings in the supplied diff.

Head: 80f8730
Base: 7b0294d
CI: pending; mergeable: true.

Validation: code/tests NOT EXECUTED. Diff-only preliminary analysis; not approval. Human review and repository gates remain required.

@aiuo-codepilot aiuo-codepilot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AIUO CodePilot · Preliminary review

Diff-only preliminary review of the session-delete running-guard and session-operation changes. The patch synchronizes `session.delete` with active-turn bookkeeping and serializes it against other session operations; the compact handler is also refactored onto the same lock. No concrete, quote-supported defects are evident in the added code. Verification limits: I could not run the app, tests, type checks, or inspect surrounding lock/turn-lifecycle code, so lock ordering, exception-translation behavior to the renderer, and cross-path interactions remain unverified.

No evidenced findings in the supplied diff.

Head: c328cab
Base: 7b0294d
CI: pending; mergeable: true.

Validation: code/tests NOT EXECUTED. Diff-only preliminary analysis; not approval. Human review and repository gates remain required.

@vastsa vastsa left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original deletion defect is real, but the queued-start case remains reproducible on this head. I loaded the production registerSessionIpc and createSessionCoordination in an isolated worktree integrated with main 7841a98 (only external boundaries stubbed): acquire the session operation on behalf of prompt setup; invoke sessionDelete while activeTurns is empty; set activeTurns to the newly durable turn before releasing the prompt operation. The queued delete then calls host session.delete while that turn remains active. The same diagnostic reproduces on main; adding a guard inside the acquired lock prevents the host delete (control passed).

Please check activeTurns after await acquireSessionOperation(id), inside the try/finally, before session.delete. The existing pre-lock check may remain as a fast refusal, but cannot be the authoritative check. Add behavioral regressions for a queued prompt that creates a turn before releasing the lock, an already-running turn, idle deletion, and lock release on refusal/error. The current head adds no tests for the delete change. This is the core race the PR claims to close, so I have not approved or merged it. Validation here was the production-handler/production-lock diagnostic, not full Host/Electron E2E.

@vastsa

vastsa commented Nov 13, 2026

Copy link
Copy Markdown
Owner

The defect is real, but before landing:

  1. This branch also contains the fix(agent-ipc): hold the session operation across manual compaction #2290 agentCompact change; please keep it to the delete fix.
  2. The activeTurns.has(id) check runs before acquireSessionOperation(id); a prompt holding the operation registers its turn and releases it, after which delete proceeds against a running turn. Do the check after acquiring the operation.
  3. User path: deleting a running session from the sidebar now rejects with an untranslated "Cannot delete a running session" and project-slice.ts deleteSession has no handling for it. Either abort the turn and then delete (likely what the user intends), or surface an i18n message.
  4. Please add a test for the busy rejection/abort path and the check-after-lock ordering.

sessionDelete now mirrors session.moveProject's contract: acquire the session operation, then check activeTurns, then cascade. The check-after-acquire ordering closes the queued-start window — a prompt holding the operation registers its turn and releases it, and the delete still refuses that turn (issue vastsa#2291).

The sidebar's row menu and batch delete pre-check running sessions and surface a translated notice (nav.deleteRunningSessionBlocked, all locales), and project-slice's deleteSession renders the main-side AGENT_BUSY backstop through the same message instead of the raw IPC error.

Branch rebuilt from latest main so it carries only the delete fix; the agentCompact rework lives on fix/compact-session-operation (vastsa#2290). Regression tests execute the production handler: busy refusal before any host cascade, the prompt-held-operation repro, operation held for the delete's duration, and a clean idle delete.
@SeanLiu326
SeanLiu326 force-pushed the fix/session-delete-running-guard branch from c328cab to f75d2c2 Compare November 15, 2026 14:10
@SeanLiu326

Copy link
Copy Markdown
Contributor Author

All four points addressed — head f75d2c27e, rebuilt from latest main so the branch carries only the delete fix.

  1. Branch split: the agentCompact change is gone from this branch; it lives only on fix/compact-session-operation (fix(agent-ipc): hold the session operation across manual compaction #2290).
  2. Check-after-acquire: sessionDelete now mirrors session.moveProject's contract — acquire the session operation, then check activeTurns, then cascade. Your repro is pinned as a regression test: a prompt acquires the operation, registers its durable turn, releases, and the delete still refuses with AGENT_BUSY.
  3. UX: took the i18n option — the sidebar's row menu and the batch delete pre-check runningSessions and show a translated notice (nav.deleteRunningSessionBlocked, added to all nine locales, mirroring the move entry's pre-check pattern), and project-slice.deleteSession renders the main-side AGENT_BUSY backstop through that same message instead of the raw IPC error. I stayed away from abort-then-delete for now: aborting inside the delete handler only helps if the delete then waits for the turn's full settlement (otherwise the cascade still races the teardown), which means waiting on turn end inside a delete IPC. Happy to switch if you'd rather have that behavior.
  4. Tests (session-delete-running-guard.test.mjs, executing the production handler with a real promise-tail operation): busy refusal before any host cascade; your prompt-held-operation repro; the operation held for the delete's own duration (no turn can begin between the check and the host call); and a clean idle delete including the outbox drop.

Desktop tsc --noEmit clean.

@vastsa
vastsa merged commit 9ff4a9a into vastsa:main Nov 15, 2026
5 of 6 checks passed
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.

sessionDelete cascades away a running turn's rows (no running guard, no session operation)

2 participants