Repository navigation
fix: avoid duplicate cloud worker teardown during recovery - #140377
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: needs maintainer review before merge. Reviewed September 6, 2026, 4:08 PM ET / 20:08 UTC. ClawSweeper reviewWhat this changesPrevents background cloud-worker recovery from repeating pending teardown and preserves request timeout errors while reading provider responses. Merge readiness✅ Ready for maintainer review This PR remains useful: current main still contains both defects, and the related merged PRs do not replace it. No blocking correctness or security finding remains after reviewing the timeout addition and retained cleanup behavior. Priority: P2 Review scores
Verification
How this fits togetherThe Gateway coordinates cloud-worker cleanup and session recovery, retaining unfinished workspace results until teardown succeeds. Separately, shared HTTP helpers turn provider responses into bounded results or actionable errors for plugins such as Vydra. flowchart TD
A[Background recovery] --> B[Environment cleanup owner]
C[Explicit Stop or Move] --> B
B --> D{Cleanup already requested?}
D -->|Background request| E[Report pending and retain recovery state]
D -->|First request or explicit retry| F[Provider teardown]
G[Provider response body] --> H[Preserve transport timeout]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +20, Tests +88. Total +108 across 14 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep cleanup retries with the environment owner, preserve unfinished workspace fences, and propagate actual transport timeout causes through the existing HTTP helpers. Do we have a high-confidence way to reproduce the issue? Yes: current source exposes the duplicate teardown path and swallowed request timeout, with focused regressions and reported before/after runs matching both mechanisms; this read-only review did not execute them. Is this the best way to solve the issue? Yes: the patch distinguishes cleanup requests from retries at the existing lifecycle owner and preserves timeout identity at the shared HTTP boundary without changing deadlines or stored formats. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 9474ff67da1f. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles) |
|
@clawsweeper re-review The current head also repairs the provider timeout race exposed by CI: shared HTTP error extraction now preserves the request's TimeoutError, and Vydra classifies that cause without a wall-clock guess. Real HTTP 200/500 regressions fail before the repair and pass afterward; 133 owner/provider sibling tests, changed-file gates, and independent P2 review pass. The PR body preserves the exact earlier cloud build/live provenance. |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Merged via squash.
|
…rol-ui * origin/main: docs: remove the empty release-sections nav group (#140427) fix(tooling): omit Codex machine squash credit (#140420) chore(ui): refresh control ui locales (#140384) refactor(plugin-sdk): reuse native approval input contracts (#140415) fix: silent model WebSocket streams hang past the idle timeout (#140335) perf(ai): avoid unused text extraction for image results (#140409) fix(ui): distinguish failed GitHub status checks from disconnected accounts (#140333) refactor(cron): share runtime feedback schema fields (#140408) fix: avoid duplicate cloud worker teardown during recovery (#140377) fix(cli): show executable approval scope (#138386) refactor(ui): reuse shared requirement records (#140407) test(gateway): table-drive device token lifecycle checks (#140403) fix(chat): fence delayed history at terminal retirement (#140379) test(skills): compare large upload bytes natively (#140402) refactor(delivery): reuse the canonical rendered batch plan type (#140386) docs(start): repair the first-run path from landing page to first channel (#140390) # Conflicts: # docs/.i18n/glossary.zh-CN.json
…140377) * fix: avoid duplicate cloud worker teardown during recovery * test: install recovery interception before runtime creation * fix: preserve request timeout causes during body reads
What Problem This Solves
Fixes an issue where Gateway shutdown waits for a second physical cloud-worker Stop after background recovery has already tried to clean up the same lease. A failed deletion can add tens of seconds to shutdown and repeats provider work without gaining new evidence.
Related: #138900 and the requested cloud-session performance follow-ups.
Why This Change Was Made
Environment reconciliation performed the first teardown attempt, then placement recovery unconditionally called destruction again. Background recovery now requests cleanup through the same environment owner, which checks the existing destroy intent under its existing lock. Already-requested, unfinished cleanup reports pending instead of invoking the provider again. Explicit Stop and Move retain their retry behavior.
Pending-result recovery receives the same background service view, so a pending deletion cannot be mistaken for successful cleanup or release an accepted checkpoint/turn fence. No schema, stored representation, public protocol, configuration option, provider deadline, or physical-operation join changes.
User Impact
Failed cleanup is attempted once per background recovery sweep. Operators can still explicitly retry Stop and receive the current provider error. The Gateway continues to wait for admitted physical cleanup; an unknown lease is not treated as proof that resources are gone.
Evidence
ff930fa95e359b59960b7c911f549c1bb79f2a6fwith temporary timing instrumentation: a real periodic recovery sweep held an in-flight Crabbox Stop through SIGINT, then started a second Stop for the same historical task lease. The first took approximately 47.8s and the duplicate another 36.6s. Natural Gateway shutdown took 84.738s, with 84.209s in placement reconciliation. Every owned process was joined; no allocation or state rewrite was requested.aaa7957e8d0ec48adb770525bda5b5b5fca5a930in 3m56.7s. The matched live periodic-shutdown probe passed: 84.738s before → 46.639s after, and two physical Stops → one. The provider call remained joined; the Gateway exited naturally with code 0, all owned processes were absent, the test port was closed, and the unresolved historical lease remained recorded as destroying. Provider latency varies; the independent command count proves duplicate elimination.TimeoutError, but shared HTTP error extraction swallowed it, and Vydra guessed timeout from wall-clock time. The shared extractor now preserves the actual timeout; Vydra labels that cause and removes the clock inference. Real loopback HTTP regressions for 200 and 500 responses fail before this fix and pass afterward, with native timers and unchanged deadlines. Another regression preserves the exact error identity. All 133 owner and media-provider sibling cases pass, including ordinary broken-body metadata and custom body-timeout labels; independent P2 review is clean.The normal Move recovery path already rejects a destroy-requested attachment at its reclaim admission check. Paired-device abandonment replay retains its separate, explicit durable-decision contract. No background retry behavior is inferred from a missing authorization callback.
Production: +20 net lines: +17 for the cloud request-versus-retry boundary and +3 to preserve the existing transport timeout through shared error handling. Tests/support: +88 net lines. Temporary diagnostic instrumentation used to isolate the delay is excluded from the patch.
Build and live cloud proof remain attributed to
aaa7957e8d0ec48adb770525bda5b5b5fca5a930. Later changes fix the captured-method fixture and the separately reproduced HTTP timeout race; earlier proof is not relabeled. Exact-head CI on6d0ad0487fc667e662b0c189cb14ad4a2042c983passed: 107 successful jobs, 17 skipped, including every previously failing job. Fresh ClawSweeper review on that head reports no findings or before-merge requirements.