Repository navigation
fix(workers): clean transfer scratch across gateway restarts - #123859
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 14, 2026, 6:32 PM ET / 22:32 UTC. ClawSweeper reviewWhat this changesThe 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 provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readinessNo 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 Review scores
Verification
How this fits togetherGateway 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
Decision needed
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
Agent review detailsSecurityNone. PR surfaceSource +13, Tests +158. Total +171 across 5 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest 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. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
07d0936 to
c98cbbb
Compare
|
Land-ready on exact head 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. |
|
Merged via squash.
|
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.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.