Skip to content

fix(harness): prevent missed wakeups during startup#1848

Open
HeadBro1 wants to merge 1 commit into
agentscope-ai:mainfrom
HeadBro1:fix/harness-wakeup-startup-drain
Open

fix(harness): prevent missed wakeups during startup#1848
HeadBro1 wants to merge 1 commit into
agentscope-ai:mainfrom
HeadBro1:fix/harness-wakeup-startup-drain

Conversation

@HeadBro1

Copy link
Copy Markdown

AgentScope-Java Version

2.0.0-SNAPSHOT

Description

WakeupDispatcher previously drained the durable wakeup queue before subscribing to the transient wakeup signal. A wakeup enqueued between those operations could remain queued until another signal arrived. Startup recovery also drained only one batch of 64 entries, so a larger backlog could remain unprocessed without a follow-up signal.

This PR:

  • subscribes to wakeup signals before performing the startup drain
  • continues draining full batches until the durable queue contains fewer than 64 entries
  • adds regression tests for the startup subscription window and a 65-entry backlog

Tested with:

mvn -pl agentscope-harness -am -Dtest=WakeupDispatcherTest -Dsurefire.failIfNoSpecifiedTests=false test

All 6 WakeupDispatcherTest tests pass.

Checklist

Please check the following items before code is ready to be reviewed.

  • Code has been formatted and passes Spotless checks
  • All tests are passing (mvn test) — targeted harness tests pass; the full suite was not run locally
  • Javadoc comments are complete and follow project conventions
  • Related documentation has been updated (no external documentation changes are required)
  • Code is ready for review

@HeadBro1 HeadBro1 requested a review from a team June 21, 2026 13:06
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


“caihr” seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@HeadBro1 HeadBro1 closed this Jun 21, 2026
@HeadBro1 HeadBro1 reopened this Jun 21, 2026
@HeadBro1

Copy link
Copy Markdown
Author

Reopening to retrigger CI after an unrelated transient JUnit temp-directory cleanup failure.

@HeadBro1 HeadBro1 closed this Jun 21, 2026
@HeadBro1 HeadBro1 reopened this Jun 21, 2026
@codecov

codecov Bot commented Jun 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.00000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...tscope/harness/agent/gateway/WakeupDispatcher.java 90.00% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@AgentScopeJavaBot AgentScopeJavaBot added bug Something isn't working area/harness agentscope-harness (test/runtime support) labels Jun 22, 2026

@AgentScopeJavaBot AgentScopeJavaBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI Review

This is a clean, well-targeted bug fix addressing two real race conditions in WakeupDispatcher.start():

  1. Subscribe-before-drain reorder: The old order (drain → subscribe) had a window where a wakeup enqueued after the drain but before the subscription could sit unprocessed until the next signal. The fix correctly subscribes first, then drains — the standard "subscribe-then-catchup" pattern.

  2. Full queue drain loop: The old code drained only one batch of 64 entries on startup. The fix loops until entries.size() < MAX_DRAIN_COUNT, ensuring backlogs larger than 64 are fully processed.

Both regression tests are well-designed: startup_subscribesBeforeInitialDrain uses a clever EnqueueOnSubscribeMessageBus to inject a wakeup at the exact moment of subscription, and initialDrain_processesMoreThanOneBatch pushes 65 entries to validate the loop fix. The code is correct, thread-safe (concurrent drain calls get disjoint entry sets; dispatch is idempotent via isSessionRunning guard), and introduces no new issues.

@AgentScopeJavaBot AgentScopeJavaBot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI Review

This is a clean, well-targeted bug fix addressing two real race conditions in WakeupDispatcher.start():

  1. Subscribe-before-drain reorder: The old order (drain → subscribe) had a window where a wakeup enqueued after the drain but before the subscription could sit unprocessed until the next signal. The fix correctly subscribes first, then drains — the standard "subscribe-then-catchup" pattern.

  2. Full queue drain loop: The old code drained only one batch of 64 entries on startup. The fix loops until entries.size() < MAX_DRAIN_COUNT, ensuring backlogs larger than 64 are fully processed.

Both regression tests are well-designed: startup_subscribesBeforeInitialDrain uses a clever EnqueueOnSubscribeMessageBus to inject a wakeup at the exact moment of subscription, and initialDrain_processesMoreThanOneBatch pushes 65 entries to validate the loop fix. The code is correct, thread-safe (concurrent drain calls get disjoint entry sets; dispatch is idempotent via isSessionRunning guard), and introduces no new issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/harness agentscope-harness (test/runtime support) bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants