Skip to content

fix(compression): let explicit interrupts cancel safely (salvage #74449) - #76647

Merged
kshitijk4poor merged 2 commits into
NousResearch:mainfrom
kshitijk4poor:salvage/compression-interrupt
Aug 2, 2026
Merged

fix(compression): let explicit interrupts cancel safely (salvage #74449)#76647
kshitijk4poor merged 2 commits into
NousResearch:mainfrom
kshitijk4poor:salvage/compression-interrupt

Conversation

@kshitijk4poor

@kshitijk4poor kshitijk4poor commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

Makes interrupt-protected context compression cancellable by an explicit user or lifecycle stop (Ctrl+C, /stop, gateway shutdown), without weakening protection against ordinary incoming messages, voice interjections, or active-turn redirects.

The bug: context compression held the session compression lease while generating its handoff summary. When the user pressed Ctrl+C, interrupt protection kept the summary worker alive after the frontend's grace period. The CLI accepted another turn while that worker still held the lease, and the next persistence operation failed with session storage could not be written.

Based on #74449 by @suparious, cherry-picked with authorship preserved.

Rebase onto current main (2026-08-02)

Rebased onto latest main (was 51 commits behind, CONFLICTING). Repairs made during the rebase — the previous head carried stale-base revert hunks that this update removes:

  • restored the message.react RPC handler (7d92056), the kanban session deny-list (e41d202), and the include_row_ids / queued-prompt-generation fixes (d508585) in tui_gateway/methods_session.py — the intrinsic diff there is now only the intended 6-line hard-interrupt change
  • restored BedrockAuxiliaryClient.close() (main's _close_cached_client shutdown path calls it)
  • resolved gateway/run.py _interrupt_and_clear_session in favor of main's process-reaper flow + request_hard_interrupt

Changes

  • agent/interrupt_compat.py (new): request_hard_interrupt() — feature-detected hard_interrupt() with legacy interrupt() fallback (getattr_static so MagicMock/RPC proxies don't fabricate support)
  • agent/auxiliary_client.py: AuxiliaryExplicitCancellation (BaseException), _run_protected_sync_provider_call (daemon worker isolation for protected calls only), _AuxiliaryCancellationDecision (atomic cancel/timeout linearization)
  • agent/context_compressor.py: try/except around _generate_summary, _last_cooldown_refresh_was_authoritative for rollback
  • agent/conversation_compression.py: CompressionCommitFence cancel admission, full rollback path (transcript, compressor state, cooldown, lease)
  • run_agent.py: hard_interrupt() method, _hard_interrupt_requested Event, per-agent fence registration
  • cli.py, gateway/run.py, acp_adapter/server.py, cron/scheduler.py, tools/delegate_tool.py, tui_gateway/: propagate request_hard_interrupt through all stop surfaces
  • hermes_state.py: raw cooldown row get/restore for exact rollback (the active getter filters expired rows and cannot serve as a lossless rollback source)
  • Follow-up commit: gateway/run.py _abandon_timed_out_gateway_turn (landed on main after this PR's base, eb4772e) widened to the same hard-stop semantics as every other inactivity-timeout surface in this change

Validation

Result
PR tests 174 passed
tests/agent -k compress/interrupt/auxiliary 657 passed
tests/run_agent 1311 passed (1 failure reproduces on clean upstream/main — pre-existing)
tests/tui_gateway 327 passed
Mutation check (revert auxiliary_client.py to main) 12/13 new tests fail → tests bind the fix
E2E smoke (real AIAgent + SessionDB, worktree imports) cancel unblocks in 0.017s, lease released, session writable, shared client untouched
ruff clean

Closes #74449

@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/cli CLI entry point, hermes_cli/, setup wizard comp/gateway Gateway runner, session dispatch, delivery comp/tui Terminal UI (ui-tui/ + tui_gateway/) comp/acp Agent Communication Protocol adapter comp/cron Cron scheduler and job management tool/delegate Subagent delegation area/compression Context compression and continuation sessions P1 High — major feature broken, no workaround 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 sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades labels Aug 2, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Related: #74449 is the open predecessor. This current-head salvage preserves its explicit-stop compression repair while resolving current-main conflicts in the pre-LLM feasibility and TUI interrupt paths; review should choose the current salvage versus the now-dirty predecessor.

@kshitijk4poor
kshitijk4poor force-pushed the salvage/compression-interrupt branch from 11ea844 to faa0cc9 Compare August 2, 2026 07:12
suparious and others added 2 commits August 2, 2026 21:47
Makes interrupt-protected context compression cancellable by an explicit
user or lifecycle stop, without weakening protection against ordinary
incoming messages, voice interjections, or active-turn redirects.

Separates explicit hard cancellation from ordinary interrupt/redirect
state with a dedicated threading.Event; introduces
AuxiliaryExplicitCancellation as an attempt-local frozen-cause signal;
isolates the synchronous provider callback in a bounded daemon worker
during protected compression; atomically linearizes Codex timeout
cleanup against explicit cancellation; propagates hard cancellation
through child agents and explicit stop surfaces; serializes hard-cancel
admission against compression commit admission with
CompressionCommitFence; aborts before session rotation or late DB commit,
restores in-place transcript mutations and compressor state, and releases
the heartbeat and compression lease.

Based on NousResearch#74449 by @suparious. Resolved merge conflicts in
agent/context_compressor.py (feasibility check + try/except) and
tui_gateway/methods_session.py.
_abandon_timed_out_gateway_turn landed on main (eb4772e) after this
PR's base and still used the soft interrupt(). Every other inactivity-
timeout surface in this change (cron, gateway executor poll, delegate
children) treats a timeout as an explicit stop that may cancel a
protected compression summary — widen the same fix to this sibling.
@kshitijk4poor
kshitijk4poor force-pushed the salvage/compression-interrupt branch from faa0cc9 to 513fc96 Compare August 2, 2026 16:41
@kshitijk4poor
kshitijk4poor enabled auto-merge (rebase) August 2, 2026 16:42
@kshitijk4poor
kshitijk4poor merged commit 4ea379c into NousResearch:main Aug 2, 2026
35 checks passed
@kshitijk4poor
kshitijk4poor deleted the salvage/compression-interrupt branch August 5, 2026 07:08
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/acp Agent Communication Protocol adapter comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/cli CLI entry point, hermes_cli/, setup wizard comp/cron Cron scheduler and job management comp/gateway Gateway runner, session dispatch, delivery comp/tui Terminal UI (ui-tui/ + tui_gateway/) needs-decision Awaiting maintainer decision before any implementation P1 High — major feature broken, no workaround sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades 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.

3 participants