Repository navigation
test(config): preserve native environment across provider tests - #130975
Merged
Merged
Conversation
Restore provider keys individually with Vitest env stubs instead of replacing process.env. The plain object replacement leaked across reused runtime-config forks, so later reconcile workers inherited a different shared state database and their leases were absent from the lifecycle test fence. Reproduced both lifecycle failures after the provider tests on macOS and Linux Node 24. The repaired ordered pair passes 35 tests on both platforms; the broader session run passes 1042 tests across 92 files. check-changed and Codex autoreview pass. Production lease semantics and lifecycle assertions are unchanged.
Contributor
|
🦞👀 Pull request received. I will update this pull request when review starts. |
Contributor
Author
|
Merged via squash.
|
This was referenced Aug 27, 2026
github-actions Bot
pushed a commit
to Desicool/openclaw
that referenced
this pull request
Aug 28, 2026
…claw#130975) Restore provider keys individually with Vitest env stubs instead of replacing process.env. The plain object replacement leaked across reused runtime-config forks, so later reconcile workers inherited a different shared state database and their leases were absent from the lifecycle test fence. Reproduced both lifecycle failures after the provider tests on macOS and Linux Node 24. The repaired ordered pair passes 35 tests on both platforms; the broader session run passes 1042 tests across 92 files. check-changed and Codex autoreview pass. Production lease semantics and lifecycle assertions are unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Problem This Solves
The merge gate has been intermittently red today:
src/config/sessions/session-transcript-reconcile.lifecycle.test.ts(added in #130185) fails withexpected 1 to be 2at its lease-count assertion — three consecutive failures on one PR's run (#130956, attempts 1-3), while other runs pass. The lifecycle test itself is correct; the failure is execution-order contamination from a different file in the same non-isolated fork.Root cause:
src/config/config.web-search-provider.test.tsrestored env by replacing theprocess.envobject (process.env = { ...savedEnv }, from 3a3c2da). Node treatsnew Worker()env inheritance natively:internal/workerpassesnullto the native WorkerImpl whenenv === process.env— but after the object swap, later per-key changes (like the lifecycle fixture'sOPENCLAW_STATE_DIRset viawithEnvAsync) reach the parent's JS object and not the native environment the worker inherits. The reconcile worker then resolves the default test state dir, claims its agent-DB lease inopenclaw-test-state/<pid>-<workerId>/state/openclaw.sqlite, and the lifecycle test's count — querying the fixture state DB — sees only the parent's lease. Direct row evidence: worker lease UUIDs found in the fallback state DB, parent lease intact in the fixture DB (refuting parent-closure, path-canonicalization, lease-retry, and WAL-timing theories). Vitest's per-key env snapshot/restore machinery cannot undo an untracked replacement of the native-backed object (test/non-isolated-runner.ts:477).Why CI "randomly" failed: vitest's cold ordering favors larger files, so the provider test often (not always) runs before the lifecycle test in the runtime-config fork. Running the pair in that order reproduces both failures deterministically on macOS and Linux.
Why This Change Was Made
Fix at the producer, per the repo's tracked-env doctrine: the provider test now stubs its fixture providers' declared env keys individually with
vi.stubEnvand restores withvi.unstubAllEnvs— never replacing the native env object. Reusing the existing provider fixture removes duplicated key inventory (net −11 test lines). A comment records the cross-file worker-inheritance invariant. No production, lease-lifecycle, isolation-flag, sleep, or assertion-tolerance changes; the lifecycle test's assertions are untouched and remain the regression oracle when run after the former contamination producer.User Impact
None at runtime (test-only). Restores a reliably green core-runtime-config shard for every PR.
Evidence
--no-cacheand under Node 24. Containerized Linux (node:24-bookworm, aarch64, read-only source mount, isolated native esbuild/rolldown binaries, no remote lease): 33 pass / 2 fail with the identical assertion.internal/workerenv selection semantics confirmed on installed Node 26 and Linux Node 24.19.0; vitest 4.1.11 env proxy forwards per-key changes only.check-changedand Codex autoreview: pass, no findings.