Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Fix the dev-server white screen from a two-barrel import cycle (#9852)

Daniel Hand617be27049c
diff --git a/studio/frontend/src/hooks/use-model-memory.ts b/studio/frontend/src/hooks/use-model-memory.ts
index fcd768cca5c..d780194b26e 100644
--- a/studio/frontend/src/hooks/use-model-memory.ts
+++ b/studio/frontend/src/hooks/use-model-memory.ts
@@ -10,24 +10,30 @@
* one. Ten rows of the same model cost one read.
*/
+// Deep paths, not the `@/features/chat` barrel, and that is load-bearing. The barrel
+// reaches this file back: chat -> apply-inference-status-to-store -> model-picker ->
+// model-selector -> pickers -> here. Importing the barrel closed that ring, and under
+// dev's unbundled ESM the app died on a blank page with "Cannot access
+// 'CHAT_GPU_MEMORY_MODE_KEY' before initialization". Production builds hid it, because
+// the bundler hoists the declarations into one module and the ordering stops mattering.
+import { estimateKvCache } from "@/features/chat/api/chat-api";
import {
CHAT_GPU_MEMORY_MODE_KEY,
CHAT_SPECULATIVE_TYPE_KEY,
- estimateKvCache,
readPersistedGpuMemoryMode,
readPersistedSpeculativeType,
useChatRuntimeStore,
-} from "@/features/chat";
+} from "@/features/chat/stores/chat-runtime-store";
import {
normalizeGgufVariantIdentity,
normalizeModelIdentity,
-} from "@/features/hub";
+} from "@/features/hub/lib/model-identity";
import {
PER_MODEL_CONFIG_STORAGE_KEY,
PER_MODEL_CONFIG_UPDATED_EVENT,
type PerModelConfig,
listPerModelConfigs,
-} from "@/features/model-picker";
+} from "@/features/model-picker/model-config/per-model-config";
import {
loadVramBudgetSettings,
subscribeVramBudgetSettings,
diff --git a/studio/frontend/tests/module-scope-cycle-safety.test.ts b/studio/frontend/tests/module-scope-cycle-safety.test.ts
index 4cf58a40088..6e3efc26624 100644
--- a/studio/frontend/tests/module-scope-cycle-safety.test.ts
+++ b/studio/frontend/tests/module-scope-cycle-safety.test.ts
@@ -116,3 +116,38 @@ test("the key is still read at module scope, so the guard above is load-bearing"
"general-tab no longer reads the key at module scope; drop this file's guards",
);
});
+
+/**
+ * The same white screen, reached a second way.
+ *
+ * `use-model-memory.ts` imported `CHAT_GPU_MEMORY_MODE_KEY` and friends from the
+ * `@/features/chat` barrel, and the barrel reaches this file back:
+ *
+ * chat -> apply-inference-status-to-store -> model-picker -> model-selector
+ * -> pickers -> use-model-memory -> chat
+ *
+ * Under dev's unbundled ESM that ring evaluated `use-model-memory` before the chat
+ * barrel had finished, and the module-scope const read threw "Cannot access
+ * 'CHAT_GPU_MEMORY_MODE_KEY' before initialization". Measured on main: the page threw,
+ * `#root` had 0 children and the body was empty. With the deep imports below there is
+ * no page error and the app renders.
+ *
+ * Production builds never showed it. The bundler hoists these declarations into one
+ * module, so the ordering the dev server exposes stops existing, which is exactly the
+ * kind of defect that survives review and CI and only ever bites whoever runs the dev
+ * server next.
+ */
+const MODEL_MEMORY = path.join(SRC, "hooks/use-model-memory.ts");
+
+test("the model memory hook imports no feature barrel", async () => {
+ const text = await readFile(MODEL_MEMORY, "utf8");
+ const barrels = staticSpecifiers(MODEL_MEMORY, text).filter((specifier) =>
+ /^@\/features\/[^/]+$/.test(specifier),
+ );
+
+ assert.deepEqual(
+ barrels,
+ [],
+ "a bare @/features/<name> import here closes the cycle and the dev server white screens again",
+ );
+});