Skip to content

fix(gateway): salvage stale-output/typing interrupt handling#12494

Merged
kshitijk4poor merged 3 commits into
mainfrom
salvage/helix4u-gateway-interrupt
Apr 19, 2026
Merged

fix(gateway): salvage stale-output/typing interrupt handling#12494
kshitijk4poor merged 3 commits into
mainfrom
salvage/helix4u-gateway-interrupt

Conversation

@kshitijk4poor

Copy link
Copy Markdown
Collaborator

Summary

  • salvages helix4u's gateway interrupt/typing-loop fix from fix(gateway): stop typing loops on session interrupt #12388 onto current main
  • preserves the original contributor commits and adds one current-main follow-up commit to address review findings
  • fixes stale commentary/tool-progress/typing leakage after /stop or /new

What this fixes

This PR hardens the gateway interrupt path so old runs cannot keep leaking output after they are invalidated:

  • generation invalidation now drops stale results safely
  • adapter typing keepalive listens to session interruption and stops at the source
  • control interrupt messages are filtered so they are not recycled as follow-up user input

Current-main follow-up fixes included

On top of the original PR, this salvage fixes the review findings:

  • deferred post-delivery callbacks are now generation-aware end-to-end, so stale runs cannot clear callbacks registered by a fresher run for the same session
  • callback ownership is bound to the active session event at run start and snapshotted inside base adapter processing, avoiding the shared-event mutation race
  • proxy mode now receives run_generation and drops stale proxy streams/final results too
  • stop/new interrupt cleanup is centralized into one helper instead of being duplicated across multiple branches
  • internal control interrupt reason strings use shared constants
  • removed the return from BasePlatformAdapter._process_message_background()'s finally block so cleanup no longer swallows cancellation/exception flow
  • added focused regressions for generation forwarding, proxy stale suppression, and newer-callback preservation

Files changed

  • gateway/platforms/base.py
  • gateway/run.py
  • tests/gateway/test_pending_event_none.py
  • tests/gateway/test_run_progress_topics.py
  • tests/gateway/test_session_race_guard.py
  • tests/gateway/test_status_command.py
  • tests/gateway/test_proxy_mode.py

Verification

Focused gateway suite:

  • scripts/run_tests.sh tests/gateway/test_base_topic_sessions.py tests/gateway/test_run_progress_topics.py tests/gateway/test_session_race_guard.py tests/gateway/test_pending_event_none.py tests/gateway/test_status_command.py tests/gateway/test_plan_command.py tests/gateway/test_proxy_mode.py -q
  • result: 81 passed

Syntax/smoke:

  • py_compile gateway/run.py
  • py_compile gateway/platforms/base.py
  • py_compile tests/gateway/test_status_command.py
  • py_compile tests/gateway/test_proxy_mode.py

Contributor credit

This PR cherry-picks helix4u's original commits from #12388 so rebase-merge preserves their authorship in git history.

helix4u and others added 3 commits April 19, 2026 14:37
Follow-up on top of the helix4u #12388 cherry-picks:
- make deferred post-delivery callbacks generation-aware end-to-end so
  stale runs cannot clear callbacks registered by a fresher run for the
  same session
- bind callback ownership to the active session event at run start and
  snapshot that generation inside base adapter processing so later event
  mutation cannot retarget cleanup
- pass run_generation through proxy mode and drop stale proxy streams /
  final results the same way local runs are dropped
- centralize stop/new interrupt cleanup into one helper and replace the
  open-coded branches with shared logic
- unify internal control interrupt reason strings via shared constants
- remove the return from base.py's finally block so cleanup no longer
  swallows cancellation/exception flow
- add focused regressions for generation forwarding, proxy stale
  suppression, and newer-callback preservation

This addresses all review findings from the initial #12388 review while
keeping the fix scoped to stale-output/typing-loop interrupt handling.
@kshitijk4poor kshitijk4poor merged commit 4b6ff0e into main Apr 19, 2026
3 of 5 checks passed
@kshitijk4poor kshitijk4poor deleted the salvage/helix4u-gateway-interrupt branch April 19, 2026 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants