Skip to content

improve: reduce disk allocation in Local AI lifecycle tests - #1647

Merged
shanselman merged 1 commit into
mainfrom
shanselman-reduce-model-fixture-disk-work
Oct 6, 2026
Merged

shanselman merged 1 commit into
mainfrom
shanselman-reduce-model-fixture-disk-work

Conversation

@shanselman

@shanselman shanselman commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Local AI lifecycle tests repeatedly provision a 22,663,387,424-byte zero-filled fake model with ordinary file extension, reserving model-sized storage for each fixture.

User Impact

No product-visible change. Connection tests retain real catalog-sized, independently mutable fixtures without model-sized Windows allocation. No tests are removed or disabled.

Why This Change Was Made

A test-local helper marks the new file sparse through its existing SafeFileHandle before the unchanged SetLength. Windows errors remain explicit with no allocating fallback; Unix retains SetLength hole semantics. Catalog/receipt metadata, production size/hash checks, and startup/stop/ownership assertions are unchanged. No packages, project configuration, product code, or workflows change.

Evidence

One matched local full-suite pair: native Windows ARM64 10.0.28000, .NET SDK 10.0.401, Debug, no coverage, identical isolated TEMP/environment. Both builds include the same three added helper tests; only lifecycle provisioning differs.

Measurement Original fixture Sparse fixture
Full Connection process wall time 35.474 s 23.244 s
Lifecycle summed TRX durations (113 results) 18.580 s 3.944 s
Full Connection passed / skipped / failed 1564 / 5 / 0 1564 / 5 / 0
Added helper tests passed 3 3
Logical model length 22,663,387,424 bytes 22,663,387,424 bytes
Windows allocation API, each of 3 pairs 22,663,387,424 bytes 0 bytes

Single-pair local observations are not a statistical performance guarantee. Summed test durations are not wall time; reported allocation is not bytes written. Three interleaved provisioning probes measured 0.859/0.867/1.197 ms before versus 0.776/0.322/0.330 ms after; sampled reads and cleanup succeeded. No model downloads or full-model reads occurred.

Current-head hosted proof: Build and Test run 37419643864 succeeded. Core and CLI tests passed in 2m58s. Its Connection step took 25 seconds; downloaded test-results-core TRX shows 1568 passed, 1 existing skip, 0 failed, all 3 helper tests passed, and 113 lifecycle results totaling 14.057 seconds. Earlier separately hosted observations were 463 seconds for the Connection step and 449.95 seconds summed for 109 lifecycle cases, and 477.193 seconds summed for 113 lifecycle cases without coverage. These historical comparisons are not controlled same-host pairs, but the current hosted execution directly confirms the optimized behavior. Coverage alone did not explain the earlier slow runs.

Initial local baselines exposed environment preconditions: long isolated TEMP paths broke existing mklink; a shorter drive-root TEMP inherited unsuitable ACLs. Failed runs were retained separately. Final clean before/after runs both used short user-owned C:\Users\scottha\s2dd1c196; no unrelated code or skips were changed. Task-owned temporary roots were cleaned.

Change Type

  • Tests or validation
  • Docs or instructions

Scope

  • Tests, CI, or docs

Required proof pools

  • none: test-fixture-only storage change; no application UI, gateway, node capability, installer, or custom device behavior changes.

Validation

Source validated and committed unchanged as 412d325b70923e1e7700acf9be13e93a59607463:

  • dotnet build .\tests\OpenClaw.Connection.Tests\OpenClaw.Connection.Tests.csproj --configuration Debug --verbosity quiet: pass with zero warnings/errors, baseline and after.
  • dotnet test .\tests\OpenClaw.Connection.Tests\OpenClaw.Connection.Tests.csproj --no-build --no-restore --configuration Debug --logger "trx;LogFileName=connection.trx" --results-directory <baseline-or-after>: both 1564 passed, 5 existing skips, 0 failed, 1569 total.
  • .\build.ps1: all projects passed, native win-arm64.
  • dotnet test .\tests\OpenClaw.Shared.Tests\OpenClaw.Shared.Tests.csproj --no-restore: 4232 passed, 36 existing skips, 0 failed.
  • dotnet test .\tests\OpenClaw.Tray.Tests\OpenClaw.Tray.Tests.csproj --no-restore: 3899 passed, 0 skipped/failed.
  • Fresh Shared/Tray test projects were built before testing; counts confirm no restore-less no-ops. OPENCLAW_REPO_ROOT and isolated tray data were set.
  • Hosted CI Gate, Core/CLI, fast validation, proof-pool contracts, and CodeQL succeeded. Unrelated hosted lanes were skipped by existing classification, not changed here; mandatory local Shared/Tray/build still ran.
  • App-native Hanselman exact-commit reviews: Claude Opus 5.5 and GPT-6 Astra found no actionable issues. Opus's informational Unix allocation-assertion note does not change the pre-existing Unix SetLength behavior. CLI autoreview's isolated Git config interpreted unrelated CRLF files as a broad patch, and the parent confirmed Codex CLI absent; authorized app-native review was used without tool/config changes.

Real Behavior Proof

  • Environment tested: native Windows ARM64 locally and hosted Windows CI.
  • PR head tested: 412d325b70923e1e7700acf9be13e93a59607463.
  • Exact steps: full Connection command above and hosted Connection step.
  • Evidence: all 3 helper tests passed locally and hosted. They check exact 22,663,387,424-byte length, zero samples at beginning/middle/end and EOF, Windows sparse attribute and allocation below 1 MiB, independent last-byte mutation, overwrite refusal, and cleanup. Three local allocation probes returned 0 at unchanged logical length.
  • Observed result: less fixture allocation, preserved lifecycle coverage, and measured local/hosted durations above.
  • Screenshot or artifact links verified? Yes: downloaded current-run test-results-core artifact and parsed Connection TRX. Raw local TRX/log/CSV and failed environment attempts retained in session artifacts.
  • Not verified or blocked: non-Windows allocation/runtime was not measured. Existing symlink/cross-volume and Shared integration skips remain disclosed; none were added. Historical hosted timings are not controlled benchmarks.

Security Impact

  • New permissions or capabilities? No
  • Secrets or tokens handling changed? No
  • New or changed network calls? No
  • Command or tool execution surface changed? No
  • Data access scope changed? No

Compatibility and Migration

  • Backward compatible? Yes, product behavior unchanged.
  • Config or environment changes? No product changes. Windows test TEMP must support sparse files; unsupported marking fails explicitly rather than allocating a model-sized fallback.
  • Migration needed? No

Review Conversations

  • Independent source reviews reconciled; no actionable findings.
  • No inline GitHub review comments were outstanding at the pre-merge check.

Preserve catalog-sized logical files and per-test mutations while avoiding model-sized fixture allocation on Windows.

Co-authored-by: Copilot App <[email protected]>
@clawsweeper

clawsweeper Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@shanselman shanselman added the status: 🚢 actively landing A maintainer or agent is actively driving this item through implementation, validation, or merge. label Oct 6, 2026
@clawsweeper clawsweeper Bot added P3 Low-risk cleanup, docs, polish, ergonomics, or speculative feature. proof: sufficient Contributor real behavior proof is sufficient. 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 Oct 6, 2026
@clawsweeper

clawsweeper Bot commented Oct 6, 2026

Copy link
Copy Markdown

Codex review: needs maintainer review before merge. Reviewed October 6, 2026, 1:41 AM ET / 05:41 UTC.

ClawSweeper review

What this changes

The PR creates sparse model-sized files for Local AI lifecycle tests and adds checks for allocation, readable zeros, isolation, overwrite refusal, and cleanup.

Merge readiness

✅ Ready for maintainer review

This remains a useful, focused test improvement absent from current main. No actionable correctness or security defect was found, and the supplied Windows measurements directly support the allocation reduction.

Priority: P3
Reviewed head: 412d325b70923e1e7700acf9be13e93a59607463

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused implementation with direct Windows allocation evidence and relevant regression coverage.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The changed test fixture helper was exercised on native Windows ARM64 at the pinned head through full Connection runs and direct create/read/delete allocation probes, with exact length retained and zero allocated bytes observed. Required build, Shared, and Tray results are reported; no stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The changed test fixture helper was exercised on native Windows ARM64 at the pinned head through full Connection runs and direct create/read/delete allocation probes, with exact length retained and zero allocated bytes observed. Required build, Shared, and Tray results are reported; no stored-data contract changes.
Evidence reviewed 7 items Pinned introduced scope: The merge-base-to-head patch changes only three test files and one documentation row. It adds no product code, dependencies, workflow changes, or persisted-data contracts.
Fixture invariants: The helper retains CreateNew and exclusive access, marks the existing Windows handle sparse before SetLength, and reports marking failures explicitly. Tests cover exact logical length, sampled zeros and EOF, Windows allocation below 1 MiB, independent mutations, overwrite refusal, negative-length rejection, and cleanup.
Current main still needs the change: The fetched main fixture still creates an ordinary FileStream and calls SetLength without sparse marking. The PR replaces only this provisioning step; manifest creation and lifecycle assertions remain intact.
Findings None None.
Security None None.

How this fits together

Local AI lifecycle tests create temporary model installations to exercise runtime startup, shutdown, and ownership behavior. The changed fixture helper supplies those installations with full-length zero-filled files while reducing physical disk allocation.

flowchart TD
 A[Model catalog size] --> B[Temporary model fixture]
 B --> C{Windows host?}
 C -->|Yes| D[Mark file sparse]
 C -->|No| E[Extend logical length]
 D --> E
 E --> F[Lifecycle and isolation checks]
