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 local review: keep the configured-default sentinel across a model refresh

[._.]/ Adam Eivybc4c9e279ff6
diff --git a/client/src/components/models/HarnessesTab.jsx b/client/src/components/models/HarnessesTab.jsx
index a38b157d1c..3d3ce567f6 100644
--- a/client/src/components/models/HarnessesTab.jsx
+++ b/client/src/components/models/HarnessesTab.jsx
@@ -200,7 +200,9 @@ export default function HarnessesTab() {
const [error, setError] = useState(null);
// `{ harness, action }` while the SSE modal is open; null = closed.
const [pendingAction, setPendingAction] = useState(null);
- const [refreshingId, setRefreshingId] = useState(null);
+ // A SET, not one slot: two rows can refresh at once, and a single slot lets
+ // the first completion re-enable the second row's button mid-flight.
+ const [refreshingIds, setRefreshingIds] = useState(() => new Set());
// Keyed by harness id so one row's outcome cannot overwrite another's.
const [refreshResults, setRefreshResults] = useState({});
@@ -219,7 +221,13 @@ export default function HarnessesTab() {
useEffect(() => { load(); }, [load]);
const handleRefreshModels = async (harness) => {
- setRefreshingId(harness.id);
+ setRefreshingIds((prev) => new Set(prev).add(harness.id));
+ // Drop any banner from this row's previous refresh, so a stale outcome
+ // cannot sit under the row while a new probe is running.
+ setRefreshResults((prev) => {
+ const { [harness.id]: _dropped, ...rest } = prev;
+ return rest;
+ });
const result = await refreshHarnessModels(harness.id, { silent: true })
.then((data) => ({
ok: true,
@@ -227,7 +235,11 @@ export default function HarnessesTab() {
}))
.catch((err) => ({ ok: false, message: err?.message || 'Could not read the model list.' }));
setRefreshResults((prev) => ({ ...prev, [harness.id]: result }));
- setRefreshingId(null);
+ setRefreshingIds((prev) => {
+ const next = new Set(prev);
+ next.delete(harness.id);
+ return next;
+ });
// Deliberately no reload: the refresh writes `models` and `defaultModel`,
// and this page shows neither — the banner above already reports what
// changed. Re-reading would cost a probe sweep to render the same rows.
@@ -279,7 +291,7 @@ export default function HarnessesTab() {
harness={harness}
onAction={(target, action) => setPendingAction({ harness: target, action })}
onRefreshModels={handleRefreshModels}
- refreshing={refreshingId === harness.id}
+ refreshing={refreshingIds.has(harness.id)}
refreshResult={refreshResults[harness.id]}
/>
))}
@@ -298,12 +310,18 @@ export default function HarnessesTab() {
params={pendingAction ? { action: pendingAction.action } : undefined}
streamMethod="POST"
onClose={() => setPendingAction(null)}
+ // Re-read the list, but LEAVE THE MODAL OPEN — its terminal frame is the
+ // result ("…is up to date (1.19.0)", "…has been removed"), and clearing
+ // `pendingAction` here unmounts it the instant that frame arrives, so a
+ // removal and a no-op update look identical: a modal that blinks shut.
+ // The user closes it, matching every other caller of this modal.
+ //
// `load()`, not `load({ fresh: true })`: the stream already re-probed the
// acted-on harness with `fresh` on the server and wrote that into the
// status cache, and clicking Install cannot have changed what npm has
// published — a fresh read here would spend five registry round trips to
// render identical numbers.
- onComplete={() => { setPendingAction(null); load(); }}
+ onComplete={() => load()}
/>
</div>
);
diff --git a/client/src/components/models/HarnessesTab.test.jsx b/client/src/components/models/HarnessesTab.test.jsx
index 0f8fb87aae..5e0227816d 100644
--- a/client/src/components/models/HarnessesTab.test.jsx
+++ b/client/src/components/models/HarnessesTab.test.jsx
@@ -128,6 +128,10 @@ describe('HarnessesTab', () => {
// have changed what npm has published.
await waitFor(() => expect(getHarnesses).toHaveBeenCalledTimes(2));
expect(getHarnesses).toHaveBeenLastCalledWith(expect.objectContaining({ fresh: false }));
+ // The modal's terminal frame IS the result ("…is up to date (1.19.0)").
+ // Unmounting it on completion makes a removal and a no-op update look
+ // identical — a modal that blinks shut with nothing said.
+ expect(screen.getByTestId('install-modal')).toBeInTheDocument();
});
it('renders a refusal reason verbatim instead of a generic failure', async () => {
diff --git a/server/services/harnessActionStream.js b/server/services/harnessActionStream.js
index 52d9001675..471f0630a5 100644
--- a/server/services/harnessActionStream.js
+++ b/server/services/harnessActionStream.js
@@ -213,7 +213,7 @@ export async function streamHarnessAction(req, res, { runtime: runtimeId, action
// availability seconds ago, and re-reading it would report the state the
// action just changed.
const after = await getProviderRuntimeStatus(row.id, { fresh: true });
- emit(terminalFrame({ action, code, status: after, copy, command: row.command }));
+ emit(terminalFrame({ action, code, status: after, copy, command: row.command, before: status.version }));
safeEnd();
} catch (err) {
// Child-process completion runs outside Express's request lifecycle.
@@ -228,7 +228,7 @@ export async function streamHarnessAction(req, res, { runtime: runtimeId, action
* The one terminal SSE frame an action ends on, decided from the exit code AND
* the re-probed availability.
*/
-function terminalFrame({ action, code, status, copy, command }) {
+function terminalFrame({ action, code, status, copy, command, before }) {
if (code !== 0) {
return { type: 'error', message: `${status.label} ${copy.noun} exited with code ${code}.` };
}
@@ -241,7 +241,18 @@ function terminalFrame({ action, code, status, copy, command }) {
return { type: 'error', message: `The ${copy.noun} finished, but PortOS still cannot run \`${command}\`. npm wrote it to a bin directory that is not on this machine's PATH — run \`npm prefix -g\` in a terminal, add that directory (plus \`/bin\` off Windows) to your PATH, then restart PortOS.` };
}
const version = status.version ? ` (${status.version})` : '';
- return action === 'update'
- ? { type: 'complete', message: `${status.label} is up to date${version}.` }
- : { type: 'complete', message: `${status.label} is installed and available to PortOS${version}.` };
+ if (action !== 'update') {
+ return { type: 'complete', message: `${status.label} is installed and available to PortOS${version}.` };
+ }
+ // Report what the version actually DID, never "up to date" from an exit code
+ // alone. A vendor updater that exits 0 without touching the copy on PATH would
+ // otherwise claim currency in the modal while the row behind it still shows
+ // the Update-available badge against the published version — two contradictory
+ // claims on one screen. A version we could not read on either side says so.
+ if (!status.version || !before) {
+ return { type: 'complete', message: `${status.label} updater finished. PortOS could not read a version to compare.` };
+ }
+ return status.version === before
+ ? { type: 'complete', message: `${status.label} updater finished and left it on ${before} — that is the newest ${command} can reach itself. If a newer release exists, install it the way this copy was installed.` }
+ : { type: 'complete', message: `${status.label} updated: ${before} → ${status.version}.` };
}
diff --git a/server/services/harnessActionStream.test.js b/server/services/harnessActionStream.test.js
index dcc4b00d48..07414eb991 100644
--- a/server/services/harnessActionStream.test.js
+++ b/server/services/harnessActionStream.test.js
@@ -73,7 +73,7 @@ beforeEach(() => {
});
describe('streamHarnessAction — update', () => {
- it('runs the vendor updater and reports the version it landed on', async () => {
+ it('reports the version transition the update actually produced', async () => {
installer.getProviderRuntimeStatus
.mockResolvedValueOnce(statusOf('opencode'))
.mockResolvedValueOnce(statusOf('opencode', { version: '1.19.0' }));
@@ -81,10 +81,30 @@ describe('streamHarnessAction — update', () => {
const response = await runAction('runtime=opencode&action=update', { stdout: 'upgraded\n' });
expect(installer.spawnRuntimeInstaller).toHaveBeenCalledWith('opencode', { action: 'update' });
- expect(response.text).toContain('OpenCode CLI is up to date (1.19.0).');
+ expect(response.text).toContain('OpenCode CLI updated: 1.18.27 → 1.19.0.');
expect(response.text).toContain('upgraded');
});
+ // "Up to date" asserted from an exit code alone contradicts the row behind the
+ // modal, which still shows Update-available against the published version. Say
+ // what the version did instead.
+ it('does not claim currency when the version did not move', async () => {
+ installer.getProviderRuntimeStatus.mockResolvedValue(statusOf('opencode'));
+
+ const response = await runAction('runtime=opencode&action=update');
+
+ expect(response.text).toContain('left it on 1.18.27');
+ expect(response.text).not.toContain('up to date');
+ });
+
+ it('says so when it could not read a version to compare', async () => {
+ installer.getProviderRuntimeStatus.mockResolvedValue(statusOf('opencode', { version: null }));
+
+ const response = await runAction('runtime=opencode&action=update');
+
+ expect(response.text).toContain('could not read a version to compare');
+ });
+
// An install short-circuits on "already there"; an update must NOT — that is
// the whole point of the button, and "you are on the latest" is the vendor
// updater's answer to give, not ours to guess from a cached registry read.
diff --git a/server/services/harnesses.js b/server/services/harnesses.js
index 6af36c3eda..eb32f84608 100644
--- a/server/services/harnesses.js
+++ b/server/services/harnesses.js
@@ -33,7 +33,7 @@ import { prepareCliSpawn } from '../lib/bufferedSpawn.js';
import { commandOutput } from '../lib/commandExists.js';
import { compareHarnessVersions, parseHarnessModels, parseNpmLatestVersion } from '../lib/harnessOutput.js';
import { findCommandOnPath } from '../lib/processEnv.js';
-import { getOpencodeLocalProviderNamespace } from '../lib/providerModels.js';
+import { getOpencodeLocalProviderNamespace, isConfiguredDefaultModel } from '../lib/providerModels.js';
import { providerRuntimeKey } from '../lib/providerPrerequisites.js';
import { createStaleWhileRevalidate } from '../lib/staleWhileRevalidate.js';
import * as providerService from './providers.js';
@@ -117,7 +117,33 @@ export function __resetLatestVersionCache() {
* is silent in the worst direction: a refresh replacing a working `models` list
* with ids that record's own backend cannot resolve.
*/
-export const usesHarnessCatalog = (provider) => !getOpencodeLocalProviderNamespace(provider);
+export const usesHarnessCatalog = (provider) =>
+ !getOpencodeLocalProviderNamespace(provider) && !declaresOwnOpencodeProvider(provider);
+
+/**
+ * Does this record hand-declare its own OpenCode provider entries?
+ *
+ * The `*Backed` / `gatewayBacked` markers above are only ever written by
+ * PortOS's own editor, so a user who hand-wrote an `OPENCODE_CONFIG_CONTENT`
+ * with `provider: { myco: … }` and a model list scoped to it is invisible to
+ * them — and one Refresh click would replace that curated list with the
+ * harness's own catalog, which their config cannot resolve. A declared provider
+ * entry IS the backend marker for those records.
+ *
+ * The seeded Zen wrappers ship `{"permission":"allow"}` with no `provider` key,
+ * so they stay in the class. An unparseable config declares nothing.
+ */
+function declaresOwnOpencodeProvider(provider) {
+ const stored = provider?.envVars?.OPENCODE_CONFIG_CONTENT;
+ if (typeof stored !== 'string' || stored === '') return false;
+ let parsed = null;
+ try {
+ parsed = JSON.parse(stored);
+ } catch {
+ return false; // unparseable — it declares nothing OpenCode can read either
+ }
+ return Object.keys(parsed?.provider || {}).length > 0;
+}
/**
* Every provider record this harness's runtime row actually answers for.
@@ -143,11 +169,13 @@ const providersForHarness = (providers, runtime) => {
* account name.
*/
export async function listHarnesses({ fresh = false, run = commandOutput, ...probeDeps } = {}) {
- const [statuses, data] = await Promise.all([
+ const [statuses, providers] = await Promise.all([
getProviderRuntimeStatuses({ ...probeDeps, fresh }),
- providerService.getAllProviders(),
+ // `listProviders()`, not `getAllProviders()`: that one resolves an ENVELOPE
+ // (`{ activeProvider, providers: [...] }`), and reaching past it by hand is
+ // the mistake its own docblock records.
+ providerService.listProviders(),
]);
- const providers = Object.values(data?.providers || {});
return Promise.all(PROVIDER_RUNTIMES.map(async (runtime) => {
const status = statuses[runtime.id] || {};
@@ -231,18 +259,24 @@ export async function refreshHarnessModels(id, { run = commandOutput, ...probeDe
};
}
- const data = await providerService.getAllProviders();
- const targets = providersForHarness(Object.values(data?.providers || {}), runtime).filter(usesHarnessCatalog);
+ const targets = providersForHarness(await providerService.listProviders(), runtime).filter(usesHarnessCatalog);
const updated = [];
for (const provider of targets) {
- // A stored default that the harness no longer lists would leave the record
+ // A `*-configured-default` sentinel is NOT a model the vendor will ever
+ // print — it is the "send no --model, let the CLI use its own default"
+ // marker (`resolveCliModel` maps it to null). Dropping it would silently
+ // repin an agy/grok wrapper onto a concrete model AND remove the option
+ // from the editor's picker, which renders it from this same list. So it
+ // survives the rewrite rather than reading as an orphaned id.
+ const next = [...(provider.models || []).filter(isConfiguredDefaultModel), ...models];
+ // A stored default the harness no longer lists would leave the record
// pinned to a model its own picker cannot show. Keep it when it survived
- // the refresh, otherwise fall to the first id the vendor listed (vendors
- // list newest first).
- const defaultModel = models.includes(provider.defaultModel) ? provider.defaultModel : models[0];
+ // the refresh, otherwise fall to the first id (sentinel first when there
+ // is one, then whatever the vendor listed newest-first).
+ const defaultModel = next.includes(provider.defaultModel) ? provider.defaultModel : next[0];
// Serialized rather than batched: each write is a read-modify-write of the
// same providers.json, and Promise.all would have them clobber each other.
- await providerService.updateProvider(provider.id, { models, defaultModel });
+ await providerService.updateProvider(provider.id, { models: next, defaultModel });
updated.push(provider.id);
}
console.log(`🔄 ${runtime.label}: ${models.length} models → ${updated.length} provider(s)`);
diff --git a/server/services/harnesses.test.js b/server/services/harnesses.test.js
index e661df10db..6a16c959c1 100644
--- a/server/services/harnesses.test.js
+++ b/server/services/harnesses.test.js
@@ -5,7 +5,11 @@ const npmGlobalBin = vi.hoisted(() => ({ adoptNpmGlobalBinDir: vi.fn(async () =>
vi.mock('../lib/npmGlobalBin.js', () => npmGlobalBin);
const providerService = vi.hoisted(() => ({
- getAllProviders: vi.fn(),
+ // `listProviders()` resolves the records as an ARRAY — the envelope
+ // (`{ activeProvider, providers: [...] }`) is `getAllProviders`'s shape, and
+ // mocking the wrong one is exactly how a caller's `Array.isArray` guard
+ // silently yields an empty list.
+ listProviders: vi.fn(),
updateProvider: vi.fn(async () => ({})),
}));
vi.mock('./providers.js', () => providerService);
@@ -38,7 +42,7 @@ const providers = {
beforeEach(() => {
__resetRuntimeStatusCache();
__resetLatestVersionCache();
- providerService.getAllProviders.mockResolvedValue({ providers });
+ providerService.listProviders.mockResolvedValue(Object.values(providers));
providerService.updateProvider.mockClear();
});
@@ -88,6 +92,27 @@ describe('usesHarnessCatalog', () => {
it('reads the legacy per-gateway boolean, so old records need no migration', () => {
expect(usesHarnessCatalog({ command: 'opencode', orcarouterBacked: true })).toBe(false);
});
+
+ // The `*Backed` markers are only ever written by PortOS's own editor, so a
+ // hand-written config declaring its own provider entry is invisible to them —
+ // and a refresh would replace its curated list with ids that config cannot
+ // resolve. A declared provider entry IS the backend marker for those records.
+ it('is false for a record that hand-declares its own OpenCode provider entry', () => {
+ expect(usesHarnessCatalog({
+ command: 'opencode',
+ envVars: { OPENCODE_CONFIG_CONTENT: '{"provider":{"myco":{"npm":"@ai-sdk/openai-compatible"}}}' },
+ })).toBe(false);
+ });
+
+ it('stays true for the seeded Zen shape and for an unparseable config', () => {
+ // The seeds ship a posture and nothing else.
+ expect(usesHarnessCatalog({
+ command: 'opencode',
+ envVars: { OPENCODE_CONFIG_CONTENT: '{"permission":"allow"}' },
+ })).toBe(true);
+ // OpenCode cannot read a broken config either, so it declares nothing.
+ expect(usesHarnessCatalog({ command: 'opencode', envVars: { OPENCODE_CONFIG_CONTENT: '{not json' } })).toBe(true);
+ });
});
describe('listHarnesses', () => {
@@ -122,13 +147,11 @@ describe('listHarnesses', () => {
// its own PATH. Attributing those here would inflate the removal warning and
// let a refresh rewrite them from a catalog a different binary printed.
it('does not claim a provider that pins its own path or PATH', async () => {
- providerService.getAllProviders.mockResolvedValue({
- providers: {
- pathed: { id: 'pathed', type: 'cli', command: '/opt/tools/opencode', name: 'Pathed' },
- envd: { id: 'envd', type: 'cli', command: 'opencode', name: 'Own PATH', envVars: { PATH: '/opt/tools' } },
- plain: { id: 'plain', type: 'cli', command: 'opencode', name: 'Plain' },
- },
- });
+ providerService.listProviders.mockResolvedValue(Object.values({
+ pathed: { id: 'pathed', type: 'cli', command: '/opt/tools/opencode', name: 'Pathed' },
+ envd: { id: 'envd', type: 'cli', command: 'opencode', name: 'Own PATH', envVars: { PATH: '/opt/tools' } },
+ plain: { id: 'plain', type: 'cli', command: 'opencode', name: 'Plain' },
+ }));
const opencode = (await listHarnesses(deps())).find((row) => row.id === 'opencode');
@@ -164,12 +187,10 @@ describe('refreshHarnessModels', () => {
it('repoints a default model the harness no longer lists, and keeps one it does', async () => {
const run = vi.fn(async (command, args) => (args[0] === 'models' ? OPENCODE_MODELS : '1.18.27'));
- providerService.getAllProviders.mockResolvedValue({
- providers: {
- stale: { id: 'stale', type: 'cli', command: 'opencode', models: [], defaultModel: 'opencode/gone' },
- kept: { id: 'kept', type: 'cli', command: 'opencode', models: [], defaultModel: 'opencode/mimo-v2.5-free' },
- },
- });
+ providerService.listProviders.mockResolvedValue(Object.values({
+ stale: { id: 'stale', type: 'cli', command: 'opencode', models: [], defaultModel: 'opencode/gone' },
+ kept: { id: 'kept', type: 'cli', command: 'opencode', models: [], defaultModel: 'opencode/mimo-v2.5-free' },
+ }));
await refreshHarnessModels('opencode', { run, ...found });
@@ -180,6 +201,31 @@ describe('refreshHarnessModels', () => {
expect(patches.kept.defaultModel).toBe('opencode/mimo-v2.5-free');
});
+ // A `*-configured-default` is the "send no --model" marker, not a model the
+ // vendor will ever print. Dropping it silently repins the wrapper onto a
+ // concrete model AND removes the option from the editor's picker, which is
+ // rendered from this same list — so the refresh would be unrecoverable in the UI.
+ it('preserves a configured-default sentinel the harness will never list', async () => {
+ const run = vi.fn(async (command, args) => (args[0] === 'models'
+ ? 'Available models:\n * grok-4.6 (default)\n - grok-4.5\n'
+ : 'grok 1.0.13'));
+ providerService.listProviders.mockResolvedValue([{
+ id: 'grok-cli',
+ type: 'cli',
+ command: 'grok',
+ models: ['grok-configured-default'],
+ defaultModel: 'grok-configured-default',
+ }]);
+
+ const result = await refreshHarnessModels('grok', { run, ...found });
+
+ expect(result.ok).toBe(true);
+ const [, patch] = providerService.updateProvider.mock.calls[0];
+ expect(patch.models).toEqual(['grok-configured-default', 'grok-4.6', 'grok-4.5']);
+ // The pin survives, so the provider keeps sending no `--model` at all.
+ expect(patch.defaultModel).toBe('grok-configured-default');
+ });
+
it('refuses an empty probe rather than blanking every picker', async () => {
// A signed-out CLI or a changed output shape both parse to nothing. Writing
// that through would erase working model lists on a guess.