Skip to content

refactor: unify wake scheduling and background session ownership - #138451

Merged
steipete merged 1 commit into
mainfrom
codex/heartbeat-retirement-surfaces
Sep 7, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/heartbeat-retirement-surfaces

Conversation

@steipete

@steipete steipete commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Related: #135933. First of two stacked slices; #139624 follows this branch. Landing is now authorized.

What Problem This Solves

Background work can wait across compaction, delivery, and session replacement. Reconstructing its owner later from a logical session key can bind that work to a different session or store. This change carries the captured session/database identity through admission and reclamation, preserving connected compactions while rejecting replacements, foreign stores, and restart-invalidated work.

A single process-owned wake queue handles heartbeat, cron-task, and system-event wakes. It owns target backoff, spacing, barriers, cancellation, waiter settlement, and handler replacement. Separate heartbeat wake lifecycle, target, and settlement modules are removed; existing SDK names remain a facade. Quiet heartbeat outcomes are claimed at the common admitted runtime boundary for built-in and native harnesses, with equivalent CLI admission behavior.

Compatibility and Integration

No new database schema, stored representation, migration requirement, user configuration option/default, Gateway wire field, or protocol version is introduced relative to main 71e3383a0ef8414891c61cadb067d42c7f909198. Existing heartbeat settings and saved state remain supported. Current main's foreground-maintenance priority, structured context fragments, async database opening, and logical agent ownership for session archival are preserved.

Production: −12 lines. Removed redundant identity-publication helpers and reused the existing lifecycle types. State/logging tests have a separate type-check shard because the added regression files exceeded two existing shard caps; the cap and coverage remain unchanged.

Validation

Current candidate: 5713d882d624e62f8593c42b0273bf0cf9ba4bb4.

  • 600 admission, registry, harness, CLI, and prompt tests pass.
  • 132 transaction, identity, reclamation, archive, and active-cap tests pass.
  • After identity cleanup, 17 identity, compaction, and parent-fork tests pass.
  • The complete changed-code gate against the pinned main passes: all type graphs, formatting/lint, architecture/storage guards, unused-export scans, and runtime-cycle checks.
  • Independent review findings were checked against complete owner types and current source; no actionable finding remains. Two reported issues assumed nonexistent harness/re-export contracts; actual source and full type checks disprove those assumptions.

Current-head CI passes. Fresh Testbox build and Gateway proof exits 0 on tree 2e776b74ceb56e9424859c5c3cd48ef1a00a20d5, identical to the current PR head (QA carrier 0c2f25d9fca3644e122319989aeccb466d108ef6). Natural cron fired once and delivered once on both OpenClaw and Codex with live providers. A separate real-Gateway scenario with a mock provider confirmed heartbeat routing omits inbound metadata while ordinary ingress retains it. Delivery used synthetic qa-channel destinations. The owned Testbox lease is stopped.

The earlier composed-stack quiet/alert and saved-outcome proof remains here; that evidence belongs to its earlier pinned tree.

The material risk remains concurrency and lifecycle ordering. The second slice removes the separate monitoring execution/delivery route.

@clawsweeper

clawsweeper Bot commented Sep 4, 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 scripts Repository scripts agents Agent runtime and tooling extensions: codex size: L maintainer Maintainer-authored PR labels Sep 4, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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. labels Sep 4, 2026
@clawsweeper

clawsweeper Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 7, 2026, 12:51 PM ET / 16:51 UTC.

ClawSweeper review

What this changes

Consolidates background wake scheduling, retains session and database ownership across delayed work, and supplies silent heartbeat outcomes to admitted user turns across runtimes.

Merge readiness

⛔ Blocked before merge - 3 items remain

This remains useful work: current main retains the separate heartbeat scheduler, and no merged replacement is established. The verified test merge resolves the previous integration concern; source review found no blocking introduced defect.

Priority: P2
Reviewed head: 5713d882d624e62f8593c42b0273bf0cf9ba4bb4

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A coherent consolidation with meaningful regression coverage and no identified blocking defect; integrated Gateway verification remains outstanding.
Proof confidence 🌊 off-meta tidepool Not applicable: The ordinary contributor-proof gate is exempt for this member-authored PR. Earlier composed-stack Gateway evidence remains credited to its recorded tree; the PR's expressly requested current-candidate Gateway refresh remains a separate before-merge action.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The ordinary contributor-proof gate is exempt for this member-authored PR. Earlier composed-stack Gateway evidence remains credited to its recorded tree; the PR's expressly requested current-candidate Gateway refresh remains a separate before-merge action.
Evidence reviewed 8 items Policy and review scope: Read the complete root and applicable ancestor policies: scripts, agents, embedded run, gateway, and test AGENTS.md. No maintainer-notes directory exists. The checkout remained clean, and no target code or tests were executed.
Verified integration replaces the earlier conflict concern: The test merge has exactly the pinned base 814ca08 followed by the reviewed head as parents. Its changed-path list matches the introduced scope. The previous review had no remaining findings and requested integration refresh; its historical conflict warning no longer applies.
Work remains distinct from main and release: Inspection of fetched main and v2026.9.2 shows the separate heartbeat scheduler and lifecycle helpers still present. The supplied related PRs are open or closed unmerged; none establishes a merged replacement.
Findings None None.
Security None None.

How this fits together

Heartbeat, cron, and system events request background agent work through the wake scheduler. Session admission and SQLite lifecycle owners determine when that work may run and which conversation state it may use.

flowchart TD
  A[Heartbeat and cron requests] --> C[Shared wake queue]
  B[System events] --> C
  C --> D[Session and database admission]
  D --> E{Owner still current?}
  E -->|Yes| F[Agent execution and context]
  E -->|No| G[Reject stale work]
  F --> H[Delivery and waiter settlement]
Loading

Before merge

  • Resolve merge risk (P1) - The consolidation changes admission, cancellation, and post-commit ordering; an integration error could attach delayed work to incorrect session state. The earlier composed-stack proof does not establish the current candidate's behavior.
  • Complete next step (P2) - Complete the fresh Gateway verification explicitly required by the PR body for this candidate, preserving the earlier proof's source identity.
  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source -12, Tests +2964, Other +3. Total +2955 across 72 files.

View PR surface stats
Area Files Added Removed Net
Source 36 1486 1498 -12
Tests 34 3081 117 +2964
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 2 5 2 +3
Total 72 4572 1617 +2955

Review metrics

Metric Value Why it matters
Production versus regression coverage Production net −12 lines; tests/support net +2,953 lines The consolidation reduces production code while adding substantial ownership, cancellation, and transaction regression coverage.

Stored data model

Persistent data-model change detected: unknown-data-model-change: src/config/sessions/session-accessor.sqlite-initial-entry.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Complete the candidate Gateway verification (recommended)
    Record the promised integrated Gateway results before landing, keeping the earlier composed-stack evidence separately identified.

Technical review

Best possible solution:

Retain one lifecycle-owned wake queue and exact store claims, with Gateway evidence confirming session continuity and rejection of stale work on the integrated candidate.

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

Not applicable as a single reported bug: this is a consolidation with several source-backed lifecycle regressions; no runtime reproduction was executed during this read-only review.

Is this the best way to solve the issue?

Yes. Reusing one scheduler and retaining ownership at admission is a coherent repair boundary, and the patch preserves existing heartbeat entrypoints and stored formats.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 8dde3559a551.

Labels

Label changes:

  • add merge-risk: 🚨 session-state: Delayed admission and reclamation now share revised ownership and settlement paths whose integrated candidate verification remains pending.
  • remove proof: sufficient: Current real behavior proof status is not_applicable, not sufficient.

Label justifications:

  • P2: This is a useful internal reliability improvement without evidence of an urgent user-facing outage.
  • merge-risk: 🚨 session-state: Delayed admission and reclamation now share revised ownership and settlement paths whose integrated candidate verification remains pending.
  • 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 ordinary contributor-proof gate is exempt for this member-authored PR. Earlier composed-stack Gateway evidence remains credited to its recorded tree; the PR's expressly requested current-candidate Gateway refresh remains a separate before-merge action.

Evidence

