Compare commits

...
Author SHA1 Message Date
jason.woltje 196505e6ef fix(bus): review round: the restart notice shows only on a ready catalogue, since a fenced, colliding or down proxy still refuses after a restart (#1873, lane pickup-launch)
A bus booted with the proxy on a fenced instance reads the same unavailable catalogue, so the
notice sent the owner to a restart that stops running agents and starts none. The test proves
that and shows the notice again once the fence is gone. The disabled check goes away with it;
the disabled test now says the routes verb answers disabled itself.
2026-11-19 12:08:41 -06:00
jason.woltje f7c0e4f46c fix(bus): a bus that picked up the shared proxy says on its catalogue that a restart is needed to start agents on these models (#1873, lane pickup-launch)
A picked-up client serves accounts and the catalogue, but a launch on it is refused at bus
admission (model-provider-unavailable): the host launcher keeps its boot system with no proxy,
and the bus has no ModelKeys. While the bus holds a late client and the catalogue is not
disabled, the catalogue appends one notice after its own: "Restart this organization to start
agents on these models." A boot proxy, a disabled catalogue, refused settings and a dropped
client carry no such notice. Tests cover the launch refusal, refused settings, a dropped
client and a key scan over the launch path.
2026-11-19 12:08:41 -06:00
jason.woltje 5c975faddd fix(model-proxy): review round: the preflight comment says every v8 proxy applies a key PUT by an async reload; a re-probe waits about the time left, not the client default; the README says the proxy unit reads PIN from the tree it was installed from and names .codex-refresh; two test headers stop naming only 8.0.42 (#1873, lane proxy-pin) 2026-11-19 11:08:23 -06:00
jason.woltje 462215b4bd chore(model-proxy): pin CLIProxyAPI 8.0.79; proxy.json from an earlier PIN stays valid; preflight re-probes a just-issued key's 401 briefly (#1873, lane proxy-pin)
The PIN moves from 8.0.42 to 8.0.79 with the upstream archive checksum and the
extracted binary checksum. The panel stays 1.26.7.

proxy.json keeps the binary path of the PIN it was created under. A path of the
form <dataRoot>/opt/cliproxyapi/<version>/cli-proxy-api now validates and reads
as the current pinned path, so an instance created on 8.0.42 needs no edit. The
runner still runs only the verified pinned install.

8.0.79 applies a key-list PUT by an async reload a few milliseconds after it
answers, so a just-issued key answers 401 at first. Preflight now probes again
on 401 only, for at most ISSUE_PROBE_TIMEOUT_MS (2 s). Any other non-2xx still
refuses on the first answer.
2026-11-19 11:08:23 -06:00
10 changed files with 405 additions and 17 deletions

No files matched your search

+17 -3
View File
@@ -6,6 +6,8 @@ import { isDeepStrictEqual } from 'node:util';
import { BusError } from './broker.mjs';
export const REVOKE_TIMEOUT_MS = 5000;
export const REVOKE_POLL_MS = 25;
export const ISSUE_PROBE_TIMEOUT_MS = 2000;
export const ISSUE_REPROBE_MIN_MS = 250;
export const MODEL_STOP_TIMEOUT_MS = 5000;
const keyId = key => createHash('sha256').update(key).digest('hex').slice(0, 12);
const fail = code => { throw new BusError(code); };
@@ -223,9 +225,21 @@ export class ModelKeys {
this.#sentinel(keys);
return this.#issue(instance, false, keys);
});
let status;
try { status = await this.#client.probeKey(proxy.key); }
catch { fail('proxy-down'); }
// Every v8 CLIProxyAPI applies a key-list PUT by an async reload after it answers, so a
// just-issued key can answer 401 for a moment. On 8.0.79 that moment outlasts the confirming
// GET (measured, #1873). Only 401 is probed again, until a short deadline; a re-probe waits
// about the time left, at least ISSUE_REPROBE_MIN_MS. Any other non-2xx refuses on the first
// answer, as before.
const deadline = performance.now() + ISSUE_PROBE_TIMEOUT_MS;
let status, first = true;
for (;;) {
const options = first ? undefined : { timeout: Math.max(ISSUE_REPROBE_MIN_MS, Math.ceil(deadline - performance.now())) };
first = false;
try { status = await this.#client.probeKey(proxy.key, options); }
catch { fail('proxy-down'); }
if (status !== 401 || performance.now() >= deadline) break;
await new Promise(resolve => setTimeout(resolve, REVOKE_POLL_MS));
}
if (status < 200 || status >= 300) fail('proxy-key-refused');
return proxy;
}
+12 -2
View File
@@ -887,8 +887,18 @@ export async function startBroker({
// One check at a time; an unexpected failure drops a late client, never keeps it.
const syncProxy = () => (proxySync = proxySync.then(pickProxy).catch(() => dropLateProxy('The model proxy could not be checked (proxy-down). Try again shortly.')));
// Unavailable with no client: the catalogue names the cause instead of a bare unavailable.
const explainCatalogue = value => value?.status === 'unavailable' && value.reason === undefined && !modelProxyClient && proxyCause
? { ...value, reason: 'proxy-not-configured', notices: [proxyCause] } : value;
// pickup-launch: a late client serves accounts and the catalogue, but a launch on it needs what
// only the start path builds (ModelKeys here, the proxy in the host launcher's boot system), so
// while this bus holds one a ready catalogue says plainly that a restart is needed. Not on an
// unavailable one: a fence, a collision or a down proxy still refuses after a restart.
const RESTART_TO_LAUNCH = 'Restart this organization to start agents on these models.';
const explainCatalogue = value => {
if (value?.status === 'unavailable' && value.reason === undefined && !modelProxyClient && proxyCause)
return { ...value, reason: 'proxy-not-configured', notices: [proxyCause] };
if (lateProxy && value?.status === 'ready')
return { ...value, notices: [...(value?.notices ?? []), RESTART_TO_LAUNCH] };
return value;
};
const baseCatalogue = settings ? createModelCatalogue({ pluginDataRoot:instanceRoot ?? dataRoot, client: () => modelProxyClient, settings: id => settings.current(id).plugins ?? {},
// A view, so a lock taken by a later pickup or init counts as it does for the start path's.
proxyLock: { assertCertain: () => proxyLock?.assertCertain(), generation: () => proxyLock?.generation() } }) : null;
+26 -2
View File
@@ -11,7 +11,7 @@ import { tmpdir } from 'node:os';
import { createHash, randomBytes } from 'node:crypto';
import { Credentials } from '../src/credentials.mjs';
import { ManagementClient } from '../../model-proxy/src/client.mjs';
import { ModelKeys, REVOKE_TIMEOUT_MS, REVOKE_POLL_MS } from '../src/model-keys.mjs';
import { ModelKeys, REVOKE_TIMEOUT_MS, REVOKE_POLL_MS, ISSUE_PROBE_TIMEOUT_MS, ISSUE_REPROBE_MIN_MS } from '../src/model-keys.mjs';
import { startBroker } from '../src/runtime.mjs';
import { busOrganization } from '../src/organization-context.mjs';
import { Registry } from '../../seat/src/session.mjs';
@@ -42,6 +42,7 @@ async function fixture(t, { delayed = 0 } = {}) {
const key = req.headers.authorization?.slice(7);
const accepted = state.keys.includes(key) || (state.removed.has(key) && performance.now() - state.removed.get(key) < state.delay);
state.onProbe?.(state.status ?? (accepted ? 200 : 401));
if (state.stallProbe?.()) return;
res.writeHead(state.status ?? (accepted ? 200 : 401)); res.end('{}');
});
await new Promise(resolve => server.listen(0, '127.0.0.1', resolve));
@@ -123,10 +124,33 @@ test('proxy-revoke-revision-conflict keeps local revoking record and ids-only re
assert.equal(JSON.stringify(f.receipts).includes(key), false);
await f.create().reconcile(); assert.equal(f.credentials.modelRecord('demo/coder') === null, true);
});
for (const status of [401, 503, 302]) test(`proxy-key-refused: preflight rejects HTTP ${status} with exactly one probe`, async t => {
for (const status of [503, 302]) test(`proxy-key-refused: preflight rejects HTTP ${status} with exactly one probe`, async t => {
const f = await fixture(t); await f.manager.reconcile(); await f.manager.ensure('demo/coder'); f.state.status = status;
await assert.rejects(f.manager.preflight('demo/coder'), failCode('proxy-key-refused')); assert.equal(f.state.probes, 1);
});
test('proxy-key-refused: a key that keeps answering 401 refuses once the short probe deadline passes', async t => {
const f = await fixture(t); await f.manager.reconcile(); await f.manager.ensure('demo/coder'); f.state.status = 401;
const started = performance.now();
await assert.rejects(f.manager.preflight('demo/coder'), failCode('proxy-key-refused'));
const took = performance.now() - started;
assert.ok(f.state.probes > 1, 'a 401 is probed again'); assert.ok(took >= ISSUE_PROBE_TIMEOUT_MS && took < ISSUE_PROBE_TIMEOUT_MS + 2000, `bounded: ${took}`);
});
test('proxy-down: a re-probe that stalls ends near the probe deadline, not the client default', async t => {
const f = await fixture(t); await f.manager.reconcile(); await f.manager.ensure('demo/coder'); f.state.status = 401;
f.state.stallProbe = () => f.state.probes >= 2;
const started = performance.now();
await assert.rejects(f.manager.preflight('demo/coder'), failCode('proxy-down'));
const took = performance.now() - started;
assert.equal(f.state.probes, 2); assert.ok(took < ISSUE_PROBE_TIMEOUT_MS + ISSUE_REPROBE_MIN_MS + 1000, `bounded: ${took}`);
});
// Every v8 CLIProxyAPI applies the PUT by an async reload; on 8.0.79 a just-issued key answers 401
// past the confirming GET (#1873).
test('first launch passes when the proxy applies the new key a moment after the PUT answers', async t => {
const f = await fixture(t); await f.manager.reconcile(); f.state.status = 401;
f.state.onProbe = () => { if (f.state.probes === 3) f.state.status = null; };
const answer = await f.manager.preflight('demo/coder');
assert.equal(f.state.probes, 3); assert.equal(f.state.keys.includes(answer.key), true);
});
test('rotate keeps old key while its run lives, new launches use new, exit removes old', async t => {
const f = await fixture(t); await f.manager.reconcile(); const first = await f.manager.ensure('demo/coder');
f.runs.push({ instance: 'demo/coder', run: 'old', keyId: hash(first.key) });
+299
View File
@@ -0,0 +1,299 @@
// #1873 pickup-launch: a bus that picked up the shared proxy late serves accounts and a ready
// catalogue, but a launch on a proxy model still needs a restart (no ModelKeys on the bus, no proxy
// in the host launcher's boot system). While it holds such a client, its catalogue answer says so
// in one plain notice, and a launch refuses exactly as before. A refused or dropped client shows
// its cause instead. Real buses, a real launcher whose model ops go to the bus, a fake loopback
// management server; no live config.
import test from 'node:test';
import assert from 'node:assert/strict';
import fs from 'node:fs';
import http from 'node:http';
import { join } from 'node:path';
import { tmpdir } from 'node:os';
import { createHash, randomBytes } from 'node:crypto';
import { pathToFileURL } from 'node:url';
import { startBroker } from '../src/runtime.mjs';
import { busOrganization } from '../src/organization-context.mjs';
import { createProxyLock } from '../src/proxy-lock.mjs';
import { Registry, launchLogFile } from '../../seat/src/session.mjs';
import { loadBusiness } from '../../organization/src/organization-config.mjs';
import { resolveInstance } from '../../organization/src/resolve.mjs';
import { businessDoc, rolesCopy, systemFor, writeJson } from '../../organization/tests/helpers.mjs';
import { PIN } from '../../model-proxy/src/common.mjs';
import { initializeProxy, installPaths, loadProxy } from '../../model-proxy/src/settings.mjs';
import { createLauncher } from '../../cli/src/launcher.mjs';
import { initializeControl } from '../../processing-control/src/state.mjs';
import { ZAI_URL } from '../../plugins/model-provider/cliproxy/index.mjs';
import { fakeHarnesses, humanEnv, withoutHostCredentials } from '../../cli/tests/helpers.mjs';
import { REPO_SKILLS } from '../../harness/tests/helpers.mjs';
const RESTART = 'Restart this organization to start agents on these models.';
const MODEL = 'claude-claude-opus-5-5';
const sha = value => createHash('sha256').update(value).digest('hex');
// A loopback stand-in for the proxy's management API: one ready Claude account with one model,
// and an access key list that keeps what a PUT sends, so a boot ModelKeys reconciles against it.
async function fakeProxy(t, key, port = 0, { groups = [] } = {}) {
const seen = { calls: 0, wrongKey: 0 };
let accessKeys = [];
const server = http.createServer((req, res) => {
seen.calls++;
if (req.headers.authorization !== `Bearer ${key}`) { seen.wrongKey++; res.writeHead(401); res.end('{}'); return; }
const url = new URL(req.url, 'http://127.0.0.1');
if (url.pathname === '/v8/management/config/access/api-keys' && req.method === 'PUT') {
const chunks = [];
req.on('data', c => chunks.push(c));
req.on('end', () => { accessKeys = JSON.parse(Buffer.concat(chunks)); res.end(JSON.stringify({ status: 'ok' })); });
return;
}
const answer = url.pathname === '/v8/management/credentials' ? { files: [{ id: 'acct-1', name: 'acct-1', provider: 'claude', status: 'ready', priority: 1 }] }
: url.pathname === '/v8/management/credentials/models' ? { models: [{ id: 'claude-opus-5-5' }] }
: url.pathname === '/v8/management/config/api-keys/claude' ? groups
: url.pathname === '/v8/management/config/access/api-keys' ? accessKeys
: null;
if (answer === null) { res.writeHead(404); res.end('{}'); return; }
res.end(JSON.stringify(answer));
});
await new Promise((resolve, reject) => { server.once('error', reject); server.listen(port, '127.0.0.1', resolve); });
t.after(async () => { server.closeAllConnections(); await new Promise(resolve => server.close(resolve)); });
return { port: server.address().port, seen, server };
}
// One instance (config dir + data root) and a fake proxy install whose bytes a test pin names.
function instance(t) {
const root = fs.mkdtempSync(join(tmpdir(), 'pl-'));
t.after(() => fs.rmSync(root, { recursive: true, force: true }));
const configDir = join(root, 'config'), dataRoot = join(root, 'instance');
fs.mkdirSync(join(configDir, 'secrets', 'agents'), { recursive: true, mode: 0o700 });
fs.chmodSync(join(configDir, 'secrets'), 0o700);
fs.mkdirSync(dataRoot, { mode: 0o700 });
const paths = installPaths(dataRoot);
fs.mkdirSync(join(paths.dir, 'static'), { recursive: true, mode: 0o700 });
fs.writeFileSync(paths.binary, 'fixture proxy binary\n', { mode: 0o700 });
fs.writeFileSync(paths.panel, '<!doctype html>\n', { mode: 0o600 });
const pin = { ...PIN, binary: { ...PIN.binary, sha256: sha('fixture proxy binary\n') }, panel: { ...PIN.panel, sha256: sha('<!doctype html>\n') } };
const rolesDir = rolesCopy(root), system = systemFor(root);
const key = `pl1873-${randomBytes(24).toString('hex')}`;
return { root, configDir, dataRoot, paths, pin, rolesDir, system, key };
}
// A real organization bus on the instance, started with no proxy unless `binding.proxy` gives one.
async function orgBus(t, f, id, { providers = ['cliproxy'], binding = {} } = {}) {
const doc = businessDoc(f.root, id);
doc.plugins = { harness: ['pi'], 'model-provider': providers };
writeJson(join(f.configDir, 'businesses', `${id}.json`), doc);
const business = loadBusiness(id, { dir: f.configDir, rolesDir: f.rolesDir }), resolved = {};
for (const name of Object.keys(business.roles)) resolved[name] = resolveInstance({ system: f.system, business, instance: name });
const dataRoot = join(f.root, `${id}-bus`); fs.mkdirSync(dataRoot, { mode: 0o700 }); new Registry(dataRoot);
const bus = await startBroker({ dataRoot, businesses: { [id]: busOrganization(business, resolved) },
organization: { dir: f.configDir, rolesDir: f.rolesDir, system: f.system },
instanceRoot: f.dataRoot, org: { id }, instanceDataRoot: f.dataRoot, instanceConfigDir: f.configDir,
initProxy: args => initializeProxy({ ...args, pin: f.pin }), ...binding });
t.after(() => bus.close().catch(() => {}));
const human = bus.broker.bindHuman({ business: id, human: 'jason', via: 'cli', outsideAgent: true });
const ask = (verb, args) => Promise.resolve().then(() => bus.broker.request(human, { verb, args }));
return { id, bus, ask, dataRoot };
}
// Every stderr line written while `run` is in flight.
async function capture(run) {
const write = process.stderr.write, lines = [];
process.stderr.write = (chunk, ...rest) => { lines.push(String(chunk)); return write.call(process.stderr, chunk, ...rest); };
try { return { value: await run(), lines }; } finally { process.stderr.write = write; }
}
async function initThroughA(t, f, a, options) {
const settings = await a.ask('proxy.init', { key: f.key });
const proxy = await fakeProxy(t, f.key, settings.port, options);
return { settings, proxy };
}
// The owner picks the catalogue's proxy model for the coder on the Routing page, through the bus.
async function pickModel(o) {
const view = await o.ask('routes');
assert.equal(view.catalogue.status, 'ready');
assert.ok(view.catalogue.models.some(m => m.key === MODEL));
await o.ask('routes.set', { revision: view.revision, routes: { coder: { harness: 'pi', model: MODEL, thinking: 'low', fallback: null } } });
}
// The host launcher as cli.mjs builds it for a bus that booted with no proxy.json: its system has
// no proxy. The model ops go to the bus itself; the rest are the launch-routes stub, and
// authorizeLaunch stops a launch that passed every check before it.
async function hostLauncher(t, f, o, { system = {} } = {}) {
initializeControl(o.dataRoot);
// A launch whose role names a skill that is not enabled refuses before the model gate.
if (!fs.existsSync(join(f.dataRoot, 'skills-enabled'))) fs.cpSync(REPO_SKILLS, join(f.dataRoot, 'skills-enabled'), { recursive: true });
const env = withoutHostCredentials(humanEnv({ MOSAIC_CONFIG: join(f.configDir, 'config.json'), MOSAIC_ROLES_DIR: f.rolesDir }), { piKey: true });
const answers = [], ops = [];
const host = { business: o.id, beforeClose: () => {}, op: async m => {
ops.push(m.op);
if (m.op === 'identity') return { business: o.id, role: 'pm' };
if (m.op === 'mayLaunch') return { allow: true };
if (m.op === 'modelAdmission' || m.op === 'modelPreflight') { const answer = await o.bus[m.op](m); answers.push({ op: m.op, answer }); return answer; }
if (m.op === 'authorizeLaunch') throw Object.assign(Error('fixture authorization stop'), { code: 'fixture-policy' });
return {};
} };
const cliproxy = JSON.stringify(pathToFileURL(new URL('../../plugins/model-provider/cliproxy/index.mjs', import.meta.url).pathname).href);
const makeLoader = await fakeHarnesses(t, { pi: null }, write => write('model-provider', 'cliproxy', `export * from ${cliproxy};\n`));
// The validated system config shape (mosaic-config.mjs), as cli.mjs passes it with the org root.
const config = { configVersion: 1, environment: 'development', dataRoot: o.dataRoot, instanceRoot: f.dataRoot,
execution: { backend: 'docker', provider: 'zai', model: 'glm-5.3-flash', adapter: 'mock' }, ...system };
const launcher = createLauncher({ host, system: config, env, makeLoader, bwrap: '/usr/bin/true', log: () => {} });
t.after(() => launcher.close?.().catch?.(() => {}));
const events = () => { try { return fs.readFileSync(launchLogFile(o.dataRoot, o.id), 'utf8').trim().split('\n').filter(Boolean).map(l => JSON.parse(l)); } catch { return []; } };
return { launch: () => launcher.fromSession('fixture-cap', 'coder'), answers, ops, events };
}
const restartNotices = view => view.catalogue.notices.filter(n => n === RESTART).length;
test('a bus that picked up the proxy says on its ready catalogue that a restart starts agents on these models, and the launch refuses as before', async t => {
const f = instance(t);
const a = await orgBus(t, f, 'alpha'), b = await orgBus(t, f, 'beta');
const before = await b.ask('routes');
assert.equal(before.catalogue.status, 'unavailable');
assert.equal(restartNotices(before), 0, 'no client yet: the not-set-up cause, not the restart notice');
await initThroughA(t, f, a);
await pickModel(b);
const view = await b.ask('routes');
assert.equal(view.catalogue.status, 'ready');
assert.equal(restartNotices(view), 1);
assert.equal(restartNotices(await b.ask('routes')), 1, 'one notice at every read');
// The bus that ran init holds a client it did not boot with too.
const own = await a.ask('routes');
assert.equal(own.catalogue.status, 'ready');
assert.equal(restartNotices(own), 1);
// The launch refuses as before, with the existing code and line, before any key or run: the
// launcher booted with no proxy sends no proxy transport, and the bus's admission refuses that.
const host = await hostLauncher(t, f, b);
assert.deepEqual(await host.launch(), { ok: false, error: 'model-provider-unavailable' });
assert.deepEqual(host.answers, [{ op: 'modelAdmission', answer: { allow: false, code: 'model-provider-unavailable' } }]);
assert.equal(host.ops.includes('authorizeLaunch'), false);
assert.equal(host.ops.includes('modelPreflight'), false);
const refused = host.events().filter(e => e.event === 'refused');
assert.equal(refused.length, 1);
assert.equal(refused[0].code, 'model-provider-unavailable');
assert.equal(refused[0].why, 'model cliproxy/claude/claude-opus-5-5 unavailable (model-provider-unavailable)');
// The bus side has no ModelKeys: a preflight issues no key.
assert.equal(await b.bus.modelPreflight({ business: 'beta', role: 'coder' }), null);
});
test('the restart notice is added after the notices the catalogue already carries', async t => {
const f = instance(t);
const a = await orgBus(t, f, 'alpha'), b = await orgBus(t, f, 'beta');
// A z.ai upstream group with no models: the cliproxy catalogue's own notice.
await initThroughA(t, f, a, { groups: [{ 'base-url': ZAI_URL, keys: [{ name: 'group-1' }] }] });
const view = await b.ask('routes');
assert.equal(view.catalogue.status, 'ready');
assert.deepEqual(view.catalogue.notices, ['z.ai account has no models configured. Add them on Model proxy.', RESTART]);
});
test('a bus started with the proxy shows no restart notice', async t => {
const f = instance(t);
const a = await orgBus(t, f, 'alpha');
await initThroughA(t, f, a);
const c = await orgBus(t, f, 'gamma', { binding: { proxy: loadProxy(f.configDir, f.dataRoot) } });
const view = await c.ask('routes');
assert.equal(view.catalogue.status, 'ready', JSON.stringify(view.catalogue));
assert.deepEqual(view.catalogue.notices, []);
});
test('an organization with no model provider shows a disabled catalogue with no restart notice (the routes verb answers disabled itself)', async t => {
const f = instance(t);
const a = await orgBus(t, f, 'alpha'), b = await orgBus(t, f, 'beta', { providers: [] });
await initThroughA(t, f, a);
await b.ask('proxy.accounts', {});
assert.ok(b.bus.modelProxy, 'the client is held');
const view = await b.ask('routes');
assert.equal(view.catalogue.status, 'disabled');
assert.deepEqual(view.catalogue.notices, []);
});
test('a fenced catalogue on a picked-up client reads unavailable with no restart notice, since a restart would not help', async t => {
const f = instance(t);
const a = await orgBus(t, f, 'alpha'), b = await orgBus(t, f, 'beta');
const { proxy } = await initThroughA(t, f, a);
assert.equal(restartNotices(await b.ask('routes')), 1);
createProxyLock({ stateDir: join(f.dataRoot, 'proxy'), identity: `${f.configDir}:${proxy.port}` }).fence({ org: 'alpha' });
const view = await b.ask('routes');
assert.equal(view.catalogue.status, 'unavailable');
assert.ok(b.bus.modelProxy);
assert.equal(restartNotices(view), 0);
// A bus that booted with the proxy on the same fenced instance, which is what a restart gives,
// reads the same unavailable catalogue: the restart notice would have sent the owner nowhere.
const c = await orgBus(t, f, 'gamma', { binding: { proxy: loadProxy(f.configDir, f.dataRoot) } });
assert.equal((await c.ask('routes')).catalogue.status, 'unavailable');
// Once the fence is gone, the ready catalogue says again that a restart is needed.
fs.rmSync(join(f.dataRoot, 'proxy', 'mosaic-keys.uncertain'));
const after = await b.ask('routes');
assert.equal(after.catalogue.status, 'ready', JSON.stringify(after.catalogue));
assert.equal(restartNotices(after), 1);
});
test('refused settings still refuse the launch and name their cause, not the restart notice', async t => {
const f = instance(t);
const a = await orgBus(t, f, 'alpha'), b = await orgBus(t, f, 'beta');
await initThroughA(t, f, a);
await pickModel(b);
// The management key file stops being private: the start path refuses it.
fs.chmodSync(join(f.configDir, 'secrets', 'proxy-management.key'), 0o644);
const view = await b.ask('routes');
assert.equal(view.catalogue.status, 'unavailable');
assert.equal(view.catalogue.reason, 'proxy-not-configured');
assert.equal(view.catalogue.notices.length, 1);
assert.match(view.catalogue.notices[0], /management key does not load/);
assert.equal(b.bus.modelProxy, null);
const host = await hostLauncher(t, f, b);
// The bus itself refuses now: the catalogue keeps the model it saw, marked unavailable.
assert.deepEqual(await host.launch(), { ok: false, error: 'model-provider-unavailable' });
assert.deepEqual(host.answers, [{ op: 'modelAdmission', answer: { allow: false, code: 'model-provider-unavailable' } }]);
assert.match(host.events().at(-1).why, /^model cliproxy\/claude\/claude-opus-5-5 unavailable \(model-provider-unavailable\)$/);
});
test('a dropped client refuses the next launch, and the catalogue names the cause instead of the restart notice', async t => {
const f = instance(t);
const a = await orgBus(t, f, 'alpha'), b = await orgBus(t, f, 'beta');
await initThroughA(t, f, a);
await pickModel(b);
const host = await hostLauncher(t, f, b);
assert.deepEqual(await host.launch(), { ok: false, error: 'model-provider-unavailable' });
assert.equal(restartNotices(await b.ask('routes')), 1);
fs.rmSync(join(f.configDir, 'proxy.json'));
// The next launch refuses with the same code and line.
assert.deepEqual(await host.launch(), { ok: false, error: 'model-provider-unavailable' });
assert.deepEqual(host.answers.map(a => a.answer), [{ allow: false, code: 'model-provider-unavailable' }, { allow: false, code: 'model-provider-unavailable' }]);
assert.equal(host.events().filter(e => e.event === 'refused').length, 2);
// The page's next read drops the client and names the cause.
const view = await b.ask('routes');
assert.equal(b.bus.modelProxy, null);
assert.equal(view.catalogue.status, 'unavailable');
assert.equal(view.catalogue.reason, 'proxy-not-configured');
assert.deepEqual(view.catalogue.notices.length, 1);
assert.match(view.catalogue.notices[0], /not been set up/);
});
test('the management key is in no stderr line, response, refusal, launch log or file the launch path writes', async t => {
const f = instance(t);
const a = await orgBus(t, f, 'alpha'), b = await orgBus(t, f, 'beta');
await initThroughA(t, f, a);
await pickModel(b);
const host = await hostLauncher(t, f, b);
const outputs = [];
const { lines } = await capture(async () => {
outputs.push(await b.ask('routes'));
outputs.push(await host.launch());
outputs.push(await b.bus.modelPreflight({ business: 'beta', role: 'coder' }));
fs.chmodSync(join(f.configDir, 'secrets', 'proxy-management.key'), 0o644);
outputs.push(await b.ask('routes'));
outputs.push(await host.launch());
fs.chmodSync(join(f.configDir, 'secrets', 'proxy-management.key'), 0o600);
outputs.push(await b.ask('routes'));
outputs.push(await host.launch());
});
outputs.push(host.answers, host.events());
assert.equal(lines.join('').includes(f.key), false, 'stderr');
assert.equal(JSON.stringify(outputs).includes(f.key), false, 'responses, answers and launch log');
const walk = dir => fs.readdirSync(dir, { withFileTypes: true }).flatMap(e => e.isDirectory() ? walk(join(dir, e.name)) : e.isFile() ? [join(dir, e.name)] : []);
const files = [...walk(b.dataRoot), ...walk(join(f.dataRoot, 'proxy')).filter(p => !p.endsWith('/config.yaml'))];
assert.ok(files.some(p => p === launchLogFile(b.dataRoot, 'beta')), 'the launch log is scanned');
for (const file of files) assert.equal(fs.readFileSync(file).includes(f.key), false, file);
});
+5 -5
View File
@@ -1,12 +1,12 @@
{
"version": "8.0.42",
"version": "8.0.79",
"archive": {
"asset": "CLIProxyAPI_8.0.42_linux_amd64.tar.gz",
"url": "https://github.com/router-for-me/CLIProxyAPI/releases/download/v8.0.42/CLIProxyAPI_8.0.42_linux_amd64.tar.gz",
"sha256": "1e10566fe0042ed5a9b80306cf296bf86a83de590cd967a8b177988b896c8d31"
"asset": "CLIProxyAPI_8.0.79_linux_amd64.tar.gz",
"url": "https://github.com/router-for-me/CLIProxyAPI/releases/download/v8.0.79/CLIProxyAPI_8.0.79_linux_amd64.tar.gz",
"sha256": "7cbb9709ed939ff3684e10592a45cc538ee82d5da759daa7e18c7e1dc3b32acd"
},
"binary": {
"sha256": "74661f8cf949977870231359e8bf4344e07946766a673c08fa25a3e5f72fc95e"
"sha256": "4968bd27b04f813849add020b95a26dc7abf3e30810b97d291c0d88f495fe601"
},
"panel": {
"version": "1.26.7",
+21 -1
View File
@@ -56,8 +56,28 @@ uses a new temp root and private network namespace, with made-up credentials,
and calls the page's bus verbs. If the page cannot pass against the new PIN,
the upgrade stops; Sage takes Q46's fallback to Jason through Mos.
A running instance takes a new PIN in three steps, in this order. First run
the new code: update the checkout or pinned copy the bus, Console and proxy
unit start from. The proxy unit runs `run.mjs` and reads `PIN` from the tree
it was installed from (`systemctl --user cat <unit>` shows it). If the new
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
under `<dataRoot>/opt/cliproxyapi/<version>/`. 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
Console as well so their status and Fetch use the new PIN. `proxy.json` keeps
the path from the PIN it was created under. That path stays valid, and the
proxy always runs the hash-verified install for the current PIN. Signed-in
accounts in `<dataRoot>/proxy/auth/` carry over. From 8.0.55 the proxy also
keeps a `kv.db` file in that directory, and 8.0.79 adds a `.codex-refresh/`
directory there once a Codex account renews. The old release directory can be
removed once the new one runs.
The native `/proxy` page uses human-only bus verbs; only the bus holds the
management client. On PIN 8.0.42, OAuth credentials are listed under
management client. On PIN 8.0.79, OAuth credentials are listed under
`/v8/management/credentials` and priority is patched as `{name, priority}`.
API-key groups are absent from that list: z.ai keys use the Claude-compatible
provider configuration at `/v8/management/config/api-keys/claude`, whose keys
+13 -2
View File
@@ -7,12 +7,23 @@ export function installPaths(dataRoot, pin = PIN) {
const dir = path.join(dataRoot, 'opt', 'cliproxyapi', pin.version);
return { dir, binary: path.join(dir, 'cli-proxy-api'), panel: path.join(dir, 'static', 'management.html') };
}
// proxy.json records the install path from the PIN it was created under, and nothing
// rewrites it. After a PIN bump an earlier release's path under this data root stays valid
// and reads as the current pinned path. The runner executes only the hash-verified pinned
// install, never the recorded path, so an old value selects nothing.
const releasePath = (dataRoot, binary) => {
const base = path.join(dataRoot, 'opt', 'cliproxyapi') + path.sep;
if (typeof binary !== 'string' || !binary.startsWith(base)) return false;
const [version, file, ...rest] = binary.slice(base.length).split(path.sep);
return rest.length === 0 && file === 'cli-proxy-api' && /^\d{1,4}\.\d{1,4}\.\d{1,6}$/.test(version);
};
export function validateProxy(value, dataRoot, pin = PIN) {
const pinned = installPaths(dataRoot, pin).binary;
if (!value || typeof value !== 'object' || Array.isArray(value)
|| Object.keys(value).some(k => !['binary', 'port', 'rotateGraceMinutes', 'firstOutputSeconds'].includes(k))
|| !Number.isInteger(value.port) || value.port < 1024 || value.port > 65535 || value.port === 8317
|| value.binary !== installPaths(dataRoot, pin).binary) refuse('proxy-config-invalid');
return { port: value.port, binary: value.binary, ...proxyTiming(value) };
|| (value.binary !== pinned && !releasePath(dataRoot, value.binary))) refuse('proxy-config-invalid');
return { port: value.port, binary: pinned, ...proxyTiming(value) };
}
export function loadProxy(configDir, dataRoot) {
const file = path.join(configDir, 'proxy.json');
@@ -1,4 +1,4 @@
// P4 pinned8.0.42 regression: absent Claude provider config is HTTP404.
// P4 regression since PIN 8.0.42 (still so on 8.0.79): absent Claude provider config is HTTP 404.
// Normalize only that fixed GET; all other methods/endpoints/statuses refuse.
import test from 'node:test';
import assert from 'node:assert/strict';
@@ -13,3 +13,13 @@ for (const [field, maximum, code] of [['rotateGraceMinutes', 1440, 'proxy-rotate
assert.throws(() => validateProxy({ ...base, [field]: value }, dataRoot), e => e.code === code);
});
}
// #1873 PIN bump: a sidecar written under an earlier PIN keeps the instance config valid.
test('a proxy.json written under an earlier PIN reads as the current pinned path', () => {
const old = { ...base, binary: '/fixture-data/opt/cliproxyapi/8.0.42/cli-proxy-api' };
assert.deepEqual(validateProxy(old, dataRoot), base);
assert.deepEqual(validateProxy({ ...old, rotateGraceMinutes: 60 }, dataRoot), { ...base, rotateGraceMinutes: 60 });
});
for (const binary of ['/bad', '/fixture-data/opt/cliproxyapi/8.0.42/other', '/fixture-data/opt/cliproxyapi/latest/cli-proxy-api',
'/fixture-data/opt/cliproxyapi/8.0.42/x/cli-proxy-api', '/fixture-data/opt/cliproxyapi/../cliproxyapi/8.0.42/cli-proxy-api',
'/other-data/opt/cliproxyapi/8.0.42/cli-proxy-api', '/fixture-data/opt/cliproxyapi/8.0/cli-proxy-api', 7])
test(`proxy-config-invalid: binary ${JSON.stringify(binary)}`, () => assert.throws(() => validateProxy({ ...base, binary }, dataRoot), e => e.code === 'proxy-config-invalid'));
@@ -1,4 +1,4 @@
// P4 client contract; endpoint/payload cases are probe-pending on PIN8.0.42.
// P4 client contract; endpoint/payload cases were probe-pending on PIN 8.0.42.
// Catches management key/body/query values leaking into receipts, redirects/retries.
import test from 'node:test';
import assert from 'node:assert/strict';