Skip to content

feat(local-ai): add verified legacy model cache migration - #1388

Merged
shanselman merged 5 commits into
mainfrom
shanselman-hf-cache-migration
Sep 10, 2026
Merged

shanselman merged 5 commits into
mainfrom
shanselman-hf-cache-migration

Conversation

@shanselman

@shanselman shanselman commented Sep 10, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Layer 2 of the current-main replacement train for #1288 (feat(local-ai): store downloaded models in the standard HF hub cache), stacked after #1385 (feat(shared): add safe Hugging Face cache primitives).

  • adds an explicit, cancellable LocalAiManifestStore.MigrateLegacyModelToHubCacheAsync transaction
  • copies canonical legacy model weights into the standard Hugging Face snapshot layout from the same SHA-256-verified source handle, including across volumes
  • validates or reuses pre-existing destinations only through HuggingFaceHubCache.TryOpenVerifiedCacheFileAsync
  • roots cache and legacy path walks at Windows volume handles, rejects reparse segments and hard-linked partials, and performs cache mutation/promotion/rollback through exact handles
  • records a transitional schema-4 cache receipt without changing the active legacy ModelPath
  • keeps LoadAsync, runtime refresh, status, uninstall, normal downloads, active model selection, installer, reconciler, and setup wiring unchanged

The parent train item remains open. Layer 3 owns normal Hub-cache downloads and switching active selection.

Layer 3 contract

  • LocalAiInstallManifest.CurrentSchemaVersion remains 3 for normal setup writes.
  • Schema 4 means a verified cache-copy receipt exists.
  • ModelPath remains the active legacy path in this layer.
  • ModelCacheRoot is the normalized cache root used for verification.
  • CachedModelPath is the verified standard snapshot path.
  • Invoke MigrateLegacyModelToHubCacheAsync explicitly. Do not trigger migration from LoadAsync or another status/runtime/uninstall read path.
  • A concurrent manifest change aborts receipt persistence without deleting either model copy. Retry reuses the verified destination.
  • Layer 3 must continue verifying receipts through HuggingFaceHubCache before selecting cached content, wire HuggingFaceModelInstaller / LocalAiArtifactInstaller / reconciler / setup behavior, and decide rollout or downgrade gating before enabling migration automatically.

Required proof pools

  • none: this is a non-UI manifest and filesystem migration API. Deterministic Windows tests and an explicit two-volume local proof cover the changed behavior without a custom host class.

Validation

  • ./build.ps1 - passed
  • dotnet test ./tests/OpenClaw.Shared.Tests/OpenClaw.Shared.Tests.csproj --no-restore - 3,991 passed, 32 skipped
  • dotnet test ./tests/OpenClaw.Tray.Tests/OpenClaw.Tray.Tests.csproj --no-restore - 2,888 passed
  • dotnet test ./tests/OpenClaw.Connection.Tests/OpenClaw.Connection.Tests.csproj --no-restore - 746 passed, 1 cross-volume proof skipped unless explicitly configured
  • dotnet test ./tests/OpenClaw.SetupEngine.Tests/OpenClaw.SetupEngine.Tests.csproj --no-restore - 1,134 passed
  • focused migration suite with OPENCLAW_TEST_HF_CACHE_ROOT=E:\OpenClawHfMigrationProof - 29 passed, 0 skipped
  • autoreview: python .agents\skills\autoreview\scripts\autoreview --mode branch --base origin/main ... - clean, no accepted/actionable findings
  • final rubber-duck review - no blocking findings

Real behavior proof

Current-head cross-volume proof:

Legacy fixture volume: C:\
HF cache proof volume: E:\
Passed OpenClaw.Connection.Tests.LocalAiManifestMigrationTests.Migration_CopiesAcrossConfiguredDistinctVolume
Total tests: 1
Passed: 1

The proof asserts the destination bytes equal the pinned content, the legacy source remains unchanged, and the schema-4 receipt records the standard snapshot path. Focused deterministic coverage also proves interruption recovery, cancellation cleanup, hard-link preservation, destination collision handling, directory-swap rejection, source/cache-root reparse rejection, concurrent manifest update/deletion handling, nested Hub paths, and rollback preserving shared-cache content.

Add an explicit, recoverable migration that copies verified legacy model weights into the standard Hugging Face cache while keeping the legacy model active for layer 3.

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

