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.
This commit is contained in:
1 parent
d0293d6602
commit
462215b4bd
6 files changed
+70
-12
No files matched your search
@@ -6,6 +6,7 @@ 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 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 +224,17 @@ export class ModelKeys {
|
||||
this.#sentinel(keys);
|
||||
return this.#issue(instance, false, keys);
|
||||
});
|
||||
// CLIProxyAPI applies a key-list PUT by an async reload after it answers. From 8.0.79 a
|
||||
// just-issued key answers 401 for a few milliseconds, so only 401 is probed again until a
|
||||
// short deadline. Any other non-2xx refuses on the first answer, as before.
|
||||
const deadline = performance.now() + ISSUE_PROBE_TIMEOUT_MS;
|
||||
let status;
|
||||
try { status = await this.#client.probeKey(proxy.key); }
|
||||
catch { fail('proxy-down'); }
|
||||
for (;;) {
|
||||
try { status = await this.#client.probeKey(proxy.key); }
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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 } 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';
|
||||
@@ -123,10 +123,24 @@ 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}`);
|
||||
});
|
||||
// CLIProxyAPI 8.0.79 answers 401 for a just-issued key for a few milliseconds after the PUT.
|
||||
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) });
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -56,8 +56,22 @@ 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. 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. 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
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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'));
|
||||
Reference in new issue
Block a user