Skip to content

fix(worker): preserve process.env identity when sharing environments - #42

Merged
steipete merged 2 commits into
mainfrom
claude/fix-share-env-object-identity
Oct 1, 2026
Merged

steipete merged 2 commits into
mainfrom
claude/fix-share-env-object-identity

Conversation

@steipete

@steipete steipete commented Sep 30, 2026 •

Copy link
Copy Markdown

Preserve the original process.env and Bun.env objects when the first Worker({ env: SHARE_ENV }) starts. Promotion previously installed a new object, leaving cached references pointed at an orphaned map and breaking shared mutations and environment cleanup.

The original environment object now forwards to the shared backing store. Promotion removes its stale property slots, shared reads avoid value caching, and absent-property caching is disabled because workers can introduce keys. Windows retains its original proxy, prototype, and receiver behavior. Its common write path coerces values before choosing the backing store, so a toString() that creates the first SHARE_ENV worker cannot lose an assignment or property definition. Symbol rejection and descriptor validation retain Node's ordering.

Validation on macOS arm64, rebased onto b02bb8a0c5:

  • The actual Windows proxy is imported into deterministic tests on every platform, with native callbacks substituted. The original proxy fails four cases; the fixed proxy passes all 10 tests. Coverage includes assignment, property definition, throwing coercion, empty keys, symbol errors, descriptor getters, and delete-key coercion. Native Windows execution remains a Windows-platform check.
  • All five native SHARE_ENV fixture modes pass under Node 24 and the patched release build: main-thread founder, snapshot-worker founder, assignment coercion, property-value coercion, and descriptor-getter promotion.
  • Worker suites: 197 passed. Process suite: 194 passed. CLI environment suites: 107 passed. JavaScript lint and builtin-module type checking pass. The first process-suite attempt lacked the fresh checkout's pinned test dependencies; it passed after installation.
  • Current OpenClaw consumer rerun: all 13 direct files passed (420 tests) on checkout 03020c996833, using private home/state/temp directories and the patched Bun explicitly. No test assertions or application guards were changed.
  • The staged full PR diff and the fresh post-CI committed PR diff both passed independent Codex P2 reviews (scoped-clean, no accepted findings). Format, JavaScript lint, and Source lints all passed on exact head 88cfa05da7.

The original before/after consumer proof found all 13 direct files passing after the identity fix. Across 78 direct/dependent files, 49 passed before and 77 after; the one unchanged failure contained three Node-executable fixture assumptions in src/cli/node-cli/daemon.test.ts. That broader proof is historical and was not rerun for this Windows ordering follow-up.

Upstream search found no exact identity-preservation fix. Related work includes oven-sh#40571 and oven-sh#39677; neither fixes this object replacement. No upstream patch was copied. All existing main changelog and compatibility-document entries were retained during the rebase.

@steipete
steipete marked this pull request as ready for review September 30, 2026 11:54
Coerce environment values before selecting the Windows backing store. Preserve symbol rejection and descriptor validation, including promotion during assignment or property definition. Exercise the actual Windows proxy on every platform and extend the native SHARE_ENV fixtures.
@steipete
steipete force-pushed the claude/fix-share-env-object-identity branch from 973a36c to 88cfa05 Compare October 1, 2026 08:22
@steipete
steipete merged commit 6ea7ca5 into main Oct 1, 2026
4 checks passed
@steipete
steipete deleted the claude/fix-share-env-object-identity branch October 1, 2026 08:30
steipete added a commit that referenced this pull request Oct 1, 2026
)

Regression from #42 (first bad commit; SHARE_ENV process.env identity): after SHARE_ENV promotion, JIT-cached property absence let hot delete/Reflect.deleteProperty on process.env bypass the shared store, so a worker kept seeing deleted keys. Prohibit property caching on the environment map (adapted from oven-sh#38871). Repro: test/js/node/worker_threads/fixture-share-env-delete.js (delete and reflect modes after 20k warm iterations). Fixes three OpenClaw suites that passed on 57fadf5 and failed on 6ea7ca5 (test-helpers.server-env, state-migrations.caller-mode.storage, update-command-post-update).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant