Skip to content

refactor: run immediate notifications through ordinary session execution - #167113

Merged
steipete merged 13 commits into
mainfrom
deslop/heartbeat-s2-integration-20261008
Oct 8, 2026
Merged

steipete merged 13 commits into
mainfrom
deslop/heartbeat-s2-integration-20261008

Conversation

@steipete

@steipete steipete commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Related: #134994, #135933, #164265. Second of three sequential slices; Claw deletion/Cron custody landed in #166889.

Comparison: base 61a5fc58ecce321bc0bb1b224b447f8d446d099e, head 9f5cc13c3f9b18775fcdd0202140fec5ee0c9e5f.

What Problem This Solves

Background completions and immediate notifications depend on heartbeat execution even though they belong to an existing conversation. This slice moves them into ordinary session execution. Doctor conversion and periodic heartbeat retirement remain one atomic final slice.

User Impact

Host exec completions, CLI watchdogs, ACP parent notifications, immediate HTTP hook wakes, restart continuations, and session-state notices enter the ordinary reply queue. They retain the originating history, physical session identity, account/thread route, permission ceiling, cancellation, and automatic-delivery opt-out. Busy sessions preserve FIFO order. Acceptance remains separate from terminal settlement; reset or replacement cannot redirect delayed work.

Watcher notices preserve one reconciliation per destination within the original 20-second window. A batch retains its original occurrences and acknowledges frozen watermarks only at adoption. Explicit consumption of one notice preserves surviving originals; whole-batch cancellation cannot restart work. Shutdown cancels newer buffered notices while older batches await adoption.

Cancellation before execution now preserves the preceding run's terminal state. Previously, a cancelled watchdog follow-up emitted a terminal event without identifying itself as unstarted. Its asynchronous projection overwrote the foreground timeout after deletion had captured its expected row, so deletion correctly refused the changed row. The ordinary runner now supplies the existing executionStarted: false and providerStarted: false facts from the canonical reply-operation state. The existing projection guard handles them; deletion's CAS, authority checks, started-run cancellation, and non-cancellation preparation failures remain intact.

Periodic heartbeats, node notices, and deferred next-heartbeat hooks retain their behavior until the final cutover. Stored configuration/data formats are unchanged here. No delivery options, migration, or deprecated SDK aliases are introduced. The deprecated reply-runtime export budget stays 1. Peter's approved Doctor notice and breaking heartbeat SDK removal belong to the final slice.

The SDK adds the "event" discriminator while retaining existing values, including "heartbeat"; exhaustive plugin switches may need an event case. Existing reply-wrapper names, option fields, and callback signatures remain available. Event authority stays host-only, and system-event-runtime.enqueueSystemEventEntry retains its original two-argument contract.

Why This Change Was Made

The existing reply executor owns admission, execution, and delivery. Producer-owned occurrences carry their original target and lifetime through that owner, including detached completion after the initiating request ends. Captured restrictions intersect current restrictions. Stop, deletion, plugin fallback interruption, and exact reply-operation settlement retain their native owners.

Main's newer selected-session database reader remains the initialization owner. The integration carries the event creation guard through its options helper and keeps event source authority independent of the retained database reader. The duplicate initialization parameter type is removed. Later commits, including watcher batching, reapplied unchanged.

Production is +3,401/−716 = +2,685; tests/support are +6,362/−1,576 = +4,786. The ordinary event target/handoff owner drives the increase. Main's code is not reintroduced, and generated output and test support are excluded. Each immediate occurrence has one owner. The remaining periodic executor retires with its migration in slice 3.

Evidence

The original watchdog failure reproduced through registered Gateway methods on the rebased candidate. Diagnostics established the exact sequence: foreground timeout persisted, deletion captured its post-cleanup row, then a different, unstarted cancellation overwrote nine terminal fields. Session/lifecycle identity stayed equal; this was a late write, not serialization order or stale cache. A deterministic deferred-boundary regression failed before the repair; its started-run control passed.

The repaired production path passed 129 focused tests across six files, including all six original watchdog cases, lifecycle projections, runner/backstop behavior, and suppression checks (420.04 seconds including preparation). The final regression was placed in the existing terminal-failures owner to respect the unchanged 1,000-line cap. That file passed 33 tests with one worker: 58.67 seconds for the file, 65.32 seconds including preparation. Assertions, deadlines, retries, skips and budgets were not weakened. These selections overlap and are not summed.