Copilot-Session: e7ffdfcb-cd94-420d-9f35-b268846a60fc
Keep cache directory and temporary file identities open through copy, verification, promotion, and rollback so reparse swaps and content races fail closed without touching unrelated paths.

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

Copilot-Session: e7ffdfcb-cd94-420d-9f35-b268846a60fc
Walk cache and legacy model paths from Windows volume handles, reject every reparse segment, release failed recovery handles, and validate decoded Hugging Face path segments before migration.

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

Copilot-Session: e7ffdfcb-cd94-420d-9f35-b268846a60fc
Support volume-root and UNC cache paths, allow migration beside active read-only model use, preserve flat legacy layout for nested Hub paths, and report unconfigured cross-volume proof as skipped.

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

Copilot-Session: e7ffdfcb-cd94-420d-9f35-b268846a60fc
@clawsweeper

clawsweeper Bot commented Sep 10, 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 Sep 10, 2026
@clawsweeper clawsweeper Bot added P2 Normal priority bug or improvement with limited blast radius. 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 Sep 10, 2026
@clawsweeper

clawsweeper Bot commented Sep 10, 2026

Copy link
Copy Markdown

Codex review: needs maintainer review before merge. Reviewed September 10, 2026, 12:24 AM ET / 04:24 UTC.

ClawSweeper review

What this changes

Adds an explicit migration API that verifies and copies legacy Local AI models into the Hugging Face cache, records a migration receipt, and preserves the active legacy model.

Merge readiness

✅ Ready for maintainer review

This remains useful, distinct work absent from main and the latest release. No blocking patch defect was found; the staged migration preserves existing model selection and leaves automatic rollout to the next layer.

Priority: P2
Reviewed head: ccc3c6a429c7403bf766791a800aefbb7edf2658

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A coherent staged implementation with substantial filesystem coverage and reported native cross-volume validation; no actionable blocker was identified.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: The external-contributor gate does not apply to this collaborator-authored PR. Its supplied C: to E: terminal trace exercises the production migration API through a real-filesystem test; inspected assertions check copied bytes, preserved legacy content, and the new receipt. No unresolved authority-chain proof requirement was established.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The external-contributor gate does not apply to this collaborator-authored PR. Its supplied C: to E: terminal trace exercises the production migration API through a real-filesystem test; inspected assertions check copied bytes, preserved legacy content, and the new receipt. No unresolved authority-chain proof requirement was established.
Evidence reviewed 8 items Pinned scope and repository policy: Read the full root AGENTS.md and proof-validation skill. No applicable nested AGENTS.md or maintainer-notes directory was found. The verified merge-base-to-head diff contains exactly three files; git diff --check passed and git status --porcelain was empty. Builds, tests, and bundled reviewers were not executed during this read-only review.
Current-main necessity: Current main retains schema 3 and has no explicit cache migration API or cache receipt fields. The merged prerequisite supplies verified cache reads, not this migration transaction.
Latest-release comparison: The supplied latest release, v2026.7.1-4, also uses schema 3 and rejects other schema versions. Its manifest source contains none of the new migration API or receipt fields. GitHub contents inspection succeeded after the release blob was unavailable locally.
Findings None None.
Security None None.

How this fits together

Local AI uses an installation manifest to locate the model launched by the Windows inference runtime. This migration copies verified weights into the shared Hugging Face cache without redirecting that runtime.

flowchart TD
  A[Explicit migration request] --> B[Read legacy installation receipt]
  B --> C{Cache destination exists?}
  C -->|Yes| D[Verify existing cache content]
  C -->|No| E[Verify source and copy through held handles]
  D --> F[Check manifest unchanged and save receipt]
  E --> F
  F --> G[Runtime continues using legacy model]
Loading

Before merge

None.

Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Production and test growth production +1,577/-11; tests +774/-0 The substantial production addition implements native handle-bound copying, promotion, rollback, and manifest coordination within the stated migration boundary.
Focused regression coverage 29 migration tests added Coverage includes compatibility, recovery, cancellation, filesystem interference, and an explicitly configured cross-volume case.

Technical review

Best possible solution:

Keep migration explicit and legacy selection intact, with cache activation and downgrade compatibility handled together in the later acquisition layer.

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

Not applicable: this adds an explicit migration capability rather than reporting a current-main bug; the supplied cross-volume trace and inspected tests exercise that capability.

Is this the best way to solve the issue?

