Skip to content

fix(gateway): stop endless thaw recovery on busy gateways - #149369

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-host-thaw-busy-gateway-20260915
Sep 16, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-host-thaw-busy-gateway-20260915

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes repeated admission closures and stale channel recovery when a busy Gateway mistakes CPU-bound event-loop stalls for host sleep.

On team.openclaw.ai on September 15, 2026, one hour of journal evidence showed 119 deferred-thaw messages, 119 admission closures, and 119 reopenings—one triple per maintenance tick—even though the host never slept. Event-loop utilization was 1.0, CPU core ratio was 1.0–2.2, and one p99 event-loop delay reached 16.2 seconds at 17:07 UTC. Recovery could remain pending until an arbitrary idle moment hours later.

Related: #131046.

User Impact

Busy Gateways keep accepting work during deferred thaw checks, avoid channel recovery caused by CPU load, and stop carrying stale post-thaw restart requests after ten minutes. Genuine low-CPU sleep gaps still recover when idle. No configuration or operator migration is required.

Why This Change Was Made

The thaw owner samples cumulative process CPU time at every maintenance tick. A qualifying wall-clock gap with CPU time at least half its duration is logged once as load and schedules no thaw actions. Keeping the existing event-loop measurements avoids masking the load; ordinary health and presence maintenance continues.

A real thaw starts a ten-minute restart window (20 normal maintenance ticks), including time spent waiting for admission to reopen. Deferral logs once per thaw; expiration logs once and clears the pending restart. Maintenance reads the canonical active-work snapshot before synchronously preparing and committing admission, preserving the existing restart fence without busy-path close/rollback cycles.

The 45-second threshold, channel restart mechanics, health probes, and ordinary channel health monitoring are unchanged. The CPU ratio is a heuristic: heavy CPU work mixed with a real sleep can classify the gap as load. After the ten-minute window, automatic channel health monitoring owns further recovery. In-flight restart work is allowed to settle.

Evidence

Regression-first proof used the same two test files before and after the production edit:

node scripts/run-vitest.mjs src/gateway/host-thaw-recovery.test.ts src/gateway/server-maintenance.test.ts

Before: 6 failed, 45 passed. After: 51 passed.

  • does not recover from a CPU-busy gap with ratio %s (0.5, 1, 2.2): previously restarted once; now schedules no recovery.
  • recovers at the threshold with CPU ratio %s (0, 0.499): real low-CPU gaps still recover.
  • abandons busy retries after ten minutes, logging deferral and abandonment once: previously made 22 attempts where the bound allows 20; now stops and permits an independent later thaw.
  • does not renew the restart window while admission stays closed: previously restarted after expiration; now only refreshes health/presence after admission reopens.
  • leaves admission untouched on busy thaw ticks and retries a failed idle pass: previously emitted two preparing → accepting cycles; now emits none while busy and retains fenced idle retries.

Additional validation: node scripts/check-changed.mjs, node scripts/check-docs-mdx.mjs docs/cli/channels.md, and git diff --check. Independent Codex autoreview found no actionable P0–P2 issues. Updated docs/cli/channels.md with detection, retry-window, and health-monitor behavior.

Proof uses controlled CPU samples and synthetic maintenance timers with the real admission owner. No live Gateway was restarted, and no physical sleep/wake or production-load test was run. Exact-head CI will be recorded after the PR run completes. This PR is handed off for coordinator review and landing.

@clawsweeper

clawsweeper Bot commented Sep 15, 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 size: S maintainer Maintainer-authored PR labels Sep 15, 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 15, 2026
@clawsweeper

clawsweeper Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 15, 2026, 10:18 PM ET / September 16, 2026, 02:18 UTC (Revision 4).

ClawSweeper review

What this changes

The PR distinguishes CPU-heavy timing gaps from host pauses, limits thaw restart retries to ten minutes, and keeps admission open during busy checks.

Merge readiness

⛔ Blocked before merge - 4 items remain

This remains useful work: current main and v2026.9.4 still have unbounded thaw retries. No discrete implementation bug was found, but the previously raised recovery tradeoff for accounts with health monitoring disabled remains unresolved.

Priority: P2
Reviewed head: 589f48c9ce3faf357e95396a9251ef478a5678ef
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Focused implementation and meaningful regression coverage support normal good quality; the recovery compatibility choice remains separate from patch correctness.
Proof confidence 🌊 off-meta tidepool Not applicable: The MEMBER-authored PR is exempt from the external-contributor proof gate. Its synthetic CPU/timer regressions exercise the thaw and admission owners, but provide no live after-fix sleep/load evidence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The MEMBER-authored PR is exempt from the external-contributor proof gate. Its synthetic CPU/timer regressions exercise the thaw and admission owners, but provide no live after-fix sleep/load evidence.
Evidence reviewed 8 items Current main still needs the fix: The fetched main implementation uses a boolean pending restart, retries without a deadline, logs each deferral, and classifies timing gaps without CPU samples.
Latest release retains the existing recovery contract: The v2026.9.4 source also retains indefinite pending retries and timer-only detection; the proposed behavior has not shipped in the supplied latest release.
Expiry removes the eventual thaw retry: The introduced expiry clears pending recovery after ten minutes, including admission-closed time. The new tests explicitly verify that becoming idle after expiry does not restart channels.
Findings None None.
Security None None.

