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 (self): LM Studio loaded-models null sentinel + encode HF repo URL path

Adam Eivy1377d2c863ff
diff --git a/server/services/huggingFaceCatalog.js b/server/services/huggingFaceCatalog.js
index 4a5ddcb1fd..e48b56bb3e 100644
--- a/server/services/huggingFaceCatalog.js
+++ b/server/services/huggingFaceCatalog.js
@@ -258,7 +258,10 @@ const repoSizeCache = new Map()
async function fetchRepoSizeBytes(repoId) {
if (repoSizeCache.has(repoId)) return repoSizeCache.get(repoId)
- const model = await fetchWithTimeout(`${HF_API_BASE}/${repoId}?blobs=true`, { headers: hfHeaders() }, HF_TIMEOUT_MS)
+ // repoId comes from the HF search response (untrusted upstream) — encode each
+ // path segment so a `?`/`#`/`..` in the id can't reshape the request path/query.
+ const safeRepoPath = String(repoId).split('/').map(encodeURIComponent).join('/')
+ const model = await fetchWithTimeout(`${HF_API_BASE}/${safeRepoPath}?blobs=true`, { headers: hfHeaders() }, HF_TIMEOUT_MS)
.then((res) => (res.ok ? res.json() : null))
.catch(() => null)
// Re-run the same quant picker against the now-sized siblings.
diff --git a/server/services/lmStudioManager.js b/server/services/lmStudioManager.js
index c013e5bc3e..bd835808ab 100644
--- a/server/services/lmStudioManager.js
+++ b/server/services/lmStudioManager.js
@@ -31,7 +31,10 @@ const DEFAULT_CONFIG = {
// Cached state
let config = { ...DEFAULT_CONFIG }
let isAvailable = null
-let loadedModels = []
+// null = not yet fetched; any array (even empty) = a cached result — mirrors
+// availableModels below so an idle LM Studio (server up, 0 models loaded)
+// doesn't re-hit /api/v0/models on every status poll.
+let loadedModels = null
// null = not yet fetched; any array (even empty) = a cached result. Lets the
// catalog-overlay path (queried per keystroke) reuse the list instead of
// re-hitting /api/v0/models each time. Busted to null by resetCache().
@@ -109,12 +112,13 @@ async function checkLMStudioAvailable() {
* @returns {Promise<Array>} - Loaded models
*/
async function getLoadedModels(forceRefresh = false) {
- if (!forceRefresh && loadedModels.length > 0) {
+ if (!forceRefresh && loadedModels !== null) {
return loadedModels
}
const available = await checkLMStudioAvailable()
if (!available) {
+ // Don't cache — unavailable is transient, so the next call re-probes.
return []
}
@@ -145,8 +149,12 @@ async function getLoadedModels(forceRefresh = false) {
created: model.created,
ownedBy: model.owned_by
}))
+ return loadedModels
}
- return loadedModels
+
+ // Both list endpoints failed — return empty WITHOUT caching (loadedModels
+ // stays null) so the next call retries instead of pinning a bogus empty.
+ return []
}
/**
@@ -458,7 +466,7 @@ function updateConfig(newConfig) {
*/
function resetCache() {
isAvailable = null
- loadedModels = []
+ loadedModels = null
availableModels = null
lastListError = null
lastCheckAt = null