Repository navigation
fix(sessions): deleted sessions remain visible during worker cleanup - #132233
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
Live deletion proofThe isolated development Gateway and disposable paired worker exercised the real deletion path. The old server refused an active worker placement; the repaired path removed its row in 16 ms, completed safe reclaim/deletion in 11,990 ms, and preserved a file that existed only on the worker in the managed-worktree Git snapshot. The checkout, session, and worker environment were removed; the paired device stayed available and its worker slot was released. No provider inference or paid cloud VM was used. Before the final baseline-only conflict rebase, the browser removed a normal session in 61 ms while its request was still held. I opened another session, forwarded the unchanged request to the real Gateway, and verified completion did not replace the newer navigation. Separate negative flows verified row restoration after transport interruption and a visible real server rejection after the initiating header had unmounted. The recordings use asserted UI states, not sleeps for synchronization. Attached media, in order:
All media were inspected and contain synthetic test sessions only. The original reported screenshot and production session data are not included. Both development processes were stopped after cleanup. Remote-exec placement has regression-test coverage; this live worker run exercised worker-turn placement. Build/ownership evidence: full build passed; integrated Gateway runtime and UI rebuilds passed; rebased owner/shell tests passed 206/206; native request tests passed 34/34; independent autoreview is scoped-clean through P2. The final rebased UI measures 345,606 B gzip / eight startup JS requests: +892 B from the newly lowered main baseline, but 1,717 B below the explicitly approved 347,323 B baseline and 340 B smaller than the preceding candidate. The hard ceiling and growth/variance allowances remain unchanged. The later producer-owned deletion-generation repair has separate before/after evidence and is included in the current PR head. Final conflict-rebase head: Integration commands: OPENCLAW_VITEST_MAX_WORKERS=4 node scripts/run-vitest.mjs ui/src/lib/sessions/session-delete-mutations.test.ts ui/src/lib/sessions/session-deletion-generations.test.ts ui/src/lib/sessions/index.test.ts ui/src/lib/sessions/index.event-refresh.test.ts ui/src/lib/sessions/reconcile.test.ts ui/src/app/app-host.deleted-session.test.ts src/gateway/server.sessions.reset-hooks.test.ts src/gateway/server.sessions.delete-state-lifecycle.test.ts src/gateway/server.sessions.delete-lifecycle.test.ts src/gateway/server.sessions.worker-original-order.test.tsnode scripts/run-vitest.mjs run --config test/vitest/vitest.ui-e2e.config.ts --configLoader runner ui/src/e2e/session-management.delete.e2e.test.ts ui/src/e2e/session-management.archive.e2e.test.tsnode scripts/check-changed.mjs -- src/gateway/session-reset-service.ts ui/src/lib/sessions/session-placement-recovery.ts config/control-ui-startup-budget-baseline.jsonExact-head CI: https://github.com/openclaw/openclaw/actions/runs/33231351525. The exact-head workflow completed successfully on attempt 1, including the required openclaw/ci-gate. The macOS job waited for capacity, then passed on its original runner path. A targeted retry request was rejected while queued; the subsequent cancellation safety check detected runner acquisition and stopped before any cancellation or restart. Native review guards/artifacts are refreshed and the candidate is ready for native prepare/merge; this comment does not yet claim a merge. The latest ClawSweeper finding is resolved; its retained-checkout history limitation is covered by the complete local base-to-head history and range comparison. Direct sibling-Codex inspection was repeated against pinned 0.150.1 source at session-delete-final-navigation.mp4session-delete-worker-after.mp4 |
|
Codex review: needs maintainer review before merge. Reviewed August 28, 2026, 11:34 PM ET / August 29, 2026, 03:34 UTC. ClawSweeper reviewWhat this changesThe PR makes Control UI session deletion immediate while the Gateway drains and safely reclaims attached cloud workers before committing the delete. Regression provenancePossible regression — probable (reviewed change; known regression link). No predecessor PR is attributed. Merge readinessKeep this maintainer-authored PR open for its normal merge path. The reviewed Gateway and Control UI owners correctly preserve delete generation identity and avoid stale-row resurrection; exact-head CI and the required Codex-runtime inspection remain incomplete in this review environment. Priority: P1 Review scores
Verification
How this fits togetherThe Control UI sends session-delete requests to the Gateway, which owns persistent session state and cloud-worker cleanup. Session events and refreshed rosters then update sidebars, open chat panes, and the Sessions page. flowchart LR
UI[Control UI delete action] --> Optimistic[Optimistic session owner]
Optimistic --> Gateway[Gateway deletion request]
Gateway --> Drain[Worker drain and reclaim]
Drain --> Store[Session lifecycle commit]
Store --> Events[Session change events]
Events --> Views[Sidebar, chat pane, sessions page]
Before merge
Agent review detailsSecurityNone. Review metrics
Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep the generation-aware delete path and complete exact-head CI plus direct Codex-boundary inspection before merge. Do we have a high-confidence way to reproduce the issue? Yes: fetched current main enriches keyed lifecycle events from the current row, while the branch's generation-carrying delete path and focused tests demonstrate the stale-replacement sequence from source. Is this the best way to solve the issue? Unclear: the Gateway-to-client generation handoff is the appropriate owner-boundary solution, but the included Codex runtime changes require the unavailable direct Codex inspection for a complete best-fix verdict. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 826c1660d5b3. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles)
|
ClawSweeper deletion-generation finding addressedFixed in b2d3fe7. The removed Both rank-up moves are covered: producer-owned identity and a failing-before delayed-delete-after-recreation regression. The focused shell cases cover subscription/direct delivery, identified/key-only events, and the absence of any prior local deletion. They preserve B's row, navigation, draft and queue, then prove a genuine B deletion still retires B. Real RPC-to-SQLite-to-emitter coverage recreates B before broadcast and proves the event retains A's identity without borrowing B's snapshot. Incognito reset and the dynamic lifecycle bridge are covered too. Fault-injected real-Gateway browser proof: delete A, create B at the same key, wait for canonical B and enter a draft, then deliver A's actual deletion payload late. The delivery envelope keeps continuous sequence numbers to model delayed publication rather than packet loss. This distinction matters: an initial raw-frame hold triggered transport recovery and was not the reproduction. Before the fix, B vanished and navigation moved Home even though the server still held B. After the fix, the notification retains A's ID and B's row, navigation, and typed draft remain. The two attached videos show before and after; only idle setup was trimmed, and all media were inspected. Synthetic sessions only, with the proof session and dev Gateway cleaned up afterward. Verification: 939 UI/Gateway/TUI tests across 48 files, plus 34 tests across seven full browser files, pass. The final fixture cleanup was rerun. Gateway/UI builds pass and independent autoreview is scoped-clean through P2. The event fix adds a judged 26 production lines for authoritative metadata and the two destructive-generation/no-enrichment boundaries; duplicate observation and the old separate null-result delete branch were removed. There is no SQLite table/schema/version change, new store, configuration option, protocol-version bump, or native Codex history deletion. The final measured startup baseline is 345,946 B (+575 B from the integrated baseline, within the previously approved 862 B adjustment); hard ceiling, growth/variance allowances, and eight startup requests are unchanged. The PR body records the pre-existing Android offline-cleanup and mock-Gateway metadata follow-ups rather than claiming those separate owners are fixed. Exact-head CI remains a separate merge gate; this comment does not claim it is green or bypass it. late-delete-before-trimmed.mp4late-delete-after-trimmed.mp4 |
Remove confirmed selections optimistically, retain canonical generation ownership across stale responses and reconnects, and reconcile failures without restoring old navigation. Share archive/delete lifecycle drains and safely reclaim worker workspaces before deletion commits. Preserve exact caller, session, and placement authority through asynchronous cleanup. Fixes #132057.
Use real session capability publications, support independent subscribers, assert postcommit placement retirement, and distinguish selected threads from the configured main session in browser fixtures. Preserve archived-action and geometry assertions.
Carry deleted session identity from lifecycle results, skip current-row enrichment for deletion broadcasts, and reconcile key-only notifications without purging a replacement. Cover delayed events, incognito reset, and the real RPC-to-broadcast boundary. Record the final measured startup baseline within the approved adjustment.
b2d3fe7 to
97dbc44
Compare
|
Merged via squash.
|
…penclaw#132233) * fix(sessions): delete immediately and safely reclaim workers Remove confirmed selections optimistically, retain canonical generation ownership across stale responses and reconnects, and reconcile failures without restoring old navigation. Share archive/delete lifecycle drains and safely reclaim worker workspaces before deletion commits. Preserve exact caller, session, and placement authority through asynchronous cleanup. Fixes openclaw#132057. * test(sessions): align fixtures with canonical deletion ownership Use real session capability publications, support independent subscribers, assert postcommit placement retirement, and distinguish selected threads from the configured main session in browser fixtures. Preserve archived-action and geometry assertions. * fix(sessions): bind delete events to the removed generation Carry deleted session identity from lifecycle results, skip current-row enrichment for deletion broadcasts, and reconcile key-only notifications without purging a replacement. Cover delayed events, incognito reset, and the real RPC-to-broadcast boundary. Record the final measured startup baseline within the approved adjustment.


