diff --git a/packages/model-proxy/README.md b/packages/model-proxy/README.md index 7bb75fb5c..4d69afb68 100644 --- a/packages/model-proxy/README.md +++ b/packages/model-proxy/README.md @@ -64,7 +64,7 @@ code is in that same tree, a restart picks it up. If it is in another tree, the unit keeps the old PIN until it is installed again from the new tree: stop it, remove its unit file, then `mosaic proxy unit install` from the new tree, because install never replaces a unit. Then run `mosaic proxy fetch` (or Fetch on the Console's -Model proxy settings), which installs the new release beside the old one +Model setup page), which installs the new release beside the old one under `/opt/cliproxyapi//`. Then restart the proxy with `mosaic proxy unit restart`. Before the fetch, the proxy fails to start with `proxy-install-missing`, and keeps failing until the fetch is done. Restart the bus and diff --git a/packages/model-proxy/src/admin-control.mjs b/packages/model-proxy/src/admin-control.mjs index 7aa963f64..59d51fd9b 100644 --- a/packages/model-proxy/src/admin-control.mjs +++ b/packages/model-proxy/src/admin-control.mjs @@ -60,17 +60,24 @@ export function createProxyAdmin({ dataRoot, configDir, instance = null, unitDir // intent. Any other failure leaves it: the add may have happened. async function rideOne(rider, wasRidden) { const id = rider.id, local = decide(rider, wasRidden); - if (local === 'fixture') return { id, outcome: 'fixture', running: !(await stopped(rider)) }; + // settings-p3 (R2): with no bus status (the single-business Console) whether its bus runs is unknown (null). + if (local === 'fixture') return { id, outcome: 'fixture', running: typeof rider.status === 'function' ? !(await stopped(rider)) : null }; if (local !== 'ready') return { id, outcome: local === 'already' ? 'already' : 'skipped', reason: local }; let current; try { current = await rider.call('plugins'); } catch { return { id, outcome: 'skipped', reason: 'bus-down' }; } try { await rider.call('proxy.accounts'); } catch (error) { return { id, outcome: 'skipped', reason: error?.code === 'not-configured' ? 'no-proxy-client' : 'proxy-check-failed' }; } const providers = Array.isArray(current?.plugins?.['model-provider']) ? current.plugins['model-provider'] : []; if (providers.includes('cliproxy')) return { id, outcome: 'already' }; - // The receipts are read again here: a removal saved while this run worked on earlier - // organizations is on file now, and the decision above came from the run's first read. - const now = ridden()(id); - if (now !== false) return { id, outcome: 'skipped', reason: now === null ? 'unreadable' : 'removed' }; + // The organization (its file and change log) and the receipts are read again here: an add and + // remove saved on its Settings page, or a removal saved while this run worked on earlier + // organizations, is on file now, and the decision above came from the run's first read + // (settings-p3 R1). A read that fails, or an organization no longer listed, is skipped as unreadable. + let fresh; + try { fresh = (await riders()).find(r => r?.id === id); } catch { fresh = null; } + if (!fresh) return { id, outcome: 'skipped', reason: 'unreadable' }; + const again = decide(fresh, ridden()); + if (again === 'already') return { id, outcome: 'already' }; + if (again !== 'ready') return { id, outcome: 'skipped', reason: again }; try { receipt({ op: 'ride-intent', org: id }); } catch { return { id, outcome: 'skipped', reason: 'not-recorded' }; } try { await rider.call('plugins.set', { revision: current.revision, plugins: { 'model-provider': [...providers, 'cliproxy'] } }); } catch (error) { @@ -83,7 +90,12 @@ export function createProxyAdmin({ dataRoot, configDir, instance = null, unitDir return { id, outcome: 'added' }; } async function rideSummary() { - try { const wasRidden = ridden(); return (await riders()).map(r => ({ id: r.id, state: decide(r, wasRidden) })); } catch { return null; } + // settings-p3 (review P3-3): a stand-in organization with no bus status (the single-business + // Console) can't be moved; running null says so before any Ride all run. + try { + const wasRidden = ridden(); + return (await riders()).map(r => { const state = decide(r, wasRidden); return state === 'fixture' && typeof r.status !== 'function' ? { id: r.id, state, running: null } : { id: r.id, state }; }); + } catch { return null; } } function nextSteps({ release, init, unitState, fence, lock }) { if (!release.fetched || release.problem) return ['fetch']; @@ -221,6 +233,9 @@ export function createProxyAdmin({ dataRoot, configDir, instance = null, unitDir if (!rider) return { org, moved: false, reason: 'unknown' }; const local = decide(rider, ridden()); if (local !== 'fixture') return { org, moved: false, reason: local }; + // settings-p3 (R2): with no bus status (the single-business Console) its bus can't be shown + // stopped, so stopping it would not help: moving is not available there. + if (typeof rider.status !== 'function') return { org, moved: false, reason: 'not-available' }; if (!(await stopped(rider))) return { org, moved: false, reason: 'bus-running' }; if (typeof move !== 'function') return { org, moved: false, reason: 'not-available' }; const owner = await ownerModels(); diff --git a/packages/model-proxy/tests/ride-fence.test.mjs b/packages/model-proxy/tests/ride-fence.test.mjs index 47a1bf982..4689e0f86 100644 --- a/packages/model-proxy/tests/ride-fence.test.mjs +++ b/packages/model-proxy/tests/ride-fence.test.mjs @@ -102,10 +102,12 @@ test('after Ride all the launcher asks admission for a direct anthropic route an }; const launchOf = async riding => { const root = tmp(t); + // A Claude model on a legacy entry counts as OAuth and runs on claude-code only. The stand-in adapter + // path skips only the binary check; the launch stops at authorizeLaunch, before any adapter runs. const f = fixture(root, 'acme', doc => { - doc.plugins = { ...doc.plugins, harness: ['pi'] }; + doc.plugins = { ...doc.plugins, harness: ['claude-code'] }; doc.launch.models['claude-opus-5-5'] = { provider: 'anthropic', model: 'claude-opus-5-5' }; - doc.roles.coder.vars = { harness: 'pi', model: 'claude-opus-5-5', thinking: 'low' }; + doc.roles.coder.vars = { harness: 'claude-code', model: 'claude-opus-5-5', thinking: 'low' }; return doc; }); if (riding) await ride(join(root, 'config', 'businesses', 'acme.json')); @@ -119,7 +121,7 @@ test('after Ride all the launcher asks admission for a direct anthropic route an if (x.op === 'authorizeLaunch') throw Object.assign(Error('fixture authorization stop'), { code: 'fixture-policy' }); return {}; } }; - const makeLoader = await fakeHarnesses(t, { pi: null }, write => write('model-provider', 'cliproxy', `export * from ${JSON.stringify(new URL('../../plugins/model-provider/cliproxy/index.mjs', import.meta.url).href)};`)); + const makeLoader = await fakeHarnesses(t, { 'claude-code': '/fixture-unused' }, write => write('model-provider', 'cliproxy', `export * from ${JSON.stringify(new URL('../../plugins/model-provider/cliproxy/index.mjs', import.meta.url).href)};`)); const system = { ...JSON.parse(readFileSync(f.config, 'utf8')), proxy: { port: 1, binary: '/fixture-unused' } }; const launcher = createLauncher({ host, system, env: f.env, makeLoader, bwrap: '/usr/bin/true', log: () => {} }); return { answer: await launcher.fromSession('fixture-cap', 'coder'), ops }; diff --git a/packages/model-proxy/tests/ride.test.mjs b/packages/model-proxy/tests/ride.test.mjs index 9eca28f06..bff59095d 100644 --- a/packages/model-proxy/tests/ride.test.mjs +++ b/packages/model-proxy/tests/ride.test.mjs @@ -201,6 +201,43 @@ test('a removal saved while Ride all works on earlier organizations is read befo assert.equal(g2.calls.some(([v]) => v === 'plugins.set'), false); }); +test('settings-p3 R1: the change log is read again before each add, and a read that fails skips the add', async t => { + // While Ride all works on 'first', the owner adds cliproxy to 'late' on its Settings page and takes it + // off again. Only its change log shows that; the receipts do not. The run's first read showed nothing. + let lateLog = ''; + const first = bus({ providers: [] }), late = bus({ providers: [] }); + const firstCall = async (verb, args) => { if (verb === 'plugins') lateLog = committed([{ path: 'plugins.model-provider', old: [], new: ['cliproxy'] }]) + committed([{ path: 'plugins.model-provider', old: ['cliproxy'], new: [] }]); return first.call(verb, args); }; + const f = admin(t, { riders: async () => [{ id: 'first', fixture: false, cliproxy: false, changes: '', call: firstCall }, { id: 'late', fixture: false, cliproxy: false, changes: lateLog, call: late.call }] }); + const r = await f.admin.rideAll(); + assert.deepEqual(r.added, ['first']); assert.deepEqual(r.skipped, [{ id: 'late', reason: 'removed' }]); + assert.equal(late.calls.some(([v]) => v === 'plugins.set'), false); + assert.deepEqual(receipts(f.dataRoot).filter(x => x.org === 'late').map(x => x.op), []); + // Fail closed: a change log that can no longer be read, an organization that is no longer listed, + // or a list that can't be read again skips the add as unreadable, with no intent and no plugins.set. + for (const [name, again] of [ + ['log unreadable', b => [{ id: 'o', fixture: false, cliproxy: false, changes: null, call: b.call }]], + ['no longer listed', () => []], + ['list throws', () => { throw new Error('read failed'); }], + ]) { + const b = bus({ providers: [] }); + let reads = 0; + const g = admin(t, { riders: async () => (reads++ === 0 ? [{ id: 'o', fixture: false, cliproxy: false, changes: '', call: b.call }] : again(b)) }); + assert.deepEqual((await g.admin.rideAll()).skipped, [{ id: 'o', reason: 'unreadable' }], name); + assert.equal(b.calls.some(([v]) => v === 'plugins.set'), false, name); + assert.deepEqual(receipts(g.dataRoot).filter(x => x.op === 'ride-intent'), [], name); + } +}); + +test('settings-p3 review P3-1: an organization that took cliproxy during the run reads as already using it, with no add', async t => { + const b = bus({ providers: [] }); + let reads = 0; + const f = admin(t, { riders: async () => [{ id: 'o', fixture: false, cliproxy: reads++ > 0, changes: '', call: b.call }] }); + const r = await f.admin.rideAll(); + assert.deepEqual([r.added, r.already, r.skipped], [[], ['o'], []]); + assert.equal(b.calls.some(([v]) => v === 'plugins.set'), false); + assert.deepEqual(receipts(f.dataRoot).filter(x => x.op === 'ride-intent'), []); +}); + test('an intent receipt that cannot be written stops that add before plugins.set', async t => { const b = bus({ providers: [] }); const f = admin(t, { riders: async () => [{ id: 'w', fixture: false, cliproxy: false, changes: '', call: b.call }] }); @@ -388,10 +425,15 @@ test('a fixture organization moves only when stopped, with a proxy, a riding bus assert.deepEqual(await f.admin.rideMove({ org: 'nope', principal }), { org: 'nope', moved: false, reason: 'unknown' }); assert.deepEqual(await f.admin.rideMove({ org: 'real', principal }), { org: 'real', moved: false, reason: 'ready' }); assert.deepEqual(await f.admin.rideMove({ org: 'live', principal }), { org: 'live', moved: false, reason: 'bus-running' }); - // A slow or busy bus that does not answer, a status that cannot be read, or no status at all is running. - for (const org of ['busy', 'unproven', 'no-status']) assert.deepEqual(await f.admin.rideMove({ org, principal }), { org, moved: false, reason: 'bus-running' }, org); + // A slow or busy bus that does not answer, or a status that cannot be read, is running. + for (const org of ['busy', 'unproven']) assert.deepEqual(await f.admin.rideMove({ org, principal }), { org, moved: false, reason: 'bus-running' }, org); + // settings-p3 R2: no status at all (the single-business Console) can never show the bus stopped, so + // "stop its bus" would not help: moving is not available there, and whether it runs is unknown. + assert.deepEqual(await f.admin.rideMove({ org: 'no-status', principal }), { org: 'no-status', moved: false, reason: 'not-available' }); const listed = await f.admin.rideAll(); - assert.deepEqual(listed.fixtures, [{ id: 'stand-in', running: false }, { id: 'live', running: true }, { id: 'busy', running: true }, { id: 'unproven', running: true }, { id: 'no-status', running: true }]); + assert.deepEqual(listed.fixtures, [{ id: 'stand-in', running: false }, { id: 'live', running: true }, { id: 'busy', running: true }, { id: 'unproven', running: true }, { id: 'no-status', running: null }]); + // settings-p3 review P3-3: the status summary says so before any run, without asking any bus. + assert.deepEqual((await f.admin.status()).ride.filter(r => r.state === 'fixture'), [{ id: 'stand-in', state: 'fixture' }, { id: 'live', state: 'fixture' }, { id: 'busy', state: 'fixture' }, { id: 'unproven', state: 'fixture' }, { id: 'no-status', state: 'fixture', running: null }]); ownerNow = { ...owner, proxy: false }; assert.deepEqual(await f.admin.rideMove({ org: 'stand-in', principal }), { org: 'stand-in', moved: false, reason: 'no-proxy' }); ownerNow = { ...owner, riding: false }; diff --git a/packages/webui/src/proxy-admin.mjs b/packages/webui/src/proxy-admin.mjs index 9e1b9f4c3..bdf6c88b0 100644 --- a/packages/webui/src/proxy-admin.mjs +++ b/packages/webui/src/proxy-admin.mjs @@ -10,10 +10,15 @@ export { createProxyAdmin }; // #1873: one organization's catalogue row for the setup page. A count is shown only when the bus // answered with a model list; otherwise models is null and the page shows a dash, never a made-up 0. +const RESTART_TO_LAUNCH = 'Restart this organization to start agents on these models.'; export async function orgCatalogue(call) { try { const value = await call('routes'); - return { status: value?.catalogue?.status ?? 'unknown', models: Array.isArray(value?.catalogue?.models) ? value.catalogue.models.length : null }; + const status = value?.catalogue?.status ?? 'unknown'; + // settings-p3 (re-check 3 P3-5): a bus that picked the service up after it started reads ready but + // starts agents on these models only after a restart (bus runtime.mjs RESTART_TO_LAUNCH). + const launchRestart = status === 'ready' && Array.isArray(value.catalogue.notices) && value.catalogue.notices.includes(RESTART_TO_LAUNCH); + return { status, models: Array.isArray(value?.catalogue?.models) ? value.catalogue.models.length : null, ...(launchRestart ? { launchRestart: true } : {}) }; } catch { return { status: 'bus-unavailable', models: null }; } } diff --git a/packages/webui/src/public/bus.js b/packages/webui/src/public/bus.js index 380eab04d..f7cb69ae7 100644 --- a/packages/webui/src/public/bus.js +++ b/packages/webui/src/public/bus.js @@ -1378,7 +1378,9 @@ // fixture-only catalogue is ready with no model proxy). Before the setting is read it falls // back to the catalogue status, as before. const proxyOn=harnessSettings?(Array.isArray(harnessSettings.plugins?.['model-provider'])?harnessSettings.plugins['model-provider']:[]).includes('cliproxy'):v.catalogue?.status!=='disabled'; - const catalogueInfo=v.catalogue?.status==='ready'?`

Model catalogue, observed ${txt(window.MosaicLocalTime(v.catalogue.observedAt))}.

${(v.catalogue.notices??[]).map(n=>`

${txt(n)}

`).join('')}`:v.catalogue?.status==='unavailable'?catalogueLine(proxyOn,v.catalogue):'

Model catalogue not enabled.

'; + // settings-p3 (re-check 3 P3-5): a ready catalogue the bus picked up late says agents start on these + // models after a restart; that notice gets the organization's Restart (not primary: Save routes is). + const catalogueInfo=v.catalogue?.status==='ready'?`

Model catalogue, observed ${txt(window.MosaicLocalTime(v.catalogue.observedAt))}.

${(v.catalogue.notices??[]).map(n=>`

${txt(n)}${n===window.MosaicConsole?.RESTART_TO_LAUNCH&&window.MosaicOrg?.id?` ${window.MosaicConsole.orgRestartButton(window.MosaicOrg.id,{name:window.MosaicOrg.label||window.MosaicOrg.id})}`:''}

`).join('')}`:v.catalogue?.status==='unavailable'?catalogueLine(proxyOn,v.catalogue):'

Model catalogue not enabled.

'; const providerControl=canSend&&!isTester?`

`:''; const harnessControl=canSend&&!isTester?`
Harnesses${harnessSettings ? [...new Set([...harnessSettings.available.harness,...(harnessSettings.plugins.harness??[])])].map(name=>``).join('')+` ` : '

Harnesses unavailable.

'}

${txt(harnessReceipt)}

`:''; const off=v.harnesses.length?'':'

No harness is switched on for this organization, so every launch is refused, and so is a save that changes a harness. Switch one on under Harnesses.

'; @@ -1507,7 +1509,7 @@ if (page==='tokens' && s.launch && !s.launch.refused) takeSnapshot(s.launch); const notify = typeof n.binding==='string' ? `${txt(n.binding)}` : n.refused ? `Could not be read: ${txt(n.refused)}` : 'None set'; const contents={limits:()=>launchForm(s.launch),routing:()=>routesSection(routes,instances),agents:()=>agentsSection(instances)+agentLevels,assistant:()=>assistantSection(s.launch,names),tokens:()=>tokenLimits(limitRows,limitsRefused)+tokenUsage(usage),names:()=>testerNames(names,instances),about:()=>`
Address
${txt(s.address)||'unknown'}
Release
${txt(s.release)||'unknown'}
Business
${txt(s.business)||none}
Board
${txt(s.board)||'unknown'}
Notifier binding
${notify}
`, 'model-proxy':()=>'
Open Model setup
'}; - const helpers={limits:'Leave a limit blank for no limit. Zero stops new launches. Running sessions keep running when limits or models change.',routing:"Each agent’s harness, model and thinking, and the fallback a launch takes when the primary harness fails its preflight. A fallback sets all three or none. Running sessions keep their route. The next launch reads the change. A harness is the program that runs the model, such as Claude Code. Preflight is the check a launch makes before it starts.",agents:'Each agent with its definition, launch membership and runs. A launch refuses until the agent has a route in Routing.',assistant:'The definition stays an assistant one. Holder and credentials stay hand edits.',tokens:'Token limits the bus checks, and token use read from session transcripts.'}; + const helpers={limits:'Leave a limit blank for no limit. Zero stops new launches. Running sessions keep running when limits or models change.',routing:"Each agent’s harness, model and thinking, and the fallback a launch takes when the primary harness fails its preflight. A fallback sets all three or none. Running sessions keep their route. The next launch reads the change. A harness is the program that runs the model. Preflight is the check a launch makes before it starts.",agents:'Each agent with its definition, launch membership and runs. A launch refuses until the agent has a route in Routing.',assistant:'The definition stays an assistant one. Holder and credentials stay hand edits.',tokens:'Token limits the bus checks, and token use read from session transcripts.'}; return settingsShell(page,contents[page](),`${get.oldest()?`Read ${when(get.oldest())}.`: 'Reading…'} ${helpers[page]||''}`); } let settingsFocusDisclosure=false; @@ -1730,11 +1732,13 @@ const page = path.split('/')[2] || 'appearance', id = window.MosaicOrg?.id, row = id ? window.MosaicOrg.row?.(id) : null; const org = txt(window.MosaicOrg?.label || id || ''), name = settingsPages.find(([p]) => p === page)?.[1] || 'this page'; if (id && row?.busHealthy === false && !refusal(err)) { - const restart = window.MosaicConsole?.orgRestartButton?.(id, { name: window.MosaicOrg.label || id, primary: true }) || ''; const state = row.busStopped ? `${org} is stopped` : `${org} isn't running`; - // Why it is down, from the read the dashboard row uses (MosaicConsole.orgDownReason). - const label = window.MosaicOrg.label || id, whyText = v => !v ? '' : v.plain && v.plain !== `${label} did not start.` ? txt(v.plain) : `Why it stopped: ${txt(v.detail)}`; + // Why it is down, from the read the dashboard row uses (MosaicConsole.orgDownReason). Only a + // refused start is a reason it stopped; anything else is what the last check saw (P3-9). + const label = window.MosaicOrg.label || id, whyText = v => !v ? '' : v.plain && v.plain !== `${label} did not start.` ? txt(v.plain) : `${v.refused === false ? 'Last check' : 'Why it stopped'}: ${txt(v.detail)}`; const why = window.MosaicConsole?.orgDownReason?.(id, label, v => { const p = document.querySelector(`[data-org-down="${CSS.escape(id)}"] [data-org-down-why]`); if (p) { p.innerHTML = whyText(v); p.hidden = !p.innerHTML; } }) ?? null; + // settings-p3 (re-check 3 P3-4): after a refusal a restart can't clear, Restart is not the primary. + const restart = window.MosaicConsole?.orgRestartButton?.(id, { name: label, primary: !(window.MosaicConsole?.orgRefusal?.(id)?.restart === false || why?.restart === false) }) || ''; return settingsShell(page, `

This instance's own pages still work: Appearance, Model setup${triageOwner ? ', Triage' : ''} and Console.

`); } return settingsShell(page, ``); diff --git a/packages/webui/src/public/console-restart.js b/packages/webui/src/public/console-restart.js index 643a84770..4f42cd015 100644 --- a/packages/webui/src/public/console-restart.js +++ b/packages/webui/src/public/console-restart.js @@ -207,7 +207,9 @@ // The refusal the bus host wrote, with one plain line in front when its code is known. function refusalLine(name, message) { const text = String(message || 'The restart was refused. Nothing was retried.'); - if (/\bfixture-proxy-configured\b/.test(text)) return { plain: `${name} runs on test models, which can't share this machine with your model service. It did not start.`, detail: text }; + // settings-p3 (re-check 3 P3-4): a restart is refused the same way again, so `restart: false` + // tells the page not to keep Restart as its primary action. + if (/\bfixture-proxy-configured\b/.test(text)) return { plain: `${name} runs on test models, which can't share this machine with your model service. It did not start.`, detail: text, restart: false }; return { plain: `${name} did not start.`, detail: text }; } // #1873 review P1-1, P2-2: the cause a running bus gives for a catalogue it cannot read @@ -218,7 +220,7 @@ // plain line, so the page shows the bus's words. function catalogueCause(name, notices, reason) { // Two different models that slug to one key: the catalogue names it in `reason`, with no notice. - if (reason === 'model-key-collision') return { code: reason, plain: `Two of your models get the same short name, so ${name} can't tell them apart. A restart won't change that.`, restart: false, fix: 'service', detail: reason }; + if (reason === 'model-key-collision') return { code: reason, plain: `Two of your models get the same short name, so ${name} can't tell them apart. A restart won't change that. Take one of them out of an API key's Models list on Model setup. If both come from signed-in accounts, this can't be changed from Console yet.`, restart: false, fix: 'service', detail: reason }; const list = (Array.isArray(notices) ? notices : []).filter(n => typeof n === 'string' && n); if (!list.length) return null; const detail = list.join(' '), code = /\(([a-z][a-z-]*)\)/.exec(detail)?.[1] ?? (/has not been set up/.test(detail) ? 'proxy-not-set-up' : null); @@ -240,8 +242,8 @@ return ` ${receipt}`; } const paintOrg = id => document.querySelectorAll(`[data-org-restart-box="${CSS.escape(id)}"]`).forEach(el => { - const b = el.querySelector('[data-org-restart]'); - el.outerHTML = orgRestartButton(id, { name: b?.dataset.orgName || id, label: b?.dataset.label, primary: b?.hasAttribute('data-primary') }); + const b = el.querySelector('[data-org-restart]'), r = orgReceipts.get(id); + el.outerHTML = orgRestartButton(id, { name: b?.dataset.orgName || id, label: b?.dataset.label, primary: b?.hasAttribute('data-primary') && r?.restart !== false }); }); async function restartOrg(id, name) { if (orgBusy.has(id) || !orgAllowed()) return null; @@ -275,12 +277,21 @@ // (workspace-read.mjs). It is the reason the dashboard row shows. One read per organization at a // time, kept for 15 seconds; until it lands this returns what was read before, or null. A reason // that only restates "not running" is not a reason. + // settings-p3 (re-check 3 P3-9): only a refused start is a stop reason (`refused: true`); any other + // reason (a slow or failed read, a host that does not answer yet) is what the last check saw. + // P3-11: the raw reason is kept and each caller's line is built with its own name when used, and + // every caller that asked while the read was pending is told when it lands. const downReasons = new Map(); + const downLine = (raw, name) => !raw ? null : raw.refused ? { ...refusalLine(name, raw.text), refused: true } : { plain: null, detail: raw.text, refused: false }; function orgDownReason(id, name = id, onRead = null) { if (typeof id !== 'string' || !id) return null; const got = downReasons.get(id); - if (got && (got.pending || Date.now() - got.at < 15000)) return got.value ?? null; - downReasons.set(id, { at: got?.at ?? 0, value: got?.value ?? null, pending: true }); + if (got && (got.pending || Date.now() - got.at < 15000)) { + if (got.pending && typeof onRead === 'function') got.waiters.push([name, onRead]); + return downLine(got.raw, name); + } + const entry = { at: got?.at ?? 0, raw: got?.raw ?? null, pending: true, waiters: typeof onRead === 'function' ? [[name, onRead]] : [] }; + downReasons.set(id, entry); nativeFetch(`/api/workspace?${new URLSearchParams({ org: id, sections: 'tasks' })}`, { cache: 'no-store', redirect: 'manual' }) .then(r => (r.ok ? r.json() : null)) .then(body => { @@ -288,11 +299,16 @@ const reason = row && row.state !== 'ok' && typeof row.reason === 'string' ? row.reason.trim() : ''; if (!reason || /^the bus is not (running|answering)\.?$/i.test(reason)) return null; const refused = /^the bus refused to start: ([\s\S]+)$/.exec(reason); - return refused ? refusalLine(name, refused[1]) : { plain: null, detail: reason }; + return refused ? { refused: true, text: refused[1] } : { refused: false, text: reason }; }) .catch(() => null) - .then(value => { downReasons.set(id, { at: Date.now(), value, pending: false }); onRead?.(value); }); - return got?.value ?? null; + .then(raw => { + downReasons.set(id, { at: Date.now(), raw, pending: false, waiters: [] }); + for (const [who, callback] of entry.waiters) { try { callback(downLine(raw, who)); } catch { /* one caller's repaint does not stop the others */ } } + }); + return downLine(got?.raw ?? null, name); } - window.MosaicConsole = Object.freeze({ ready, settingsMarkup, busButton, attachBus, orgRestartButton, restartOrg, catalogueCause, orgDownReason, orgRefusal: id => orgReceipts.get(id) ?? null, get busRestart() { return busAllowed(); }, get config() { return config; } }); + // The notice the bus adds to a ready catalogue it picked up after it started (bus runtime.mjs RESTART_TO_LAUNCH). + const RESTART_TO_LAUNCH = 'Restart this organization to start agents on these models.'; + window.MosaicConsole = Object.freeze({ RESTART_TO_LAUNCH, ready, settingsMarkup, busButton, attachBus, orgRestartButton, restartOrg, catalogueCause, orgDownReason, orgRefusal: id => orgReceipts.get(id) ?? null, get busRestart() { return busAllowed(); }, get config() { return config; } }); })(); diff --git a/packages/webui/src/public/display.js b/packages/webui/src/public/display.js index b94ddf27c..7c9812507 100644 --- a/packages/webui/src/public/display.js +++ b/packages/webui/src/public/display.js @@ -170,7 +170,7 @@ window.MosaicLocalTime = value => Number.isFinite(Date.parse(value)) ? new Date( const bus = notRead(o.bus) ? 'bus not read' : refused ? `not running: its last start failed at ${when(o.bus.lastStart.at)} (bus ${clean(o.bus.state) || 'not read'})${why ? '' : '. Restart it on the dashboard to see why'}` : `bus ${clean(o.bus.state) || 'not read'}`; const proc = notRead(o.processing) ? 'processing not read' : o.processing.invalid === true ? 'processing state not valid' : o.processing.halted === true ? 'processing stopped' : 'processing on'; // A known refusal reads as its plain line; any other shows the bus's words. - const reason = !why ? '' : why.plain && why.plain !== `${orgName(o.id)} did not start.` ? ` ${why.plain}` : ` Why it stopped: ${clean(why.detail).replace(/\.$/, '')}.`; + const reason = !why ? '' : why.plain && why.plain !== `${orgName(o.id)} did not start.` ? ` ${why.plain}` : ` ${why.refused === false ? 'Last check' : 'Why it stopped'}: ${clean(why.detail).replace(/\.$/, '')}.`; lines.push(`${orgName(o.id)}: ${bus}, ${proc}, config ${configWords(o.config)}${reason ? `.${reason}` : ''}`); } return lines; @@ -568,8 +568,8 @@ if (document.documentElement.hasAttribute('data-settings-proxy-document') && !lo + '

The model service lets your organizations use your own model accounts. Each step is checked on this machine. Keys are never shown.

' + '
' + '

' - + '