Repository navigation
fix: prevent attachment staging after worktree removal - #174104
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. What this changesAttachment staging retains the managed workspace owner and checks its current authority before filesystem mutations. Example: Remove a managed worktree while attachment.txt containing “ordinary attachment bytes” is being read.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR fixes a current-main workspace-lifetime defect; the prior mock-export finding is resolved, and no blocking introduced defect remains. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherInbound reply preparation passes attachment sources and session workspace metadata to sandbox staging, which produces private workspace files and rewritten media references. flowchart LR
A[Inbound attachment] --> B[Session workspace preparation]
B --> C[Retained managed workspace owner]
C --> D[Source read]
D --> E[Guarded filesystem root]
C --> E
E --> F[Private attachment and media references]
Technical reviewBest possible solution: Land the focused repair that retains the existing workspace owner through guarded attachment publication. Do we have a high-confidence way to reproduce the issue? Current-main source establishes the lifetime gap, and the supplied deterministic regression records the matching base failure; this read-only review ran no target code. Is this the best way to solve the issue? The repair extends the existing owner's lifetime and reuses filesystem mutation guards while preserving information-only callers and SSH staging. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 28f8cab70da1. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +35, Tests +183, Docs +3, Other -4. Total +217 across 13 files. Added test files: 1. View PR surface stats
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (1 earlier review cycle)
Reviewed October 16, 2026, 6:52 AM ET / 10:52 UTC (Revision 2). |
|
The four sandbox mock factories now explain their deliberate fixture isolation, and the generated baseline removes their four obsolete entries without adding exemptions. The mock-export ratchet passes on the current head. @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Fixed: pending attachments no longer create files after their managed worktree is removed. |
Prevent pending attachment staging from recreating files after its managed worktree is removed. Fixes openclaw#174029.
What Problem This Solves
Fixes #174029.
Removing a managed project worktree while an inbound attachment is being read can leave a successful attachment stage in its retired sandbox projection. The removal finishes before the delayed read, but staging then creates a private input directory and file using a path whose workspace owner has already been released.
User Impact
A pending attachment can no longer publish new files after its managed worktree is retired. Ordinary staging keeps the same attachment bytes and paths, and the managed original remains available when staging fails. The temporary workspace owner is released after success, a read failure, or cancellation.
This preserves the existing permission and removal behavior. It adds no configuration, data migration, retention policy, or backend requirement. Callers that only need workspace information retain their existing result and disposal behavior.
Why This Change Was Made
Sandbox workspace preparation already selects and validates the managed projection. Its information-only entry point disposed that owner before returning, while attachment staging still had asynchronous source work ahead of it.
The shared preparation now also exposes an owned result for writers. Attachment staging retains it for the whole operation and supplies its current-state assertion to the existing safe-filesystem root. The root checks that authority before creating both the privacy marker and the attachment, alongside the existing cancellation checks. The information-only entry point releases the same preparation immediately; selection and layout remain in one owner.
Evidence
The focused regression uses real managed-worktree creation and removal, persisted session metadata, sandbox preparation, and production attachment staging. A deferred source-read result makes removal finish before the stage resumes. Unchanged production code at c316eca reports one staged file after retirement and fails the required zero count.
The corrected owner regression passes all four cases: ordinary bytes, failed reads, cancellation, and retirement during the held read. It also verifies that the real owner stays current while reading and is disposed after settlement. The retirement case leaves no new input directory or file.
Remote validation passed changed-file formatting/lint, the affected production and test type checks, and 820 tests across 47 selected files. These cover existing source policy, history, SSH, workspace information, cancellation, and private-input reconciliation/restore. The native E2E runtime prerequisite also built successfully.
pnpm test src/gateway/server-methods/sandbox-media.workspace-lifetime.test.ts --maxWorkers=1took 36.51 seconds wall time, including 14.57 seconds of cold worker preparation; its four test bodies took 9.49 seconds. The Git, registry, and session-owner composition is needed to exercise real retirement through its actual lifecycle owners. The remaining related batch took 785.18 seconds including its E2E prerequisite. Full PR CI passed on the current head.