Skip to content

fix(test): isolate legacy agent directory overrides - #132874

Merged
steipete merged 1 commit into
mainfrom
steipete/fix-model-status-test-isolation-20260829
Aug 29, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/fix-model-status-test-isolation-20260829

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes model-status tests failing when the parent process exports PI_CODING_AGENT_DIR. The shared test environment cleared OPENCLAW_AGENT_DIR but left its still-supported legacy selector active, so an otherwise isolated status invocation selected the inherited directory instead of the fixture's mocked directory.

The three recorded failures looked like masking, runtime-quarantine, and mixed-auth-route problems. Native assertion diffs instead showed one missing default-directory resolver call and two mismatched auth-store display paths.

Why This Change Was Made

Restore legacy-selector isolation at the three existing test lifetime owners: shared test-home setup/restore, shared-worker file cleanup, and integration test-state/spawn environment construction. Explicit fixture overrides retain precedence, including agentEnv: "main", and cleanup restores absent, empty, and populated caller values.

The runtime-internalization change in #85341 removed this test cleanup while model status retained the selector. The alias is also present in stable tag v2026.7.1-2; this repair deliberately leaves production model-status behavior and assertions unchanged rather than removing the alias or teaching tests to accept leaked paths.

Production LOC: +0/-0. Test support: +5/-0. Tests: +124/-52, extending existing tables and the real shared-worker producer/observer fixture rather than adding a production test seam.

User Impact

No production behavior, public configuration, schema, dependency, or persistence changes. Isolated tests no longer borrow the launcher's legacy agent directory. The existing explicitly allowed real-home test mode and explicit fixture overrides remain intact. All validation used synthetic, task-owned state; no operator Gateway, service, config, or credential state was changed.

Evidence

Current retained native proof on base 8cd61f02bf48c190a439ccb53d56e9f47a87a110, then the six-file repair, using Node 24.15.0 and Vitest 4.1.11:

Native scope Before After
Original commands-light partition, 19 files 539 passed / the original 3 failures 542 passed
test/test-env.test.ts 11 passed / 4 legacy-selector failures 15 passed
src/test-utils/openclaw-test-state.test.ts 16 passed / 4 legacy-selector failures 20 passed
test/non-isolated-runner.test.ts Native child observer failed on inherited PI_CODING_AGENT_DIR 1 outer boundary test passed; its unchanged child contract requires 34 passing cases plus the intentional collection failure

Native commands, each run with a fresh private HOME/state/provider environment, a seeded PI_CODING_AGENT_DIR, one worker, and verbose plus JSON reporters:

node scripts/run-vitest.mjs run --config test/vitest/vitest.commands-light.config.ts --passWithNoTests=false
node scripts/run-vitest.mjs test/test-env.test.ts
node scripts/run-vitest.mjs src/test-utils/openclaw-test-state.test.ts
node scripts/run-vitest.mjs test/non-isolated-runner.test.ts

The complete model-status file retains its original assertion order and both explicit environment-override cases. The full original partition was replayed, not just three selected assertions; native file scheduling differed after prior failures. Every retained run records an unchanged source diff during execution.

Execution limitations, not hidden passes: cache-enabled original-partition attempts stalled before assertions. A PID/birth-bound native sample observed a libuv filesystem worker waiting in rename, without identifying the pathname or establishing the cause of every timeout. The retained original-partition before/after runs used the existing outer OPENCLAW_VITEST_FS_MODULE_CACHE=0 option. The environment and test-state owner proofs used the default outer cache setting.

The shared-worker semantic runs also disabled that optional cache on the outer runner only. Its child builder intentionally drops parent VITEST*/OPENCLAW_VITEST* variables and keeps its existing one-worker, isolate: false, native configuration. The installed Vitest default is the forks pool; its optional module cache is unset/default-false, but temporary transformed-module copies can still be written. No nested defaults, pool, deadlines, or assertions were changed. A positive shared-worker attempt timed out at its existing 120-second test deadline; after exact cleanup and the static gates, the one bounded unchanged retry passed. No blanket signals, raised deadlines, or retries beyond the bounded attempts described above were used. Earlier lost temporary QA artifacts are not counted as current proof.

Also passed:

node scripts/check-changed.mjs -- test/test-env.ts test/test-env.test.ts test/non-isolated-runner.ts test/non-isolated-runner.test.ts src/test-utils/openclaw-test-state.ts src/test-utils/openclaw-test-state.test.ts
git diff --check

The selected gate included core/core-test/root-test typechecks, core and script lint, format and architecture guards. Fresh isolated Codex P0 autoreview returned no findings. The committed patch is byte-identical to the patch used for the successful static gate and final native proof. Exact-head CI will be recorded after this PR is ready; no CI or live-provider success is claimed here yet.

Out of scope: the separately owned post-update service-identity fixture repair; the shell test-state helper's separate selector-cleanup gap; invocation-local strengthening of model-status mock-call assertions; and diagnosis of the host filesystem wait itself.

AI-assisted. Awaiting maintainer source/proof judgment before merge.

@clawsweeper

clawsweeper Bot commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added size: S maintainer Maintainer-authored PR labels Aug 29, 2026
@steipete
steipete marked this pull request as ready for review August 29, 2026 22:25
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 29, 2026
@clawsweeper

clawsweeper Bot commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 29, 2026, 6:32 PM ET / 22:32 UTC.

ClawSweeper review

What this changes

This PR prevents isolated tests and shared test workers from inheriting the legacy PI_CODING_AGENT_DIR agent-directory selector while preserving explicit fixture overrides.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open. The test-only patch repairs the legacy selector at each isolation owner and has no source-level blocking finding; the latest bot comment body was unavailable, so any earlier rank-up moves could not be rechecked.

Priority: P3
Reviewed head: e0ca7a9fd5b57a907b46616095fc8cd30f84f684

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, source-supported test repair with substantial owner-boundary coverage and no blocking correctness finding.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored test-only PR is exempt from the external-contributor proof gate; its body nevertheless supplies native before/after runs tied to the changed environment owners.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored test-only PR is exempt from the external-contributor proof gate; its body nevertheless supplies native before/after runs tied to the changed environment owners.
Evidence reviewed 7 items Retained runtime selector: Model status still selects the legacy directory when OPENCLAW_AGENT_DIR is absent, establishing the isolation invariant the patch protects.
Test-state spawn isolation: The introduced environment builder clears PI_CODING_AGENT_DIR before applying scenario and explicit fixture overrides, so explicit overrides retain precedence.
Test-environment lifetime owner: The isolated test environment now snapshots, clears, and restores the legacy selector; its expanded table covers normal, hermetic, and real-home modes.
Findings None None.
Security None None.

How this fits together

Test utilities create private HOME and agent-state environments for model-status and integration tests. Their environment setup and shared-worker cleanup feed test fixtures, which must not borrow agent directories from the launching process.

flowchart LR
  Caller[Caller environment] --> Setup[Test environment setup]
  Setup --> State[Test state builder]
  Setup --> Runner[Shared test runner]
  State --> Fixture[Model-status fixture]
  Runner --> Fixture
  Fixture --> Result[Test result]
Loading

Before merge

  • Resolve merge risk (P1) - One ClawSweeper bot comment is omitted from the supplied discussion and GitHub was unreachable, so any prior rank-up moves should be checked before landing.
  • Complete next step (P2) - This open maintainer-authored PR already owns the bounded repair; normal exact-head validation and maintainer handling remain.
Agent review details

Security

None.

PR surface

Source +1, Tests +76. Total +77 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 1 1 0 +1
Tests 5 128 52 +76
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 129 52 +77

Review metrics

Metric Value Why it matters
Production versus test LOC production +0/-0; test support +5/-0; tests +124/-52 The change is confined to test lifecycle owners and focused regression coverage, with no shipped runtime growth.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Land the focused lifecycle-owner repair once the exact head satisfies the remaining repository merge gates and any prior review rank-up move is confirmed or explicitly skipped.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Land the focused lifecycle-owner repair once the exact head satisfies the remaining repository merge gates and any prior review rank-up move is confirmed or explicitly skipped.

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

Yes, by source: setting only PI_CODING_AGENT_DIR makes model status use that external directory, while the base test lifetime owners did not clear it. The supplied PR body also records native before/after owner-test runs, but this read-only review did not execute them.

Is this the best way to solve the issue?

Yes. Clearing the selector at test-environment setup, test-state spawn construction, and post-unstub shared-worker cleanup fixes the producer/lifecycle boundary without altering the retained runtime compatibility behavior.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 7781b904db87.

Labels

Label changes:

  • add P3: This is a low-risk test-isolation repair with no proposed production behavior change.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored test-only PR is exempt from the external-contributor proof gate; its body nevertheless supplies native before/after runs tied to the changed environment owners.

Label justifications:

  • P3: This is a low-risk test-isolation repair with no proposed production behavior change.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored test-only PR is exempt from the external-contributor proof gate; its body nevertheless supplies native before/after runs tied to the changed environment owners.

Evidence

