Skip to content

fix: heartbeats fail after successful replies in explicit agent fleets - #123303

Merged
steipete merged 2 commits into
mainfrom
codex/fix-ambient-owner-recurrence
Aug 13, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/fix-ambient-owner-recurrence

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Related: #123283

What Problem This Solves

Fixes an issue where heartbeats in explicit multi-agent fleets could complete the model run successfully but then fail during post-run usage accounting or outbound channel bootstrap, preventing the completed reply from being delivered.

Why This Change Was Made

The completed run already carries the authoritative agent id and agent directory. This change preserves that ownership through reply pricing, persisted session accounting, diagnostics, follow-up delivery, post-compaction context lookup, and heartbeat channel bootstrap instead of asking those downstream consumers to rediscover a default agent that does not exist in an explicit fleet.

The same ownership invariant is applied to status and Doctor heartbeat probes. No config, protocol, storage schema, or fallback behavior changes.

Production LOC: +23/-5 (net +18) | Tests: +96/-2. The production growth is the explicit owner-context propagation across the reply-accounting and heartbeat-routing sibling surfaces; it removes ambiguous default-agent resolution from the affected paths.

User Impact

Operators using explicit multi-agent ownership can expect a successful heartbeat run to finish its accounting and delivery path instead of failing after the response has already been generated.

Evidence

Live recurrence on release 927a97c1ea1f7ca19cbd721ad17294ed940ce6ea:

  • Gateway ready at 2026-08-13T20:09:45.628Z.
  • Heartbeat started at 2026-08-13T20:09:45.805Z.
  • The model run completed and persisted its final response and terminal artifacts.
  • At 2026-08-13T20:11:11.675Z, post-run accounting threw through accountAgentTurn -> buildReplyUsageState -> resolveModelCostConfig because the selected agent directory had been dropped. No outbound delivery occurred.

Regression proof before the fix:

  • Reply usage-state pricing failed through resolveDefaultAgentId in an explicit fleet.
  • Response usage-line pricing failed through the same fallback.
  • Persisted session pricing silently omitted estimatedCostUsd.
  • Three heartbeat target tests showed the selected agentId was absent from cold plugin bootstrap.

Proof after the fix:

  • Focused reply/accounting, outbound target, agent-runner, and follow-up suites: 243 tests passed.
  • Targeted persisted-session cost regression: 1 test passed.
  • Windows-only usage-template test is updated for the required owner context and skipped as expected on macOS.
  • node scripts/check-changed.mjs -- <15 changed paths> passed the core and coreTests lanes, including formatting, typechecks, lint, import cycles, native schema, and database-first guards.
  • .agents/skills/autoreview/scripts/autoreview --mode local reported no accepted/actionable findings on the exact committed bundle (patch is correct, confidence 0.97).
  • git diff --check passed.

Remaining proof gap: this exact PR head has not yet been deployed to the manager-owned live Gateway, so a post-fix live heartbeat delivery remains for the independent verifier. GitHub CI is also pending. This PR should not merge until that independent verification is complete.

@clawsweeper

clawsweeper Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@steipete
steipete marked this pull request as ready for review August 13, 2026 20:47
@openclaw-barnacle openclaw-barnacle Bot added commands Command implementations size: S maintainer Maintainer-authored PR labels Aug 13, 2026
@steipete steipete self-assigned this Aug 13, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. 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: 🦐 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. labels Aug 13, 2026
@clawsweeper

clawsweeper Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 13, 2026, 5:16 PM ET / 21:16 UTC.

ClawSweeper review

What this changes

The branch carries the selected agent’s directory and ID through post-run pricing, session accounting, follow-up delivery, heartbeat routing, and status/Doctor probes in explicit agent fleets.

Regression provenance

Possible regression — probable (reproduction; failure trace). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open: this maintainer-labeled PR addresses a credible P1 delivery regression, but its own body confirms after-fix live heartbeat delivery has not yet been independently demonstrated.

Priority: P1
Reviewed head: 7e2ebefb3317ddc7599f2ff5754d05a1564d7c78

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The repair has focused validation evidence, but the required independent after-fix delivery proof remains absent.
Proof confidence 🦐 gold shrimp (3/6) Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.
Evidence reviewed 3 items PR evidence: The PR body records a live pre-fix failure after model completion and says no outbound delivery occurred; it also explicitly identifies an after-fix live Gateway delivery proof gap.
Related merged repair: The provided context identifies merged PR 123283 as the preceding owner-context delivery repair; this branch addresses remaining accounting and probe propagation paths.
Inspection limitation: Local read-only inspection could not run: the command environment returned bwrap: loopback: Failed RTM_NEWADDR: Operation not permitted, so no additional repository files, scoped policies, history, or diff lines were claimed as inspected.
Findings None None.
Security None None.

