Repository navigation
fix(gateway): recover workspace sync from slow process probes - #149963
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: blocked before merge. Reviewed September 16, 2026, 12:26 PM ET / 16:26 UTC (Revision 4). ClawSweeper reviewWhat this changesRetries slow workspace process checks, preserves watchdog recovery progress, caps recovery attempts, and adds diagnostics, documentation, and regression coverage. Regression provenancePossible 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 Review scores
Verification
How this fits togetherWorkspace 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]
Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +68, Tests +303, Docs +2. Total +373 across 3 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest 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:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 22c4164c86b5. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles)
|
|
Merged via squash.
|
…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
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
psoutput. 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 withETIMEDOUT.Earlier bounded loops include the original
ps scannercase 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 onb3f22597413a26f24b9f35b7bafcc0e0ea16b070.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
psthen 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.mjsandautoreview --mode branch --base origin/main --max-priority P1: passed / scoped-clean. Head:65c1cace8dd0a27e95f145bcbfbaa1950b21dbca. Cumulative LOC: production +131/−63, tests +312/−9, docs +2/−0.