What I checked:

  • Retained runtime selector: Model status still selects the legacy directory when OPENCLAW_AGENT_DIR is absent, establishing the isolation invariant the patch protects. (src/commands/models/list.status-command.ts:107, a5475eab7a)
  • Test-state spawn isolation: The introduced environment builder clears PI_CODING_AGENT_DIR before applying scenario and explicit fixture overrides, so explicit overrides retain precedence. (src/test-utils/openclaw-test-state.ts:240, e0ca7a9fd5b5)
  • Test-environment lifetime owner: The isolated test environment now snapshots, clears, and restores the legacy selector; its expanded table covers normal, hermetic, and real-home modes. (test/test-env.ts:222, e0ca7a9fd5b5)
  • Shared-worker cleanup owner: After Vitest unstubs environment values between non-isolated files, the runner again clears both agent-directory selectors before the next file. (test/non-isolated-runner.ts:482, e0ca7a9fd5b5)
  • Regression coverage: The added fixture creates and unstubs both selectors in one file, then verifies both are absent in the following shared-worker file; the state-helper table also covers applied, unapplied, absent, empty, and explicit values. (test/non-isolated-runner.test.ts:149, e0ca7a9fd5b5)
  • Introduction scope: The verified test merge changes only the six declared test and test-support files; no production runtime behavior is introduced. (test/test-env.ts:222, fbb71aea3856)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Check the omitted latest ClawSweeper comment for any rank-up moves before landing.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete

Copy link
Copy Markdown
Contributor Author

Source/proof review is complete for e0ca7a9fd5b57a907b46616095fc8cd30f84f684. This repairs a test-harness environment leak, not an OAuth, quarantine, routing, or persistence failure. The five support lines neutralize the inherited legacy selector at shared test-home setup/restore, post-unstub shared-worker restoration, and fixture/spawn environment construction. The shipped model-status alias and explicit fixture override precedence remain unchanged. Production LOC: +0/-0; test support +5/-0; tests +124/-52.

The six changed files, complete model-status command/test, environment helper, callers, siblings, and Vitest contracts were reviewed. Native main-baseline inspection used 90c1d798cad44f0d1901524a613acef33a4e42b6; a post-prepare read at 5b532a78ee1f697aeb484104f0aa980501b8fc1b confirmed all six owners and the status path remain unchanged from the failing base. Main's separate Gateway E2E process-bounding change was inspected and does not affect these non-E2E/explicit-file proof commands. No rebase or source changes were needed.

Retained native before/after proof uses Node 24.15.0 and Vitest 4.1.11 with fresh secretless synthetic HOME/state, the legacy selector seeded, one worker, and verbose/JSON reports. The original 19-file partition moved from 539 passed / the original 3 failures to 542/542. Test-home and fixture-state owners moved from 11/15 to 15/15 and 16/20 to 20/20. The native shared-worker observer failed on the leaked alias before the fix; the final outer boundary passed 1/1, requiring 34 passing child cases plus its existing intentional collection failure.

node scripts/run-vitest.mjs run --config test/vitest/vitest.commands-light.config.ts --passWithNoTests=false
node scripts/run-vitest.mjs test/test-env.test.ts
node scripts/run-vitest.mjs src/test-utils/openclaw-test-state.test.ts
node scripts/run-vitest.mjs test/non-isolated-runner.test.ts
node scripts/check-changed.mjs -- test/test-env.ts test/test-env.test.ts test/non-isolated-runner.ts test/non-isolated-runner.test.ts src/test-utils/openclaw-test-state.ts src/test-utils/openclaw-test-state.test.ts
git diff --check 8cd61f02bf48c190a439ccb53d56e9f47a87a110 e0ca7a9fd5b57a907b46616095fc8cd30f84f684

The selected static/type/lint/architecture gates passed, and fresh isolated Codex P0 autoreview found no defects. The committed patch matches the successful retained proof byte-for-byte. Exact-head CI 33278578433 passed on attempt 1, and Workflow Sanity 33278513650 also passed. Native review-init, main/PR checkout, artifact initialization/validation, and OPENCLAW_TESTBOX=1 scripts/pr prepare-run 132874 completed successfully. The hosted verifier selected exact-head evidence; publication was a no-op because the remote already matched the prepared head.

Limits remain explicit: earlier cache-enabled partition attempts stalled before assertions; a birth-bound sample showed a filesystem rename wait without pathname/root-cause attribution. Retained partition/shared-worker semantic runs disabled only the existing outer optional module cache. The child drops inherited Vitest options; its defaults, pool, isolation, assertions, and deadline were unchanged. An initial positive shared-worker attempt timed out at its existing deadline; the single authorized unchanged retry passed after exact cleanup/static gates. These timeouts and lost earlier temporary artifacts are not counted as passing proof. Model-status assertion order was preserved, but whole-partition file scheduling differed. No live-provider or operator-state success is claimed.

The full ClawSweeper review, including its rank-up list, and the omitted acknowledgement were read. The omitted comment contains no findings or rank-up moves, resolving the discussion-availability concern. No actionable source finding remains. This comment records pre-merge readiness, not a completed merge.

@steipete
steipete merged commit 9e86e08 into main Aug 29, 2026
240 checks passed
@steipete
steipete deleted the steipete/fix-model-status-test-isolation-20260829 branch August 29, 2026 23:07
@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 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant