Skip to content

fix(gateway): recover workspace sync from slow process probes - #149963

Merged
steipete merged 4 commits into
mainfrom
upd/flake-workspace-sync-watchdog
Sep 16, 2026
Merged

steipete merged 4 commits into
mainfrom
upd/flake-workspace-sync-watchdog

Conversation

@steipete

@steipete steipete commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes cloud-worker workspace reconciliation failing on slow process probes, and prevents watchdog recovery from repeatedly resuming the same workers while later workers remain stopped.

User Impact

Workspace quiescence tolerates transient process-probe stalls. Recovery keeps completed work across at most four passes and reports an explicit terminal exhaustion outcome with unfinished PID/start references. PID identity, current-lease checks, and thaw-before-watchdog-retirement ordering remain intact; no public options, dependencies, or SQLite schema change. Terminal diagnostics use the existing external-tool lease.

Why This Change Was Made

The original census, identity, and status probes propagated their first two-second timeout. The common owner now shares a 30-second monotonic budget across a command or recovery pass, with two-second initial attempts and increasing retry allowances. This leaves room under the paired-node command's existing 60-second deadline for terminal output and cleanup; SIGKILL keeps stalled probes bounded.

ClawSweeper's exact-head P1 identified a flaw in the first version: each watchdog retry reread the unchanged full process list. Enough slow probes exhausted every pass on the same prefix. The repair retains only unfinished PID/start references, advances after verified completion, and retains the same deadline for non-budget retries. Only explicit budget exhaustion opens a subsequent bounded pass over the remaining references. Observing a renewed lease invalidates cached recovery progress and deadline. The shared resume helper preserves foreground diagnostics.

Follow-up lead review (r2) found that limiting individual passes still allowed endless recovery when every identity probe timed out. Recovery now allows at most four 30-second passes plus 1, 2, and 4 seconds of backoff: a 127-second probe/backoff budget. On exhaustion, the watchdog exits and retains its terminal reason and unfinished PID/start references in the existing lease. Foreground resume, renewal, and orphan recovery emit the saved reason through the existing Gateway error path; a later healthy recovery can still resume workers and remove the lease. Lease renewal starts a new recovery episode only after the current lease is revalidated.

Evidence

  • Original incident: CI job on PR #149918, initial quiesce exit 1 after 2,379 ms. Its assertion omitted child output, so that historical exception remains unproven. Quiesce/resume assertions now include captured command results.

  • Original slow-probe regressions fail pre-fix with spawnSync ps ETIMEDOUT; the explicit-exhaustion test proves the real 30-second budget and operator-visible reason. A lease-expiry regression also fails pre-fix by renewing expired authority.

  • Multi-process regression: 16 live workers, successful identity probes delayed one second, every second probe stuck until killed. Before the repair, the first recovered worker was revisited after approximately 43 seconds, demonstrating prefix replay. Afterward, all 16 resumed without revisiting that worker, and the lease was removed.

  • Linux node:24, non-root, procps, read-only source mount: 16/16 resumed, 31 probes, 15 timed-out attempts, one exhausted pass followed by completion, 58.8 seconds including lease expiry. The first worker was probed once; exhaustion identified the six pending worker PIDs.

  • Earlier deterministic-fixture full file: 20/20 passed. The slow-census and identity fixtures now model a three-second probe through their existing child preload: virtual time reaches the first two-second limit, the owner retries, and a larger allowance permits real ps output. The former wall-clock sleeps/busy wait are removed; production and test timeout limits are unchanged. In the full run these cases took 328 ms and 336 ms. Both still fail against the original non-retrying owner with ETIMEDOUT.

  • Earlier bounded loops include the original ps scanner case and both deterministic slow-probe cases: 20/20 invocations per mode, 60/60 selected cases normally and 60/60 under contention. The owned CPU hog was stopped and reaped.

  • Changed type, lint, and repository guards: passed. Six test-only lint errors were corrected; the test-scoped changed check and remaining production guards then passed, reusing unchanged production type/export proof.

  • Full staged-candidate Codex P1 review: scoped-clean.

  • autoreview --mode branch --base origin/main --max-priority P1: scoped-clean on b3f22597413a26f24b9f35b7bafcc0e0ea16b070.

The initial investigation also recorded a distinct local outer timeout (19/20 normal, 20/20 contention) and 60/60 Linux script probes before the product fix. This PR does not claim the historical CI exception was conclusively identified or claim physical Raspberry Pi validation.

Earlier test-only fixup: 9a6dfc8e38734017c7cc78670c3b808368b66072. Test-scoped changed checks and Codex P1 review passed. The sandbox descriptor failure observed on the previous CI run is outside this change; that code was not modified.

Lead review r2 repair

The always-timeout regression uses eight live workers and the existing child preload to advance probe time. Before this repair it reached 269,999 ms of simulated probe work and continued retrying past the 120,000 ms allowance. The repaired watchdog ends within four passes, preserves all eight unfinished references, and the actual Gateway quiescence caller surfaces the recorded reason. Restoring ps then resumes all eight workers and clears the lease. The test publishes forced expiry by atomic rename so the accelerated watchdog cannot read partial JSON.

Final full file: 21/21 passed; the 16-worker case resumed every worker in 58.1 seconds, and the always-timeout case finished in 2.0 seconds. Final normal and contention loops each passed 20/20 invocations, 80/80 selected cases (scanner, slow census, slow identity, and terminal recovery). Contention used one Vitest worker and an owned CPU hog, which was stopped and reaped.

Intermediate failures are retained in the evidence: the first full file had an empty-output initial-quiesce timeout (20/21), and the first normal loop was 16/20 with two partial-lease fixture races and two empty-output command timeouts. The lease-publication race was fixed by atomic rename. A separate 20-run Node startup probe passed; the empty-output timeout cause remains unproven. No test timeout was raised and no assertion was weakened.

Full node scripts/check-changed.mjs and autoreview --mode branch --base origin/main --max-priority P1: passed / scoped-clean. Head: 65c1cace8dd0a27e95f145bcbfbaa1950b21dbca. Cumulative LOC: production +131/−63, tests +312/−9, docs +2/−0.

@clawsweeper

clawsweeper Bot commented Sep 16, 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: M maintainer Maintainer-authored PR labels Sep 16, 2026
@steipete
steipete marked this pull request as ready for review September 16, 2026 10:07
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 Sep 16, 2026
@clawsweeper

clawsweeper Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 16, 2026, 12:26 PM ET / 16:26 UTC (Revision 4).

ClawSweeper review

What this changes

Retries slow workspace process checks, preserves watchdog recovery progress, caps recovery attempts, and adds diagnostics, documentation, and regression coverage.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⛔ Blocked before merge - 3 items remain

The earlier watchdog-progress finding is fixed, and the contribution remains useful on current main. One source-proven acquisition rollback defect still blocks merge.

Priority: P2
Reviewed head: 65c1cace8dd0a27e95f145bcbfbaa1950b21dbca

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Strong recovery evidence supports useful work, but the exhausted-budget rollback path remains incorrect.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Recorded Linux runs exercise the production quiescence scripts with real stopped workers and faulted ps processes, showing recovery of all 16 workers without prefix replay; final-head evidence also demonstrates retained unfinished references and successful subsequent resume. This supports the exercised paths but does not cover the newly identified acquisition rollback defect.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): Recorded Linux runs exercise the production quiescence scripts with real stopped workers and faulted ps processes, showing recovery of all 16 workers without prefix replay; final-head evidence also demonstrates retained unfinished references and successful subsequent resume. This supports the exercised paths but does not cover the newly identified acquisition rollback defect.
Evidence reviewed 8 items Introduced rollback defect: The new processProbe has one immutable 30-second deadline. After acquisition exhausts it, the rollback at lines 369–372 calls resumeProcesses through that same exhausted probe, which throws before checking identity or sending SIGCONT.
Failed acquisition leaves no caller release handle: The caller passes a 12-minute lease duration and throws on acquisition failure before returning a quiescence handle. Without a separate recovery attempt, already-stopped workers therefore wait for the original watchdog expiry.
Re-review continuity: Exact GitHub contents at the previous reviewed head were compared with the checkout: both the shared deadline and acquisition rollback are unchanged. The new finding is a late discovery. The prior progress finding is resolved by retaining remainingProcesses and advancing it after completed identity checks. Local historical blob inspection failed; pinned GitHub source and commit patches supplied the comparison.
Findings 1 actionable finding [P2] [P2] Keep rollback usable after exhausting the acquisition budget
Security None None.

