Skip to content

feat(node): add the HF read surface, release durability, and model fetch - #623

Open
beardthelion wants to merge 15 commits into
feat/model-hosting-publishfrom
feat/model-hosting-read
Open

beardthelion wants to merge 15 commits into
feat/model-hosting-publishfrom
feat/model-hosting-read

Conversation

@beardthelion

Copy link
Copy Markdown
Collaborator

Summary

Adds the model-hosting read surface and durability layer: Hugging Face-compatible metadata and ranged download routes, an outbox worker that pins every release object to IPFS and anchors the release on Arweave, and twigpine model fetch so a client can rebuild a release byte-identically with no node at all. Stacked on #622.

Motivation & context

Completes the model-hosting milestone. With this, a published release is retrievable three ways: through the node's HF-compatible API, through IPFS by CID, and end-to-end without the node via model fetch, which verifies the anchored manifest against the publisher DID before trusting any content.

Kind of change

  • Bug fix
  • Feature
  • Security fix
  • Docs
  • Tests / CI
  • Refactor (no behavior change)
  • Breaking or protocol change (issue required first)

What changed

  • twigpine-node: /hf/api/models/... metadata routes (model info, revision, tree, refs) and /hf/{owner}/{repo}/resolve/{rev}/{path} ranged downloads for both Git-resident and chunked files. Revisions resolve to published releases only; main falls back to the newest published release. Private or visibility-ruled repos get the same 404 as a missing repo, and the denial echoes the caller's requested path rather than internal identifiers. Pickle files carry "unsafe": true in tree and sibling entries.
  • twigpine-node: a durability outbox (model_durability_jobs) draining pin_block, pin_manifest, pin_reconstruction, pin_block_map, and anchor jobs oldest-first under a batch budget. Git-resident file bytes (config.json, tokenizer, README) are pinned and indexed in the block map too, since an off-node fetch cannot reach the Git store. The publicity policy fence is re-checked between the local Kubo pin and the off-node Pinata pin so a publicity flip cannot publish mid-job. The Irys anchor posts only after every other job completes and carries the repo, owner DID, release commit, manifest CID and signature, reconstruction CID, and block map CID.
  • twigpine-cli: twigpine model fetch <owner>/<name> --expect-did <did> discovers release anchors on Arweave, verifies each candidate against the caller-supplied DID (the anchor's own DID is never the verifying key), skips forged or malformed candidates with warnings, then streams the rebuild with per-chunk and per-file SHA-256 checks, path-traversal rejection, and a bounded block cache.
  • docs: docs/MODEL-HOSTING.md covers operator setup, the durability tiers, HF client usage (including the bare-key owner form huggingface_hub accepts), and node-free fetching. .env.example and docs/RUN-A-NODE.md updated for the new settings.

How a reviewer can verify

cargo test -p twigpine-node --features test-harness --test hf_api
cargo test -p twigpine-node --features test-harness --test model_hosting_e2e
cargo test -p twigpine-cli --test model_fetch
cargo test -p twigpine-node --features test-harness --test deny_harness

The e2e seeds a real release, drains the durability worker against mocked IPFS and Arweave providers, shuts the node down, and rebuilds every file byte-identically from the anchor alone, then exercises the forged-anchor and tampered-block legs.

Before you request review

  • Scope is one logical change; no unrelated churn
  • cargo test --workspace passes locally
  • New behavior is covered by tests (required for fixes)
  • cargo fmt --all and cargo clippy --workspace --all-targets -- -D warnings are clean
  • Commit titles use Conventional Commits (feat(...), fix(...), docs(...))
  • Docs / .env.example updated if behavior or config changed (or N/A)
  • Checked existing PRs so this isn't a duplicate

cargo test --workspace was not re-run on the final tree; the suites above plus models_api, the model lib tests, and authz_guard all pass on it.

Protocol & signing impact

  • Touches DID / did:key, Ed25519 / RFC 9421 signatures, UCAN, ref certs, or P2P wire formats
  • Discussed in an issue before implementation
  • Backward-compatible with existing nodes and previously signed history

The gitlawb/model-release-anchor/v1 Arweave payload is a new artifact carrying the release's manifest CID and claim signature; verification of it in model fetch anchors on the caller-supplied --expect-did, never the DID the anchor names.

Notes for reviewers

  • The deny-harness HF rows are listed as ExternalDependencyUnavailable because the harness has no published-release fixture yet; the same denial legs (anonymous and signed stranger, private and visibility-ruled repos) are driven for all six HF routes in hf_api.rs. Converting the rows to driven fixtures is a reasonable follow-up.
  • HF_ENDPOINT points unmodified huggingface_hub clients at the node with one caveat: the owner's repo id segment must be the bare DID key (the client's validate_repo_id rejects the colons in a literal did:key: segment before any request). The node normalizes the bare key to the full DID; MODEL-HOSTING.md documents this.
  • Deferred cleanups, not bugs: shared Arweave pagination between clone.rs and model.rs, and an Arc allocation in the CLI block cache.

