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): canonicalize loopback hosts + real persisted signal

[._.]/ Adam Eivyd73fdfc5919d
diff --git a/server/services/localModelHealing.js b/server/services/localModelHealing.js
index 43fb187b30..0043fdf57c 100644
--- a/server/services/localModelHealing.js
+++ b/server/services/localModelHealing.js
@@ -99,9 +99,19 @@ function managerOrigin(backend) {
return normalizeOrigin(base);
}
+// Loopback hosts that all name the same local instance — canonicalized to one
+// token so a provider at `127.0.0.1:11434` matches a manager at `localhost:11434`.
+const LOOPBACK_HOSTS = new Set(['localhost', '127.0.0.1', '[::1]', '::1']);
+
function normalizeOrigin(url) {
const cleaned = String(url || '').replace(/\/v1\/?$/, '').replace(/\/+$/, '');
- try { const u = new URL(cleaned); return `${u.protocol}//${u.host}`; } catch { return ''; }
+ try {
+ const u = new URL(cleaned);
+ const hostname = u.hostname.toLowerCase();
+ const host = LOOPBACK_HOSTS.has(hostname) ? 'localhost' : hostname;
+ const port = u.port || (u.protocol === 'https:' ? '443' : '80');
+ return `${u.protocol}//${host}:${port}`;
+ } catch { return ''; }
}
/**
@@ -166,8 +176,10 @@ export async function healMissingLocalModel({ provider, requestedModel }) {
const patch = computeProviderPatch(provider, installedIds, fallback, requestedModel);
let persisted = false;
if (provider?.id && Object.keys(patch).length) {
+ // updateProvider resolves to the updated provider object, or null when the
+ // id no longer exists — Boolean(updated) is the real persisted signal.
persisted = await updateProvider(provider.id, patch)
- .then(() => true)
+ .then((updated) => Boolean(updated))
.catch((err) => {
console.error(`⚠️ Failed to repoint ${provider.id} to ${fallback}: ${err.message}`);
return false;
diff --git a/server/services/localModelHealing.test.js b/server/services/localModelHealing.test.js
index 47db43667f..f3cf317c41 100644
--- a/server/services/localModelHealing.test.js
+++ b/server/services/localModelHealing.test.js
@@ -169,6 +169,25 @@ describe('healMissingLocalModel', () => {
expect(mocks.updateProvider).not.toHaveBeenCalled();
});
+ it('treats loopback host spellings as the same instance (127.0.0.1 == localhost)', async () => {
+ // Manager lists from localhost:11434; a provider on 127.0.0.1:11434 is the
+ // SAME instance and must not be refused over a loopback spelling difference.
+ mocks.ollamaInstalled.mockResolvedValue([{ id: 'llama3.1:8b' }]);
+ const provider = { id: 'ollama', endpoint: 'http://127.0.0.1:11434/v1', defaultModel: 'gone', models: [] };
+ const result = await healMissingLocalModel({ provider, requestedModel: 'gone' });
+ expect(result).toMatchObject({ healed: true, model: 'llama3.1:8b' });
+ });
+
+ it('reports persisted:false when updateProvider returns null (provider id gone)', async () => {
+ mocks.ollamaInstalled.mockResolvedValue([{ id: 'llama3.1:8b' }]);
+ mocks.updateProvider.mockResolvedValue(null); // toolkit returns null for an unknown id
+ const provider = { id: 'stale-ollama', name: 'Ollama', defaultModel: 'gone', models: [] };
+ const result = await healMissingLocalModel({ provider, requestedModel: 'gone' });
+ expect(result).toMatchObject({ healed: true, model: 'llama3.1:8b', persisted: false });
+ const [, message] = mocks.emitLog.mock.calls[0];
+ expect(message).toContain('for this run');
+ });
+
it('excludes LM Studio embedding models from the fallback pick', async () => {
mocks.lmStudioAvailable.mockResolvedValue([
{ id: 'nomic-embed', type: 'embeddings' },