How this fits together

Gateway maintenance detects long timer gaps and coordinates channel recovery with the shared work-admission owner. It refreshes health and presence, while channel lifecycle management performs eligible reconnects.

flowchart TD
  A[Maintenance tick and CPU samples] --> B{Long low-CPU gap?}
  B -->|No| C[Ordinary maintenance]
  B -->|Yes| D[Refresh health and presence]
  B -->|Yes| E{Idle within ten minutes?}
  E -->|Yes| F[Fence admission and reconnect channels]
  E -->|No| G[Expire thaw retry]
  G --> H[Health monitoring if enabled]
Loading

Decision needed

Question Recommendation
Should the ten-minute expiry also remove eventual thaw reconnects for accounts with health monitoring disabled? Accept bounded recovery with an explicit opt-out outcome: Retain universal expiry, document possible operator reconnection for monitor-disabled accounts, and cover that outcome alongside monitor-enabled recovery.

Why: The expiry is intentional, but its advertised health-monitor fallback does not cover supported opt-outs; selecting their recovery guarantee changes shipped behavior.

Before merge

  • Resolve merge risk (P1) - After a genuine pause followed by more than ten minutes of active work, an account with health monitoring disabled loses its previous eventual thaw reconnect and may require operator reconnection if its transport does not recover independently.
  • Resolve merge risk (P1) - The process-wide CPU heuristic can suppress genuine sleep recovery when substantial CPU work occurs in the same sampling interval; the PR acknowledges this tradeoff, but physical sleep/load behavior has not been demonstrated.
  • Complete next step (P2) - Explicitly accept or preserve eventual recovery for health-monitor-disabled accounts, then document and cover the selected expiry outcome.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.
Agent review details

Security

None.

PR surface

Source +36, Tests +79, Docs +2. Total +117 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 2 56 20 +36
Tests 2 87 8 +79
Docs 1 2 0 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 145 28 +117

Review metrics

Metric Value Why it matters
Recovery policy Unbounded retries → 10-minute window; CPU cutoff ≥ 0.5 core These are the two operational behavior changes that affect genuine-pause recovery.

Merge-risk options

Maintainer options:

  1. Accept and document the bounded recovery contract (recommended)
    Explicitly accept the monitor-disabled reconnect tradeoff and add focused coverage and operator guidance before landing.
  2. Preserve the existing opt-out recovery guarantee
    Adjust expiry handling so monitor-disabled accounts retain eventual recovery without restoring busy-path admission churn.

Technical review

Best possible solution:

Keep recovery bounded and admission quiet, with an explicit, tested recovery outcome for existing health-monitor opt-outs and maintainer acceptance of that upgrade tradeoff.

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

Yes, from source: a qualifying timer gap followed by repeated busy snapshots keeps current-main recovery pending indefinitely and repeatedly cycles admission. The supplied regression results support this path; this read-only review did not execute it.

Is this the best way to solve the issue?

Yes for CPU filtering and synchronous idle-before-admission checks. Universal expiry is a reasonable bounded policy, but its monitor-disabled upgrade outcome needs explicit acceptance and coverage.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 78052a3386b3.

Labels

Label justifications:

  • P2: This addresses demonstrated busy-Gateway recovery churn with a bounded lifecycle change.
  • merge-risk: 🚨 compatibility: Existing health-monitor opt-outs can lose the eventual thaw reconnect supplied by the released implementation.
  • 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 MEMBER-authored PR is exempt from the external-contributor proof gate. Its synthetic CPU/timer regressions exercise the thaw and admission owners, but provide no live after-fix sleep/load evidence.

Evidence

What I checked:

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • steipete: 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.

  • Resolve and document the health-monitor-disabled expiry outcome, with focused coverage for the accepted behavior.

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 (3 earlier review cycles)
  • reviewed 2026-09-15T19:33:45.621Z sha 37c4e1f :: blocked before merge. :: none
  • reviewed 2026-09-15T20:55:03.299Z sha 264e875 :: blocked before merge. :: none
  • reviewed 2026-09-15T22:59:28.680Z sha 7f92b28ffdbbf61f16bec7e8931b6bd328f2ebde :: blocked before merge. :: none

@steipete
steipete force-pushed the steipete/perf-host-thaw-busy-gateway-20260915 branch from 37c4e1f to 264e875 Compare September 15, 2026 20:30
@steipete
steipete force-pushed the steipete/perf-host-thaw-busy-gateway-20260915 branch from 264e875 to 7f92b28 Compare September 15, 2026 22:15
Distinguish CPU-bound timing gaps from host suspension and bound post-thaw channel restart retries to ten minutes. Inspect active work before preparing admission so busy maintenance ticks leave work admission untouched.
@steipete
steipete force-pushed the steipete/perf-host-thaw-busy-gateway-20260915 branch from 7f92b28 to 589f48c Compare September 16, 2026 02:08
@steipete
steipete merged commit 3b090e4 into main Sep 16, 2026
188 checks passed
@steipete
steipete deleted the steipete/perf-host-thaw-busy-gateway-20260915 branch September 16, 2026 03:56
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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 gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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