Closes #132057
What Problem This Solves
Fixes an issue where users deleting a session in the Control UI would keep seeing its sidebar row and open conversation while server cleanup ran. Refreshes and cached sidebar rows could bring the row back, the Sessions page ignored publications during a mutation, and active cloud-worker sessions were rejected instead of safely reclaimed.
Why This Change Was Made
Deletion now has one shared optimistic owner for single and batch operations. It removes the complete confirmed selection immediately, fences stale list/history/event results, and navigates away through the shell/pane lifecycle rather than a late caller callback. Failed operations restore only their own rows and reconcile canonical server membership without undoing unrelated edits or newer navigation. Drafts and attachments retire only after confirmed deletion; failures remain visible even after the initiating header unmounts.
On the Gateway, Archive and Delete share the existing lifecycle drain and safe worker reclaim. Deletion retains exact session, caller, and placement ownership checks through asynchronous cleanup and the synchronous commit boundary, then retires placement metadata only after deletion succeeds. This removes the archive-only implementation, duplicated client deletion flows, obsolete navigation adapters, and an outer reclaim-promise map that could deadlock against the lifecycle fence. UI, CLI, and shared iOS/macOS request builders reuse the existing ten-minute safe-reclaim deadline; explicit CLI overrides still win.
Delete notifications also carry the identity actually removed by the lifecycle result, including incognito reset. Neither leading nor delayed broadcasts sample the row currently occupying that key. Clients confirm only the identified generation; key-only lifecycle notices request canonical reconciliation rather than purging a replacement.
The maintainer explicitly approved safe reclaim as part of Delete. There is no forced abandonment, new configuration, SQLite schema change, protocol version change, or native Codex history deletion. The registered production inference-drain seam replaces a test-only duck-typed fallback. One nearby Swift test now requires valid UTF-8 instead of silently repairing malformed encoded bytes.
User Impact
Deleting one or several sessions feels immediate. The Gateway can finish slower worker reconciliation and cleanup in the background. If safe reclaim fails, the session and recovery state remain available and the UI reports the failure; a row can reappear without pulling the user away from whatever they opened next. Reconciled managed worktrees keep the existing snapshot/preservation behavior. Main-session, plugin-owner, locked-model, and archive-only permission restrictions remain intact.
Release-note context: Control UI session deletion no longer waits for cleanup or lets stale roster/history results resurrect deleted rows; attached workers stop and reconcile safely before deletion commits.
Evidence
Regression tests were first run against the original implementation and failed for immediate single/batch removal, stale prefetch, mutation-pending Sessions-page publication, list-owner rollback contamination, safe reclaim and unsynced failure, reclaim deadlock, premature placement retirement, and authority/session replacement across cleanup boundaries. The repaired owner and sibling suites pass.
Final generation/roster owner suites passed 192 tests and caller/pagination siblings passed 154 tests. After integrating the upstream refresh-queue fix, the owner/shell run passed 206 tests across 10 files. Additional proof includes 44 CLI lifecycle/transport tests, 98 archive/placement/reclaim tests, 71 Gateway plus 38 real-parser tests, and broader deletion/worktree/SQLite/Codex sibling coverage. These runs overlap and are not presented as one aggregate count. Production/test typechecks, scoped TypeScript lint/format, i18n verification, and the full changed-file core guard plan passed. Shared native request tests passed 34 tests; checksum-verified SwiftLint 0.65.0 and SwiftFormat 0.62.1 checks pass without changing the host's global tool installation.
Independent Codex autoreview identified six client generation/reconnect/result defects during development; ClawSweeper subsequently identified a key-only deletion-event rebinding defect. Every accepted finding received failing-before proof and an owner-level repair. The final event-repair review is scoped-clean through P2. The full build and subsequent integrated Gateway/UI rebuilds passed. After the final baseline-only conflict rebase, the measured startup baseline is 345,606 B gzip, 892 B above the newly lowered main baseline and 1,717 B below the maintainer-approved 347,323 B baseline. This is 340 B smaller than the preceding candidate. The 350 KiB hard baseline cap, 512 B growth allowance, 64 B variance allowance, and startup request budget are unchanged; startup uses eight JS requests.
Production LOC: +1,047/−814 (net +233). Tests/support: +2,488/−655 (net +1,833), with moved tests and extracted fixtures counted separately from production. The growth supplies a real new optimistic lifecycle owner with canonical generation/request-order facts, row-scoped rollback and confirmation-only cleanup. It is not a downstream hiding guard; duplicated deletion/navigation paths and the archive-only drain were removed, while the backend repair is net-negative.
Live proof uses an isolated development Gateway and a real disposable paired worker, not the operator's Gateway. The old server rejected deletion of an active placement. With the repair, the real browser removed the row in 16 ms, before the RPC completed; safe reclaim and deletion finished in 11,990 ms with no transport faults. A synthetic file written only on the worker survived in the managed-worktree snapshot, the checkout and worker environment were removed, and the paired device remained available with its slot released. This exercised worker-turn placement without provider inference; remote-exec is covered by the owner regression suites, not claimed as live here.
Final rebased browser proof observed removal in 61 ms while the request was still held, then navigated to a different session before forwarding the real deletion. Completion preserved that newer selection. A real expected-session-ID rejection restored the row and displayed an error after the initiating header had unmounted; a separately injected transport disconnect restored the unchanged server session without reverting navigation. Only inspected synthetic test sessions appear in attached media; no production screenshot or session data is included. The test Gateway and node were stopped after verifying cleanup.
The deletion-event repair passes 939 UI/Gateway/TUI tests across 48 files, plus 34 tests across seven full mocked-browser files. CI's stale fixtures were separately repaired with real capability publications and multi-subscriber behavior; their focused/sibling run passed 267 tests. One readonly fixture initialization and repeated goal setup were corrected during static checks without weakening assertions or raising file limits. The final conflict rebase onto
383a293b32d97254014437430b62aaf406bc11acreran 223 tests across ten files, including deletion generations, shell navigation, incognito reset and original-order worker cleanup. Git range-diff confirms the reviewed production/test patches are unchanged; only the measured startup-baseline metadata differs.A second real-Gateway browser fault sequence deletes A, recreates B at the same key, then delivers A's actual deletion payload after B is visible. Transport sequence numbers are kept continuous to model delayed publication, not packet loss. Before the repair, B disappeared and navigation moved away while B still existed on the server. Afterward, the event retains A's ID and B's row, navigation, and typed draft survive. The initial raw-frame hold triggered transport recovery and is not counted as the reproduction.
Final build, independent review, exact-head CI, measured LOC, and the final live verdict are recorded in the land-ready proof comment.
Provenance: await-then-refresh deletion was carried forward by #117103 (session/navigation reconnect refactor); the mutation-time publication guard came from #125018 (duplicate Sessions-page query fix); revision-only prefetch validation came from #125128 (instant transcript snapshots). The outer reclaim map came from #108398 (cloud worker run/reclaim), and premature placement retirement from #120715 (fallback-disconnect cleanup). The blamed code, PR authorship, and merge attribution for those changes all resolve to @steipete. Active-placement deletion refusal was intentional prior policy, not a newly attributed regression; changing it to safe reclaim was explicitly approved.
Scope boundary
Related but not fixed: #127388, where pending archive publication failures can poison unrelated cleanup and starve recovery. This change reconciles UI membership after rejection rather than claiming that server state rolled back, but deliberately does not redesign the durable archive retry/completion policy.
Two named follow-ups were recorded during the audit. Android's pre-existing
ChatControllerdelete-event consumer still purges offline cache/outbox state by key/agent rather than generation; its native persistence lifecycle needs a separate repair and proof, and is not claimed fixed here. The mock Gateway's global defaults also need coherent per-session main/history/pin facts; this PR corrects only the causally failing browser scenarios without removing deliberate stale-ID fault fixtures.