Skip to content

fix(update): use a private workspace when the system temp directory is unsafe - #187737

Merged
steipete merged 1 commit into
mainfrom
fix/update-private-temp-187657
Oct 29, 2026
Merged

steipete merged 1 commit into
mainfrom
fix/update-private-temp-187657

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Updates can refuse before package mutation when the selected temp root has a group- or world-writable ancestor without sticky protection.

Fixes #187657. Thanks @Yachiyo1680 for the report.

User Impact

OpenClaw warns with the rejected ancestor and continues using private scratch under the selected state directory's tmp directory. If both locations are unsafe, the refusal identifies the directory and gives chmod +t or chmod go-w guidance. Shared permissions are never changed.

Node 26.8.1 is admitted with security-upgrade guidance per #186589; 26.12.1 is the recommended security patch level, rather than the current runtime admission floor. This change does not alter Node admission.

Why This Change Was Made

On POSIX, the shared selector prefers /tmp/openclaw, with a per-user os.tmpdir()/TMPDIR fallback. It checked the private leaf while workspace admission also checked ancestors. Filter unsafe ancestors at selection and reuse the same fs-safe private-root resolver for the state fallback. This covers update artifacts, candidate admission, install workspaces, and Doctor snapshot staging through their existing callers. Coordination databases and service locks explicitly keep their existing shared locations across profiles and updater versions; Android ancestor group admission remains with fs-safe. Artifact retention after uncertain child cleanup and identity-checked removal stay with their existing owner.

The canonical state resolver is reused. Home-path context initializes lazily so importing the selector remains browser-safe. Fallback selection stays stable when state does not yet exist, and disposable scratch remains under state/tmp.

Evidence

  • Two real-filesystem regressions failed on base 82777f305ef8: the unsafe system root was selected, and the unsafe-state case did not refuse. With the fix, a real 0775 non-sticky ancestor selects private state scratch; fs-safe admits a workspace there and removes it after use. Both unsafe roots produce directory-specific repair guidance.
  • A real local npm tarball update from fixture version 1.0.0 to 1.0.1 stages and activates through the fallback, runs lifecycle scripts and Doctor, preserves canonical state isolation, and cleans its workspace. Existing refusal, identity-replacement, and uncertain-child retention cases remain covered.
  • Bun: 65 focused cases passed across selector, coordination-path, browser-import, home-path, and artifact lifecycle suites; the final unsafe-temp npm activation case took 431 ms. Node ran the same live npm case successfully in 465 ms.
  • Node: the initial 143-file sibling selection completed with three inherited service-definition failures. Restoring both changed production modules byte-for-byte to base 82777f3 and rerunning the unchanged 20-case service-definition suite reproduced the same three failures (17 passed, 3 failed). The final 91-file coordination/ownership selection passed all 11 shards (1,485.03 seconds including preparation). The 47-file SDK/barrel consumer selection passed.
  • Targeted infra and update-CLI typechecks, scoped oxlint, oxfmt, git diff --check, and Madge (0 cycles) passed. Both ratchets passed: 404 grandfathered suppressions; 6,267,403 test lines against a 6,325,142 ceiling. No baseline changes.
  • Independent Codex autoreview of the complete local diff against 82777f305ef8, through P2: scoped-clean. The SQLite inventory portion of full check:changed was omitted under the campaign's local gate budget; PR CI supplies broad proof.

All fixtures and live npm work used isolated, realpath-resolved per-user temp roots. The reporter's exact rejected directory is unknown; the synthetic permission layout reproduces the policy mismatch without claiming the original deployment layout.

The inherited failures are Doctor maintenance retains pending recovery without another activation after an operator edit (expected revoked authority/recovery-pending, received the fixture activation error), and the legacy LaunchAgent migration cases (20, throttle=10) and (600, throttle=1) (expected timeout/throttle repair, plist retained the old values). No assertions, retries, or timeouts were changed to hide them.