How this fits together

A completed agent run flows into usage accounting and outbound delivery. Those consumers must retain the admitted agent owner so pricing and channel bootstrap do not attempt ambiguous default-agent selection.

flowchart LR
  A[Explicit agent fleet] --> B[Completed agent run]
  B --> C[Owner context]
  C --> D[Usage accounting]
  C --> E[Heartbeat routing]
  E --> F[Channel bootstrap]
  D --> G[Delivered reply]
  F --> G
Loading

Before merge

  • Resolve merge risk (P1) - The PR body confirms that this exact head lacks independent after-fix live heartbeat delivery proof; a completed reply could still fail in an unexercised integration path.
  • Complete next step (P2) - The protected maintainer PR needs independent live delivery verification rather than an automated code repair.
Agent review details

Security

None.

PR surface

Source +19, Tests +166. Total +185 across 17 files.

View PR surface stats
Area Files Added Removed Net
Source 11 27 8 +19
Tests 6 168 2 +166
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 17 195 10 +185

Review metrics

Metric Value Why it matters
Production versus test delta production +18 net; tests +94 net The stated owner-context propagation spans accounting and delivery paths, making real integration proof material before merge.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/commands/doctor-heartbeat-session-target.ts, serialized state: src/auto-reply/reply/session-usage.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Verify the live heartbeat path (recommended)
    Before merge, run an explicit-fleet heartbeat through the live Gateway and attach a redacted trace proving the selected agent completes accounting and outbound delivery.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Attach a redacted live Gateway trace showing explicit-fleet heartbeat accounting and reply delivery succeed for the selected agent.

Technical review

Best possible solution:

Retain the admitted agent owner through every post-run accounting and heartbeat-delivery boundary, then attach a redacted live Gateway trace showing a selected explicit-fleet agent completes accounting and sends its heartbeat reply.

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

No: the PR reports a live pre-fix recurrence and focused tests, but local execution was unavailable and no independent after-fix live delivery trace is present.

Is this the best way to solve the issue?

Unclear: the supplied patch consistently carries the selected owner, which matches the described failure, but local whole-path and sibling-surface inspection was unavailable.

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

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

Labels

Label changes:

  • add P1: The reported regression can prevent completed heartbeats from delivering replies for explicit multi-agent operators.
  • add merge-risk: 🚨 message-delivery: The branch changes heartbeat target bootstrap and follow-up delivery owner propagation.
  • add merge-risk: 🚨 session-state: The branch changes agent context passed into persisted session usage accounting.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.

Label justifications:

  • P1: The reported regression can prevent completed heartbeats from delivering replies for explicit multi-agent operators.
  • merge-risk: 🚨 message-delivery: The branch changes heartbeat target bootstrap and follow-up delivery owner propagation.
  • merge-risk: 🚨 session-state: The branch changes agent context passed into persisted session usage accounting.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Real behavior proof is not required for maintainer- or bot-authored pull requests.

Evidence

What I checked:

  • PR evidence: The PR body records a live pre-fix failure after model completion and says no outbound delivery occurred; it also explicitly identifies an after-fix live Gateway delivery proof gap. (7e2ebefb3317)
  • Related merged repair: The provided context identifies merged PR 123283 as the preceding owner-context delivery repair; this branch addresses remaining accounting and probe propagation paths. (src/infra/outbound/targets.ts, 927a97c1ea1f)
  • Inspection limitation: Local read-only inspection could not run: the command environment returned bwrap: loopback: Failed RTM_NEWADDR: Operation not permitted, so no additional repository files, scoped policies, history, or diff lines were claimed as inspected.

Likely related people:

  • steipete: The supplied context attributes both this PR and the immediately preceding merged owner-context repair to this contributor. (role: recent area contributor; confidence: medium; commits: 927a97c1ea1f, 7e2ebefb3317; files: src/infra/outbound/targets.ts, src/auto-reply/reply/agent-runner-result-accounting.ts)

Rank-up moves

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

  • Attach a redacted live Gateway trace showing an explicit-fleet heartbeat completes accounting and outbound delivery.

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.

@steipete
steipete merged commit babba71 into main Aug 13, 2026
136 checks passed
@steipete
steipete deleted the codex/fix-ambient-owner-recurrence branch August 13, 2026 21:19
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 14, 2026
openclaw#123303)

* fix: keep heartbeat reply accounting agent-scoped

* fix: close ambient owner fallback gaps
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations maintainer Maintainer-authored PR merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. 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: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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.

1 participant