How this fits together

Workspace quiescence pauses dedicated cloud-worker processes while the Gateway reconciles their files. A lease and detached watchdog coordinate renewal, process identity checks, and eventual resumption.

flowchart TD
  A[Completed cloud turn] --> B[Acquire workspace lease]
  B --> C[Probe and pause workers]
  C --> D[Reconcile workspace files]
  D --> E[Resume workers]
  C --> F[Acquisition failure]
  F --> E
  B --> G[Expiry watchdog]
  G --> E
  G --> H[Retain unfinished recovery]
Loading

Before merge

  • [P2] Keep rollback usable after exhausting the acquisition budget (P2) - If acquisition has already SIGSTOPped workers and a later census exhausts this deadline, its catch calls resumeProcesses through the same expired processProbe. Every cleanup identity check then throws immediately, even with healthy ps. Acquisition returns no release handle, and without another recovery attempt those workers remain stopped until the original 12-minute lease expires. Reserve bounded rollback capacity or promptly expire/hand off the failed lease, and cover exhaustion after at least one worker is frozen. This is a late discovery: the deadline and rollback are unchanged from the previous reviewed head.
  • Resolve merge risk (P1) - The intentional four-pass cutoff removes indefinite automatic thaw retries: workers still stopped at exhaustion require a later Gateway recovery attempt, potentially operator-initiated, even after ps becomes healthy.
  • Complete next step (P2) - Repair acquisition rollback after probe-budget exhaustion and add coverage showing already-stopped workers recover without waiting for the original lease expiry.

Findings

  • [P2] [P2] Keep rollback usable after exhausting the acquisition budget — src/gateway/worker-environments/workspace-quiescence-scripts.ts:9-13
Agent review details

Security

None.

PR surface

Source +68, Tests +303, Docs +2. Total +373 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 131 63 +68
Tests 1 312 9 +303
Docs 1 2 0 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 445 72 +373

Review metrics

Metric Value Why it matters
Automatic recovery limit Indefinite retries → at most 4 failed passes The new terminal handoff can leave unfinished workers awaiting a later Gateway recovery attempt.

Merge-risk options

Maintainer options:

  1. Repair failed-acquisition thaw (recommended)
    Provide bounded rollback capacity or promptly hand the failed lease to its watchdog, and verify that already-stopped workers recover without waiting for the original lease deadline.

Technical review

Best possible solution:

Preserve the documented bounded recovery policy, but give failed acquisition a prompt, usable thaw path instead of leaving cleanup on an exhausted probe budget.

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

Yes, from source: freeze a worker during acquisition, exhaust the shared budget on a later census, then let ps recover; rollback still throws before SIGCONT. This path was not executed during the read-only review.

Is this the best way to solve the issue?

Not yet: sharing retry policy and preserving watchdog progress are appropriate, but acquisition failure must retain usable cleanup capacity. The maintainer-authored body already explicitly selects the four-pass terminal policy.

Full review comments:

  • [P2] [P2] Keep rollback usable after exhausting the acquisition budget — src/gateway/worker-environments/workspace-quiescence-scripts.ts:9-13
    If acquisition has already SIGSTOPped workers and a later census exhausts this deadline, its catch calls resumeProcesses through the same expired processProbe. Every cleanup identity check then throws immediately, even with healthy ps. Acquisition returns no release handle, and without another recovery attempt those workers remain stopped until the original 12-minute lease expires. Reserve bounded rollback capacity or promptly expire/hand off the failed lease, and cover exhaustion after at least one worker is frozen. This is a late discovery: the deadline and rollback are unchanged from the previous reviewed head.
    Confidence: 0.96
    Late finding: first raised on code an earlier review cycle already covered.

Overall correctness: patch is incorrect
Overall confidence: 0.94

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 22c4164c86b5.

Labels