Yes, for this staged scope: it reuses verified cache reads, preserves the active model, and separates filesystem migration from automatic installation and runtime rollout.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: This is a bounded Local AI storage improvement with no demonstrated urgent regression in current product workflows.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit 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: The external-contributor gate does not apply to this collaborator-authored PR. Its supplied C: to E: terminal trace exercises the production migration API through a real-filesystem test; inspected assertions check copied bytes, preserved legacy content, and the new receipt. No unresolved authority-chain proof requirement was established.

Label justifications:

  • P2: This is a bounded Local AI storage improvement with no demonstrated urgent regression in current product workflows.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The external-contributor gate does not apply to this collaborator-authored PR. Its supplied C: to E: terminal trace exercises the production migration API through a real-filesystem test; inspected assertions check copied bytes, preserved legacy content, and the new receipt. No unresolved authority-chain proof requirement was established.

Evidence

What I checked:

  • Pinned scope and repository policy: Read the full root AGENTS.md and proof-validation skill. No applicable nested AGENTS.md or maintainer-notes directory was found. The verified merge-base-to-head diff contains exactly three files; git diff --check passed and git status --porcelain was empty. Builds, tests, and bundled reviewers were not executed during this read-only review. (AGENTS.md:1, ccc3c6a429c7)
  • Current-main necessity: Current main retains schema 3 and has no explicit cache migration API or cache receipt fields. The merged prerequisite supplies verified cache reads, not this migration transaction. (src/OpenClaw.Connection/LocalAi/LocalAiManifest.cs:138, ce3f51fcb29b)
  • Latest-release comparison: The supplied latest release, v2026.7.1-4, also uses schema 3 and rejects other schema versions. Its manifest source contains none of the new migration API or receipt fields. GitHub contents inspection succeeded after the release blob was unavailable locally. (src/OpenClaw.Connection/LocalAi/LocalAiManifest.cs:123, c7c6fb06be03)
  • Upgrade boundary and persistence: Normal manifests still default to schema 3. Migration checks the original manifest bytes under the shared write lock before saving schema 4, while ModelPath remains unchanged. Setup reconciliation continues verifying and selecting the legacy path. No production caller enables migration. The PR explicitly reserves automatic rollout and downgrade gating for layer 3; older binaries cannot read an explicitly migrated receipt. (src/OpenClaw.Connection/LocalAi/LocalAiManifest.cs:315, ccc3c6a429c7)
  • Filesystem safety and existing implementation reuse: Read the complete migration implementation. Source verification and copying share one read handle; temporary files are opened exclusively, verified, promoted without replacement, and cleaned through their handles. Existing destinations use the repository's HuggingFaceHubCache.TryOpenVerifiedCacheFileAsync, including supported snapshot symlinks. No external dependency implementation is used as the authoritative oracle. (src/OpenClaw.Connection/LocalAi/LocalAiManifestMigration.cs:19, ccc3c6a429c7)
  • Migration validation and supplied native evidence: The captured PR body reports passing required build/shared/tray checks, Connection and SetupEngine suites, and 29 focused migration tests with no skips when a second volume is configured. Its current-head terminal excerpt reports the production migration entrypoint passing from C: to E:. The inspected test asserts copied bytes, preserved legacy bytes, and schema 4. Other tests cover unchanged loading, collisions, cancellation, concurrent manifest changes, symlinks, hard links, and receipt validation. These runs were contributor-reported, not rerun by this reviewer. (tests/OpenClaw.Connection.Tests/LocalAiManifestMigrationTests.cs:584, ccc3c6a429c7)

Likely related people:

  • Scott Hanselman: Raw commit 4064eb9 adds src/OpenClaw.Shared/Inference/Catalog/HuggingFaceHubCache.cs:293 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 4064eb9c230d; files: src/OpenClaw.Shared/Inference/Catalog/HuggingFaceHubCache.cs)
  • joelagnel: 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 3ce56b8 into main Sep 10, 2026
24 of 25 checks passed
@shanselman
shanselman deleted the shanselman-hf-cache-migration branch September 10, 2026 04:37
@shanselman shanselman removed the status: 🚢 actively landing A maintainer or agent is actively driving this item through implementation, validation, or merge. label Sep 10, 2026
@clawsweeper clawsweeper Bot mentioned this pull request Oct 12, 2026
6 of 16 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal priority bug or improvement with limited blast radius. 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