Skip to content

fix(agent-server): refresh idle clocks on streaming deltas - #4706

Closed
jstar0 wants to merge 1 commit into
OpenHands:mainfrom
jstar0:fix/4695-delta-activity-heartbeat
Closed

jstar0 wants to merge 1 commit into
OpenHands:mainfrom
jstar0:fix/4695-delta-activity-heartbeat

Conversation

@jstar0

@jstar0 jstar0 commented Aug 29, 2026

Copy link
Copy Markdown

HUMAN:


AGENT:

Why

#4689 made streaming deltas opt-in for PubSub subscribers (pub_sub.py filters StreamingDeltaEvent to subscribers with receives_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 refreshes idle_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

  • Opt _EventSubscriber into streaming deltas (receives_streaming_deltas = True) so token-rate events reach it again.
  • On a delta: refresh the per-conversation eviction clock (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_activity heartbeat — avoiding per-token writes.
  • Durable (non-delta) events keep the exact previous immediate-reset behavior, including the ConversationStateUpdateEvent skip.

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

uv run pytest tests/agent_server/test_event_subscriber_activity.py -v

Four regressions:

  • test_subscriber_receives_streaming_deltas — a delta published on a real PubSub reaches _EventSubscriber and fires one idle-clock reset (fails on main, 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, 12 touch() 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, keeping idle_time well 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 of main and is unrelated (worktree/git environment sensitivity).

Video/Screenshots

N/A — server-side behavior verified by the regressions above.

Type

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

Notes

  • Per-token touch() is a single monotonic write per conversation; the shared-clock writes are the throttled part.
  • The issue's acceptance criteria asked for the reset to be throttled like _ACTIVITY_SIGNAL_INTERVAL in acp_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.

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>
@jstar0

jstar0 commented Oct 5, 2026

Copy link
Copy Markdown
Author

Closing this duplicate: issue #4695 is closed as completed and is covered by the merged PR #4790, which restores the throttled runtime heartbeat for streamed deltas and adds regression coverage.

@jstar0 jstar0 closed this Oct 5, 2026
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.

[Bug]: token deltas no longer reset the runtime idle timer, so a long stream can have its pod reaped

1 participant