What I checked:

  • Policy and review scope: Read the complete root and applicable ancestor policies: scripts, agents, embedded run, gateway, and test AGENTS.md. No maintainer-notes directory exists. The checkout remained clean, and no target code or tests were executed. (AGENTS.md:1, 5713d882d624)
  • Verified integration replaces the earlier conflict concern: The test merge has exactly the pinned base 814ca08 followed by the reviewed head as parents. Its changed-path list matches the introduced scope. The previous review had no remaining findings and requested integration refresh; its historical conflict warning no longer applies. (a3d15f4d8e96)
  • Work remains distinct from main and release: Inspection of fetched main and v2026.9.2 shows the separate heartbeat scheduler and lifecycle helpers still present. The supplied related PRs are open or closed unmerged; none establishes a merged replacement. (src/infra/heartbeat-wake.ts:1, 8dde3559a551)
  • Admission and reclamation retain live ownership: Admission retains the initial database connection, rejects closed or replaced claims, and accepts compaction lineage only from the matching physical store. Reclamation composes claim liveness with the caller's existing commit guard and holds authorization through worker settlement. Actual-store regression cases cover copied IDs, foreign stores, connected compactions, and restart invalidation. (src/config/sessions/session-accessor.sqlite-reclamation.ts:434, 5713d882d624)
  • Runtime context and dependency signal: The introduced harness boundary claims bounded heartbeat context only for an active admitted user run and preserves structured context fragments. The PR explicitly claims Codex coverage; the existing Codex adapter consumes currentInboundContext through its prompt builder, establishing the dependency-specific inspection requirement. (src/agents/harness/selection.ts:545, 5713d882d624)
  • Native input contract inspected directly: Verified repository ownership through the backing cache's origin URL. TurnStartParams accepts input items, and UserInput::into_core preserves text and text elements. This supports the existing adapter's text-input boundary; it does not establish current-candidate runtime execution. (codex-rs/app-server-protocol/src/protocol/v2/turn.rs:394, 3d2ee51ca2d5)

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Jason (Json): Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

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

  • Attach the current candidate's Gateway results for wake settlement, silent-outcome recall, and lifecycle cancellation.

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 (6 earlier review cycles)
  • reviewed 2026-09-04T17:59:04.107Z sha 4c45194 :: blocked before merge. :: none
  • reviewed 2026-09-04T18:55:22.221Z sha b10837e :: blocked before merge. :: [P1] Define the public runtime-context classifier contract
  • reviewed 2026-09-04T20:06:39.173Z sha b10837e :: blocked before merge. :: [P1] Define the public runtime-context classifier contract
  • reviewed 2026-09-06T02:14:20.059Z sha 83c0491 :: blocked before merge. :: none
  • reviewed 2026-09-06T05:57:38.137Z sha 21d8b84 :: blocked before merge. :: none
  • reviewed 2026-09-06T06:16:35.260Z sha 21d8b84 :: blocked before merge. :: none

@clawsweeper clawsweeper Bot added 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. and removed 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. labels Sep 4, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Sep 4, 2026
@steipete
steipete force-pushed the codex/heartbeat-retirement-surfaces branch from b10837e to 83c0491 Compare September 6, 2026 02:03
@steipete steipete changed the title fix: preserve saved notes in native session continuations refactor: unify wake scheduling and background session ownership Sep 6, 2026
@openclaw-barnacle openclaw-barnacle Bot removed docs Improvements or additions to documentation scripts Repository scripts extensions: codex size: L labels Sep 6, 2026
@clawsweeper clawsweeper Bot removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Sep 6, 2026
@clawsweeper clawsweeper Bot added the status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. label Sep 6, 2026
@steipete
steipete force-pushed the codex/heartbeat-retirement-surfaces branch from 83c0491 to 21d8b84 Compare September 6, 2026 05:49
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. labels Sep 6, 2026
Carry physical session-store claims through admission and reclamation, and claim silent heartbeat context at the shared runtime boundary. Preserve current foreground maintenance, context fragments, and archive ownership. Related: #135933.
@steipete
steipete force-pushed the codex/heartbeat-retirement-surfaces branch from 21d8b84 to 5713d88 Compare September 7, 2026 16:43
@steipete
steipete marked this pull request as ready for review September 7, 2026 16:43
@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. labels Sep 7, 2026
@steipete
steipete merged commit 96f4a52 into main Sep 7, 2026
250 of 253 checks passed
@steipete
steipete deleted the codex/heartbeat-retirement-surfaces branch September 7, 2026 17:12
@steipete

steipete commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

steipete added a commit that referenced this pull request Sep 7, 2026
Consolidate monitoring execution and delivery with ordinary replies, route isolated cron through the shared agent entry, and keep immediate cron retries in the canonical wake queue. Preserve quiet/alert policy, scratch ownership, cancellation, and durable delivery custody while removing duplicate runtime paths.

Carry actual admission outcomes through monitoring so foreground work winning late leaves cron and exec events pending for retry. Preserve CLI/native auth and lifecycle fences for saved context and route recovery through the canonical agent/store owner. Preserve separate physical stores when reconciling exhausted recovery attempts.

No new database schema, configuration, protocol, or migration requirement. Existing heartbeat public contracts remain supported. Production decreases by 56 lines in this slice and 68 across the two slices. Related: #135933, #138451.
steipete added a commit that referenced this pull request Sep 7, 2026
Consolidate monitoring execution and delivery with ordinary replies, route isolated cron through the shared agent entry, and keep immediate cron retries in the canonical wake queue. Preserve quiet/alert policy, scratch ownership, cancellation, and durable delivery custody while removing duplicate runtime paths.

