Skip to content

fix: wake runtime for blocked WorkItem rechecks#1375

Merged
jolestar merged 5 commits into
mainfrom
issue-1356
May 23, 2026
Merged

fix: wake runtime for blocked WorkItem rechecks#1375
jolestar merged 5 commits into
mainfrom
issue-1356

Conversation

@jolestar

Copy link
Copy Markdown
Collaborator

Summary

  • wake the run loop at the next blocked WorkItem recheck_at deadline instead of sleeping indefinitely until external input
  • project the idle sleep state with the next recheck deadline so the agent state reflects the durable wake target
  • add storage lookup for the earliest unconsumed blocked WorkItem recheck and a regression test that waits for runtime idle wake behavior

Closes #1356

Verification

  • cargo fmt --all -- --check
  • cargo test recheck -- --nocapture
  • RUSTFLAGS="-D warnings" cargo check --all-targets

Copilot AI review requested due to automatic review settings May 23, 2026 06:27
@vercel

vercel Bot commented May 23, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
holon Ready Ready Preview, Comment May 23, 2026 3:16pm

Copilot AI 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.

Pull request overview

This PR fixes a runtime scheduling bug where blocked WorkItems with a recheck_at deadline could fail to wake the run loop after the deadline, leaving work stuck until external input arrives. It adds a storage query for the next unconsumed blocked recheck deadline, uses that to bound idle sleeping, and adds a regression test asserting the runtime wakes and emits a recheck tick.

Changes:

  • Add AppStorage::next_blocked_work_item_recheck_at to find the earliest unconsumed recheck_at for blocked Open WorkItems for an agent.
  • Update the runtime idle loop to sleep until the next blocked recheck deadline (or until a notify), and project sleeping_until into agent state.
  • Add a regression test ensuring the runtime emits a work_item_recheck tick and consumes the recheck without external input.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/storage.rs Adds lookup for earliest unconsumed blocked WorkItem recheck_at deadline.
src/runtime/memory_refresh.rs Exposes the storage lookup via RuntimeHandle for use by the run loop.
src/runtime.rs Bounds idle waiting by the next recheck deadline using tokio::select!(notify, sleep).
src/runtime/scheduler_executor.rs Extends idle→sleep transition to accept/projection of sleeping_until.
src/runtime/tests/work_items.rs Adds regression test for deadline-based wake + recheck consumption.
src/runtime/tests/runtime_state.rs Updates test callsite for the new idle→sleep transition signature.
Comments suppressed due to low confidence (1)

src/runtime/scheduler_executor.rs:236

  • transition_run_loop_idle_to_sleep returns None when the agent is already Asleep, so sleeping_until will not be updated in the persisted AgentState even if a new earlier/later blocked WorkItem recheck deadline is discovered after a wake (e.g., work_item_* APIs call notify_one() without changing status to AwakeIdle). Consider allowing this transition to refresh sleeping_until while already asleep (or add a dedicated ‘update sleeping_until’ path) so operator/UI state reflects the durable wake target.
        let mut guard = self.runtime.inner.agent.lock().await;
        if matches!(
            guard.state.status,
            AgentStatus::Asleep | AgentStatus::Stopped
        ) || !guard.queue.is_empty()
        {
            return Ok(None);
        }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/runtime.rs
@holonbot

holonbot Bot commented May 23, 2026

Copy link
Copy Markdown
Contributor

Holon Run Report

@jolestar

Copy link
Copy Markdown
Collaborator Author

Blocking review note (cannot submit a formal Request Changes review on an own-authored PR):

Thanks for the fix and for addressing the zero-duration overflow case. Current-head CI is green, but I found one remaining contract issue before merge.

transition_run_loop_idle_to_sleep(next_recheck_at) still returns None whenever the persisted agent status is already Asleep. That means if the runtime is already asleep and a blocked WorkItem recheck deadline is added or changed via a wake/notify path, the run loop will correctly use the newly computed timer in memory, but the persisted AgentState.sleeping_until is not refreshed. This leaves operator/UI state showing no/old durable wake target even though the runtime is now sleeping until a different recheck deadline.

Because this PR explicitly adds idle sleep projection for the next blocked recheck deadline, please update the already-asleep path to refresh sleeping_until when appropriate (while still refusing stopped/non-empty-queue transitions), and add/adjust coverage for the already-asleep + changed recheck deadline case.

@jolestar

Copy link
Copy Markdown
Collaborator Author

Addressed the final blocking note in 646e497. transition_run_loop_idle_to_sleep now only refuses stopped agents or non-empty queues, so an already-asleep runtime can re-project and persist the updated sleeping_until deadline while preserving the stopped/queue gates. Added run_loop_idle_sleep_refreshes_sleeping_until_when_already_asleep to cover the already-asleep + changed deadline case. Re-verified with cargo fmt --all -- --check, cargo test run_loop_idle_sleep_refreshes_sleeping_until_when_already_asleep -- --nocapture, cargo test recheck -- --nocapture, and RUSTFLAGS="-D warnings" cargo check --all-targets.

@jolestar

Copy link
Copy Markdown
Collaborator Author

Fixed the CI regression in the new idle sleep projection. The run loop now preserves an existing timed Sleep deadline when re-projecting an already-asleep agent without a work-item recheck deadline, so session-local sleep wake tasks do not become stale. Added run_loop_idle_sleep_preserves_existing_timed_sleep_when_no_recheck.\n\nVerification:\n- cargo test run_once --test run_once\n- cargo test recheck -- --nocapture\n- cargo fmt --all -- --check\n- RUSTFLAGS="-D warnings" cargo check --all-targets

@vercel vercel Bot requested a deployment to Preview May 23, 2026 15:16 Abandoned
@jolestar jolestar merged commit c19da17 into main May 23, 2026
5 checks passed
@jolestar jolestar deleted the issue-1356 branch May 23, 2026 15:23
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: blocked WorkItem recheck_after did not wake agent after deadline

2 participants