Skip to content

fix(workers): clean transfer scratch across gateway restarts - #123859

Merged
steipete merged 1 commit into
mainfrom
steipete/node-workspace-gc
Aug 14, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/node-workspace-gc

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where Gateway node-workspace transfer scratch could survive a crashed process, concurrent sync preparation could leave a losing context directory behind, and an upload rejected before staging could permanently retain the active upload slot.

Why This Change Was Made

The Gateway now owns the complete transfer-scratch lifecycle: it clears the private scratch root before exposing worker transfer paths, serializes context replacement per environment, releases upload ownership for every failed receive stage, and removes the root after node tunnels drain on shutdown. The change is AI-assisted and keeps the existing transfer authority and storage contracts unchanged.

User Impact

Node-hosted session workspaces recover cleanly across Gateway restarts and failed transfers without accumulating stale scratch data or wedging later reconciliation attempts. There is no new configuration, protocol, or SQLite schema surface.

Evidence

  • node scripts/run-vitest.mjs src/gateway/server-worker-environment-startup.test.ts src/gateway/worker-environments/node-workspace-transfer-service.test.ts src/gateway/worker-environments/node-worker-tunnel.test.ts — 3 files, 15 tests passed on the rebased head.
  • The four new lifecycle regressions were run against the pre-fix production code and failed for the intended reasons: stale startup scratch remained, concurrent preparation left two contexts, early upload rejection retained the active slot, and the service had no eager initialization hook.
  • OPENCLAW_CHECK_CHANGED_REMOTE_CHILD=1 node scripts/check-changed.mjs -- <five changed paths> — passed all core/core-test changed gates, including format, dead exports, type checks, lint, schema-version guard, and import cycles. The first delegated attempt was discarded because the remote checkout lacked its hydrated workspace modules.
  • Structured autoreview on the final rebased branch reported no accepted/actionable findings.

@clawsweeper

clawsweeper Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added the gateway Gateway runtime label Aug 14, 2026
@steipete
steipete marked this pull request as ready for review August 14, 2026 21:54
@openclaw-barnacle openclaw-barnacle Bot added size: M maintainer Maintainer-authored PR labels Aug 14, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 Aug 14, 2026
@clawsweeper

clawsweeper Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 14, 2026, 6:32 PM ET / 22:32 UTC.

ClawSweeper review

What this changes

The PR clears stale node-workspace transfer scratch at Gateway startup, serializes replacement of one environment’s transfer context, releases failed upload ownership, and removes scratch after node tunnels stop.

Regression provenance

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

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

No blocking correctness or security finding: the PR places transfer-scratch cleanup with the Gateway lifecycle and serializes same-environment replacement at the service owner. The protected maintainer label and exact-head checks still require maintainer handling before merge.

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

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is a focused owner-boundary repair with relevant regression coverage and no actionable review finding.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored internal Gateway lifecycle PR is outside the external-contributor proof gate; its body supplies focused regression-test evidence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored internal Gateway lifecycle PR is outside the external-contributor proof gate; its body supplies focused regression-test evidence.
Evidence reviewed 6 items Service-owner repair: The branch serializes prepare and close operations by environment, so a replacement waits for the previous context’s cleanup before publishing its own context.
Startup and shutdown ownership: Gateway runtime initializes the private scratch root before wiring transfer requests, while node-tunnel shutdown drains entries before closing all transfer contexts.
Internal queue contract: The directly imported queue preserves per-key ordering, permits unrelated environments to proceed, and continues a later task after an earlier failure.
Findings None None.
Security None None.

How this fits together

Gateway node-worker tunnels synchronize a session workspace through a private scratch directory under the Gateway state directory. The transfer service prepares and authorizes those files for the node-worker HTTP path, then must retire them when tunnel ownership ends or the Gateway stops.

flowchart LR
  A[Gateway startup] --> B[Worker runtime]
  B --> C[Transfer scratch service]
  C --> D[Per-environment transfer context]
  D --> E[Node worker tunnel]
  E --> F[Workspace transfer HTTP path]
  E --> G[Gateway shutdown cleanup]
  G --> C
Loading

Decision needed

Question Recommendation
Should Gateway startup delete and recreate its private node-workspace transfer scratch root before accepting worker-transfer requests, with startup failing if that private state directory cannot be reset? Approve after exact-head CI: Accept the private-scratch lifecycle policy and merge once required checks complete green.

Why: This is an intentional Gateway lifecycle and availability tradeoff under the protected maintainer review path; source review supports the implementation but cannot substitute for maintainer operational intent.

Before merge

  • Resolve merge risk (P1) - Production code is +13 net lines; the per-environment queue, eager lifecycle initialization, and tunnel-drained cleanup are distinct owner responsibilities, so collapsing them would reintroduce a race or separate cleanup from tunnel shutdown.
  • Complete next step (P2) - The protected maintainer label and pending exact-head checks require maintainer merge handling; no narrow automated repair is indicated.
Agent review details

Security

None.

PR surface

Source +13, Tests +158. Total +171 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 3 91 78 +13
Tests 2 159 1 +158
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 250 79 +171

Review metrics

Metric Value Why it matters
Production versus test LOC production +13, tests +157 The lifecycle repair adds a small owner-boundary queue and hooks while the larger change is focused regression coverage.

Stored data model

Persistent data-model change detected: durable storage schema: src/gateway/worker-environments/node-workspace-transfer-service.test.ts, durable storage schema: src/gateway/worker-environments/node-workspace-transfer-service.ts, serialized state: src/gateway/server-worker-environment-startup.test.ts, serialized state: src/gateway/worker-environments/node-workspace-transfer-service.test.ts, unknown-data-model-change: src/gateway/worker-environments/node-workspace-transfer-service.test.ts, unknown-data-model-change: src/gateway/worker-environments/node-workspace-transfer-service.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep the lifecycle ownership in the transfer service and merge after a maintainer accepts the startup-cleanup policy and the exact-head required checks are green.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep the lifecycle ownership in the transfer service and merge after a maintainer accepts the startup-cleanup policy and the exact-head required checks are green.

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

Yes, by source inspection: concurrent same-environment prepare calls previously overlap, an upload rejected before staging retained its active slot, and stale scratch survives until the new eager initializer runs. The PR also supplies focused pre-fix regression claims, though this read-only review did not execute them.

Is this the best way to solve the issue?

Yes. Serializing context replacement and cleanup inside the transfer service is narrower and safer than coordinating it in tunnel callers, which would miss restore and HTTP transfer lifecycle paths.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This repairs stale scratch and failed transfer recovery for node-hosted workers, a bounded workflow impact without evidence of a general Gateway outage.
  • 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: This maintainer-authored internal Gateway lifecycle PR is outside the external-contributor proof gate; its body supplies focused regression-test evidence.

Evidence

What I checked:

Likely related people:

  • steipete: Current-main blame and file history attribute the existing transfer service, node tunnel, and worker startup lifecycle to Peter Steinberger; the proposed branch continues that same area. (role: feature introducer and recent area contributor; confidence: high; commits: f22e4990c1fd; files: src/gateway/worker-environments/node-workspace-transfer-service.ts, src/gateway/worker-environments/node-worker-tunnel.ts, src/gateway/server-worker-environment-startup.ts)

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 (1 earlier review cycle)
  • reviewed 2026-08-14T22:00:40.714Z sha 07d0936 :: needs maintainer review before merge. :: none

@steipete
steipete force-pushed the steipete/node-workspace-gc branch from 07d0936 to c98cbbb Compare August 14, 2026 22:27
@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready on exact head c98cbbb9f167a320ae2b0d029e49b503015b3c90.

Maintainer decision: accept eager removal and recreation of the Gateway-private transfer scratch root before worker transfer paths become reachable. Failure to reset that private ephemeral namespace should fail worker-runtime startup visibly rather than serve stale or ambiguously owned transfer state.

Proof completed:

The +13 production LOC is the bounded lifecycle ownership surface: one per-environment queue, eager initialization, unified failed-upload release, and tunnel-drained whole-root cleanup. No protocol, config, durable data, or SQLite schema-version change is introduced.

@steipete
steipete merged commit 4fadf46 into main Aug 14, 2026
181 checks passed
@steipete
steipete deleted the steipete/node-workspace-gc branch August 14, 2026 22:35
@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

gateway Gateway runtime maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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.

2 participants