Earlier watcher proof covers 130 owner cases, plus the final 13-case notice suite and 20 wrapper/import-closure/suppression cases. Negative controls proved duplicate reconciliation turns, loss of a sibling after partial SDK consumption, and dispatch after shutdown with overlapping debounce windows. Core and affected messaging types, runtime cycles (0), Madge cycles (0), scoped typed lint, formatting and suppression checks pass. Fresh P2 autoreview is clean. The captured-terminal concern was resolved with complete production caller evidence; frozen-capture behavior was not changed.

The conflict integration separately passed 14 focused initialization/event-permission cases, core/messaging types and both cycle checks. Current base includes three independently proved main CI repairs: Gateway identity test routing (c8283bcc86c), raw-wire restart refusal coverage (76ddbf697fc), and the OpenAI runtime-carrier fixture (e09e5ddfa52). The last two preserve current runtime behavior; they change tests only.

Prior unchanged-cutover proof includes real process completion and exact polling cancellation; explicit non-main sessions.create followed by socket reads; durable restart adoption; periodic-to-background-exec handoff; runtime build; SDK surface/export guards and complete committed-ref SDK API comparison. The SDK comparison found no export/entrypoint additions or removals and confirmed the two-argument enqueue contract. Paid inference and transport were synthetic where identified; process execution, queueing, authority, and persistence were real. Historical results do not replace current-head hosted CI.

Previous exact-head CI and incorporated repairs

Head 9f714a8970d08cef08c0a7cc5ebd1c3dd485c1ec, run 37853773137, tested merge c52aa003df98bbb0b6097c18d60c4434016fea78 on main 674275e3808ed6c3f521aac391d0158c036dec29. The complete check census has 178 successes, five failures, 45 unselected skips, and one neutral result. CI itself has 144 successful jobs, four root failures plus its aggregate, and 21 unselected skips. No selected job is cancelled or zero-step. Current-head ClawSweeper completed with no findings.

Every failure is recorded separately:

  • checks-node-changed-3 (113574161702): the local-only skill-refresh fixture requested an implicit worktree base after main removed the local-HEAD fallback. Unchanged main 424b6b1 reproduced the exact missing-origin error. Main repair 61a5fc58ecc adds the explicit base. The unchanged assertions pass (52.831 seconds for the case; 130.36 seconds including preparation); suppression checks and P2 review pass. No runtime fallback is restored.
  • checks-node-changed-compact-small-21 (113574161762): the plugin reader fixture signaled on the legitimate pre-quiesce retained-work wait, then asserted admission had already closed. The original 31-file group reproduced the same assertion on unchanged main (336 passed, one failed). Main repair f59e4079321 observes the post-quiesce call drain and retains the independent closed-admission, metadata, deadline, and rollback assertions. Focused proof, types, lint, suppression checks, and P2 review passed. This authority-related assertion is repaired, not waived.
  • checks-ui-e2e (3/9) (113574157846): dashboard roster readiness at line 191 and retained prompt thumbnail at line 131. Both have exact independent main failures; natural main 37854167434/job/113574525857 proves thumbnail line 131, resolving the previous gap. Main 9d606a28e0d repairs dashboard readiness; a5106ecf049 repairs durable draft retirement before confirmed navigation. S2 changes no UI files.
  • checks-ui-e2e (7/9) (113574157771): only sidebar roster readiness at line 189 failed. Its exact independent main failure is now repaired by 9d606a28e0d. The previously failing writer-draft case passed this run.
  • openclaw/ci-gate (113578653269): completed failure aggregating those four root jobs.

The repaired watchdog shard, npm successor shard, lint, production and test types, build, SDK/package gates, and security-fast passed. All named main repairs are included in the current base. The subsequent rebase was conflict-free and all 13 commits are patch-identical. Current-head core types, runtime cycles (0), Madge cycles (0), and suppression checks pass. The current head requires its own hosted CI; prior failures are not represented as current passing proof. No merge exception is armed for unresolved failures or missing proof.

All known allocated test leases are stopped or terminal. One unpublished AWS allocation attempt still lacks its private cancellation receipt; exact status returns 404, no resource or owned process is visible, and that cleanup limitation remains recorded.

Production LOC by area

Against base 61a5fc58ecce321bc0bb1b224b447f8d446d099e. Tests, fixtures, support and generated output excluded.

