Skip to content

fix(heartbeat): serialize wake lifecycle state - #116351

Merged
steipete merged 4 commits into
mainfrom
codex/autoqa-heartbeat-20260730
Jul 30, 2026
Merged

steipete merged 4 commits into
mainfrom
codex/autoqa-heartbeat-20260730

Conversation

@steipete

@steipete steipete commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes three heartbeat lifecycle races: the same canonical session could run concurrently when callers supplied different agent/session tuple shapes, an unscoped immediate wake could overlap or starve behind targeted work instead of acting as a barrier, and stopping the heartbeat runner did not cancel active provider work.

Why This Change Was Made

Heartbeat scheduling now derives one session-first target identity, gives immediate global wakes an enqueue cutoff that separates pre-barrier from post-barrier work, and tears down active work by handler generation so stale disposers cannot cancel replacements. This is an AI-assisted change from a maintainer QA campaign.

User Impact

Operators no longer get duplicate concurrent turns for one session, global wake requests cannot be indefinitely postponed by newer targeted work, and Gateway shutdown stops active heartbeat turns before their dependencies disappear.

Evidence

@openclaw-barnacle openclaw-barnacle Bot added size: M maintainer Maintainer-authored PR labels Jul 30, 2026
@steipete
steipete marked this pull request as ready for review July 30, 2026 10:22
@steipete steipete self-assigned this Jul 30, 2026
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Jul 30, 2026
@clawsweeper

clawsweeper Bot commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 30, 2026, 7:42 AM ET / 11:42 UTC.

ClawSweeper review

What this changes

This PR splits heartbeat wake coordination into contracts, target-ordering, and lifecycle helpers so one canonical session is serialized, global immediate wakes create ordered barriers, and runner shutdown aborts active wake work.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

Keep this PR open for maintainer review. It addresses credible heartbeat scheduling and shutdown races with focused concurrency regressions and no concrete patch defect identified from the supplied final diff, but it carries the protected maintainer label and remains behind current main, so it should not enter automated cleanup or closure.

Priority: P1
Reviewed head: 5c5fd3fa56b8a64b882df923bb6f8f5a912639f8

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is a focused, well-tested core concurrency repair with no discrete correctness finding from the supplied final diff, pending maintainer review of the current merge result.
Proof confidence 🌊 off-meta tidepool Not applicable: The protected maintainer label makes the external-contributor real-behavior-proof gate inapplicable; the PR body’s focused remote test evidence remains useful supplemental validation.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The protected maintainer label makes the external-contributor real-behavior-proof gate inapplicable; the PR body’s focused remote test evidence remains useful supplemental validation.
Evidence reviewed 5 items Protected maintainer handling: The supplied PR state includes the protected maintainer label and an assignment to steipete; repository policy requires this item to remain open for explicit maintainer handling rather than automated cleanup.
Target serialization boundary: The new target-key helper gives a non-empty canonical session key precedence over a redundant agent id, preventing one session from splitting into concurrent target groups.
Lifecycle cancellation boundary: The new lifecycle helper carries an AbortSignal through AsyncLocalStorage into the existing reply cancellation contract and aborts active targets only for the retired handler generation.
Findings None None.
Security None None.

How this fits together

Heartbeat wake requests arrive from timers, tasks, manual commands, and Gateway events, then the heartbeat coordinator decides their target ordering before a runner starts provider-backed work. This PR changes the coordinator’s session identity, barrier ordering, and cancellation propagation so active work is stopped safely when the runner or handler lifecycle ends.

flowchart LR
  A[Timers, tasks, manual requests, and events] --> B[Heartbeat wake requests]
  B --> C[Canonical session target grouping]
  C --> D[Global barrier ordering]
  D --> E[Abortable wake lifecycle]
  E --> F[Heartbeat runner]
  F --> G[Provider-backed heartbeat turn]
  G --> H[Session result or shutdown]
Loading

Before merge

  • Add real behavior proof - Not applicable: The protected maintainer label makes the external-contributor real-behavior-proof gate inapplicable; the PR body’s focused remote test evidence remains useful supplemental validation.
  • Resolve merge risk (P1) - This is a core ordering and cancellation change: a missed wake class or incorrect replacement-generation boundary could still cause duplicate session work, starvation, or a heartbeat turn that outlives shutdown.
  • Resolve merge risk (P1) - GitHub reports the branch as mergeable but behind current main; refresh the final review against the current merge result before landing, without assuming the base drift itself creates a defect.
  • Complete next step (P2) - Protected maintainer handling and current-main refresh are the remaining actions; no narrow automated repair is identified.
Agent review details

Security

None.

PR surface

Source +193, Tests +253. Total +446 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 5 320 127 +193
Tests 3 263 10 +253
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 583 137 +446

Review metrics

None.

Merge-risk options

Maintainer options:

  1. Refresh against current main (recommended)
    Review the clean three-way merge result and retain the focused serialization, barrier, and stop-cancellation regressions before merging.
  2. Pause for broader scheduler audit
    Pause this PR if maintainers believe target identity or handler-generation ownership needs a wider heartbeat scheduling design decision.

Technical review

Best possible solution:

Land the bounded coordinator refactor only after maintainer review confirms its target identity and generation-cancellation semantics against the current merge result, retaining the focused regressions as the contract for future scheduler changes.

Do we have a high-confidence way to reproduce the issue?

Do we have a high-confidence way to reproduce the issue? Source-reproducible with medium confidence: the added focused tests encode the reported duplicate-target, barrier, and cancellation races, but this read-only review did not independently execute a failing current-main reproduction.

Is this the best way to solve the issue?

Is this the best way to solve the issue? Yes, provisionally: serialization and cancellation belong at the shared heartbeat wake coordinator rather than in individual callers, and the extracted target and lifecycle helpers make those invariants explicit.

AGENTS.md: unclear because the file could not be read completely.

Codex review notes: model internal, reasoning high; reviewed against fb6545738564.

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.

Label justifications:

  • P1: The change addresses active runtime races that can duplicate heartbeat turns or leave provider work running during shutdown.
  • merge-risk: 🚨 session-state: Canonical target grouping and global-barrier ordering determine whether heartbeat work for a session overlaps or is sequenced correctly.
  • merge-risk: 🚨 availability: Aborting active wake work on runner stop or handler replacement can affect shutdown completion and ongoing provider work.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The protected maintainer label makes the external-contributor real-behavior-proof gate inapplicable; the PR body’s focused remote test evidence remains useful supplemental validation.

Evidence

What I checked:

  • Protected maintainer handling: The supplied PR state includes the protected maintainer label and an assignment to steipete; repository policy requires this item to remain open for explicit maintainer handling rather than automated cleanup. (5c5fd3fa56b8)
  • Target serialization boundary: The new target-key helper gives a non-empty canonical session key precedence over a redundant agent id, preventing one session from splitting into concurrent target groups. (src/infra/heartbeat-wake-target.ts:17, 5c5fd3fa56b8)
  • Lifecycle cancellation boundary: The new lifecycle helper carries an AbortSignal through AsyncLocalStorage into the existing reply cancellation contract and aborts active targets only for the retired handler generation. (src/infra/heartbeat-wake-lifecycle.ts:15, 5c5fd3fa56b8)
  • Focused regression coverage: The supplied PR diff adds coverage for already-aborted runner ownership, manual-stop listener cleanup, active-wake cancellation, canonical-session serialization, and barrier ordering; the PR body reports focused 84/84 and 11/11 remote runs. (src/infra/heartbeat-wake-concurrency.test.ts:1, 5c5fd3fa56b8)
  • Review continuity: The latest completed ClawSweeper review at 857ab51 reported no actionable findings; the final commit extracts contracts without changing the stated scheduler behavior. (src/infra/heartbeat-wake-contracts.ts:1, 5c5fd3fa56b8)

Likely related people:

  • steipete: The supplied timeline assigns this PR to steipete, and all four supplied commits on the heartbeat coordination change are authored by steipete. (role: current assignee and recent area contributor; confidence: medium; commits: 852c24997264, 764d02768ecb, 857ab517dc72; files: src/infra/heartbeat-wake.ts, src/infra/heartbeat-wake-lifecycle.ts, src/infra/heartbeat-wake-target.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Refresh the final maintainer review against current main and allow the remaining exact-head checks to complete.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (3 earlier review cycles)
  • reviewed 2026-07-30T10:25:48.886Z sha 852c249 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-30T10:47:30.953Z sha 764d027 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-30T11:15:13.518Z sha 857ab51 :: needs real behavior proof before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Jul 30, 2026
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Jul 30, 2026
@steipete
steipete merged commit 7dd75d0 into main Jul 30, 2026
130 of 132 checks passed
@steipete
steipete deleted the codex/autoqa-heartbeat-20260730 branch July 30, 2026 11:58
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Jul 30, 2026
* origin/main: (99 commits)
  docs(automation): rename scheduled-tasks feature wording to Automations (#114855)
  feat(ui): finish cron -> Automations rename in visible strings (#114853)
  feat(cli): add openclaw automations alias and reword cron display prose (#114854)
  feat(agents): rename scheduler agent tool cron -> automations (#114841)
  fix(tui): preserve session state across switches and reconnects (#116399)
  feat(agents): report CLI command outcomes in channel progress
  fix(cli): preserve explicit option intent (#116389)
  fix(release): trust update restart harness (#116301)
  test(reef): remove false-green live guard smoke (#116393)
  test(comfy): evaluate live guards after setup (#116388)
  fix(heartbeat): serialize wake lifecycle state (#116351)
  test: remove redundant extension boundary wrapper (#116385)
  fix(test): bound Testbox agentic and extension suites (#115696)
  fix(ui): show the correct Threads page size (#116349)
  test(discord): align progress timing expectations (#116377)
  feat(ui): add composable skill references (#116330)
  fix(qa): prevent Slack cleanup from stalling profile runs (#116361)
  fix(ci): validate frozen release candidates faithfully (#116357)
  improve(ci): fail_fast option for release validation, off by default (#116352)
  fix(agents): compare shell tool names case-insensitively and stop re-parsing tool labels
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 31, 2026
* fix(heartbeat): serialize wake lifecycle state

* style(heartbeat): format wake scheduler

* refactor(heartbeat): split wake coordination

* refactor(heartbeat): extract wake contracts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant