Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

address review (codex): take only the first URL segment as the HF revision

[._.]/ Adam Eivy507d47b5ec7e
diff --git a/server/lib/huggingfaceLora.js b/server/lib/huggingfaceLora.js
index 35de1b93f4..0e45347078 100644
--- a/server/lib/huggingfaceLora.js
+++ b/server/lib/huggingfaceLora.js
@@ -66,19 +66,17 @@ export const parseHuggingfaceLoraRef = (raw) => {
);
}
const repo = `${segments[0]}/${segments[1]}`;
- // Recover a revision from `/tree/<rev>` or `/blob/<rev>` URLs. A revision can
- // itself contain slashes (a branch like `feature/foo` or a ref like
- // `refs/pr/123`), so join ALL segments after the marker — and, for /blob/
- // URLs, drop the trailing filepath component so `…/blob/main/lora.safetensors`
- // yields revision `main`, not `main/lora.safetensors`. (/tree/ URLs have no
- // trailing file, so nothing is dropped there.)
+ // Recover a revision from `/tree/<rev>/…` or `/blob/<rev>/…` URLs. The URL
+ // shape is `…/<tree|blob>/<rev>/<optional subpath>`, and the subpath itself
+ // can contain slashes (`/blob/main/weights/lora.safetensors`), so only the
+ // FIRST segment after the marker is the revision — joining the rest would
+ // mis-read a subdirectory as part of the ref and 404 the metadata fetch. This
+ // means a slash-containing branch/ref pasted as a /tree/ URL isn't recovered
+ // (genuinely ambiguous from the URL alone) — use the `org/name@refs/pr/123`
+ // form for those (the bare-ref parser above keeps the full ref).
let revision = null;
const treeIdx = segments.findIndex((s) => s === 'tree' || s === 'blob');
- if (treeIdx >= 0 && segments[treeIdx + 1]) {
- const rest = segments.slice(treeIdx + 1);
- if (segments[treeIdx] === 'blob' && rest.length > 1) rest.pop(); // drop the file path
- revision = rest.join('/') || null;
- }
+ if (treeIdx >= 0 && segments[treeIdx + 1]) revision = segments[treeIdx + 1];
return { repo, revision };
};
diff --git a/server/lib/huggingfaceLora.test.js b/server/lib/huggingfaceLora.test.js
index cbf22ff601..d19bd7e369 100644
--- a/server/lib/huggingfaceLora.test.js
+++ b/server/lib/huggingfaceLora.test.js
@@ -21,15 +21,20 @@ describe('parseHuggingfaceLoraRef', () => {
expect(parseHuggingfaceLoraRef('https://huggingface.co/fal/x/blob/main/lora.safetensors'))
.toEqual({ repo: 'fal/x', revision: 'main' });
});
- it('preserves slash-containing revisions and drops the trailing file on /blob/', () => {
- expect(parseHuggingfaceLoraRef('https://huggingface.co/fal/x/tree/feature/foo'))
- .toEqual({ repo: 'fal/x', revision: 'feature/foo' });
- expect(parseHuggingfaceLoraRef('https://huggingface.co/fal/x/tree/refs/pr/123'))
- .toEqual({ repo: 'fal/x', revision: 'refs/pr/123' });
- expect(parseHuggingfaceLoraRef('https://huggingface.co/fal/x/blob/feature/foo/lora.safetensors'))
- .toEqual({ repo: 'fal/x', revision: 'feature/foo' });
+
+ it('takes only the first segment after tree/blob as the revision (subpaths are not part of the ref)', () => {
+ // The common copy-paste case: a single-segment revision followed by a
+ // (possibly nested) subpath. Only `main` is the ref; the rest is the path.
+ expect(parseHuggingfaceLoraRef('https://huggingface.co/fal/x/blob/main/weights/lora.safetensors'))
+ .toEqual({ repo: 'fal/x', revision: 'main' });
+ expect(parseHuggingfaceLoraRef('https://huggingface.co/fal/x/tree/main/subdir'))
+ .toEqual({ repo: 'fal/x', revision: 'main' });
});
+ it('recovers a slash-containing ref from the org/name@rev form (URL form is ambiguous)', () => {
+ expect(parseHuggingfaceLoraRef('fal/x@refs/pr/123'))
+ .toEqual({ repo: 'fal/x', revision: 'refs/pr/123' });
+ });
it('parses a bare org/name id (optionally @rev or :rev)', () => {
expect(parseHuggingfaceLoraRef('fal/ltx-lora')).toEqual({ repo: 'fal/ltx-lora', revision: null });
expect(parseHuggingfaceLoraRef('fal/ltx-lora@v2')).toEqual({ repo: 'fal/ltx-lora', revision: 'v2' });