Skip to content

feat(cli): revision-aware mlx download model — detect upstream updates, sync changed files, --force - #104

Merged
Brooooooklyn merged 9 commits into
mainfrom
feat/download-model-revision-sync
Jul 30, 2026
Merged

Brooooooklyn merged 9 commits into
mainfrom
feat/download-model-revision-sync

Conversation

@Brooooooklyn

@Brooooooklyn Brooooooklyn commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Problem

mlx download model refused to re-download once the output directory looked complete — the gate was local-only and revision-blind, so an updated HuggingFace repo could only be fetched via rm -rf of the whole checkpoint (all 26 GB of it, for gemma-4-26b-a4b-it).

What this does

  • Resolves the upstream commit sha (modelInfo, retried) and pins listing + per-file fetches to it — a push mid-download can no longer mix two revisions.
  • Writes a .mlx-download-complete.json marker after every successful download — same filename/shape as the dashboard's (contract-tested against packages/dashboard/src/models.ts), so the dashboard stops classifying CLI installs as foreign dirs, and the cold-tier fingerprint takes its cheap manifest path on CLI-downloaded checkpoints.
  • "Already up to date (revision abc1234)" short-circuit only when the marker matches the upstream sha AND the local shape predicate passes (glob-partial markers can never satisfy a full run).
  • Sync pass when the marker is stale/absent/--force: per-file content verification (LFS sha256 / git-blob sha1, ported from the dashboard) — catches same-size re-uploads that a size check misses; only changed files are re-fetched. Marker-less dirs downloaded before this PR heal automatically, no rm -rf.
  • Safe prune: only old-marker files proven gone from the remote, only top-level (the non-recursive listing can't prove a nested file is gone — dashboard markers may contain nested paths), only inside the output dir, and only after successful verification.
  • --force flag: full re-verify against upstream; unchanged files still skip by hash.
  • Offline/auth failure: exactly the legacy behavior plus one warning line.

Review trail

Built via subagent-driven development (spec + plan committed in docs/superpowers/specs/). Per-task reviews plus two independent final reviews (whole-branch reviewer + Codex adversarial). Four findings from the final reviews were confirmed against control flow and fixed in 38d8cdc7: glob-marker short-circuit regression, prune-before-verify data-loss path, slug-collision prune across repos, and revision-laundering of unverified files in glob syncs — each pinned by a mutation-named test (revert-verified live).

Tests

  • 21 new unit tests (download-marker, download-sync, incl. dashboard contract tests); 62/62 download-suite tests green; full TS suite 2352 passed (5 pre-existing packages/agent failures from a stale local native addon, A/B-proven unrelated — they need yarn build:native).
  • Foreground e2e against a tiny public repo: fresh download → up-to-date short-circuit → same-size corruption re-fetched under --force (proven by sha256 round-trip, not logs) → marker-less heal → glob-then-full run downloads weights instead of short-circuiting.

🤖 Generated with Claude Code

https://claude.ai/code/session_01M6DA9gPNjKiV77T7UHGm5P


Note

Medium Risk
Changes model download correctness and can delete files during full sync prune; safeguards (marker-only prune, post-verify, repo mismatch refusal) are heavily tested but the flow is complex and touches large checkpoints.

Overview
mlx download model is now revision-aware: it resolves the upstream commit, pins listing and fetches to that SHA, and writes .mlx-download-complete.json (same contract as the dashboard) so re-runs can sync instead of requiring rm -rf.

Re-runs short-circuit only when the marker matches the current revision, the run is a full (non-glob) install, local shape is complete, and every recorded file exists. Otherwise a sync pass hash-verifies size-matched files (LFS sha256 / git blob sha1), re-downloads only what changed, and on full runs prunes files the old marker listed but the recursive remote tree no longer has—after downloads succeed, with path safety and repo-ownership guards. --force skips the up-to-date gate but still skips unchanged files by hash. Glob runs mark scope: partial; offline revision resolution keeps the prior local-only behavior with a warning.

New CLI modules download-marker and download-sync hold marker I/O and pure sync helpers; download-model wires the flow. The dashboard gains scope on markers, treats partial markers as owned but not installed, and documents that current CLI installs are no longer “foreign.” Docs and a design spec describe behavior; extensive CLI contract and mutation-named tests cover edge cases (slug collision, glob short-circuit, prune ordering, revision under-claim on glob sync).

Reviewed by Cursor Bugbot for commit 3121ce3. Bugbot is set up for automated code reviews on this repo. Configure here.

Brooooooklyn and others added 7 commits July 29, 2026 17:50
The completion marker is shared with the dashboard, which lists the repo
recursively; the CLI lists non-recursively, so nested marker entries can
never appear in the CLI's remote list. Treating that absence as "gone from
upstream" deleted live files a CLI sync could never re-download. Nested
entries are now never pruned, and buildMarkerFiles keeps nested previous
entries on disk-presence alone so a CLI sync does not forget them.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01M6DA9gPNjKiV77T7UHGm5P
- The no-glob up-to-date short-circuit now also requires the local model
  shape (config + weights): a selection-only marker from a --glob run can
  no longer satisfy a full run (canShortCircuitFullRun).
- Prune + marker write fold into finalizeSync(), invoked only from the
  three success paths — pruning before verification could destroy the only
  working copy on an upstream restructure. A verify sync also deletes the
  stale on-disk marker up front so an interrupted sync cannot masquerade
  as a complete install to other marker readers.
- A marker from a different repo (slug collision on the default output
  dir) is nulled for prune and the marker union (sameRepoCompletion), with
  an honest message instead of 'Upstream revision changed'.
- A --glob sync at a changed revision keeps the OLD marker revision
  (markerRevisionToClaim): stamping the new sha would launder unverified
  union files into a current marker and stop future full syncs.
- writeCompletion uses a unique wx-opened temp name, cleaned on failure;
  prune rm failures warn instead of aborting a finished download.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01M6DA9gPNjKiV77T7UHGm5P
Update three dashboard comments that still said mlx download writes no
marker, and note in the CLI docs that --force without --glob on a
variant-partial GGUF dir downloads all variants and that the marker makes
the directory dashboard-managed.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01M6DA9gPNjKiV77T7UHGm5P
@cursor

cursor Bot commented Jul 29, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_b8cd14dc-6f3f-4214-8419-f9865db3500c)

