Skip to content

fix(worktrees): follow the current process environment - #199572

Merged
steipete merged 1 commit into
mainfrom
fix/ew-worktree-current-environment
Nov 15, 2026
Merged

steipete merged 1 commit into
mainfrom
fix/ew-worktree-current-environment

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes managed-worktree lookups, archive restoration, and cleanup losing their registry records after stock Bun replaces process.env while starting a SHARE_ENV worker.

User Impact

Managed worktree creation, session reset/move, archive restoration, and shutdown use the current state directory consistently. Node behavior is unchanged because its environment object remains stable, and explicitly supplied environment objects remain fixed.

Why This Change Was Made

This is a stock-Bun process.env identity fix; upstream oven-sh/bun#44371.

The service stores only an explicit environment override and resolves the default environment at each use. The capacity and Git-maintenance helpers do the same. Maintenance failure and cadence maps remain single instances keyed by repository path; registry/lifecycle state uses database coordination keys. No environment-identity cache is duplicated, and no runtime branch, feature probe, or lifecycle wait is added.

The worktree directory and registry-owner audit found no other module-level default-environment captures. Other defaults are resolved within individual calls. Existing tests cover the regression, so no test or fixture changes are needed.

Evidence

Local evidence is from macOS arm64. 27 reproduced cases fail on stock before this change and pass on stock, the pinned fork, and Node afterward. Reverting only this patch reproduces the same stock failures, then the patch is restored.

File IDs Stock before Fork before/after Stock after Node after Revert control Stock wall s, before → after
src/gateway/server.sessions.archive-worktree-lifecycle.test.ts 19 19 fail 19 pass / 19 pass 19 pass 19 pass 19 fail 135.56 → 103.43
src/gateway/server.sessions.archive-failed-worker.test.ts 2 2 fail 2 pass / 2 pass 2 pass 2 pass 2 fail 38.02 → 34.21
src/auto-reply/reply/session.worktree-reset.test.ts 2 2 fail 2 pass / 2 pass 2 pass 2 pass 2 fail 78.84 → 84.61
src/agents/subagents/spawn/subagent-spawn.production-boundary.test.ts 1 1 fail 1 pass / 1 pass 1 pass 1 pass 1 fail 74.37 → 55.93
src/commands/agent.test.ts 1 1 fail 1 pass / 1 pass 1 pass 1 pass 1 fail 126.04 → 165.00
src/gateway/server-close.worktree-run-end.test.ts 1 1 fail 1 pass / 1 pass 1 pass 1 pass 1 fail 48.66 → 28.74
src/gateway/server.placement-abandonment.test.ts 1 1 fail 1 pass / 1 pass 1 pass 1 pass 1 fail 64.87 → 53.33

The archive lifecycle file runs with --maxWorkers=1 under the shared build lock; wall times above exclude lock queue time. Its complete 21-test file passes after the change. Stock before/after checks use complete files except for the two spawn cases. Node/fork confirmation targets assigned cases except the complete reset and archive files. These command timings include setup/build work and are not a performance comparison.

The final service, capacity, and Git-maintenance owner runs pass on all three runtimes. One earlier Node capacity run passed 23/24: serializes distinct repositories competing for disk headroom observed zero successful creations instead of one. The complete unmodified baseline and a complete fixed confirmation both pass 24/24. No code or fixture change was made for this failure; its intermittent cause remains unproven and is retained as an investigated local failure rather than claimed fixed. Core typecheck, targeted lint, formatting, and independent P0–P2 review pass. The builtin-mock consumer gate does not apply because no import forms change. Construction/teardown scheduling is unchanged; the shutdown boundary passes directly on all three runtimes.

A synthetic benchmark of the actual service property (2,000,000 reads per round; median of five measured rounds after warm-up) measured approximately 10 ns of additional work per default environment read and less than 1 ns for explicit environments.

Linux-only-unverified (passes on macOS stock before the fix and remains in the test file):

  • src/agents/subagents/spawn/subagent-spawn.production-boundary.test.ts :: recursive spawn production boundary > managed worktrees > runs a hidden managed worktree with cleanup=keep

Initial missing workspace-dependency and stale runtime-path attempts stopped before assertions and are excluded from the evidence. An unfiltered spawn run was stopped after 409.58 seconds without a completed report; the two assigned cases were then proved with a test-name filter. The one extra archive failure outside the assigned set also disappears in the complete after run.

Resolve the default environment when the singleton and its helpers use it so stock Bun worker environment promotion does not split registry paths. Explicit environment overrides and Node behavior remain unchanged.
@clawsweeper

clawsweeper Bot commented Nov 15, 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.

@steipete
steipete marked this pull request as ready for review November 15, 2026 11:11
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Nov 15, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-15T11:12:51.282031Z 3ee0d22 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.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 15, 2026
@steipete
steipete merged commit 04615c6 into main Nov 15, 2026
207 of 210 checks passed
@steipete
steipete deleted the fix/ew-worktree-current-environment branch November 15, 2026 11:25
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 16, 2026
Resolve the default environment when the singleton and its helpers use it so stock Bun worker environment promotion does not split registry paths. Explicit environment overrides and Node behavior remain unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant