Repository navigation
Conversation
OpenHands#4689 made streaming deltas opt-in for PubSub subscribers, and _EventSubscriber does not opt in. A long streamed completion therefore stops refreshing the runtime idle clocks, and the runtime-api can reap the pod mid-stream even though a client is actively receiving tokens. Opt _EventSubscriber into streaming deltas and refresh the idle clocks on deltas at a throttled 30s cadence, mirroring the ACP activity heartbeat, so token-rate events cannot wedge the idle timers while avoiding per-token writes. Durable events keep the immediate reset. Fixes OpenHands#4695 Signed-off-by: King Star <mcxin.y@gmail.com>
Author
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.
HUMAN:
AGENT:
Why
#4689 made streaming deltas opt-in for PubSub subscribers (
pub_sub.pyfiltersStreamingDeltaEventto subscribers withreceives_streaming_deltas=True)._EventSubscriber— the subscriber that refreshes the runtime idle clocks — does not opt in, so token deltas stopped reaching it. A completion that streams longer than the injected idle threshold, producing no durable event, no longer refreshesidle_time, and the runtime-api can reap the pod mid-stream. The ACP path already has a heartbeat for exactly this reason (_setup_acp_activity_heartbeat); the standard streaming path lost its equivalent silently.Summary
_EventSubscriberinto streaming deltas (receives_streaming_deltas = True) so token-rate events reach it again.service.touch()) every time, and reset the shared runtime clocks (service.stored.updated_at,update_last_execution_time()) at most once per 30s — the same cadence as the ACP_maybe_signal_activityheartbeat — avoiding per-token writes.ConversationStateUpdateEventskip.The throttle state lives on the subscriber instance and the cadence is a module constant (
_DELTA_ACTIVITY_SIGNAL_INTERVAL); when #4671 moves deltas off the shared bus, the opt-in and this handler are the single place to migrate, so the heartbeat is not lost a second time.Issue Number
Fixes #4695
How to Test
Four regressions:
test_subscriber_receives_streaming_deltas— a delta published on a realPubSubreaches_EventSubscriberand fires one idle-clock reset (fails onmain, where PubSub filters the delta out before it reaches the subscriber).test_delta_resets_are_throttled— within the 30s window further deltas do not re-fire the shared-clock reset (11 deltas → 1 reset, 12touch()calls); a delta arriving after the window fires exactly once.test_delta_within_threshold_keeps_idle_time_below_it— a simulated 25-minute token stream (deltas every 10s, no durable event) produces resets never more than one 30s interval apart, keepingidle_timewell below the ~20 min pod-reap threshold.test_durable_event_resets_immediately— durable events still reset immediately, even right after a delta reset.Also ran the surrounding suites:
uv run pytest tests/agent_server/test_conversation_service.py tests/agent_server/test_conversation_eviction.py— 120 passed; the single failure (test_start_conversation_with_worktree_ignores_non_git_workspace) fails identically on a clean checkout ofmainand is unrelated (worktree/git environment sensitivity).Video/Screenshots
N/A — server-side behavior verified by the regressions above.
Type
Notes
touch()is a single monotonic write per conversation; the shared-clock writes are the throttled part._ACTIVITY_SIGNAL_INTERVALinacp_agent.py; this PR defines the server-side constant locally (_DELTA_ACTIVITY_SIGNAL_INTERVAL = 30.0) rather than importing an SDK-agent private, to keep the dependency direction clean.