@coderabbitai

coderabbitai Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 09b9d8a0-f0ad-493d-b5a5-ed75bbde16e3

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 73874f4414

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@cursor

cursor Bot commented Jul 30, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_2ee60cf6-f101-4252-b333-6f9a4fa966d0)

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 09e34f7066

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@cursor

cursor Bot commented Jul 30, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_041cd57d-9f07-4034-9272-7f0798498218)

@Brooooooklyn
Brooooooklyn enabled auto-merge (squash) July 30, 2026 15:04
@Brooooooklyn
Brooooooklyn merged commit 91f232b into main Jul 30, 2026
7 checks passed
@Brooooooklyn
Brooooooklyn deleted the feat/download-model-revision-sync branch July 30, 2026 15:35
robert-johansson added a commit to robert-johansson/mlx-node that referenced this pull request Jul 30, 2026
…oad, mlx-node#106 Gemma4 tools/images/restart-cache

Merge-forward of mirror/upstream (91f232b) into our patched main.
Upstream delta since mlx-node#103:
  91f232b feat(cli): revision-aware mlx download model (mlx-node#104)
  e6598c6 fix(agent): recover Gemma 4 tools, images, and restart cache (mlx-node#106)

Conflict resolutions:
- packages/agent (3 TS files): kept our genmlx-provider extension + our
  genmlx-only test, added upstream's mlx-local-image-input extension (order:
  mlx-provider, genmlx-provider, mlx-local-image-input, ...); took upstream's
  richer gemma4 FamilyTraits (reasoning + thinkingLevelMap).
- crates/mlx-core auto-merged textually but broke the build: mlx-node#106 migrated the
  VLM image hash u64 -> engine::ImageCacheDigest, while our fork-only
  vlm_prepare_vision_continuation kept &[u64]. Migrated its signature to
  &[engine::ImageCacheDigest] (pure pass-through to vlm_prepare_vision_features;
  sole caller qwen3_5_moe already passes the digest type). Rebuild clean.
- nested mlx-sys/mlx gitlink kept ours (b55ff6e6).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant