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): refuse pinned revisions, stamp per-runner render metadata

[._.]/ Adam Eivy05c7b9d0340a
diff --git a/server/lib/huggingfaceModel.js b/server/lib/huggingfaceModel.js
index bda3dfee69..fbcf5d220b 100644
--- a/server/lib/huggingfaceModel.js
+++ b/server/lib/huggingfaceModel.js
@@ -112,6 +112,26 @@ const IMAGE_DEFAULTS = {
[RUNNER_FAMILIES.QWEN]: { steps: 30, guidance: 4.0 },
};
+// Static per-runner registry metadata the render path needs beyond `repo` —
+// FIXED per family (identical across the shipped built-ins), so a self-service
+// add can stamp them and the entry renders without hand-editing:
+// - flux2: quantization:'none' → runner loads `repo` directly (no tokenizerRepo)
+// - ernie: ErnieImagePipeline isn't in diffusers' auto-registry; usePromptEnhancer on
+// - hidream: HiDreamImagePipeline + the (gated) Llama-3.1 text encoder + its class names
+// - qwen: QwenImagePipeline pinned so a registry edit can't fight auto-resolution
+// z-image needs nothing beyond `repo` (autodetected). Mirrors DEFAULT_REGISTRY.
+const RUNNER_METADATA = {
+ [RUNNER_FAMILIES.FLUX2]: { quantization: 'none' },
+ [RUNNER_FAMILIES.ERNIE]: { pipelineClass: 'ErnieImagePipeline', usePromptEnhancer: true },
+ [RUNNER_FAMILIES.HIDREAM]: {
+ pipelineClass: 'HiDreamImagePipeline',
+ textEncoderRepo: 'meta-llama/Meta-Llama-3.1-8B-Instruct',
+ textEncoderClass: 'LlamaForCausalLM',
+ tokenizerClass: 'PreTrainedTokenizerFast',
+ },
+ [RUNNER_FAMILIES.QWEN]: { pipelineClass: 'QwenImagePipeline' },
+};
+
// Inspect the repo's file list. `.gguf` present (llama.cpp/ggml) is the format
// we can never load in the image/video pipeline; `.safetensors` is required.
// Reuses the shared sibling lister from huggingfaceLora.js.
@@ -311,14 +331,15 @@ export const buildCustomModelEntry = ({ repo, model, classification, name, steps
entry.runtime = classification.runtime;
} else {
entry.runner = classification.runner;
- // flux2 defaults missing `quantization` to 'sdnq', which then REQUIRES a
- // `tokenizerRepo` (the gated base repo) — a self-service add has neither, so
- // without this the entry registers but every render 400s with
- // IMAGE_GEN_FLUX2_MISCONFIGURED. A plain HF repo added here is treated as an
- // unquantized base (`none`): the runner loads `repo` directly, no tokenizer
- // sidecar needed. A user who added a quantized community repo can edit the
- // JSON to set sdnq/int8 + the required sibling repo.
- if (classification.runner === RUNNER_FAMILIES.FLUX2) entry.quantization = 'none';
+ // Stamp the static per-runner metadata the render path requires beyond
+ // `repo` (flux2 quantization:'none', ernie/hidream/qwen pipelineClass +
+ // hidream's gated text encoder). Without these the entry would register but
+ // 400 at render (IMAGE_GEN_*_MISCONFIGURED) — the strict-refusal guarantee
+ // is "renders what it classified, or is refused," so we must supply them.
+ // For HiDream the text encoder is a GATED Llama repo: the add succeeds but
+ // the first render will prompt the user to accept that license + set an HF
+ // token, same as the shipped built-in.
+ Object.assign(entry, RUNNER_METADATA[classification.runner] || {});
}
return entry;
};
diff --git a/server/lib/huggingfaceModel.test.js b/server/lib/huggingfaceModel.test.js
index dae80f8f15..2beaadcadd 100644
--- a/server/lib/huggingfaceModel.test.js
+++ b/server/lib/huggingfaceModel.test.js
@@ -204,6 +204,38 @@ describe('buildCustomModelEntry', () => {
});
expect(entry).toMatchObject({ runner: 'flux2', quantization: 'none', source: 'user' });
});
+
+ it('stamps ERNIE pipeline metadata the runner requires', () => {
+ const entry = buildCustomModelEntry({
+ repo: 'baidu/ERNIE-Image',
+ model: hf({}),
+ classification: { kind: 'image', runner: 'ernie', format: 'safetensors' },
+ });
+ expect(entry).toMatchObject({ runner: 'ernie', pipelineClass: 'ErnieImagePipeline', usePromptEnhancer: true });
+ });
+
+ it('stamps HiDream pipeline + gated text-encoder metadata', () => {
+ const entry = buildCustomModelEntry({
+ repo: 'HiDream-ai/HiDream-I1-Full',
+ model: hf({}),
+ classification: { kind: 'image', runner: 'hidream', format: 'safetensors' },
+ });
+ expect(entry).toMatchObject({
+ runner: 'hidream',
+ pipelineClass: 'HiDreamImagePipeline',
+ textEncoderRepo: 'meta-llama/Meta-Llama-3.1-8B-Instruct',
+ textEncoderClass: 'LlamaForCausalLM',
+ });
+ });
+
+ it('stamps the Qwen pipeline class', () => {
+ const entry = buildCustomModelEntry({
+ repo: 'Qwen/Qwen-Image',
+ model: hf({}),
+ classification: { kind: 'image', runner: 'qwen', format: 'safetensors' },
+ });
+ expect(entry).toMatchObject({ runner: 'qwen', pipelineClass: 'QwenImagePipeline' });
+ });
});
describe('searchHuggingfaceModels', () => {
diff --git a/server/services/mediaModelInstall.js b/server/services/mediaModelInstall.js
index b66e2226fc..99ec838517 100644
--- a/server/services/mediaModelInstall.js
+++ b/server/services/mediaModelInstall.js
@@ -24,6 +24,7 @@ import {
} from '../lib/huggingfaceModel.js';
import { addUserModelEntry } from '../lib/mediaModels.js';
import { getHfToken } from '../lib/hfToken.js';
+import { ServerError } from '../lib/errorHandler.js';
// Add a media model from a HuggingFace repo. `input.url` is any HF ref shape
// (URL or org/name@rev). Optional `kind` ('image'|'video'), `runtime` (video),
@@ -31,6 +32,19 @@ import { getHfToken } from '../lib/hfToken.js';
// `guidance` override the derived defaults. Returns the new registry entry.
export const addModelFromHuggingface = async (input, { fetchImpl = fetch } = {}) => {
const { repo, revision } = parseHuggingfaceLoraRef(input?.url);
+ // Refuse a pinned revision (`org/name@rev`, `/tree/<rev>`). The registry
+ // entry stores only `repo`, and the download + render paths pull the default
+ // branch — so classifying against a pinned revision but generating against
+ // `main` would silently render different weights. Rather than persist a
+ // revision the render path ignores, reject it up front (the strict-refusal
+ // guarantee: an add either renders what it classified, or is refused). A user
+ // who needs a specific revision can pin it by hand-editing media-models.json.
+ if (revision) {
+ throw new ServerError(
+ `HuggingFace repo "${repo}" was given a pinned revision ("${revision}"), which the model download/render paths don't honor — they always use the default branch. Add the repo without a revision (the default branch), or pin the revision by editing data/media-models.json directly.`,
+ { status: 422, code: 'HF_REVISION_UNSUPPORTED' },
+ );
+ }
// Stored/env/CLI token — needed only for gated repos, harmless on public ones.
const token = (typeof input?.token === 'string' && input.token.trim()) || (await getHfToken()) || '';
const model = await fetchHuggingfaceModel(repo, { token, revision, fetchImpl });
diff --git a/server/services/mediaModelInstall.test.js b/server/services/mediaModelInstall.test.js
index 255875e236..918875000a 100644
--- a/server/services/mediaModelInstall.test.js
+++ b/server/services/mediaModelInstall.test.js
@@ -49,6 +49,14 @@ describe('addModelFromHuggingface', () => {
expect(addUserModelEntry).not.toHaveBeenCalled();
});
+ it('refuses a pinned revision (render path only pulls the default branch)', async () => {
+ const fetchImpl = mockFetch({ id: 'org/x', siblings: [{ rfilename: 'model.safetensors' }], tags: ['ltx'] });
+ await expect(
+ addModelFromHuggingface({ url: 'org/[email protected]' }, { fetchImpl }),
+ ).rejects.toThrow(/pinned revision/);
+ expect(addUserModelEntry).not.toHaveBeenCalled();
+ });
+
it('honors explicit kind + runner overrides', async () => {
const fetchImpl = mockFetch({
id: 'someone/custom',