Skip to content

fix(cli): stop new sessions adopting dead sessions' delegation completions (#64484) - #64593

Merged
teknium1 merged 2 commits into
mainfrom
salvage/64240-cli-delegation-drain
Jul 15, 2026
Merged

fix(cli): stop new sessions adopting dead sessions' delegation completions (#64484)#64593
teknium1 merged 2 commits into
mainfrom
salvage/64240-cli-delegation-drain

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

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 every delivery_state='pending' completion at startup regardless of origin; the CLI idle drain's ownership key resolves to "" outside a turn, hitting drain_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

  • Salvaged fix(cli): scope async delegation delivery to session #64240 by @rabadaki: HermesCLI._owns_process_notification (session-id + compression-lineage via resolve_resume_session_id) + _drain_process_notifications used by both CLI drain sites.
  • tools/async_delegation.py: restore_undelivered_completions stamps restored=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 durable session_id when the approval-context key is empty (the CLI case) — without this, the CLI's new positive-ownership filter could never claim its own completions.
  • Tests: 6 new regression tests (restore stamp round-trip on a real SQLite store, unfiltered/foreign/owner/callback drain matrix) + the salvaged PR's 3 CLI ownership tests.

Validation

Before After
Issue's cross-process repro (proc 1 persists → proc 2 fresh boot, unfiltered drain) foreign completion consumed 0 leaked; owner drain still receives it
tests (restored_ownership, cli_async_delivery, process_registry, async_delegation, delegate) 294/294 pass

Salvages #64240 by @rabadaki (authorship preserved). Fixes #64484. Complements #63317 (TUI) and 75efd73 (gateway).

Infographic

cli-delegation-drain

rabadaki and others added 2 commits July 14, 2026 13:01
…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 ''.
@alt-glitch alt-glitch added type/bug Something isn't working comp/cli CLI entry point, hermes_cli/, setup wizard tool/delegate Subagent delegation sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages P1 High — major feature broken, no workaround labels Jul 14, 2026
@teknium1
teknium1 merged commit 47d853f into main Jul 15, 2026
31 checks passed
@teknium1
teknium1 deleted the salvage/64240-cli-delegation-drain branch July 15, 2026 05:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard P1 High — major feature broken, no workaround sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state tool/delegate Subagent delegation type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: New CLI session adopts a dead session's async delegation completions (durable restore bypasses CLI drain ownership)

3 participants