Label justifications:

  • P2: This is a focused cloud-workspace reliability repair with a remaining bounded availability defect.
  • merge-risk: 🚨 availability: Exhausted acquisition probes prevent immediate rollback, and the new terminal cutoff can leave workers stopped pending separate recovery.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (live_output): Recorded Linux runs exercise the production quiescence scripts with real stopped workers and faulted ps processes, showing recovery of all 16 workers without prefix replay; final-head evidence also demonstrates retained unfinished references and successful subsequent resume. This supports the exercised paths but does not cover the newly identified acquisition rollback defect.
  • proof: sufficient: Contributor real behavior proof is sufficient. Recorded Linux runs exercise the production quiescence scripts with real stopped workers and faulted ps processes, showing recovery of all 16 workers without prefix replay; final-head evidence also demonstrates retained unfinished references and successful subsequent resume. This supports the exercised paths but does not cover the newly identified acquisition rollback defect.

Evidence

What I checked:

  • Introduced rollback defect: The new processProbe has one immutable 30-second deadline. After acquisition exhausts it, the rollback at lines 369–372 calls resumeProcesses through that same exhausted probe, which throws before checking identity or sending SIGCONT. (src/gateway/worker-environments/workspace-quiescence-scripts.ts:10, 65c1cace8dd0)
  • Failed acquisition leaves no caller release handle: The caller passes a 12-minute lease duration and throws on acquisition failure before returning a quiescence handle. Without a separate recovery attempt, already-stopped workers therefore wait for the original watchdog expiry. (src/gateway/worker-environments/workspace-quiescence.ts:15, 65c1cace8dd0)
  • Re-review continuity: Exact GitHub contents at the previous reviewed head were compared with the checkout: both the shared deadline and acquisition rollback are unchanged. The new finding is a late discovery. The prior progress finding is resolved by retaining remainingProcesses and advancing it after completed identity checks. Local historical blob inspection failed; pinned GitHub source and commit patches supplied the comparison. (src/gateway/worker-environments/workspace-quiescence-scripts.ts:372, 9a6dfc8e3873)
  • Current main still needs the useful fix: Pinned current main retains first-timeout failure for two-second process probes and rereads the complete process list on watchdog retries; it does not contain this branch's recovery-progress repair. (src/gateway/worker-environments/workspace-quiescence-scripts.ts:1, 22c4164c86b5)
  • Shipped recovery contract: The latest release retains watchdog retries until recovery succeeds or the lease disappears. The PR body explicitly documents changing that policy to four failed passes followed by retained recovery state. (src/gateway/worker-environments/workspace-quiescence-scripts.ts, 3a9d69db306c)
  • Recorded production-path recovery evidence: The supplied PR-body snapshot records a non-root Linux Node 24 run using actual stopped workers and killable process probes: 16/16 workers resumed, 31 probes, 15 timed-out attempts, and lease removal after 58.8 seconds. The final-head evidence also records eight unfinished references surviving terminal exhaustion and all eight workers resuming after ps restoration. The accelerated exhaustion fixture is supplemental; this reviewer did not execute tests. (src/gateway/worker-environments/workspace-sync-scripts.test.ts:705, 65c1cace8dd0)

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.

  • Repair and regress acquisition exhaustion after a real worker has been stopped, verifying prompt thaw or watchdog handoff.

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-16T10:14:06.039Z sha 9694a55 :: blocked before merge. :: [P1] Preserve watchdog progress across probe-budget exhaustion
  • reviewed 2026-09-16T11:03:23.835Z sha b3f2259 :: blocked before merge. :: none
  • reviewed 2026-09-16T11:43:21.562Z sha 9a6dfc8 :: needs maintainer review before merge. :: none

@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. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 16, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. 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 16, 2026
@steipete
steipete merged commit eacab25 into main Sep 16, 2026
203 checks passed
@steipete
steipete deleted the upd/flake-workspace-sync-watchdog branch September 16, 2026 17:01
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 17, 2026
…aw#149963)

* fix(gateway): retry slow probes within the workspace quiescence budget

* fix(gateway): keep workspace recovery progress across slow probes

* test(gateway): make slow workspace probe fixtures deterministic

* fix(gateway): bound total workspace recovery time
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: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. 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. size: L status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant