fix(cli): stop new sessions adopting dead sessions' delegation completions (#64484) - #64593
Merged
Conversation
…atch identity Three-layer companion to the salvaged CLI drain-ownership fix (#64240): 1. restore_undelivered_completions stamps restored=True (in-memory only) on every durable completion re-enqueued at process start. 2. drain_notifications' legacy unfiltered branch re-queues restored events instead of consuming them — a fresh process can no longer adopt a dead session's delegation results (#64484). Same-process keyless events keep the legacy behavior. 3. delegate_tool's async dispatch now falls back to the parent agent's durable session_id when the approval-context key resolves empty (the CLI case), so the CLI's new positive-ownership drain can actually claim its own completions instead of failing closed on ''.
This was referenced Jul 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A brand-new CLI session can no longer adopt a dead, unrelated session's async delegation results (#64484). Durable restore now marks its events, the unfiltered legacy drain fails closed on them, and both CLI drain sites plus CLI dispatch carry a real session identity.
Root cause (3 layers, all confirmed on main): since #63494 made completions durable,
ProcessRegistry.__init__re-enqueues everydelivery_state='pending'completion at startup regardless of origin; the CLI idle drain's ownership key resolves to""outside a turn, hittingdrain_notifications' legacy consume-everything branch; and the CLI post-turn drain passes no filter at all. The #58684/#55578 ownership filter was effectively dead code on the CLI.Changes
HermesCLI._owns_process_notification(session-id + compression-lineage viaresolve_resume_session_id) +_drain_process_notificationsused by both CLI drain sites.tools/async_delegation.py:restore_undelivered_completionsstampsrestored=True(in-memory only, never persisted).tools/process_registry.py: the unfiltered legacy drain branch re-queues restored events (fail closed — they stay pending on disk for the owning session's--resume); same-process keyless events keep legacy behavior.tools/delegate_tool.py: async dispatch falls back to the parent agent's durablesession_idwhen the approval-context key is empty (the CLI case) — without this, the CLI's new positive-ownership filter could never claim its own completions.Validation
Salvages #64240 by @rabadaki (authorship preserved). Fixes #64484. Complements #63317 (TUI) and 75efd73 (gateway).
Infographic