Area Additions Deletions Net
src/auto-reply/reply 1,505 116 +1,389
src/config/sessions 354 65 +289
src/gateway/server 293 117 +176
src/sessions 260 79 +181
src/agents 200 101 +99
src/gateway 154 75 +79
src/agents/cli-runner 168 58 +110
src/plugin-sdk 174 33 +141
src/infra 173 18 +155
src/agents/subagents/spawn 40 31 +9
src/plugins/runtime 43 17 +26
src/agents/tools 27 0 +27
src/cron/isolated-agent 2 2 +0
src/auto-reply 2 1 +1
src/auto-reply/reply/queue 3 0 +3

@clawsweeper

clawsweeper Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: XL labels Oct 8, 2026
@steipete
steipete marked this pull request as ready for review October 8, 2026 09:48
@github-actions

github-actions Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: 9f5cc13c3f9b18775fcdd0202140fec5ee0c9e5f
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/agents/cli-runner/tool-authority.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.

Carefully review these changes before merging.

@clawsweeper

clawsweeper Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

The branch routes immediate process, hook, restart, and session notifications through ordinary conversation execution while preserving producer ownership and delivery restrictions.

Example: A user posts a hook wake with text "The sample import completed" and mode "now".

  • Before: The notification enters the system-event queue and requests heartbeat execution.
  • After: The notification enters ordinary session execution, waiting behind existing conversation work.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, owner-approved work with strong boundary coverage, delivered as an intentionally partial architectural cutover.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): Recorded Gateway watchdog and public session-creation/socket runs exercise ordinary admission, real process execution, and persistence; production-tool permission runs cover allowed writes and rejection after restrictions. Inference and channel transport are synthetic where stated. Runtime receipt changes preserve existing stored formats, so no data migration is required.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Refactor · Worth it: Yes · Fix scope: Partial
User problem: Background results and immediate notifications depend on a separate heartbeat executor even though they belong to an existing conversation.
Reason: The area owner's recorded design approves consolidation into ordinary session execution. This intentionally bounded slice implements immediate notifications; periodic retirement and migration remain separate.

Merge readiness

✅ Ready for maintainer review

Keep open: this is an approved, distinct implementation slice, and current main still routes these notifications through heartbeat execution. No concrete blocking patch defect was identified.

Priority: P2
Reviewed head: 9f5cc13c3f9b18775fcdd0202140fec5ee0c9e5f

Before merge

None.

Findings

None.

Provenance

  • src/plugin-sdk/reply-runtime.ts: original intent not found (unknown: Content-history searches were limited by unavailable promisor blobs; the pinned base establishes the existing public wrappers, which this PR retains.)
Agent review details

How this fits together

The Gateway receives background results and trusted notifications for existing conversations. The ordinary reply executor admits those turns, retains conversation history and permissions, and delivers their results to the captured destination.

flowchart TD
  A[Background results and immediate notifications] --> B[Capture conversation and producer restrictions]
  B --> C[Validate current session and authority]
  C --> D[Ordinary conversation queue]
  D --> E[Execute with conversation history]
  E --> F[Recheck authority before effects]
  F --> G[Deliver or record intentional silence]
Loading

Technical review

Best possible solution:

Use ordinary session execution for immediate producer-owned work, preserving its native authority and settlement owners, and complete periodic retirement with the approved Doctor migration in the final slice.

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

Not applicable to the architectural request. Source confirms the separate heartbeat path on current main, and recorded Gateway proof plus the focused cancellation regression establish the associated failure mechanism.

Is this the best way to solve the issue?

Yes for this approved slice: the existing reply executor owns admission, queueing, execution, and delivery, while producer-specific lifetime and cancellation remain explicit.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 7e80556f503d.

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Accepted product direction: Retire heartbeat into ordinary automations and session execution #134994 explicitly approves moving immediate producer-owned events through normal session admission while preserving routing, permissions, cancellation, freshness, and settlement. This PR identifies itself as the second implementation slice and leaves periodic retirement and Doctor conversion together.
  • Work remains distinct on current main: Fetched main still imports requestHeartbeat and uses it for background exec completion. Changes after the pinned base affect iOS fleet code and a compaction test, without overlapping this PR's touched paths. (src/agents/bash-tools.exec-runtime.ts:302, 7e80556f503d)
  • Pinned introduction: The verified merge-base-to-head diff establishes the branch's changes independently of the bounded file inventory supplied in context. (9f5cc13c3f9b)
  • Execution and final-effect ownership: The handoff retains occurrence cancellation, session-generation facts, captured permission ceilings, and producer callbacks through ordinary dispatch. Delivery passes current-authority assertions to the final outbound adapter handoff. (src/auto-reply/reply/session-event-handoff.ts, 9f5cc13c3f9b)
  • Allowed and revoked filesystem effects: The permission suite drives ordinary admission and production host tools against real files. Allowed work writes "completed\n"; restricted or revoked work leaves "original\n", including retained tools used after session or configuration restriction. The PR body records passing execution of the relevant owner suites; this review did not execute them. (src/auto-reply/reply/session-event-permissions.test.ts:202, 9f5cc13c3f9b)
  • Prior watcher finding addressed: Watcher batching uses a destination-specific 20-second window, transfers surviving original occurrences, and acknowledges only after adoption. Native owner coverage checks FIFO execution, partial cancellation, whole-batch cancellation, retained permission intersections, and frozen cursor watermarks. (src/auto-reply/reply/session-event-permissions.test.ts:604, 9f5cc13c3f9b)

PR surface

PR surface statistics unavailable: the file list is incomplete.

Review metrics

Metric Value Why it matters
Public trigger contract 1 added discriminator value; existing values retained Third-party exhaustive switches may need an event case, as explicitly acknowledged in the accepted scope.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is approved execution consolidation with meaningful reliability benefits and no newly demonstrated urgent outage.
  • merge-risk: 🚨 compatibility: The public trigger union gains event; the maintainer-authored description explicitly accepts the exhaustive-switch compatibility tradeoff while retaining existing values.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (14 earlier review cycles; latest 8 shown)
  • reviewed 2026-10-08T15:29:07.049Z sha bc9c57c :: blocked before merge. :: none
  • reviewed 2026-10-08T16:24:49.266Z sha b4577c1d2b984976ca6a9aeed7c778d27183610c :: blocked before merge. :: none
  • reviewed 2026-10-08T16:44:16.842Z sha 1b6afd16100b373a3ac4575d616d195c4062f122 :: blocked before merge. :: none
  • reviewed 2026-10-08T18:26:51.212Z sha 007d055c28897f1760b257054aaa6ec27005338d :: blocked before merge. :: [P2] Preserve watcher-wide batching when admitting notification turns
  • reviewed 2026-10-08T18:57:54.227Z sha f44994f :: blocked before merge. :: [P2] Preserve watcher-wide batching when admitting notification turns
  • reviewed 2026-10-08T20:14:11.706Z sha 8bb35633d9b0ab3b270c3cfbb8855ad0ded7f36d :: blocked before merge. :: none
  • reviewed 2026-10-08T22:38:07.668Z sha 9f714a8970d08cef08c0a7cc5ebd1c3dd485c1ec :: needs maintainer review before merge. :: none
  • reviewed 2026-10-08T23:16:34.004Z sha 9f714a8970d08cef08c0a7cc5ebd1c3dd485c1ec :: needs maintainer review before merge. :: none

Reviewed October 8, 2026, 7:27 PM ET / 23:27 UTC (Revision 15).

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. proof: sufficient ClawSweeper judged the real behavior proof convincing. labels Oct 8, 2026
@steipete
steipete force-pushed the deslop/heartbeat-s2-integration-20261008 branch from fa245c6 to 2172049 Compare October 8, 2026 13:14
@clawsweeper clawsweeper Bot added the proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. label Oct 8, 2026
@steipete
steipete force-pushed the deslop/heartbeat-s2-integration-20261008 branch from 2172049 to bc9c57c Compare October 8, 2026 14:28
@openclaw-barnacle openclaw-barnacle Bot added extensions: codex channel: discord Channel integration: discord labels Oct 8, 2026
@clawsweeper clawsweeper Bot removed the proof: telegram-e2e This PR needs Telegram Test Server proof with the repository E2E skill. label Oct 8, 2026
@steipete
steipete force-pushed the deslop/heartbeat-s2-integration-20261008 branch from 1b6afd1 to 007d055 Compare October 8, 2026 18:16
@clawsweeper clawsweeper Bot added status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 8, 2026
@steipete
steipete force-pushed the deslop/heartbeat-s2-integration-20261008 branch 2 times, most recently from f44994f to 8bb3563 Compare October 8, 2026 19:59
@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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 8, 2026
@steipete
steipete force-pushed the deslop/heartbeat-s2-integration-20261008 branch from 8bb3563 to 9f714a8 Compare October 8, 2026 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling channel: discord Channel integration: discord docs Improvements or additions to documentation extensions: codex gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. security-sensitive-changed size: XL 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