Repository navigation
fix(test): release acquired state when wrapper setup fails - #132301
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 28, 2026, 11:27 PM ET / August 29, 2026, 03:27 UTC. ClawSweeper reviewWhat this changesThe PR makes auth and gateway-instance test wrappers release acquired fixture state when their local setup fails before returning a cleanup handle. Merge readinessKeep open for normal maintainer review. The branch repairs a real test-fixture ownership gap that current main still lacks; no introduced correctness or security defect was found. Priority: P3 Review scores
Verification
How this fits togetherThe shared test-state factory allocates an isolated filesystem, environment, and database fixture. Auth and gateway-instance test wrappers stage that fixture before handing its cleanup handle to callers. flowchart LR
A[Test requests fixture] --> B[Test-state factory]
B --> C[Wrapper staging]
C --> D{Setup succeeds?}
D -->|Yes| E[Return cleanup handle]
D -->|No| F[Release state fixture]
F --> G[Propagate failure]
Before merge
Agent review detailsSecurityNone. PR surfaceTests +200. Total +200 across 4 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Retain the narrow wrapper-level cleanup boundary and land it after the assigned maintainer completes the protected-PR review. Do we have a high-confidence way to reproduce the issue? Yes—source establishes the acquired-state interval before either wrapper returns a cleanup handle, and the added tests target each staging failure within it. Is this the best way to solve the issue? Yes—the wrappers own this interval, so calling the existing state cleanup there is the narrow canonical repair. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 30772d506144. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
|
Maintainer review is complete for baa00511d9b1; ready for native preparation and landing. No actionable findings. The lead’s direct source/dependency/best-fix review and fresh independent Codex autoreview (scoped-clean at P0) cover this exact four-file patch; the landing worker also inspected the affected helpers, tests, callers, cleanup owners, current main, and filesystem contracts. Both wrappers acquired state before fallible staging, so failure could occur before callers received cleanup. Best fix: catch only wrapper-owned directory/config staging, await the existing Retained red proof has five intended failures and two passing success cases. Exact candidate proof on Node 24.20.0 passed 55/55, six files in four serial shards, without retry, using a literal credential-free launcher with fresh synthetic HOME/state/TMP/XDG roots: node scripts/run-vitest.mjs test/helpers/auth-wizard.test.ts test/helpers/openclaw-test-instance.acquisition.test.ts test/helpers/openclaw-test-instance.test.ts src/test-utils/openclaw-test-state.test.ts src/test-utils/env.test.ts src/test-utils/session-state-cleanup.test.ts --maxWorkers=1 --no-file-parallelism --no-isolate
node scripts/check-changed.mjs -- test/helpers/auth-wizard.ts test/helpers/auth-wizard.test.ts test/helpers/openclaw-test-instance.ts test/helpers/openclaw-test-instance.acquisition.test.tsBoth exited 0; the changed gate covered formatting, test-root types, scripts lint, and guards. Exact-head CI run 33230748235, attempt 1 completed successfully, including openclaw/ci-gate. Native hosted verification rechecks the evidence before preparation. The earlier unchanged startup-clock flake and pre-existing auth-lifecycle |
|
Merged via squash.
|
What Problem This Solves
Resolves a problem where auth-wizard and process-instance test setup could leak an acquired fixture when wrapper setup failed before returning its cleanup handle. An agent-directory mkdir failure left the auth fixture root, environment overrides, and open fixture database handles behind. Initial instance-config merge, serialization, or filesystem-write failures left the instance root behind.
Related: #132257 (merged test-home acquisition rollback) and #132282 (independent factory-allocation cleanup). This PR repairs the caller-owned interval after the state factory returns; it does not duplicate or close either companion repair.
Why This Change Was Made
Each wrapper now catches failures in its own staging, awaits the existing
state.cleanup(), and rethrows the original error. The factory has already handed ownership to the wrapper, while downstream callers do not yet have a handle, so neither can release this state instead.The canonical cleanup sequence is unchanged: drain session work, close scoped auth readers and agent databases before shared state, restore the environment, then remove the owned root. Successful auth-fixture lifetime and the entire successful instance lifecycle remain unchanged. No new abstraction, teardown sequence, fallback, or runtime seam is introduced.
User Impact
No product-user-visible change. Developers get isolated failed test setup without leaked roots, environment overrides, or fixture database handles. No changelog, UI capture, live provider, or operator Gateway proof is applicable to this test-support-only change.
Product runtime LOC: 0. Test support: +28/-16 (net +12). Tests: +188/-0. The six net support lines per wrapper establish the missing ownership boundary using the existing cleanup owner. No dependency, configuration/environment option, protocol, or SQLite/schema changes.
AI-assisted with Codex. The maintainer reviewed the ownership boundary; a fresh independent scoped autoreview reported no accepted/actionable findings in its selected priority scope (P0). That review inspected tests but did not run them; the separate executed proof follows.
Evidence
Before the source fixes, these exact child commands exercised the two new suites:
Before: 5 intended failures and 2 successful auth-lifetime cases passed. Both prior-agent-env variants leaked on mkdir rejection; merge, serialization, and real
EISDIRconfig-write failures leaked roots. After: all 7 passed. Tests use real state acquisition and cleanup, inspect environment restoration/database openness/root removal/error identity, and do not mock the state factory or cleanup.The published candidate was rebased once onto
31baa67f98743ac5adb4c01f2e7fe0a94d3a3f66, including the merged test-home rollback. All four approved file hashes remained unchanged. On candidatebaa00511d9b1a51b7344b9bc49cc6a3d3ff118d2, macOS Node 24.20.0 ran:55/55 passed across 6 files and 4 serial Vitest shards; wrapper output:
[test] passed 4 Vitest shards in 58.47s, exit 0. This includes all 7 new cases, the unchanged 26-case instance suite, and all 22 shared state/env/session cleanup cases. All 28 recorded synthetic fixture process instances exited; the exact owned temporary root was removed.Passed, exit 0: changed formatting, test-root typecheck, scripts lint (0 warnings / 0 errors), and selected repository guards. The temp-creation inventory emitted a warning for the acquisition test’s real-mkdtemp spy; the spy observes the factory allocation and the test has exact-root cleanup in
finally.git diff --checkalso passed.All local test/check commands run through a launcher with a literal credential-free environment: fresh synthetic HOME/state/config/TMP/XDG roots and a fixed Node/system PATH. No ambient credentials, operator paths, live provider, or actual OpenClaw Gateway are inherited or started. The existing lifecycle suite starts synthetic fixture children only. Proof artifacts and raw logs remain local; no inaccessible artifact links are presented as public evidence.
Caveats: an earlier Node 24 combined run passed 54/55 because the unchanged
SIGKILLs a TERM-resistant gateway group before releasing statecase missed its 500ms startup deadline; its single-case rerun passed unchanged, and the candidate's full 55-case run above passed without a retry. Startup-clock coupling remains a separate follow-up; no timeout or assertion was weakened. Earlier Node 26 proof also passed 55/55. Supplemental core lint passed both new suites and the instance wrapper, but whole-file auth-wrapper lint reports the pre-existingunicorn/no-array-reversein unchanged lifecycle cleanup (cleanups.splice(0).reverse(), also present on the candidate base). The required changed gate is reported separately, not as a claim that this supplemental baseline lint is green. Local Windows/Linux, full-suite, and live-product execution were not performed; attached exact-head CI is separate evidence.Exact-head GitHub CI: run 33230748235, attempt 1 completed success for
baa00511d9b1a51b7344b9bc49cc6a3d3ff118d2(100 successful jobs, 17 skipped). The openclaw/ci-gate passed, and the exact-head watcher exited 0 withGREEN, zero pending checks. This records CI evidence only; independent review and the maintainer landing decision remain separate.