Loading

Before merge

None.

Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Production and test LOC production +0/-0; tests +136/-2; docs +1/-0 All executable growth stays in test fixture support and regression checks.
Observed fixture allocation 22,663,387,424 bytes to 0 bytes in 3 Windows probe pairs The supplied measurements directly demonstrate the intended storage reduction.

Technical review

Best possible solution:

Keep fixture allocation optimization confined to tests while preserving catalog-sized files, independent mutations, and existing production validation.

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

Not applicable as a product bug; the supplied matched Windows runs and direct allocation probes demonstrate the test-fixture resource problem and its improvement.

Is this the best way to solve the issue?

Yes. Marking the test file sparse before extending it preserves existing size and isolation semantics without weakening production checks or introducing shared mutable fixtures.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 2e5e219ade50.

Labels

Label changes:

  • add P3: This improves test resource usage without changing product-visible behavior.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The changed test fixture helper was exercised on native Windows ARM64 at the pinned head through full Connection runs and direct create/read/delete allocation probes, with exact length retained and zero allocated bytes observed. Required build, Shared, and Tray results are reported; no stored-data contract changes.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The changed test fixture helper was exercised on native Windows ARM64 at the pinned head through full Connection runs and direct create/read/delete allocation probes, with exact length retained and zero allocated bytes observed. Required build, Shared, and Tray results are reported; no stored-data contract changes.

Label justifications:

  • P3: This improves test resource usage without changing product-visible behavior.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The changed test fixture helper was exercised on native Windows ARM64 at the pinned head through full Connection runs and direct create/read/delete allocation probes, with exact length retained and zero allocated bytes observed. Required build, Shared, and Tray results are reported; no stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The changed test fixture helper was exercised on native Windows ARM64 at the pinned head through full Connection runs and direct create/read/delete allocation probes, with exact length retained and zero allocated bytes observed. Required build, Shared, and Tray results are reported; no stored-data contract changes.

Evidence

What I checked:

  • Pinned introduced scope: The merge-base-to-head patch changes only three test files and one documentation row. It adds no product code, dependencies, workflow changes, or persisted-data contracts. (tests/OpenClaw.Connection.Tests/SparseFixtureFile.cs:15, 412d325b7092)
  • Fixture invariants: The helper retains CreateNew and exclusive access, marks the existing Windows handle sparse before SetLength, and reports marking failures explicitly. Tests cover exact logical length, sampled zeros and EOF, Windows allocation below 1 MiB, independent mutations, overwrite refusal, negative-length rejection, and cleanup. (tests/OpenClaw.Connection.Tests/SparseFixtureFileTests.cs:10, 412d325b7092)
  • Current main still needs the change: The fetched main fixture still creates an ordinary FileStream and calls SetLength without sparse marking. The PR replaces only this provisioning step; manifest creation and lifecycle assertions remain intact. (tests/OpenClaw.Connection.Tests/LocalAiPortLifecycleTests.cs:3167, 2e5e219ade50)
  • Native Windows allocation evidence: The captured PR body reports matched Windows ARM64 runs of the reviewed source: each of three direct filesystem probes retained 22,663,387,424 logical bytes while allocation fell from that size to zero. Both Connection suites recorded 1564 passes, 5 existing skips, and zero failures; all 113 lifecycle results were preserved. These observations exercise the changed file-creation boundary, rather than relying on mocked filesystem behavior. Hosted-CI speedup and Unix allocation were explicitly not claimed. (412d325b7092)
  • Required validation reported: The captured body reports a successful full build, Shared tests with 4232 passes and 36 existing skips, and Tray tests with 3899 passes and no failures. It explicitly addresses fresh-worktree test builds and isolated settings. This read-only review did not execute builds or tests. (AGENTS.md:7, 412d325b7092)
  • Merged area history and routing: Current-main file history includes prior Local AI cache work by shanselman and deterministic runtime validation work by RomneyDa; GitHub commit metadata verifies those handles. Older blob retrieval prevented full blame and parent-patch inspection, so these are routing candidates without introduction attribution. (tests/OpenClaw.Connection.Tests/LocalAiPortLifecycleTests.cs, 2e5e219ade50)

Likely related people:

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

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.

@shanselman
shanselman merged commit f03f1ca into main Oct 6, 2026
29 checks passed
@shanselman
shanselman deleted the shanselman-reduce-model-fixture-disk-work branch October 6, 2026 05:54
@shanselman shanselman removed the status: 🚢 actively landing A maintainer or agent is actively driving this item through implementation, validation, or merge. label Oct 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 Low-risk cleanup, docs, polish, ergonomics, or speculative feature. proof: sufficient Contributor real behavior proof is sufficient. 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant