Skip to content

Fix webhook timer reset behavior for more predictable delivery - #1192

Merged
tofarr merged 5 commits into
mainfrom
fix/webhook-timer-reset-behavior
Nov 19, 2025
Merged

tofarr merged 5 commits into
mainfrom
fix/webhook-timer-reset-behavior

Conversation

@tofarr

@tofarr tofarr commented Nov 18, 2025 •

Copy link
Copy Markdown
Collaborator

Problem

The WebhookSubscriber had a significant issue where the flush timer was reset every time a new event was received. This could cause indefinite delays in webhook delivery for conversations with steady but low activity, as the timer would continuously reset before it could fire.

Example of problematic behavior:

Event 1 → Timer starts (30s)
Event 2 (at 20s) → Timer resets (30s from now)  
Event 3 (at 25s) → Timer resets again (30s from now)
Result: Events could be delayed indefinitely

Solution

Modified the WebhookSubscriber.__call__ method to only start the timer if none exists, preventing constant resets.

New behavior:

Event 1 → Timer starts (30s)
Event 2 (at 20s) → Timer continues (10s remaining)
Event 3 (at 25s) → Timer continues (5s remaining)
Result: All events posted at 30s from Event 1

Changes

Code Changes

  • Modified WebhookSubscriber.__call__ method in conversation_service.py (lines 436-439)
  • Changed from: self._reset_flush_timer() (always reset timer)
  • Changed to: if self._flush_timer is None: self._reset_flush_timer() (only start timer if none exists)

Testing

  • Added comprehensive tests for new timer behavior:
    • test_timer_not_reset_on_subsequent_events: Verifies timer instance remains the same
    • test_timer_only_started_once_until_flush: Confirms timer is only started once per batch
    • test_timer_cancelled_when_buffer_full: Ensures proper timer cancellation
  • Updated existing test that relied on old timer reset behavior
  • All 36 existing webhook subscriber tests pass
  • All 36 conversation service tests pass

Benefits

  1. Predictable Maximum Latency: Events are now guaranteed to be posted within flush_delay seconds of the first event in a batch
  2. More Responsive Webhooks: No more indefinite delays in low-activity conversations
  3. Better User Experience: External monitoring systems receive more timely updates
  4. Maintains Efficiency: Still achieves optimal batching when events arrive quickly
  5. Backward Compatible: All existing functionality remains intact

Testing

# Run webhook subscriber tests
uv run pytest tests/agent_server/test_webhook_subscriber.py -v

# Run conversation service tests  
uv run pytest tests/agent_server/test_conversation_service.py -v

# Run pre-commit hooks
uv run pre-commit run --files openhands-agent-server/openhands/agent_server/conversation_service.py tests/agent_server/test_webhook_subscriber.py

This change directly addresses user complaints about unpredictable webhook delivery times while maintaining all existing functionality and improving the overall reliability of the webhook system.

@tofarr can click here to continue refining the PR


Agent Server images for this PR

• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server

Variants & Base Images

Variant Architectures Base Image Docs / Tags
java amd64, arm64 eclipse-temurin:17-jdk Link
python amd64, arm64 nikolaik/python-nodejs:python3.12-nodejs22 Link
golang amd64, arm64 golang:1.21-bookworm Link

Pull (multi-arch manifest)

# Each variant is a multi-arch manifest supporting both amd64 and arm64
docker pull ghcr.io/openhands/agent-server:d2f4735-python

Run

docker run -it --rm \
  -p 8000:8000 \
  --name agent-server-d2f4735-python \
  ghcr.io/openhands/agent-server:d2f4735-python

All tags pushed for this build

ghcr.io/openhands/agent-server:d2f4735-golang-amd64
ghcr.io/openhands/agent-server:d2f4735-golang_tag_1.21-bookworm-amd64
ghcr.io/openhands/agent-server:d2f4735-golang-arm64
ghcr.io/openhands/agent-server:d2f4735-golang_tag_1.21-bookworm-arm64
ghcr.io/openhands/agent-server:d2f4735-java-amd64
ghcr.io/openhands/agent-server:d2f4735-eclipse-temurin_tag_17-jdk-amd64
ghcr.io/openhands/agent-server:d2f4735-java-arm64
ghcr.io/openhands/agent-server:d2f4735-eclipse-temurin_tag_17-jdk-arm64
ghcr.io/openhands/agent-server:d2f4735-python-amd64
ghcr.io/openhands/agent-server:d2f4735-nikolaik_s_python-nodejs_tag_python3.12-nodejs22-amd64
ghcr.io/openhands/agent-server:d2f4735-python-arm64
ghcr.io/openhands/agent-server:d2f4735-nikolaik_s_python-nodejs_tag_python3.12-nodejs22-arm64
ghcr.io/openhands/agent-server:d2f4735-golang
ghcr.io/openhands/agent-server:d2f4735-java
ghcr.io/openhands/agent-server:d2f4735-python

About Multi-Architecture Support

  • Each variant tag (e.g., d2f4735-python) is a multi-arch manifest supporting both amd64 and arm64
  • Docker automatically pulls the correct architecture for your platform
  • Individual architecture tags (e.g., d2f4735-python-amd64) are also available if needed

openhands-agent and others added 2 commits November 18, 2025 17:28
Previously, the WebhookSubscriber would reset its flush timer every time
a new event was received. This could cause indefinite delays in webhook
delivery for conversations with steady but low activity, as the timer
would keep getting reset before it could fire.

Changes:
- Modified WebhookSubscriber.__call__ to only start timer if none exists
- Timer is no longer reset when new events arrive
- Provides predictable maximum latency equal to flush_delay
- Improves responsiveness for real-time monitoring systems

Updated tests:
- Added comprehensive tests for new timer behavior
- Updated existing test that relied on old timer reset behavior
- All existing functionality remains intact

This addresses user complaints about unpredictable webhook delivery times
while maintaining efficient batching when events arrive quickly.

Co-authored-by: openhands <openhands@all-hands.dev>
@github-actions

github-actions Bot commented Nov 18, 2025 •

Copy link
Copy Markdown
Contributor

Coverage

Coverage Report •
FileStmtsMissCoverMissing
openhands-agent-server/openhands/agent_server
   config.py56394%23, 30, 150
   conversation_service.py28817539%63, 66, 77–78, 81–84, 86, 90, 92, 95–102, 105–106, 109–113, 116–118, 120–123, 125, 132–133, 135–137, 140, 144, 146, 148, 155, 161, 169, 184, 188–190, 193, 199, 202, 213–217, 219–222, 225–230, 233–236, 238–240, 243–245, 250–253, 261, 266–268, 282–286, 289, 291, 294–296, 298, 302, 306, 313–317, 320–321, 327–332, 338–340, 358, 382, 430, 432, 434–437, 442, 444–445, 449–450, 452–453, 456–458, 461, 467, 472–475, 482–483, 487–491, 493, 498, 502–504, 508–509, 511–513, 515, 517, 530–532, 535, 538, 541–544, 551–552, 556–558, 561–562, 564
TOTAL12134555854% 

@openhands-ai

openhands-ai Bot commented Nov 18, 2025

Copy link
Copy Markdown

Looks like there are a few issues preventing this PR from being merged!

  • GitHub Actions are failing:
    • Run tests
    • Pre-commit checks

If you'd like me to help, just leave a comment, like

@OpenHands please fix the failing actions on PR #1192 at branch `fix/webhook-timer-reset-behavior`

Feel free to include any additional details that might help me get this PR into a better state.

You can manage your notification settings

@tofarr
tofarr marked this pull request as ready for review November 19, 2025 08:40

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

Thank you! 🙏

@tofarr
tofarr merged commit f70b945 into main Nov 19, 2025
@tofarr
tofarr deleted the fix/webhook-timer-reset-behavior branch November 19, 2025 09:25
StressTestor pushed a commit to StressTestor/software-agent-sdk that referenced this pull request Jun 1, 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.

3 participants