Carry actual admission outcomes through monitoring so foreground work winning late leaves cron and exec events pending for retry. Preserve CLI/native auth and lifecycle fences for saved context and route recovery through the canonical agent/store owner. Preserve separate physical stores when reconciling exhausted recovery attempts.

No new database schema, configuration, protocol, or migration requirement. Existing heartbeat public contracts remain supported. Production decreases by 56 lines in this slice and 68 across the two slices. Related: #135933, #138451.
steipete added a commit that referenced this pull request Sep 7, 2026
)

* refactor: share heartbeat and cron execution with reply runtime

Consolidate monitoring execution and delivery with ordinary replies, route isolated cron through the shared agent entry, and keep immediate cron retries in the canonical wake queue. Preserve quiet/alert policy, scratch ownership, cancellation, and durable delivery custody while removing duplicate runtime paths.

Carry actual admission outcomes through monitoring so foreground work winning late leaves cron and exec events pending for retry. Preserve CLI/native auth and lifecycle fences for saved context and route recovery through the canonical agent/store owner. Preserve separate physical stores when reconciling exhausted recovery attempts.

No new database schema, configuration, protocol, or migration requirement. Existing heartbeat public contracts remain supported. Production decreases by 56 lines in this slice and 68 across the two slices. Related: #135933, #138451.

* refactor: decouple heartbeat policy from reply run state

* fix: retain source session ownership for bound ACP admission

Keep lifecycle reset and admission in the source agent store while bound ACP execution retains its target. Update fixtures to canonical queue, store-owner, and no-send proof contracts, and register the added QA and regression coverage.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 8, 2026
…nclaw#138451)

Carry physical session-store claims through admission and reclamation, and claim silent heartbeat context at the shared runtime boundary. Preserve current foreground maintenance, context fragments, and archive ownership. Related: openclaw#135933.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 8, 2026
…claw#139624)

* refactor: share heartbeat and cron execution with reply runtime

Consolidate monitoring execution and delivery with ordinary replies, route isolated cron through the shared agent entry, and keep immediate cron retries in the canonical wake queue. Preserve quiet/alert policy, scratch ownership, cancellation, and durable delivery custody while removing duplicate runtime paths.

Carry actual admission outcomes through monitoring so foreground work winning late leaves cron and exec events pending for retry. Preserve CLI/native auth and lifecycle fences for saved context and route recovery through the canonical agent/store owner. Preserve separate physical stores when reconciling exhausted recovery attempts.

No new database schema, configuration, protocol, or migration requirement. Existing heartbeat public contracts remain supported. Production decreases by 56 lines in this slice and 68 across the two slices. Related: openclaw#135933, openclaw#138451.

* refactor: decouple heartbeat policy from reply run state

* fix: retain source session ownership for bound ACP admission

Keep lifecycle reset and admission in the source agent store while bound ACP execution retains its target. Update fixtures to canonical queue, store-owner, and no-send proof contracts, and register the added QA and regression coverage.
karmafeast pushed a commit to karmaterminal/openclaw that referenced this pull request Sep 27, 2026
…, fixture repairs

Decisions recorded on #1396 (figs, and Ronan / Emeric / Silas / Elliott):
- Restore upstream openclaw#146600. Legacy attachmentsDir/attachmentsRootDir records are
  retired without traversal on both the async and sync removal paths;
  attachmentId cleanup and the retained-completion orphan guard are kept.
  Three fork-only tests that pinned the retired recursive delete now assert the
  decided behavior: legacy records retire, and every file on disk survives.
- session-updates cache-only path: canonicalize the merged entry
  (projectCanonicalSessionEntryShape over mergeSessionEntry).

#1402: 46 of 55 src/auto-reply/continuation tests belonged to no CI or Mode-B
shard, because the reply config runs only as reply-subtree splits. Add an
auto-reply-continuation split group, plus a guard test that every file the
reply subtree include collects is scheduled. The guard fails without the fix.

Fixture repairs, from running those tests for the first time:
- work-dispatch.durable-3: the paths.js mock now spreads the real module.
- volatile-map allowlist: rename afterClearByOperation (upstream openclaw#138451); add
  four upstream-owned reply-run-registry maps, with provenance. The continuation
  attachment payload map is deliberately not allowlisted (#1403).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Fq5EX9ESA3CG9cuZxVoKAK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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