Repository navigation
fix(test): avoid service-permission failures before tests start - #160392
Conversation
Worked on by: - @VACInc Co-authored-by: VACInc <[email protected]> OpenClaw-Publication: 3dfcb5be-749a-48f1-968a-6b25efab0758
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review in progressClawSweeper is reviewing this revision. This supersedes any previous blocked status. |
Worked on by: - @VACInc Co-authored-by: VACInc <[email protected]> OpenClaw-Publication: 996f3d1d-862c-4055-9e99-f85e2ab8dcf3
|
@clawsweeper re-review Please review current head The PR body includes the original CI failure, the correction and measured cost. Production bytes remain identical to the native prerequisite build and actual runtime-consumer proof at Review only; no autofix or automerge requested. |
|
Codex review: needs maintainer review before merge. Reviewed September 28, 2026, 12:34 PM ET / 16:34 UTC (Revision 10). ClawSweeper reviewWhat this changesThe branch moves Vitest and E2E runtime preparation to an explicit build entry, checks managed Gateway artifact overlap before writes, and updates service inventory, tests, and runner documentation. Merge readiness✅ Ready for maintainer review Current main still takes the service-sensitive test preparation path, so this PR remains useful. The earlier code findings appear resolved, and the service-start race has since been explicitly accepted by the build/service owner. Priority: P2 Review scores
Verification
How this fits togetherVitest and E2E runners prepare built runtime files before starting test workers. Preparation checks artifact freshness and managed Gateway locations, then builds in the selected checkout or refuses an unsafe write. flowchart LR
A[Vitest or E2E run] --> B[Runtime prerequisite check]
B --> C{Artifacts current?}
C -- Yes --> G[Test workers]
C -- No --> D[Checkout artifact lock]
D --> E{Gateway outputs separate?}
E -- Yes --> F[Build and postbuild]
F --> G
E -- No --> H[Preparation error]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +404, Tests +880, Other +181. Total +1465 across 26 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Test preparation should write only after proving its outputs are separate from managed Gateways, while ordinary CLI and update publication keep their existing service checks. Do we have a high-confidence way to reproduce the issue? Yes at source level: current main still launches the CLI for test prerequisites, and the PR's boundary fixture exercises the protected-service permission failure. This read-only review did not run a current-main reproduction. Is this the best way to solve the issue? Yes. The dedicated test build entry reuses existing freshness, artifact ownership, and build owners while avoiding the unrelated service-publication transaction. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against ad7669535c37. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (9 earlier review cycles; latest 8 shown)
|
|
🦞👀 Re-review progress:
|
Worked on by: - @VACInc Co-authored-by: VACInc <[email protected]> OpenClaw-Publication: 799d41fc-e479-496d-a0d9-bc77d3c7ad73
|
Latest work-in-progress correction pushed as Remaining work:
Before the latest inventory extraction/Windows delta, 205 focused cases passed; native preparation passed in 68.58 s and the actual runtime consumer passed 159 cases. Latest scoped checks passed core/script/root-test types, all core-test type shards, formatting, size gates, three dead-export scans, and core lint, then stopped at the script lint error. Subsequent selected checks and final delta tests did not run. Exact-head CI and ClawSweeper remain unverified. No merge, deployment, or Gateway restart was performed. I am stopping implementation here at the requester’s direction so their agent can take over. |
|
@clawsweeper re-review Please review exact head |
|
🦞👀 Re-review progress:
|
…/session-progress-and-blocker-review
|
Superseded by head a366159. Correction: my prior statement that the service-start race had a maintainer decision was wrong. VAC owns that P2 decision; no acceptance is claimed. The duplicate AI-declaration fixture repair from this prior head was dropped because main landed it through #160532. The new head preserves only this PR's two runtime-preparation matcher substitutions in that file. |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review Maintainer decision (build/service owner): the documented service-start race is accepted as-is. The pre-test build fence must reject physically shared |
|
🦞👀 Re-review progress:
|
|
@clawsweeper re-review Head/merge commit: a366159. This final main integration uses base 25d771c. The conflict file starts from main's version, including its #160532 AI-declaration fixture fix; only this PR's two Focused test: 39/39 passed. Root-test typecheck: all four shards passed. The PR body now records this head and the evidence. VAC owns the P2 service-start race decision. No acceptance is claimed and no fence semantics changed on this head. Please review the code and report that decision as pending. |
|
🦞👀 Re-review progress:
|
…claw#160392) * fix(test): avoid service-permission failures before tests start Worked on by: - @VACInc Co-authored-by: VACInc <[email protected]> OpenClaw-Publication: 3dfcb5be-749a-48f1-968a-6b25efab0758 * fix(test): avoid service-permission failures before tests start Worked on by: - @VACInc Co-authored-by: VACInc <[email protected]> OpenClaw-Publication: 996f3d1d-862c-4055-9e99-f85e2ab8dcf3 * fix(test): avoid service-permission failures before tests start Worked on by: - @VACInc Co-authored-by: VACInc <[email protected]> OpenClaw-Publication: 799d41fc-e479-496d-a0d9-bc77d3c7ad73 * fix(daemon): include generated systemd units in inventory * fix(daemon): inspect loaded systemd Gateways before builds * fix: ignore stopped unrelated Windows tasks in live dist fence * fix: break daemon inventory type import cycle * fix: ignore unrelated unreadable launchd plists in test fence * test: copy errno owner into declaration fixture * fix: fence all test runtime build outputs * test: isolate E2E setup from AI declaration repair --------- Co-authored-by: roboclaw-bot <[email protected]> Co-authored-by: VACInc <[email protected]>
Summary
High Level TLDR
Fixes runtime-consuming tests failing before the first test starts when the caller cannot read an unrelated Gateway’s protected service environment.
User Impact
Local Vitest and E2E preparation use the explicit build path rather than invoking the CLI to trigger an automatic rebuild. Fresh artifacts remain reusable without a writable checkout; canceled preparation joins its writers before releasing ownership.
Boundary: outputs remain in the selected checkout. This is not a new filesystem sandbox. Preparation uses the existing live-Gateway overlap fence and checks loaded services plus potential Gateway definitions before artifact publication. It refuses when their safety cannot be verified; unreadable unrelated unit files do not block local preparation. Use the existing isolated runner when enforced filesystem isolation is needed. Automatic source-CLI rebuilds and actual update publication retain their strict service/maintenance checks unchanged. No production permissions, configuration, service, credentials, or database state are changed by this PR.
Root Cause
Test preparation ran
scripts/run-node.mjs --version. A missing runtime or private-QA entry therefore entered the automatic CLI rebuild’s service-publication transaction, which can require protected environment files before determining whether the checkout is unrelated.The dedicated prerequisite entry reuses the existing source freshness predicates, explicit build profile, runtime postbuild, checkout artifact ownership, and live-dist fence. It checks freshness before requesting write ownership and rechecks after acquisition. The existing cancelable-command owner carries cancellation through lock waits and compiler execution; incomplete child cleanup still retains ownership. No new agent instructions, build bypass flags, or test-selection changes.
What Problem This Solves
Local test preparation could enter a CLI rebuild transaction and read an unrelated Gateway's protected service environment before the first test ran. This PR routes that preparation through its owned build entry and keeps artifact writers joined before releasing ownership.
Service-start concurrency decision
VAC accepted the documented service-start race. The pre-test build fence rejects physically shared compiler output roots, while a Gateway starting after admission remains a documented local-operator concurrency risk. No service-activation coordination is required for this PR. This head makes no further fence-semantics change.
Evidence
The real preparation boundary and shared-output fence passed 61/61 focused cases on the prior code head. The final merge-head fixture test passed 39/39, and all root-test type graphs passed. Hosted exact-head CI and ClawSweeper review are in progress.
Verification
Real behavior proof
On the published
d890f517761910574aeed6635d4510e28e422535head,pnpm test test/scripts/prepare-vitest-runtime.test.ts test/scripts/live-gateway-dist-fence.test.ts --maxWorkers=1passed 61/61. The real preparation/build-admission boundary refuses before the compiler runs whendist-runtimeorpackages/sdk/distphysically aliases a live Gateway's output whiledistis separate. A disjoint service remains admitted. The changed preparation file alone passed 15/15 (pnpm test test/scripts/prepare-vitest-runtime.test.ts --maxWorkers=1, 39.13 s shard wall, 36.87 s Vitest, 0.238 s test execution). Script and root-test type graphs, focused lint, formatting, diff check, and independent P1 autoreview passed.What was not tested
No live Gateway was restarted or modified. The shared-output proof uses filesystem symlinks in an isolated fixture; no real bind mount or production Gateway was used. Exact-head hosted CI and ClawSweeper review are pending.
Current head:
a366159e4f2794469ece0c7cafea4657d546243ca366159e4f2794469ece0c7cafea4657d546243cintegratesorigin/mainat25d771cb8203f5afeea7b7c9dc8060210db8e43dsolely to clear the bounded-Vitest fixture conflict. Main already has the AI-declaration fixture repair from test(scripts): model AI declarations in bounded E2E preparation fixture #160532. The resolvedtest/scripts/run-vitest-bounded.test.tsstarts from main and differs only in this PR's twoscripts/prepare-vitest-runtime.mjsspawn-matcher substitutions; the duplicate fixture repair from5b31a0945f6is gone.pnpm test test/scripts/run-vitest-bounded.test.ts --maxWorkers=1, 42.38 s shard wall / 41.16 s Vitest duration).pnpm tsgo:test:rootpassed tooling, scripts, E2E, and other shards.git diff --checkpassed. Exact-head CI settled with the inherited source-contracts failure described below; ClawSweeper re-review is in progress.Exact-head CI
check-source-contractsjob 109022525871 failedlint:tmp:export-name-collisions. This is inherited from main commit5de949fc462, brought in by the final merge. It added daemon CLI exports that collide with names already exported insrc/cli/daemon-cli/*.tsandsrc/infra/update-managed-service-handoff.ts. The PR changes none of those files. This failure is not being fixed or rerun in this PR. The exact-head check rollup settled at 47 pass, 3 fail (this job plus two derivedopenclaw/ci-gateentries), 108 canceled, and 49 skipped.Previous head:
5b31a0945f67a4da24f8ffab7333dd9b6d7f6d94Previous head:
d890f517761910574aeed6635d4510e28e422535distwhile the compiler also writesdist-runtimeand package output roots.runBuildAllStepsand runtime-only test preparation now pass the canonicallistTsdownOutputRoots()to the physical-overlap fence. The fence compares every written root against every serving root, including realpath aliases and inode identity. A shared non-distroot refuses before any compiler runs; a separate checkout remains admitted.Previous head:
2a05b84769933a3bf977d65eb2e374f060f2ffb3Merged current
mainwhile preserving Windows Startup discovery. Strict inventory now checks systemd XDG, runtime, generated, transient, control, and system unit paths; Windows inventory checks every scheduled-task action and custom launcher.ClawSweeper's two later systemd findings are repaired: location-only inspection reads no service account or protected environment, while normal service operations keep their account checks; strict inventory also reads loaded manager units, including a running custom-profile Gateway after its unit file disappears. An unreadable unrelated, unloaded unit no longer blocks preparation; unverifiable loaded or recognizable Gateway units still do.
Local proof: 19/19 user and 12/12 system paths reported by
systemd-analyze unit-pathsare covered; the real read-only inventory returned one managed service with zero errors. Focused daemon tests and the strict fence case passed.node scripts/check-changed.mjspassed on the prior merge head; final-head core and core-test type graphs, formatting, lint, line cap, and diff checks passed.Windows CI on an earlier head failed before any Vitest shard during strict live-dist inventory. One unsafe false-positive path was an unreadable unrelated, stopped Task Scheduler entry; this head removes that path. Strict inventory now ignores unreadable actions on unrelated stopped/disabled tasks; unknown, queued, running, selected, and recognizable Gateway tasks remain fail-closed. The focused Windows inventory file passes 28/28, including stopped versus running/unknown state. The full changed-file gate passed on the previous code revision, including core and core-test types, lint, formatting, line cap, and dead-export checks. CI then found a type-only import cycle between
inspect-files.tsandinspect.tsand canceled the Windows job before its verdict. This head moves the shared type to the leaf module. The exact CI architecture commandpnpm check:architecturenow passes, as do core and core-test type graphs, focused lint, formatting, and diff checks. ClawSweeper then found a macOS strict-inventory P1: an unreadable unrelated plist blocked test preparation. This head narrows launchd errors to recognizable Gateway names or marker-bearing malformed content, while keeping known unreadable Gateway definitions fail-closed. The real verified fence path passes with an unreadable unrelated plist and refuses after an overlapping live Gateway plist is added. The focused macOS inventory file passes 5/5 (9.07 s command wall; 6.96 s Vitest duration), and existing inventory tests pass 52/52. Prior-head Linux and Windows CI both failed in the declaration fixture because its copied source tree omittedsrc/infra/errno.ts, newly imported by the fence; this head copies that owner file, and the exact failing fixture case passes locally (15.93 s command wall; 15.03 s Vitest duration). ClawSweeper later found the non-dist output overlap described above. No service lifecycle action was taken.Earlier revision: 509 distinct focused cases passed: preparation boundary (7), runner build admission (171), E2E global setup (5), existing live-Gateway fence (38), build owner (90), the real bundled-plugin runtime consumer (159), and bounded Vitest process ownership (39). The 7 boundary cases and 159 runtime-consumer cases passed together on published head
4f0fe3918170e6430a2294d8a0bd1608b9040041, after the final lint corrections (54.34 s command wall). Coverage includes known live-overlap refusal, immutable-deployment refusal, read-only warm reuse, postbuild failure propagation, cancellation/joining, and lock reacquisition. Existing selection, exclusion, preparation ordering, and E2E signal assertions remain intact.Native published-head proof:
OPENCLAW_BUILD_PRIVATE_QA=1 node scripts/prepare-vitest-runtime.mjscompleted successfully in 67.65 s, including the real compiler, 95 plugin builds, bootstrap import guard, and runtime postbuild. Both private-QA SDK entries were generated, artifact ownership was released, and the subsequent normalpnpm testinvocation reused the prepared runtime without another build. No service selectors, permissions, credentials, or production configuration were changed.Independent P2 autoreview: initial read-only/cancellation findings repaired; final scoped review has no actionable P0–P2 findings.
Selected static checks passed: script types, all four root-test type graphs, formatting, script/test lint, dead-export scans, and the selected repository guards. The initial aggregate stopped on a redundant synchronous
await; that and a test brace-style error were corrected and the affected lint stages passed. Hosted exact-head CI/ClawSweeper verification for the current head remains pending. The PR is open for review; this is not a landing-readiness claim.Test discipline
Measured with
pnpm test <file> --maxWorkers=1:test/scripts/prepare-vitest-runtime.test.tssrc/daemon/inspect.windows.test.tssrc/daemon/inspect.incomplete-inventory.test.tstest/scripts/test-projects-build-admission.test.tstest/scripts/vitest-e2e-global-setup.test.tsCold command wall includes the shared compiled-worker preparation; the new test file itself is below one second. Per-file hosted CI seconds are not available yet and will be added when observed. No full-suite/local live-Gateway proof is claimed.
CI fixture correction
CI job 108907403112 exposed two missed child-process interceptors in
test/scripts/run-vitest-bounded.test.ts. Six existing cases still matched the formerrun-node.mjsprerequisite and consequently launched real compiler work instead of their owned runtime fixture. This is a PR-caused fixture migration miss, not a flaky timeout or a reason to raise the memory limit.The correction changes only those two executable selectors. All existing assertions, signal/process cleanup, timeouts, and 39 cases remain intact. The full edited file passes 39/39, with formatting and focused lint clean and an independent P2 review reporting no actionable findings. Production bytes are unchanged from the native build/runtime-consumer proof.
Earlier measured fixed cost:
pnpm test test/scripts/run-vitest-bounded.test.ts --maxWorkers=1— 37.99 s command wall / 36.73 s Vitest duration. The current head passed in 32.89 s shard wall / 32.09 s Vitest duration. This existing native-process suite exercises actual CLI exits, process-group termination, worker generations, and final-report ordering; a mocked helper cannot replace those contracts. Test-audit/deslop retained every assertion and removed no incidental coverage. The test-performance pass identified unintended real builds as the wasted work; the failed hosted file took 90.497 s before correction, but that is a different machine and not a valid local percentage-speedup comparison. Fixed-head hosted timing remains pending.Worked on by
Work sessions
View the OpenClaw team session
Inherited CI failure
check-source-contracts(lint:tmp:export-name-collisions): the merge ref carriedmain's duplicatesrc/cli/daemon-cli.tsexports (assertForegroundUpdateOrigin,runDaemon*,waitForGatewayUpdateRecovery) introduced by 5de949f and fixed onmainby 385ac28. This PR does not touchsrc/cli. Every other check is green on this head; landed through the admin exception per the pre-existing-red policy.