Pre-existing slow proof was retained: the original-service integration file spent 234.7 seconds across 48 cases, with a 13.38-second maximum case; its fixtures exercise real state/lease owners with simulated native transports. The skill-library worker E2E case took 38.052 seconds through real worker authoring/lifecycle behavior. The initial broad command took 1,899.82 seconds including runtime preparation and all 23 shards.

Production: +80/-12 lines (net +68). Tests: +84/-6 lines (net +78). The added production work selects scratch roots and preserves existing coordination addresses; no schema, dependency, CLI, or config changes.

The focused Bun command was OPENCLAW_VITEST_RUNTIME=bun node scripts/run-vitest.mjs src/infra/tmp-openclaw-dir.test.ts src/infra/update-managed-service-handoff-lease-path.test.ts src/infra/tmp-openclaw-dir.browser-import.test.ts src/infra/home-dir.test.ts src/cli/update-cli/update-command-artifact.test.ts --maxWorkers=1 (65 passed). Node used the same repository runner with OPENCLAW_VITEST_RUNTIME=node for the 143-file direct/home-path selection, 91-file coordination/ownership selection, and 47-file SDK/barrel selection.

Warn with the rejected writable ancestor and use private state/tmp scratch
when the selected system temp hierarchy is unsafe. Preserve shared
coordination addresses, Android admission, and artifact retention/cleanup.

Fixes #187657. Thanks @Yachiyo1680 for the report.
@clawsweeper

clawsweeper Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime cli CLI command changes size: S labels Oct 29, 2026
@steipete
steipete marked this pull request as ready for review October 29, 2026 14:58
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-29T15:03:48.865451Z 25ffdac Draft marked ready
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 25ffdac10d

ℹ️ 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".

