Repository navigation
fix(heartbeat): deliver Android notification wakes when heartbeat.every is 0m - #166522
Conversation
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The node notifications.changed handler requests its wake as notifications-event/event/notifications-event, but the unscheduled-wake policy only admitted the immediate/"wake" shape used by system events and cron. With heartbeat.every "0m" both admission gates rejected the wake. Closes openclaw#166508 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed October 7, 2026, 5:06 AM ET / 09:06 UTC (Revision 2). ClawSweeper reviewWhat this changesThe PR allows targeted Android notification events to start an agent turn when recurring heartbeats are disabled and adds a scheduler regression case. Merge readiness✅ Ready for maintainer review This PR remains useful: current main and the latest release still reject the notification producer's wake shape. The added Gateway trace resolves the previous behavior-proof gap, and no blocking patch defect was found. Priority: P2 Review scores
Verification
How this fits togetherAndroid nodes send notification events to the Gateway, which queues them for a session and requests a heartbeat wake. Shared heartbeat admission decides whether that wake can reach agent execution without enabling a recurring schedule. flowchart TD
A[Android notification event] --> B[Gateway node event handler]
B --> C[Session event queue]
B --> D[Targeted wake admission]
E[Heartbeat configuration] --> D
D --> F[Scheduler and busy guards]
C --> G[Agent turn]
F --> G
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +5, Tests +7. Total +12 across 2 files. View PR surface stats
Review metricsNone. Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Technical reviewBest possible solution: Keep one shared admission policy that accepts the native notification producer's exact targeted shape while preserving existing scheduling and execution guards. Do we have a high-confidence way to reproduce the issue? Yes: current-main source clearly rejects the notification handler's event-shaped request with 0m cadence, and the contributor supplies a matching before/after Gateway trace. This reviewer did not execute a reproduction. Is this the best way to solve the issue? Yes: extending the existing shared predicate repairs both admission gates without changing producer semantics or adding another execution path. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against efcb55c85364. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
|
Merged via squash.
|
…ry is 0m (openclaw#166522) * test(heartbeat): cover node notification wakes with disabled cadence * fix(heartbeat): deliver node notification wakes with disabled cadence The node notifications.changed handler requests its wake as notifications-event/event/notifications-event, but the unscheduled-wake policy only admitted the immediate/"wake" shape used by system events and cron. With heartbeat.every "0m" both admission gates rejected the wake. Closes openclaw#166508 Co-authored-by: Jay Zhou <[email protected]>
Closes #166508
What Problem This Solves
Fixes: Android notification events queue for the agent but never start a turn when
heartbeat.everyis"0m".User Impact
User impact: with recurring heartbeats turned off, a posted or removed Android notification now wakes its target session once, as the heartbeat docs already promise for targeted event wakes. No recurring schedule is created.
Why This Change Was Made
The
notifications.changednode handler requests its wake asnotifications-eventwith intenteventand reasonnotifications-event.isTargetedUnscheduledWakeadmittednotifications-eventonly in theimmediate+"wake"shape thatsystem.eventand cron notifications use, so both the scheduler and the run-once gate dropped the node wake asdisabled. The policy now admits that one exact producer shape, still requiring a session target. Every other source keeps its rule, and the busy, spacing, and flood guards apply as before.Out of scope: the isolation and consumer questions in the issue. A separate point the review raised: this shape is not payload-flagged, so an effectively empty heartbeat scratch can still skip the turn as
empty-heartbeat-file, the same as at any cadence today.Evidence
src/infra/heartbeat-runner.scheduler.test.ts(targeted unscheduled wake dispatch) sends the producer's exact request withevery: "0m". Onupstream/mainit fails (runOncecalled 0 times). With the fix it passes, 32/32 in the file.it.eachtable, not a new file. The case itself takes 1 to 14 ms.pnpm test src/infra/heartbeat-runner.scheduler.test.tsruns all 32 cases in 3.69 s Vitest duration, 5.7 s wall on a warm cache. A cold run filtered to the new case (-t "runs one targeted notifications-event wake with disabled cadence") took 18.6 s wall, almost all of it transform.src/infra/heartbeat*,session-event-wake*,server-node-events*,system-event-routing, cron script-wake and failure-alert), 611/611 pass.oxlintandoxfmt --checkare clean on the changed files, andpnpm tsgo:corepasses.notifications.changed, and a local mock model, run on base and head.Real behavior proof
Setup. Each run starts the real Gateway from the checkout with
node scripts/run-node.mjs gateway run --port <port> --verbose(the same launcher aspnpm openclaw, which rebuildsdistfrom the checked-out source first). It uses a freshOPENCLAW_STATE_DIRandOPENCLAW_SKIP_CHANNELS=1. The config setsagents.defaults.heartbeat.every: "0m", token auth, a non-emptyHEARTBEAT.md, andagents.defaults.model.primary: "mock/mock-model", a customopenai-completionsprovider that points at a local HTTP server. That server answersHEARTBEAT_OKand logs every/v1/chat/completionscall, so each logged call is a real agent turn that reached the model.A tsx script outside Vitest pairs a device as an Android node through the device and node pairing store, connects to the Gateway over WebSocket with the repo's
acquireGatewayTestClienthelper fromtest/helpers/gateway-client.ts, which wrapsGatewayClient(role: "node",platform: "android"), and sendsnode.eventwithevent: "notifications.changed"and a posted notification payload. NosessionKeyis in the payload, so the handler targets the main session, the same fallback the handler uses for any node that omits it. The script then waits 25 s.Afterwards the script runs the real CLI
openclaw system event --text "Operator probe" --mode now --session-key agent:main:mainagainst the same Gateway. That wake shape is already admitted on base, so it works as a queue probe: any notification still queued shows up in that turn's prompt.What is stubbed: the model is a local mock server, the node is a script on that client helper instead of the Android app, and pairing is approved directly in the store instead of through the approval prompt. The Gateway process, WebSocket auth,
node.eventdispatch,server-node-events, the system event queue, the heartbeat wake scheduler,runHeartbeatOnce, and the agent turn are all real and unmodified.Command, from the checkout:
<scratch>/run-proof.sh basewitha282f8002a3checked out, then<scratch>/run-proof.sh headon1c59a01ea76. Build output is filtered and node ids are shortened.Base
a282f8002a3: the node event is accepted, then nothing runs for 25 s. The notification only reaches the model when the operator probe forces a wake, which shows it sat in the queue the whole time.Head
1c59a01ea76: one heartbeat turn starts about 270 ms afternode.eventreturns, and its prompt carries the notification. The probe turn that follows no longer contains it, so the notification was consumed exactly once.Proof scripts
run-proof.shnode-client.mtsmock-provider.mjsAI disclosure: this PR was written by an AI agent (Claude Code). It traced the issue from source, wrote the failing test first and the fix on top, and ran
pnpm teston the files above,oxlint,oxfmt --check, andpnpm tsgo:core. It also ran the real Gateway proof above on base and head. A second model reviewed the diff.🤖 Written and posted by an AI agent (Claude Code) on behalf of @jayzhou2309.