Serve published model releases through Hugging Face-compatible
metadata and resolve routes, resolved from release rows rather than
git history and gated on full publicity so private, mirrored, and
rule-bearing repos answer the same 404. Byte serving covers git and
chunked files with single-range, suffix, If-Range, and conditional
support under a dedicated per-IP limiter and download semaphore.

Publishing now also enqueues an idempotent durability job set: block,
manifest, reconstruction, and block-map pins to Kubo and optionally
Pinata, then a compact Irys anchor once every pin lands. A policy
fence fails every pending sibling and withholds the anchor when a
repo stops being fully public; local serving never waits on the
providers.
Off-node fetch could rebuild chunked files but had no source for the
small files the manifest keeps in git. The map job now pins those bytes
and indexes them under files, keyed by manifest sha256.
Rebuild a published release from Arweave and IPFS without the origin
node: discover release anchors by Irys tags, verify the manifest against
the caller-supplied DID, then rebuild every file with sha256 checks
under a bounded block cache. The CLI becomes a lib+bin so the node e2e
can drive the fetch in-process.
Seed a published release against mock Kubo, Irys, and Arweave, drain
durability, shut the node down, and rebuild byte-identically through
fetch_model: a forged self-signed anchor is skipped and a tampered block
fails by name.
Operator enablement, quotas, durability tiers, the HF read surface,
independent fetch, and the smoke check. README and the run/storage docs
point at the new page.
Review pass on the PR3 diff:

- Fetch the repo row once per durability job and share it with the
  publicity gate, git blob reads, and the anchor post instead of
  re-fetching it per call.
- still_publishable now delegates to require_fully_public so the
  canonical publicity predicate (public, no rules, canonical row) has
  one definition.
- Merge the near-identical durability count queries and take borrowed
  job tuples so enqueue stops allocating String for static kind names.
- Centralize the release manifest and signature paths in models:: so
  the claim reader, HF surface, and durability jobs share them.
- Drop the pin_model_object pass-through; callers use pin_git_object.
- Fix a panic: the fetch output dir sliced untrusted anchor text by
  bytes; it now truncates by chars so a multi-byte boundary is safe.
- Emit HF's real LFS pointerSize (the pointer file size, not the
  object size) in tree entries.
- Coverage: /tree/{rev}/{path} slash-boundary filtering, all six HF
  routes denying private and visibility-ruled repos for anon and
  signed stranger, pickle unsafe markers on model-info siblings, and
  lastModified proven to report published_at rather than created_at.
- Docs: the HF repo id uses the bare DID key (huggingface_hub rejects
  the did:key: colons client-side), the at-or-above threshold wording,
  current huggingface_hub wording, and the HF read/download knobs in
  .env.example and MODEL-HOSTING.md.
…ation

- Echo the requested owner/name in existence-hiding HF denials instead of
  internal storage identifiers, and assert the body leaks neither.
