Skip to content

Fix dropped async delegation completion after context compression - #65820

Closed
heyparth1 wants to merge 1 commit into
NousResearch:mainfrom
heyparth1:brutus/issue-65779
Closed

Fix dropped async delegation completion after context compression#65820
heyparth1 wants to merge 1 commit into
NousResearch:mainfrom
heyparth1:brutus/issue-65779

Conversation

@heyparth1

Copy link
Copy Markdown

Summary

This PR fixes an issue where async delegation completions dispatched before context compression were dropped by the #55578 fail-closed guard if they completed after the parent session rotated to its compression-continuation child.

Changes

  • Extracted the pinned session resolution logic into a new _resolve_pinned_delegation_session method.
  • Added a carve-out to the fail-closed guard: if the pinned session was ended due to compression, the completion is rerouted to the live compression continuation tip (get_compression_tip) instead of being dropped.
  • Maintained the existing fail-closed behavior for explicitly ended (/new reset) or unknown sessions to prevent illicit conversation revival.

Closes #65779

@alt-glitch alt-glitch added type/bug Something isn't working comp/gateway Gateway runner, session dispatch, delivery tool/delegate Subagent delegation P2 Medium — degraded but workaround exists needs-decision Awaiting maintainer decision before any implementation 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 labels Jul 16, 2026

@tonydwb tonydwb 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.

Code Review Summary

Verdict: Approved

Fixes dropped async delegation completion after context compression. Clean, well-scoped fix. No security concerns.


Reviewed by Hermes Agent

@teknium1 teknium1 left a comment

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.

Thanks for the focused fix. The premise is confirmed on current main: gateway/run.py:11241-11266 drops a completion when its pinned parent has ended_at, while hermes_state.py:3568-3629 already provides a lineage-safe compression continuation resolver that excludes branch, delegation, and tool children.

Problems

  • tests/gateway/test_async_delegation_session_binding.py:94-100 uses inspect.getsource() and a symbol-string assertion to prove wiring. This does not execute the routing path, and AGENTS.md prohibits source-reading tests.

Suggested changes

  • Replace that test with an executable handler-path regression: a compression-ended parent should route through switch_session to a live tip, while session_reset must still make no switch.

Automated hermes-sweeper review.

import inspect
from gateway.run import GatewayRunner

src = inspect.getsource(GatewayRunner._handle_message_with_agent)

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.

Please replace this source-text assertion with an executable routing test. It can pass even if the handler no longer reaches the resolver at runtime, and AGENTS.md explicitly prohibits source-reading tests.

@teknium1 teknium1 added the sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform label Jul 18, 2026
@teknium1 teknium1 added the area/compression Context compression and continuation sessions label Jul 19, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Fixed via #69312 (merged) — salvage of #64530 (first submitter) with the ack-semantics layer from #65838 folded in. Your PR independently identified and fixed the same inner-guard drop; credited in the merged PR body. Thanks for the fix!

@teknium1 teknium1 closed this Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/compression Context compression and continuation sessions comp/gateway Gateway runner, session dispatch, delivery needs-decision Awaiting maintainer decision before any implementation P2 Medium — degraded but workaround exists sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform 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.

Async delegation completion is dropped after context compression and marked delivered

4 participants