Skip to content

test(config): preserve native environment across provider tests - #130975

Merged
steipete merged 1 commit into
mainfrom
steipete/reconcile-lease-ci-red
Aug 27, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/reconcile-lease-ci-red

Conversation

@steipete

Copy link
Copy Markdown
Contributor

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 with expected 1 to be 2 at 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.ts restored env by replacing the process.env object (process.env = { ...savedEnv }, from 3a3c2da). Node treats new Worker() env inheritance natively: internal/worker passes null to the native WorkerImpl when env === process.env — but after the object swap, later per-key changes (like the lifecycle fixture's OPENCLAW_STATE_DIR set via withEnvAsync) 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 in openclaw-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.stubEnv and restores with vi.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

  • Failing-first (unchanged source, ordered pair, one serial fork): macOS Node 26.5.0 — provider 33 pass, lifecycle 2 fail at the exact CI assertion (line 176); same result with --no-cache and 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.
  • Post-fix: ordered pair 35/35 on macOS and Linux; broader sweep 1,042/1,042 tests across 92 files (all session test files + the provider test) in one non-isolated serial fork. Re-verified 35/35 on the rebased head 4f53776.
  • Direct Node inspection: internal/worker env 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-changed and Codex autoreview: pass, no findings.
  • LOC: production 0; tests +8/−19 (net −11).

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.
@clawsweeper

clawsweeper Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@steipete
steipete marked this pull request as ready for review August 27, 2026 14:39
@openclaw-barnacle openclaw-barnacle Bot added size: XS maintainer Maintainer-authored PR labels Aug 27, 2026
@steipete
steipete merged commit 22c23ba into main Aug 27, 2026
169 checks passed
@steipete
steipete deleted the steipete/reconcile-lease-ci-red branch August 27, 2026 14:48
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant