Skip to content

fix(test): release acquired state when wrapper setup fails - #132301

Merged
steipete merged 1 commit into
mainfrom
steipete/stoic-perlman-59f96c
Aug 29, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/stoic-perlman-59f96c

Conversation

@steipete

@steipete steipete commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

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:

node scripts/run-vitest.mjs test/helpers/auth-wizard.test.ts test/helpers/openclaw-test-instance.acquisition.test.ts

Before: 5 intended failures and 2 successful auth-lifetime cases passed. Both prior-agent-env variants leaked on mkdir rejection; merge, serialization, and real EISDIR config-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 candidate baa00511d9b1a51b7344b9bc49cc6a3d3ff118d2, macOS Node 24.20.0 ran:

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

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.

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.ts

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 --check also 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 state case 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-existing unicorn/no-array-reverse in 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 with GREEN, zero pending checks. This records CI evidence only; independent review and the maintainer landing decision remain separate.

@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: M maintainer Maintainer-authored PR labels Aug 29, 2026
@steipete
steipete marked this pull request as ready for review August 29, 2026 03:10
@steipete steipete self-assigned this Aug 29, 2026
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🦞 diamond lobster Very strong PR readiness with only minor 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 28, 2026, 11:27 PM ET / August 29, 2026, 03:27 UTC.

ClawSweeper review

What this changes

The PR makes auth and gateway-instance test wrappers release acquired fixture state when their local setup fails before returning a cleanup handle.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

Keep 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
Reviewed head: baa00511d9b1a51b7344b9bc49cc6a3d3ff118d2

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-boundary repair with direct regression coverage and no actionable correctness or security finding.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored test-support change is exempt from the external-contributor proof gate; its body additionally reports focused after-fix filesystem cleanup evidence.
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-support change is exempt from the external-contributor proof gate; its body additionally reports focused after-fix filesystem cleanup evidence.
Evidence reviewed 5 items Introduced ownership boundary: The two introduced catches cover only wrapper-local work after state acquisition and before returning a cleanup handle.
Canonical cleanup owner: The existing state cleanup is idempotent and closes fixture-scoped resources, restores environment state, and removes the owned root.
Boundary regression coverage: New tests exercise mkdir, configuration merge, serialization, and real filesystem-write failure paths while asserting environment restoration, database closure, root removal, and error identity.
Findings None None.
Security None None.

How this fits together

The 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]
Loading

Before merge

  • Complete next step (P2) - No repair lane is needed: there is no actionable finding, and this maintainer-owned protected PR needs normal review.
Agent review details

Security

None.

PR surface

Tests +200. Total +200 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 4 216 16 +200
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 216 16 +200

Review metrics

Metric Value Why it matters
Production versus test support production +0/-0; test support +12 net; tests +188/-0 The change is confined to shared fixture lifecycle handling and adds direct failure-boundary coverage.

Technical review

Best 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.

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • remove rating: 🦞 diamond lobster: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.

Label justifications:

  • P3: This improves developer test isolation without changing product runtime behavior.
  • 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-support change is exempt from the external-contributor proof gate; its body additionally reports focused after-fix filesystem cleanup evidence.

Evidence

What I checked:

Likely related people:

  • steipete: Auth-wrapper, instance-lifecycle, and proposed cleanup history identify this contributor as the primary current owner of the affected test helpers. (role: recent area contributor; confidence: high; commits: baa00511d9b1, 1593e2908727, 5a0702ecf828; files: test/helpers/auth-wizard.ts, test/helpers/openclaw-test-instance.ts)
  • wangmiao0668000666: Blame attributes the canonical test-state cleanup sequence used by this PR to this contributor. (role: cleanup-owner contributor; confidence: medium; commits: ca7e9e141288; files: src/test-utils/openclaw-test-state.ts)

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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-08-29T03:19:15.335Z sha baa0051 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. labels Aug 29, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

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 state.cleanup(), and rethrow. Factory cleanup cannot catch failures after handoff; downstream callers never receive the handle; a new rollback abstraction or duplicated teardown would add complexity. Canonical ordering remains session drain → scoped auth readers → agent databases → shared database → env restore → owned-root removal. Successful instance lifecycle is unchanged. Product runtime LOC 0; test support +28/-16; tests +188/-0.

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.ts

Both 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 no-array-reverse lint baseline remain disclosed and separately tracked; no timeout, assertion, or unrelated lifecycle change was made. This is internal test support: no public user flow needs actual Gateway/provider/UI/video proof, and none is claimed. The latest completed ClawSweeper review has no actionable finding or Rank-up move; its remaining normal maintainer-review step is now satisfied.

@steipete
steipete merged commit 45a1e3c into main Aug 29, 2026
205 checks passed
@steipete
steipete deleted the steipete/stoic-perlman-59f96c branch August 29, 2026 03:32
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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: M 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