- Validate anchor release_commit as a real hex commit (40 for sha1 repos,
  64 for sha256 repos) before it shapes the output dir or fetch URLs, and
  keep CID path interpolation behind URL-safe checks.
- Bound download concurrency with the configured semaphore type and
  resolve refs through published releases only.
- Bound durability retry error recording; leave non-pending jobs alone.
- Cover traversal-shaped release commits and 64-hex commits in the fetch
  suite; keep the node-down e2e honest.
@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

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

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8a9993be-7db6-4ac2-b5ef-9e9eaa110388

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
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

A sha256-format repo's commit ids are 64 hex, and three gates still
required exactly 40: the release claim rejected the commit outright, the
HF revision resolver never treated a 64-hex rev as commit-shaped, and the
CLI --parent parser rejected the same input. Centralize the check as
twigpine_core::cid::is_hex_oid so the next commit-shaped gate cannot
reintroduce a sha1-only assumption.

@jatmn jatmn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The PR adds real value—a coherent HF read surface, durability pipeline, and off-node model fetch with strong tests on the happy path and denials—but merge is blocked today by CI surface fixtures, and the default HF model card can disagree with main when more than one branch has published releases.

Post–are these real, or drift? check: Both findings below are PR-introduced (nothing equivalent exists at merge-base 27e971c). Fixes stay inside this diff—fixture rows for CI, HF resolver + test for model info—not a core or framework rewrite.

Merge readiness

  • changed surfaces is red on head (run 44682749892): scripts/test-ci-surfaces.sh fails seven fixture checks because twigpine-node now dev-depends on twigpine-cli for the in-process e2e, so the mapper correctly fans out -p twigpine-cli -p twigpine-node while fixtures still expect CLI-only packages. Downstream PR Checks jobs (fmt + clippy, workspace test, MSRV, release validation, Docker smoke, etc.) were skipped on this run—not evidence they pass on this tree.
  • Stacked on #622 (feat/model-hosting-publish → feat/model-hosting-read). Target branch head matches the captured merge-base (27e971c); no extra target drift observed, but the stack still merges into the publish PR, not main.
  • Author checklist: cargo test --workspace not re-run on final tree; focused suites listed in the PR body were run locally in review and pass (hf_api, model_hosting_e2e, model_fetch).
  • Deny harness lists six HF routes as ExternalDependencyUnavailable; denial legs for private/rule-bearing repos are exercised in hf_api.rs instead (author-noted follow-up to wire deny-harness fixtures).

Findings

🟠 P1 — Keep test-ci-surfaces.sh aligned with reverse dependency fan-out after the node→CLI dev-dependency

📍 Where: scripts/test-ci-surfaces.sh, crates/twigpine-node/Cargo.toml (dev-dependencies.twigpine-cli).

💥 What fails: The PR Checks changed surfaces job exits 1. Seven fixture cases expect rust_packages=-p twigpine-cli (or icaptcha-client fan-out without node) but the live mapper emits -p twigpine-cli -p twigpine-node for those paths because ci-surfaces.sh pulls in every crate that depends on a touched crate—including twigpine-node after the new dev-dependency.

Verified on head: bash scripts/test-ci-surfaces.sh reports the same seven failures. At merge-base the twigpine-cli dev-dependency on twigpine-node is absent.

🔎 Root cause: The E2E harness added a crate dependency edge without updating the pinned fixture expectations that guard the mapper.

📜 Stated contract:

scripts/test-ci-surfaces.sh pins the mapping.

🏷️ Attribution: PR-introduced (no twigpine-cli dev-dep on twigpine-node at merge-base).

📌 In this PR:

  • crates/twigpine-node/Cargo.toml dev-dependency on twigpine-cli
  • scripts/test-ci-surfaces.sh unchanged (stale expectations)

🔒 Unchanged on main: scripts/ci-surfaces.sh reverse-dependency algorithm is correct; do not narrow fan-out to make fixtures pass.

🔧 Required correction: Update every affected fixture row in scripts/test-ci-surfaces.sh (twigpine-cli source paths, icaptcha-client row, crate manifest row, C-quoted path cases) so rust_packages includes -p twigpine-node when the mapper now does. Re-run scripts/test-ci-surfaces.sh locally and confirm PR Checks can schedule Rust jobs again.

🛠️ Author fix: Adjust all listed fixture rows in one commit; verify with bash scripts/test-ci-surfaces.sh. Do not remove the dev-dependency or weaken CI mapping.

🚫 Out of scope: Changing workspace test scope logic in ci-surfaces.sh beyond what the dependency graph requires.


🟡 P2 — Reconcile default HF model metadata with refs / revision/main (in-pr contract conflict)

📍 Where: crates/twigpine-node/src/api/hf.rs (hf_model_info, module doc, hf_refs), crates/twigpine-node/src/db/model_queries.rs (model_release_newest), docs/MODEL-HOSTING.md (HF + snapshot_download path).

💥 What fails: With two published releases on different branches, GET /hf/api/models/{owner}/{repo} returns the repo-wide newest release (model_release_newest → ORDER BY id DESC on all published rows), while GET .../refs and .../revision/main use release_for_rev(..., "main") (newest on main, then default branch). A huggingface_hub client can see one sha and siblings on the model card but download another commit when it follows main / snapshot_download.

No hf_api test covers two branch-published releases today.

🔎 Root cause: This PR documents two different “default release” rules at once: global newest on the model-info path versus main-scoped resolution on refs/revision/resolve.

📜 Stated contract:

main names exactly the release revision/main resolves: newest on main, then the git default branch.

Metadata comes from the newest published release row and its manifest

The newest published release on the repo… (the refs endpoint's default target).

The first and third quotes require model info and refs to agree on the default release. The second (module doc) describes repo-wide newest for metadata. All three are in this PR; they cannot all be true for multi-branch publishes unless operator docs say otherwise.

🏷️ Attribution: PR-introduced (no HF surface at merge-base). Not pre-existing main debt.

📌 In this PR:

  • hf_model_info → model_release_newest
  • hf_refs, hf_revision_info, hf_tree*, hf_resolve → release_for_rev
  • Module doc at top of hf.rs
  • Misleading doc comment on model_release_newest

🔒 Unchanged on main: Release rows and branch column semantics from #622.

🔧 Required correction: Pick one default-release rule and apply it consistently on every in-diff HF operator surface:

  1. Recommended (matches refs + smoke path): Drive hf_model_info from release_for_rev(state, record, "main") (same fallback as hf_refs). Fix the model_release_newest comment. Add an integration test that publishes on two branches and asserts model info sha matches refs and revision/main.

  2. If global-newest model card is intentional instead: Keep model_release_newest for model info but change hf_refs / revision/main behavior and rewrite docs/MODEL-HOSTING.md + module doc so snapshot_download and refs tell the same story. Still add the two-branch regression test.

Either path is in scope; leaving the contradiction in place is not.

🛠️ Author fix: Resolve the contract conflict in one pass—code, comments, and docs together—plus the two-branch test. Do not patch only hf_model_info or only one markdown file.

🚫 Out of scope: Redesigning release storage from #622; durability or model fetch pipelines.

Needs maintainer decision

None for this draft: P2 allows an explicit product choice (path 1 vs 2 above) without blocking merge once docs, code, and tests match.

…cover node fan-out

Model info now resolves the default release the way refs and revision/main do (newest on main, then the git default branch) instead of the repo-wide newest. A two-branch test pins all three routes to one commit, and the module doc, query doc and MODEL-HOSTING.md state the single rule.

twigpine-node dev-depends on twigpine-cli, so the surface mapper adds -p twigpine-node for CLI paths. The seven pinned fixture rows in test-ci-surfaces.sh now expect it.
model fetch parsed the gateway's GraphQL page with r.json() after a status check, which the no_parse_before_status gate rejects and which left the body uncapped. The read now goes through read_json (status-first, capped, sanitized); a failed page still ends discovery as before.
@beardthelion

Copy link
Copy Markdown
Collaborator Author

Both findings fixed on d7ab37f.

P1: the seven pinned rows in scripts/test-ci-surfaces.sh now expect -p twigpine-node alongside -p twigpine-cli. The mapper is untouched. bash scripts/test-ci-surfaces.sh failed with the same seven lines before the edit and passes after it.

P2: hf_model_info now resolves its release with release_for_rev(.., "main"), the same rule refs and revision/main use. The module doc, the model_release_newest comment and docs/MODEL-HOSTING.md state that one rule. New test model_info_follows_main_not_repo_wide_newest publishes on main and dev, then asserts all three routes return the main commit; it failed before the change (info returned the dev commit) and hf_api passes now (32 tests).

With the Rust jobs unskipped, the workspace run found one more failure on this diff: no_parse_before_status flagged model.rs:1207, where model fetch parsed the Arweave gateway reply with r.json(). It now goes through read_json, and a failed page still ends discovery as before.

The branch was 11 commits behind #622 and is merged with it, no conflicts. On the pushed head: cargo test --locked --workspace --no-fail-fast 3588 passed, 0 failed; clippy with -D warnings and fmt are clean. No second-model pass: the round changes a fixture table, one read-surface selector behind the existing public-repo gate, and routes one read through the stricter shared reader.

@beardthelion
beardthelion requested a review from jatmn November 21, 2026 13:48

@jatmn jatmn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Follow-up on jatmn's review: the CI surface fixture mismatch and HF default-release split are fixed on this head. This pass did not re-open those items.

The PR still adds substantial value—a coherent HF read surface, durability pipeline, and off-node model fetch with strong denial and verification tests.

Are these real, or drift? (internal challenge on head d7ab37f6): Both findings below are PR-introduced (api/hf.rs absent at merge-base 2a3497ce). Fixes stay inside this diff (rustdoc + release_for_rev normalization + one hf_api case). They are not requests to change unchanged core, durability design, or HF denial JSON shape. Candidate items withdrawn after challenge: Twigpine-shaped 404 on private repos (tested in hf_api.rs), deferred durability jobs (documented), no manifest signature re-check on HF serve (module doc), Windows publish_state_round_trips (unchanged at merge-base).

Merge readiness

  • Stacked merge target: PR targets feat/model-hosting-publish (#622), not main. Plan merge order through the publish stack.
  • test (windows, non-blocking) fails on head (run 44893511514): model::tests::publish_state_round_trips panics with Access is denied on save_state → sync_all after secret_file::write. Same save_state at merge-base; job is non-blocking—not counted as a PR finding.
  • Deny harness HF rows remain ExternalDependencyUnavailable; denial legs run in hf_api.rs (author-noted follow-up).

Required checks on head (stable/beta tests, fmt+clippy, changed surfaces, build) are green. The two findings below are P3 polish; they do not block merge if you accept the documented risks.


🔵 P3 — Align hf_refs rustdoc with the implemented default-release rule

📍 Where: crates/twigpine-node/src/api/hf.rs (hf_refs doc comment vs inline comment, release_for_rev, module header, docs/MODEL-HOSTING.md).

💥 What fails: Runtime behavior is already correct. The stale function doc on hf_refs (lines 334–335) says main names the newest published commit regardless of the repo's git default branch. The handler and release_for_rev use newest on main, then default_branch (e.g. master). The mismatch is maintainer/audit copy only.

🔎 Root cause: One handler rustdoc left behind when jatmn’s default-release fix landed across model info, inline hf_refs comment, tests, and MODEL-HOSTING.md.

📜 Stated contract:

Model info, refs and revision/main all name the same default release: the newest on main, then on the git default branch.

🏷️ Attribution: PR-introduced. Not pre-existing main debt; not scope drift.

📌 In this PR:

  • hf_refs function rustdoc (incorrect)
  • Module header, inline comment at hf_refs call site, MODEL-HOSTING.md, release_for_rev, hf_api two-branch / master tests (correct)

🔒 Unchanged on main: No HF surface at merge-base.

🔧 Required correction: Rewrite the hf_refs function doc comment to match the module header and release_for_rev (main, then git default branch). No code-path change.

🛠️ Author fix: Edit that doc comment in one commit; no other HF logic changes required.

🚫 Out of scope: Changing release_for_rev behavior or other handlers.


🔵 P3 — Normalize uppercase hex commit pins on HF revision resolution

📍 Where: crates/twigpine-node/src/api/hf.rs (release_for_rev commit-shaped branch), crates/twigpine-node/src/db/model_queries.rs (model_release_by_commit).

💥 What fails: is_hex_oid accepts uppercase A-F, so /revision/{SHA} is treated as a commit pin, but commit_sha rows are lowercase from git and the SQL bind is case-sensitive. Uppercase spelling returns RevisionNotFound for an existing published release. Most clients send lowercase; this is an edge case, not a typical HF path.

🔎 Root cause: New unified is_hex_oid gate in this PR without lowercasing (or case-insensitive lookup) before model_release_by_commit.

📜 Stated contract:

A hex rev is a commit pin (40 for sha1 repos, 64 for sha256).

twigpine-core::cid::is_hex_oid accepts uppercase hex (unit tests).

🏷️ Attribution: PR-introduced. Not pre-existing; not scope drift.

📌 In this PR:

  • release_for_rev hex branch
  • model_release_by_commit equality bind

🔒 Unchanged on main: No HF revision resolver at merge-base.

🔧 Required correction: Lowercase commit-shaped rev in release_for_rev before the DB lookup (one place). Add hf_api coverage: publish a release, call revision with uppercase hex of the same commit, expect success.

🛠️ Author fix: Normalize in release_for_rev + one regression test in hf_api.rs.

🚫 Out of scope: Changing storage format or non-HF commit APIs.


Needs maintainer decision

None.

The sibling publish branch reworded this prompt to say nothing is pinned or anchored, which is true there. Here the durability pipeline exists, so say it is permanent where IPFS and Irys are configured and node-only otherwise.

@jatmn jatmn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Follow-up on my earlier review: the CI surface fixture mismatch and the HF default-release split are still fixed on 9f2839ee. Your fix(cli): state the durability behavior in the publish confirm text commit lines up with docs/MODEL-HOSTING.md—thanks for that.

I ran another full pass on this head. You still have real value here: a coherent HF read surface, the durability pipeline, and off-node model fetch with strong tests (hf_api 32/32 locally, test-ci-surfaces.sh clean). I am not re-opening the earlier P1/P2 items, and I am not asking you to rework durability tiers, HF denial bodies, or unrelated core for this PR.

Two P3 polish items from the last round are still open on 9f2839ee. They are small fixes inside this diff only.

Merge readiness

  • Stack: This targets feat/model-hosting-publish (#622), not main. Plan merge order through the publish stack.
  • Target branch: When I fetched, origin/feat/model-hosting-publish matched the merge-base (590207909); I did not see extra target drift.
  • cargo audit is red on head (run 45087066640) — RUSTSEC-2026-0486 (rustix) plus yanked core2 / spin. Your Cargo.lock delta here is mostly hex, sha2, and the twigpine-cli dev-dependency. I am not treating that audit as something you must fix in this PR unless maintainers want every stacked branch green on audit anyway.
  • Deny harness: HF routes are still ExternalDependencyUnavailable in the harness; you already exercise the same denial legs in hf_api.rs (reasonable follow-up if you want harness parity later).
  • Checklist: cargo test --workspace is still unchecked in the PR body; the focused suites you list match what I ran successfully on this tree.

Required Rust checks on head (stable/beta tests, fmt+clippy, changed surfaces, build) are green. The two items below are P3; merge is fine if you accept the edge cases as documented.


🔵 P3 — Align hf_refs rustdoc with the implemented default-release rule

📍 Where: crates/twigpine-node/src/api/hf.rs (hf_refs doc comment vs the inline comment, release_for_rev, module header, docs/MODEL-HOSTING.md).

💥 What fails: Runtime behavior is already correct. The function doc on hf_refs (lines 334–335) still says main names the newest published commit regardless of the repo's git default branch. Your handler and release_for_rev use newest on main, then default_branch (e.g. master), and the inline comment at the call site (lines 347–349) says the same. This is maintainer/audit copy only—no client bug.

🔎 Root cause: That function-level rustdoc did not get updated when you aligned model info, the inline hf_refs comment, tests, and MODEL-HOSTING.md.

📜 Stated contract:

Model info, refs and revision/main all name the same default release: the newest on main, then on the git default branch.

🏷️ Attribution: Introduced in this PR (api/hf.rs is new on the merge-base).

📌 In this PR:

  • hf_refs function rustdoc (incorrect)
  • Module header, inline comment at hf_refs, MODEL-HOSTING.md, release_for_rev, hf_api two-branch / master tests (correct)

🔒 Unchanged on main: No HF surface at merge-base.

🔧 Required correction: Rewrite the hf_refs function doc comment to match the module header and release_for_rev (main, then git default branch). No code-path change.

🛠️ Author fix: One commit that updates that doc comment only—no other HF logic changes.

🚫 Out of scope: Changing release_for_rev behavior or other handlers.


🔵 P3 — Normalize uppercase hex commit pins on HF revision resolution

📍 Where: crates/twigpine-node/src/api/hf.rs (release_for_rev commit-shaped branch), crates/twigpine-node/src/db/model_queries.rs (model_release_by_commit).

💥 What fails: is_hex_oid accepts uppercase A-F, so /revision/{SHA} is treated as a commit pin, but commit_sha rows are lowercase from git and the SQL bind is case-sensitive. If someone spells the published commit in uppercase, they get RevisionNotFound even though the release exists. Most clients send lowercase; this is an edge case, not the usual HF path.

🔎 Root cause: The unified is_hex_oid gate in this PR does not lowercase (or case-insensitive lookup) before model_release_by_commit.

📜 Stated contract:

A hex rev is a commit pin (40 for sha1 repos, 64 for sha256).

twigpine-core::cid::is_hex_oid accepts uppercase hex in unit tests.

🏷️ Attribution: Introduced in this PR (resolver + is_hex_oid are new on the merge-base).

📌 In this PR:

  • release_for_rev hex branch
  • model_release_by_commit equality bind

🔒 Unchanged on main: No HF revision resolver at merge-base.

🔧 Required correction: Lowercase commit-shaped rev in release_for_rev before the DB lookup (one place). Add hf_api coverage: publish a release, call revision with uppercase hex of the same commit, expect success.

🛠️ Author fix: Normalize in release_for_rev and add one regression test in hf_api.rs in the same pass.

🚫 Out of scope: Changing storage format or non-HF commit APIs.


Needs maintainer decision

None from my side.

@beardthelion

Copy link
Copy Markdown
Collaborator Author

Both P3 items from the last review are fixed on 32bc4b8.

Rustdoc: the hf_refs doc now says main names the newest release on main, then on the repo's git default branch, matching release_for_rev. Comment only.

Uppercase pins: release_for_rev lowercases a hex commit pin before the model_release_by_commit lookup. New test revision_accepts_uppercase_commit_pin publishes a release and requests /revision/<UPPERCASE SHA>. With the lowercase call removed it gets 404 (want 200); with it, 1 passed. The fix commit touches only api/hf.rs and tests/hf_api.rs.

cargo audit is red on this head and not because of this diff: the failing advisory is url 2.5.8 (RUSTSEC-2026-0592), the same version main's lockfile carries, and cargo audit on main's lockfile reports it too. I'm leaving it for a separate change.

hf_api: 33 passed, 0 failed. fmt and clippy with -D warnings are clean on the package. No second-model pass: the round is a doc comment and one lowercase call after the read gate.

@jatmn jatmn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Follow-up on earlier reviews: the CI surface fixture mismatch, HF default-release split, hf_refs rustdoc, HF uppercase commit pins, and Arweave discovery read_json fix are all present on this head (32bc4b8323e1214ff2c4113e806e1c23414b33ce). This pass did not re-open those items.

The PR still delivers substantial value: a coherent HF read surface, the durability pipeline with a publicity fence, and off-node model fetch with strong verification tests.

Post–are these real, or drift? check (head 32bc4b8323e1214ff2c4113e806e1c23414b33ce): The sole finding below is PR-introduced, backed by the in-diff hex-rev contract and current code on head; the correction stays inside verify_candidate + one model_fetch test (same class as your HF lowercase pin, not a REST or durability rewrite). Blind-search themes withdrawn here as not findings: empty-Irys anchor done (documented no-tier behavior), synthetic CIDs without Kubo/Pinata (node-only tier), partial Arweave discovery (warn-and-continue, shared with clone.rs), policy-fence defer without attempt bump (fail-closed), REST release path case sensitivity (unchanged at merge-base), and cargo audit (target lockfile, merge readiness only).

Merge readiness

  • Stack: Targets feat/model-hosting-publish (#622), not main. Plan merge order through the publish stack.
  • cargo audit is red on head (job log). Author notes the failing url advisory matches the target branch lockfile; not treated as a PR-owned defect in this diff.
  • Deny harness: HF routes remain ExternalDependencyUnavailable; the same denial legs run in tests/hf_api.rs (reasonable follow-up for harness parity).
  • Checklist: PR body still has cargo test --workspace unchecked; required PR Checks jobs on head are green (stable/beta, fmt+clippy, changed surfaces, build, MSRV, Docker smoke).

🔵 P3 — Normalize uppercase hex on model fetch --revision

📍 Where: crates/twigpine-cli/src/model.rs — verify_candidate revision gate (anchor.release_commit != want).

💥 What fails: twigpine_core::cid::is_hex_oid accepts uppercase A–F. Anchors and git store release commits in lowercase hex. A caller passing twigpine model fetch … --revision <UPPERCASE_SHA> skips every matching anchor and fails with “no release anchor … verified”, while the same commit resolves on the HF API after this PR’s release_for_rev lowercasing.

🔎 Root cause: This PR unified hex commit recognition with is_hex_oid on the HF resolver but left the off-node fetch revision filter case-sensitive.

📜 Stated contract:

A hex rev is a commit pin (40 for sha1 repos, 64 for sha256).

is_hex_oid unit coverage accepts uppercase hex (crates/twigpine-core/src/cid.rs).

🏷️ Attribution: PR-introduced (verify_candidate / fetch_model are absent at merge-base 590207909; not pre-existing main debt). HF lowercase fix on this head does not cover the CLI --revision filter. Not scope drift: does not require editing claim storage or REST releases/{commit} lookup.

📌 In this PR:

  • verify_candidate revision compare
  • HF release_for_rev commit branch (already lowercases — sibling reference only)

🔒 Unchanged on main: REST GET …/models/releases/{commit} case sensitivity predates this PR; do not broaden this fix into unchanged API handlers.

🔧 Required correction: Lowercase commit-shaped want in verify_candidate before comparing to anchor.release_commit (one place). Add model_fetch.rs coverage: anchor with lowercase commit, fetch with uppercase --revision, expect success.

🛠️ Author fix: One pass: normalize in verify_candidate + regression test. No HF or durability logic changes.

🚫 Out of scope: Changing stored commit_sha normalization on claim, or REST release lookup semantics on the publish stack.


Needs maintainer decision

None.

This branch has not been deployed

No deployments
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.

2 participants