Comment on lines +110 to +115
const stateDir = resolveStateDir();
try {
const fallbackRoot = resolveRoot({
...rootOptions,
preferredDir: undefined,
tmpdir: () => path.join(stateDir, "tmp"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve the caller-selected namespace for Doctor IPC

When /tmp/openclaw has an unsafe ancestor, this fallback discards the caller's tmpdir override and selects scratch from the current process's state directory. In src/infra/update-candidate-canary.ts, doctorResultOptions explicitly selects copiedStateDir for the Doctor result, while the child receives that copied directory as OPENCLAW_STATE_DIR. The parent now creates the result path under live-state scratch, but the child's resolveSafeUpdatePostInstallDoctorResultPath in src/infra/update-doctor-result.ts expects copied-state scratch and throws Unsafe post-install doctor result path. Consequently, candidate Doctor cannot publish its result and normal update rehearsal fails in the unsafe-temp environment this change is meant to support. Preserve a shared IPC namespace across the parent and child when applying the fallback.

AGENTS.md reference: AGENTS.md:L52-L52

Useful? React with 👍 / 👎.

Comment on lines +118 to +120
(options.warn ?? console.warn)(
`[openclaw] ${String(rejected)} Using private state temp dir: ${fallbackRoot}`,
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Emit the fallback warning without reentering logger initialization

With console capture enabled, default file logging, and an unsafe system-temp ancestor, this unconditional console.warn reenters the logger that is resolving this same directory. enableConsoleCapture in src/logging/console.ts forwards warnings through getLogger(), whose uncached settings resolve resolveDefaultRollingLogFile() and call this selector again. Since every selection emits another warning before settings can be cached, initialization recurses until stack exhaustion; the console wrapper catches the error, but unwinding then emits many duplicate warnings and performs repeated filesystem work. Use a non-captured warning sink or otherwise prevent warning emission from recursively initializing the logger.

Useful? React with 👍 / 👎.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 29, 2026
@clawsweeper

clawsweeper Bot commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

Select private state-directory scratch when system temporary storage has unsafe ancestor permissions, while preserving coordination locations.

Example: Linux has /tmp mode 0775 without sticky protection and a safe /home/alex/.openclaw state directory.

  • Before: Update workspace admission rejects the temporary hierarchy.
  • After: Scratch selection falls back to /home/alex/.openclaw/tmp/openclaw-1000 and reports the rejected ancestor.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) Useful, focused recovery work with meaningful filesystem coverage, but two verified consumer regressions block merge.
Proof confidence 🦐 gold shrimp (3/6) The ordinary contributor proof gate does not apply to this maintainer-authored PR; supplied evidence exercises real filesystem and npm operations through a harness, without demonstrating the shipped update flow.
Patch quality 🦪 silver shellfish (2/6) 2 actionable review findings remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Partial
User problem: Updates refuse before package mutation when temporary storage has a writable ancestor without sticky protection.
Reason: Automatic private scratch recovery has clear value, and the maintainer-authored PR establishes direction; the introduced Doctor failure prevents a complete repair.

Merge readiness

⛔ Needs changes before merge - 2 items remain

This PR addresses a real update failure, but the fallback introduces a Doctor result-path mismatch and recursive logger initialization that should be repaired before merge.

Priority: P2
Reviewed head: 25ffdac10d8bfa14ebb31c7c60311ab3dd4281b8

Before merge

  • Preserve the caller-selected Doctor result namespace during fallback (P1) - When /tmp/openclaw has an unsafe ancestor, this replacement of tmpdir ignores the copiedStateDir selected by update-candidate-canary.ts. The parent constructs the result under its live state/tmp root, while the child receives copiedStateDir as OPENCLAW_STATE_DIR and TMPDIR and selects a different root. resolveSafeUpdatePostInstallDoctorResultPath then rejects the parent's path with 'Unsafe post-install doctor result path', preventing candidate Doctor from publishing its result in the environment this fix targets. Preserve one caller-selected namespace across result creation, child validation, and consumption.
  • Emit fallback warnings without reentering logger initialization (P2) - With console capture enabled and default file logging, console.warn forwards to getLogger(). Initial logger settings resolve the rolling log path through this selector, which emits another warning before settings are cached. An unsafe system-temp ancestor therefore causes recursive initialization until stack exhaustion, followed by duplicate output and repeated filesystem work during unwinding. Use an uncaptured warning sink at this low-level boundary.

Findings

  • [P1] Preserve the caller-selected Doctor result namespace during fallback — src/infra/tmp-openclaw-dir.ts:110-115
  • [P2] Emit fallback warnings without reentering logger initialization — src/infra/tmp-openclaw-dir.ts:118-120

Tests

  • Missing end-to-end proof: The supplied fixture bypasses production candidate rehearsal; no shipped CLI run demonstrates unsafe-temp Doctor completion, console-capture startup, or a latest-stable upgrade preserving existing settings.
Agent review details

How this fits together

The shared temporary-root selector supplies update staging, Doctor IPC, logging, and plugin consumers; fs-safe admits private directories, while service locks and handoff databases need stable coordination addresses.

flowchart TD
  A[Update and runtime callers] --> B[Temporary root selector]
  B --> C[System temporary root]
  C --> D[Ancestor permission check]
  D --> E[Private state scratch fallback]
  B --> F[Stable coordination locations]
  E --> G[Workspace and Doctor consumers]
Loading

Technical review

Best possible solution:

Keep the shared selector and fs-safe admission, preserve the caller's Doctor namespace during fallback, and emit warnings through a sink that cannot initialize logging.

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

The permission mismatch and both introduced regressions are traceable through current source; supplied real-filesystem tests support the original mismatch, but this read-only review executed no target code.

Is this the best way to solve the issue?

A private fallback is appropriate and uses existing owners, but its namespace and warning behavior must satisfy existing consumers before the fix is complete.

Full review comments:

  • [P1] Preserve the caller-selected Doctor result namespace during fallback — src/infra/tmp-openclaw-dir.ts:110-115
    When /tmp/openclaw has an unsafe ancestor, this replacement of tmpdir ignores the copiedStateDir selected by update-candidate-canary.ts. The parent constructs the result under its live state/tmp root, while the child receives copiedStateDir as OPENCLAW_STATE_DIR and TMPDIR and selects a different root. resolveSafeUpdatePostInstallDoctorResultPath then rejects the parent's path with 'Unsafe post-install doctor result path', preventing candidate Doctor from publishing its result in the environment this fix targets. Preserve one caller-selected namespace across result creation, child validation, and consumption.
    Confidence: 0.99
  • [P2] Emit fallback warnings without reentering logger initialization — src/infra/tmp-openclaw-dir.ts:118-120
    With console capture enabled and default file logging, console.warn forwards to getLogger(). Initial logger settings resolve the rolling log path through this selector, which emits another warning before settings are cached. An unsafe system-temp ancestor therefore causes recursive initialization until stack exhaustion, followed by duplicate output and repeated filesystem work during unwinding. Use an uncaptured warning sink at this low-level boundary.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 01080c52372e.

Provenance checked

  • Shared secure temporary-root resolution keeps the original intent (b0603cb: Centralize filesystem safety in fs-safe instead of maintaining competing implementations.)
  • Invocation-relative home paths keeps the original intent (6830c82: Preserve invocation-relative paths while package replacement requires a different physical working directory.)
  • Stable managed-update coordination storage keeps the original intent (fix(update): repair cannot settle cancelled update custody on macOS, blocking every later update #185002: Keep terminal, Gateway, and profile callers on one store so repair settles actual update custody.)
  • Service lifecycle lock placement keeps the original intent (000af98: Retain executor and writer exclusion during package rollback and recovery.)
  • Browser-safe selector imports keeps the original intent (fix(ui): defer fs.constants eval to prevent browser bundle crash #48930: Prevent Node filesystem initialization from crashing browser imports before runtime guards execute.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test src/infra/tmp-openclaw-dir.test.ts src/infra/update-doctor-result.test.ts src/infra/update-managed-service-handoff-lease-path.test.ts src/infra/tmp-openclaw-dir.browser-import.test.ts src/infra/home-dir.test.ts src/cli/update-cli/update-command-artifact.test.ts --maxWorkers=1
  • Run focused production-boundary regressions for candidate Doctor result exchange and console-captured default logger initialization; demonstrate failure before repair and success afterward.
  • Exercise pnpm openclaw update in isolated state with an unsafe system-temp ancestor, including fresh state and a latest-stable upgrade with settings intact.
  • git diff --check

What I checked:

Likely related people:

  • Jason (Json): Raw commit 73858ce adds src/infra/update-managed-service-handoff-lease.ts:77 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 73858ce2e11f; files: src/infra/update-managed-service-handoff-lease.ts)

PR surface

Source +68, Tests +78, Docs +12. Total +158 across 9 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 4 80 12 +68
Tests 4 84 6 +78
Docs 1 12 0 +12
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 176 18 +158

Labels

Label changes:

  • add P2: The update failure affects a specific unsafe temporary-directory layout and occurs before package mutation.
  • add merge-risk: 🚨 compatibility: The SDK-exported selector changes fallback behavior and breaks the existing parent-child Doctor namespace contract.
  • add merge-risk: 🚨 availability: Default logging with console capture can recursively initialize the logger until stack exhaustion when the fallback activates.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦐 gold shrimp and patch quality is 🦪 silver shellfish.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: The update failure affects a specific unsafe temporary-directory layout and occurs before package mutation.
  • merge-risk: 🚨 compatibility: The SDK-exported selector changes fallback behavior and breaks the existing parent-child Doctor namespace contract.
  • merge-risk: 🚨 availability: Default logging with console capture can recursively initialize the logger until stack exhaustion when the fallback activates.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦐 gold shrimp and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 29, 2026, 11:15 AM ET / 15:15 UTC.

@steipete
steipete merged commit d2383bd into main Oct 29, 2026
231 of 234 checks passed
@steipete
steipete deleted the fix/update-private-temp-187657 branch October 29, 2026 15:27
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 30, 2026
…s unsafe (openclaw#187737)

Update admission refused outright when an ancestor of the system temp directory was group/world-writable without sticky protection. The shared temp-root selector now falls back to a checked owner-private workspace under the OpenClaw state directory, warns with the rejected directory, and keeps artifact retention, cleanup and shared coordination paths; it refuses only when no safe root exists, naming the directory to fix.

Fixes openclaw#187657. Thanks @Yachiyo1680 for the report.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update failure: requested (2026.9.33)

1 participant