Skip to content

fix(agents): heartbeat runs no longer block visible turns - #126853

Merged
sallyom merged 6 commits into
openclaw:mainfrom
jason-allen-oneal:codex/fix-heartbeat-background-lane
Aug 22, 2026
Merged

sallyom merged 6 commits into
openclaw:mainfrom
jason-allen-oneal:codex/fix-heartbeat-background-lane

Conversation

@jason-allen-oneal

@jason-allen-oneal jason-allen-oneal commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Closes #126803

AI-assisted: Yes — implemented and validated with Codex.

What Problem This Solves

Fixes an issue where users sending visible-channel turns could wait minutes when a slow heartbeat embedded run occupied the process-wide main lane.

Why This Change Was Made

Heartbeat embedded runs now use the existing bounded cron-nested global lane, while non-heartbeat runs continue to use main. The lane is selected once before the native-versus-CLI fallback branch, then forwarded through both fallback candidates into the embedded runner, so both execution paths share the same admission invariant. Per-session lane ownership and writer serialization are unchanged, and no new concurrency setting or capacity is introduced.

The queue contract now documents that inbound turns use main while heartbeat embedded runs use the bounded background lane.

User Impact

A slow heartbeat no longer occupies process-wide inbound capacity, so visible turns for other sessions can start while that heartbeat is still running. A visible turn in the same configured heartbeat session remains serialized by that session's existing lane, preserving session consistency.

Evidence

Real behavior proof

  • Claim: while a heartbeat is actively waiting on model output, a visible turn in an independent session reaches the provider without waiting for that heartbeat to finish.
  • Exercised surface: the real Gateway server, authenticated Gateway client, production wake and chat.send RPC handlers, heartbeat runner, embedded agent runtime, command lanes, diagnostics.lanes, and an OpenAI Responses-compatible loopback server.
  • Scenario: agents.defaults.maxConcurrent is 1; a wake starts a heartbeat in agent:main:pr126853-heartbeat; the provider holds that request; chat.send then starts a visible turn in agent:main:pr126853-visible; both provider responses remain held while lane diagnostics are captured.
  • Exact command and environment: OPENCLAW_E2E_SKIP_BUILD=1 OPENCLAW_E2E_VERBOSE=1 pnpm exec vitest run --config test/vitest/vitest.e2e.config.ts test/pr126853-heartbeat-visible-lane-proof.e2e.test.ts --reporter=verbose on Linux at head b50a455dbac2878313d2b1af8433c27c1cc859ee, immediately after the same test passed against a fresh full distribution build.
  • Observable result:
PR126853_PROVIDER_REQUEST heartbeat
PR126853_PROVIDER_REQUEST visible
PR126853_RUNTIME_TRACE {"providerOrder":["heartbeat","visible"],"lanes":[{"lane":"main","queuedCount":0,"activeCount":1,"maxConcurrent":1,"draining":false,"generation":0,"blockedBy":"lane"},{"lane":"cron-nested","queuedCount":0,"activeCount":1,"maxConcurrent":8,"draining":false,"generation":0,"blockedBy":null}],"heartbeatSessionKey":"agent:main:pr126853-heartbeat","visibleSessionKey":"agent:main:pr126853-visible"}
Test Files  1 passed (1)
Tests  1 passed (1)
  • Durable artifact: test/pr126853-heartbeat-visible-lane-proof.e2e.test.ts is committed at the reviewed head and reproduces the trace without external credentials.
  • Limits: the provider is a loopback Responses-compatible server and delivery is disabled, so this does not exercise a third-party account or channel transport. It does exercise the production Gateway/RPC/heartbeat/runtime/lane/provider boundary that owns this scheduling behavior. Heartbeats intentionally share the existing cron-nested background budget and may be deferred when that budget is saturated; this change does not alter that budget.

Regression and validation

  • Pre-fix regression proof: with the old unconditional main assignment restored, pnpm test src/agents/embedded-agent-runner/lanes.heartbeat.test.ts --run fails because the heartbeat-first/visible-turn-second interleaving produces only ["heartbeat-start"].
  • Exact-head focused lane proof: pnpm test src/agents/embedded-agent-runner/lanes.test.ts src/agents/embedded-agent-runner/lanes.heartbeat.test.ts --run — 2 files, 8 tests passed.
  • Exact-head production-boundary proof: pnpm test src/auto-reply/reply/agent-runner-execution-runtime.test.ts --run — 1 file, 10 tests passed. The owner-boundary test drives production executeAgentTurn runtime selection and asserts the native runEmbeddedAgent call receives trigger: "heartbeat" and lane: "cron-nested".
  • Exact CI-shard reproduction: pnpm exec vitest run --config test/vitest/vitest.agents-embedded-agent-overflow-compaction.config.ts — 2 files, 14 tests passed. The two full ./lanes.js harness mocks now expose the production resolveEmbeddedRunGlobalLane export, preserving the harnesses' existing normal global lanes and routing heartbeat runs to cron-nested.
  • Neighboring compaction-harness proof: pnpm exec vitest run src/agents/embedded-agent-runner/compact.hooks.test.ts src/agents/embedded-agent-runner/run.lanes.test.ts src/agents/embedded-agent-runner/run.heartbeat-lane.test.ts test/pr126853-heartbeat-visible-lane-proof.e2e.test.ts — the selected default-config files passed, 2 files and 290 tests.
  • Exact-head changed-file gate: pnpm check:changed — exit 0 across all 10 changed paths, including formatting, policy ratchets, dead-code scans, typechecks, lint, database-first checks, runtime loaders, and import-cycle checks.
  • Exact-head branch autoreview: .agents/skills/autoreview/scripts/autoreview --mode branch --base origin/main --codex-bin /home/rev/.npm-global/bin/codex — TruffleHog clean; no accepted/actionable findings; overall review 0.98.
  • Current base used for the one clean rebase is 58127fa73ed5255a95b7a982929292b4ac5408f5; pushed head is b50a455dbac2878313d2b1af8433c27c1cc859ee.
  • ClawSweeper rank-up moves applied: the after-fix real-Gateway trace is committed and recorded above, the exact CI failure was reproduced and repaired at its test-harness boundary, and the branch has a clean exact-head local gate. CI will run on this exact head after publication.
  • Current-main blame was checked for the old assignment (ad1071bcd0596458e76a982e2cc07a3c5b48864b, PR refactor: split agent runner execution and preserve probe state #108137). No existing implementation PR for [Bug]: heartbeat embedded runs hold the main lane for minutes, starving visible-channel turns #126803 was found before publication.
  • The sibling Codex source was inspected at ../codex/sdk/typescript/src/thread.ts:40-109, ../codex/sdk/typescript/src/exec.ts:86-194, and ../codex/codex-rs/app-server-protocol/src/rpc.rs:1-88; Codex keeps thread/turn streaming downstream, while OpenClaw owns this global-lane admission boundary.

@clawsweeper

clawsweeper Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: S labels Aug 20, 2026
@jason-allen-oneal
jason-allen-oneal marked this pull request as ready for review August 20, 2026 21:25
@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 20, 2026
@clawsweeper

clawsweeper Bot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 22, 2026, 3:00 PM ET / 19:00 UTC.

ClawSweeper review

What this changes

Routes heartbeat agent runs through the existing bounded background lane so a slow heartbeat does not occupy the inbound-turn lane.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

No blocking correctness finding. The shared fallback boundary now selects cron-nested for heartbeat runs and forwards it to the embedded runner, while visible turns retain main; the remaining merge gate is exact-head CI.

Priority: P1
Reviewed head: b85b6e5f394503f2041584f48167afec929a39f0

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is a focused owner-boundary repair with strong production-boundary evidence; exact-head CI remains the normal merge gate.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR body supplies an after-fix real Gateway/RPC trace showing the held heartbeat and independent visible request concurrently occupying cron-nested and main.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body supplies an after-fix real Gateway/RPC trace showing the held heartbeat and independent visible request concurrently occupying cron-nested and main.
Evidence reviewed 5 items Shared admission boundary: Heartbeat turns select cron-nested; all other turns retain main at the fallback boundary.
Embedded path receives selected lane: The embedded candidate passes the selected lane to the runner, whose orchestrator resolves it for global queue admission.
Boundary-level regression proof: The committed Gateway E2E holds a heartbeat provider request, starts an independent visible turn, and verifies both main and cron-nested are active.
Findings None None.
Security None None.

Live Verification

Command: OPENCLAW_E2E_SKIP_BUILD=1 pnpm exec vitest run --config test/vitest/vitest.e2e.config.ts test/pr126853-heartbeat-visible-lane-proof.e2e.test.ts --reporter=verbose

Result: FAIL (failed) — step 1 run OPENCLAW_E2E_SKIP_BUILD=1 pnpm exec vitest run --config test/vitest/vitest.e2e.config.ts test/pr126853-heartbeat-visible-lane-proof.e2e.test.ts --reporter=verbose: terminal command did not produce output within 20 seconds: "OPENCLAW_E2E_SKIP_BUILD=1 pnpm exec vitest run --config test/vitest/vitest.e2e.config.ts test/pr126853-heartbeat-visible-lane-proof.e2e.test.ts --reporter=verbose"

runner@runnervm76f27:/tmp/clawsweeper-live-proof-126853-mpwOwU/target$ OPENCLAW_E2E_SKIP_BUILD=1 pnpm exec vitest run --config test/vitest/vitest.e2e.config.ts
test/pr126853-heartbeat-visible-lane-proof.e2e.test.ts --reporter=verbose

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-126853-mpwOwU/target

OPENCLAW_E2E_SKIP_BUILD=1 pnpm exec vitest run --config test/vitest/vitest.e2e.config.ts test/pr126853-heartbeat-visible-lane-proof.e2e.test.ts --reporter=verbo
se












































Assertions:

  • FAIL expect_output: PR126853_PROVIDER_REQUEST visible
  • FAIL expect_output: "lane":"cron-nested"

How this fits together

Gateway reply handling chooses a global lane and a per-session lane before starting an embedded or CLI agent run. The global lane controls process-wide admission, while the session lane preserves ordering within one conversation.

flowchart LR
A[Heartbeat trigger] --> C[Reply runtime]
B[Visible channel turn] --> C
C --> D[Global lane selection]
D --> E[Session serialization]
E --> F[Embedded or CLI runner]
F --> G[Model provider]
G --> H[Reply delivery]
Loading

Before merge

  • Resolve merge risk (P1) - A heartbeat may now occupy the existing cron-nested budget while a visible turn occupies main; this intentional availability tradeoff should remain bounded by the cron budget and exact-head CI.
  • Complete next step (P2) - The focused repair is already represented by this PR; exact-head CI and normal maintainer merge handling remain.
Agent review details

Security

None.

PR surface

Source +3, Tests +333, Docs +1. Total +337 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 2 4 1 +3
Tests 2 333 0 +333
Docs 1 2 1 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 339 2 +337

Review metrics

Metric Value Why it matters
Production versus regression coverage production +3/-1; docs +2/-1; tests +332/-0 The three production additions are necessary lane plumbing across the existing fallback-to-embedded boundary; the added E2E covers the reported cross-session scheduling behavior.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #126803
Summary: This PR is the active candidate fix for the documented heartbeat lane-starvation bug.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Accept bounded background admission (recommended)
    Merge after exact-head checks confirm heartbeats remain bounded by the existing cron budget while visible turns retain inbound-lane capacity.

Technical review

Best possible solution:

Keep lane selection at the shared fallback boundary, preserving per-session serialization while using the existing bounded background budget for heartbeats.

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

Yes. The current source shows heartbeat and visible turns previously shared the main admission path, and the committed Gateway E2E reproduces the heartbeat-first, visible-turn-second interleaving.

Is this the best way to solve the issue?

Yes. Selecting the lane once at the shared fallback boundary and forwarding it to the embedded runner fixes the owner boundary without changing session serialization or adding a new setting.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P1: The repair addresses visible user turns waiting for long-running heartbeat work.
  • merge-risk: 🚨 availability: The patch changes process-wide lane admission and deliberately permits bounded background work alongside inbound work.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body supplies an after-fix real Gateway/RPC trace showing the held heartbeat and independent visible request concurrently occupying cron-nested and main.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body supplies an after-fix real Gateway/RPC trace showing the held heartbeat and independent visible request concurrently occupying cron-nested and main.

Evidence

What I checked:

Likely related people:

  • sallyom: Authored the current-head refactor and is assigned to this PR’s final verification. (role: recent area contributor; confidence: high; commits: b85b6e5f3945; files: src/auto-reply/reply/agent-runner-fallback-candidate.ts, src/auto-reply/reply/agent-runner-embedded-candidate.ts)
  • steipete: Merged PR 108137, the prior agent-runner execution split cited by this PR as the origin of the former unconditional lane choice. (role: earlier execution-path contributor; confidence: medium; commits: ad1071bcd059; files: src/auto-reply/reply/agent-runner-fallback-candidate.ts)

Rank-up moves

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

  • Wait for exact-head required checks to complete successfully.

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 (5 earlier review cycles)
  • reviewed 2026-08-20T21:32:44.123Z sha a676e426ceb4174d896fa8038ff59e63ccc782bd :: needs real behavior proof before merge. :: [P1] Forward the selected lane to the embedded candidate
  • reviewed 2026-08-21T03:38:05.572Z sha f944f00a5d447c98059bc9cbc172d439d7f9ad40 :: needs real behavior proof before merge. :: [P1] Keep heartbeat admission within the configured global cap
  • reviewed 2026-08-21T03:50:28.728Z sha f944f00a5d447c98059bc9cbc172d439d7f9ad40 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-21T08:28:09.917Z sha c1cae4cc7d9b04a9910e81d569132976857ae5eb :: needs maintainer review before merge. :: none
  • reviewed 2026-08-21T08:54:49.063Z sha b50a455dbac2878313d2b1af8433c27c1cc859ee :: needs maintainer review before merge. :: none

@jason-allen-oneal
jason-allen-oneal force-pushed the codex/fix-heartbeat-background-lane branch from a676e42 to ead8ac3 Compare August 21, 2026 03:30
@jason-allen-oneal

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@jason-allen-oneal
jason-allen-oneal force-pushed the codex/fix-heartbeat-background-lane branch from ead8ac3 to f944f00 Compare August 21, 2026 03:32
@jason-allen-oneal

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Aug 21, 2026
@jason-allen-oneal
jason-allen-oneal force-pushed the codex/fix-heartbeat-background-lane branch from f944f00 to c1cae4c Compare August 21, 2026 08:17
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 21, 2026
@sallyom sallyom self-assigned this Aug 22, 2026
@sallyom

sallyom commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the thorough fix and proof. I’m taking this through a small maintainer rebase/edit to resolve the current main conflict, preserve the new context-window propagation, and simplify the lane-selection/test shape before final verification. I’ll keep the behavior and contributor credit intact.

@sallyom
sallyom force-pushed the codex/fix-heartbeat-background-lane branch from b50a455 to b85b6e5 Compare August 22, 2026 18:54
@openclaw-barnacle openclaw-barnacle Bot removed the agents Agent runtime and tooling label Aug 22, 2026
@sallyom

sallyom commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

Maintainer review: accepting the P1 availability tradeoff. Heartbeats now use bounded cron-nested capacity so slow heartbeats cannot block inbound replies. Heartbeat timing may slip under cron/hook saturation, and one may overlap an inbound provider call; this is intentional, bounded, documented, and requires no config change. This is acceptable because heartbeats are best-effort background maintenance, while timely user replies take priority. The maintainer edit reduced production growth from +11 to +3. Exact-head CI is green; awaiting final ClawSweeper review.

@sallyom
sallyom merged commit d0700b3 into openclaw:main Aug 22, 2026
250 checks passed
@sallyom

sallyom commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 23, 2026
…26853)

* fix(heartbeat): keep background runs off the main lane

* docs(queue): describe heartbeat background lane

* fix(agents): forward heartbeat lane to embedded fallback

* test(agents): prove heartbeat and visible lane overlap

* test(agents): expose heartbeat lane in embedded harnesses

* refactor(agents): keep heartbeat lane choice at fallback boundary

Signed-off-by: sallyom <[email protected]>

---------

Signed-off-by: sallyom <[email protected]>
Co-authored-by: sallyom <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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.

[Bug]: heartbeat embedded runs hold the main lane for minutes, starving visible-channel turns

2 participants