Repository navigation
fix: keep agent temporary files in owned scratch - #202074
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
@clawsweeper review Please review final head 516ec9f, especially execution placement, explicit environment overrides, and live/queued scratch custody after container retirement. Local Codex autoreview is clean through P2; regression and synthetic btrfs evidence are in the PR body. |
|
🦞👀 Re-review progress:
|
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 516ec9ff9f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Codex review: needs maintainer review before merge. What this changesRoutes local agent temporary files into workspace scratch and extends existing cleanup discovery and custody to those workspaces. Example: An agent runs Node temporary-file creation from /workspace/project/nested.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR addresses unowned temporary-file growth; the earlier sandbox defects are fixed, and detached-service expiry is an explicitly accepted tradeoff. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherAgent execution prepares child environments for core exec, local CLI backends, and native Codex; Gateway maintenance discovers their scratch roots and applies existing expiry and live-run protection. flowchart TD
A[Admitted agent run] --> B[Shared scratch preparation]
B --> C[Local execution environments]
C --> D[Workspace scratch files]
E[Session and sandbox custody] --> F[Existing scratch maintenance]
D --> F
F --> G[Expired files removed]
Technical reviewBest possible solution: Use shared scratch preparation and existing execution and custody owners while preserving explicit overrides and the accepted 24-hour policy. Do we have a high-confidence way to reproduce the issue? Current-main source inherits host temporary storage without routing it into checkout scratch; the committed regression exercises temporary-file creation, but this review ran no target code. Is this the best way to solve the issue? The implementation addresses allocation at its producer, shares one scratch preparer across local paths, and reuses existing cleanup, sandbox selection, and active-container custody without a competing retention owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against d980b74978ad. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +148, Tests +300, Docs +32, Other +33. Total +513 across 26 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. Review metrics
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 (2 earlier review cycles)
Reviewed November 19, 2026, 5:30 PM ET / 22:30 UTC (Revision 3). |
|
Addressed both items from the latest ClawSweeper review in
Final staged Codex autoreview is clean through P2. Targeted typechecks/lint and the line-cap check pass. The PR body is current, and new exact-head CI is running. The documentation also calls out the existing Unix-socket path-length tradeoff and explicit short-temp overrides with caller-owned cleanup. @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8c3d312db0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Addressing item 1 in the latest review (detached Gateway processes) at unchanged head The scope here is the fixed 24-hour disposable-scratch contract established by #193677 and documented in managed-worktrees.md:838: live or queued agent runs protect their checkout; idle sessions and artifact references do not; durable outputs belong outside scratch. An explicitly detached service is deliberately started with no Consequently, once agent work has settled, unchanged scratch older than 24 hours remains eligible even if a detached service still wants it. This is an intentional product tradeoff. Such services must use ordinary workspace storage for retained state, or an explicit temp override with caller-owned cleanup. Making every detached service pin its scratch owner until process finalization would introduce an additional potentially indefinite retention exception, contrary to this lane's fixed-expiry requirement. No process-reference index or new retention rule is being added. The PR's User Impact now states this consequence explicitly. The two earlier findings remain fixed, with the numbered response and red/green proof in the previous review response. Final @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
* fix: keep agent temporary files in owned scratch * fix: preserve sandbox temp access and queued isolation custody
* fix(worktrees): retain recently used session checkouts * test(agents): decouple admission proof from workspace creation (cherry picked from commit f5d35bc) Release adaptation: reuse the beta.3 adaptation aef0b19dc08b for the stable workspace owner: add existing reader/error imports and the minimal #200691 removed-checkout preflight so activity marking never recreates a removed checkout. Omit only the changed assertion in the Gateway test file absent on this branch; retain existing Gateway readiness and owner coverage. Companions: #202074 is selected next. #202068 is present-equivalent (5631d96); #202204 changes later main-only GC owner-census behavior; #203057 is an independent probe optimization. Other later overlap concerns unrelated worktree refresh/reclamation, policy, restore UX, or the later absent removed-checkout fixture; not prerequisites (enumerated in lane audit). Release adaptation: reuse the sibling path-specific realpath spy and no-recreation regression (abce9babd5cab). The original one-shot spy closed authority at the preflight read instead of the target workspace boundary. Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit e3495dac6afc80bd3fe36110008dec96013d2514)
* fix: keep agent temporary files in owned scratch * fix: preserve sandbox temp access and queued isolation custody (cherry picked from commit f91bc99) Release adaptation: keep the staged #202815 Git shim implementation and independently assert both Git shim execution and writable owned temp in its merged Docker/Podman fixture. Use the beta.3 isolated custody configuration (896f33d52174), not ambient sandbox inventory. Companions: #193677 scratch expiry owner is present (99ba844); #202815 is present-equivalent (7d33d1a). #202122 is independent Git/scratch clone reclamation, #202428 is CLI history ownership, #202644 is host file-write authority, and #202874 is workspace cleanup scheduling; none prerequisite. Other later same-path commits concern separate template, sandbox, prompt, sharing, or run-lifecycle policy; see the lane companion audit. Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit a4070bc5b669308210b62a0b80b92c16af768b34)
Main extracted the same local-execution placement predicate as ownsLocalExecution (openclaw#202074); keep main's helper and drop this branch's duplicate.
What Problem This Solves
Agent validation commands can leave large temporary trees in host
/tmp, outside OpenClaw's 24-hour scratch cleanup. On hosts where/tmpis tmpfs, that consumes memory and swap until an operator intervenes.User Impact
Local agent commands now default
TMPDIR,TMP, andTEMPto their workspace's.openclaw/tmp. Temporary validation output is disposable under the existing 24-hour rule, even when artifacts reference it. Live and queued agent work remains protected; durable outputs belong outside scratch. After those runs settle, a detached background service alone does not extend the 24-hour lifetime of unchanged workspace scratch. Services needing longer-lived files must place them outside scratch or explicitly select a temp root with their own cleanup.Why This Change Was Made
Connect core exec, local CLI execution, and native Codex shell/Code Mode environment preparation to the existing scratch owner. Codex obtains the path through its run-bound host capability and applies it through thread shell policy, preserving shared app-server reuse. Docker/Podman commands use scratch in their writable workspace mount. Read-only workspaces keep writable temporary files in the container-private
/tmptmpfs, owned and released by the container lifecycle.The existing cleanup inventory now includes configured agent and local sandbox workspaces, including sandbox directories left after container retirement. Queued protection uses the production session selector, including attachment grants and immutable skill-library isolation. Sandbox scope resolution and active-command custody reuse their existing owners. No new TTL implementation, configuration option, schema, reference-protection index, or cache. Explicit CLI/command/container environment overrides remain supported. Remote execution keeps its own paths. Programs that explicitly choose
/tmpcan bypass the policy; arbitrary host temp entries are not swept by name. Deep workspace paths can exceed Unix-domain socket limits: those tools need a short workspace or an explicit short-temp override with their own cleanup. The existing test runner already owns that exception.Related: #193677. The short-lived native socket-path workaround from #196509 remains intact.
Evidence
A real core exec from a nested working directory creates its temporary file inside checkout scratch. The committed regression fails on base
f685aad5977d707e47ba402b3d072e482a6b091bat that assertion and passes with this change. Native Codex engine tests cover fresh and cold-resumed shells, login/snapshot variations, and restrictive environment filters. Local CLI tests cover default routing and explicit overrides; the generated sandbox shell creates an actual temporary directory. Hosted review identified a read-only-workspace regression; two real-shell tests reproduced it for Docker and Podman, and all 40 backend tests pass after preserving container-private temp for that mode. Cleanup tests verify expiry, live/queued protection, and queued sandbox protection after its last container registry row retires. Attachment and skill-library isolation regressions fail before the correction; all 17 custody and five managed-custody tests pass afterward. A real Docker read-only bind-mount probe fails before the temp-path correction and succeeds afterward.Synthetic btrfs workload: 62,000 scratch files / 1.181 GB, beside a physical 37.63 GB synthetic SQLite storage fixture with 5,000 session rows. Five serial A1/A2 pairs per variant (10 observations each), using the same unchanged TTL owner:
Every run preserves fresh/live/outside files and reports zero cleanup errors. This is the added cost of reclaiming previously unowned scratch, not a speedup comparison or a production-stall reproduction. A/A wall variation reached 24% on the shared virtual disk. The SQLite file supplies storage shape; this filesystem benchmark does not query the agent schema or measure whole-Gateway latency. Worker/native allocations are excluded from the heap sample.
Reproduce with
node --expose-gc --import ./scripts/tsx.mjs scripts/perf/scratch-cleanup-measure.ts --root <new-btrfs-directory> --samples 5 --mode timing --agent-temp; use--samples 1 --mode allocationfor the separate allocation pair.Focused tests, the full package build, targeted typechecks/lint, formatting, line-cap checks, and final
pnpm check:changedat8c3d312db0fa258486ab502ad7ad128a83ed8600pass. An earlier expanded check exposed an inherited SDK surface-budget regression: exact base and candidate both have 3,908 exports / 2,250 callables against limits 3,894 / 2,243. The check passes at422ff062032e6; the first expansion at5795128db2d0c(#201073) fails at 3,896 / 2,244. This is a main regression, not a budget change in this PR. No standalone SDK export was added. Final snapshot Codex autoreview is clean through P2. Production delta: +197/-49 = +148 lines, required for the missing environment handoffs, run-bound host operation, and root/custody coverage; repeated Codex placement checks and duplicate sandbox active-use logic were consolidated.