@opennodes/registry 0.1.54 → 0.1.56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/package.json +1 -1
- package/src/corpus.js +24 -0
- package/src/location.js +93 -9
- package/src/schedule.js +27 -6
- package/src/server.js +14 -5
- package/src/stageb.js +17 -5
- package/src/stagec.js +54 -2
- package/src/web/index.html +1 -1
package/README.md
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
The OpenNodes Protocol (ONP) reference registry — an open, federatable discovery service for AI inference nodes.
|
|
4
4
|
|
|
5
5
|
```bash
|
|
6
|
-
npx @opennodes/registry@0.1.
|
|
7
|
-
ONP_DB=./registry.db npx @opennodes/registry@0.1.
|
|
8
|
-
ONP_DB=postgres://user:pass@host/db npx @opennodes/registry@0.1.
|
|
6
|
+
npx @opennodes/registry@0.1.56 # web app + API on http://127.0.0.1:4300
|
|
7
|
+
ONP_DB=./registry.db npx @opennodes/registry@0.1.56 # persistent SQLite + persistent signing key
|
|
8
|
+
ONP_DB=postgres://user:pass@host/db npx @opennodes/registry@0.1.56
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
What it does:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opennodes/registry",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.56",
|
|
4
4
|
"description": "OpenNodes (ONP) reference registry: node registration with proof-of-resource qualification (Stage A/B/C), transparent ranking, enforceable estimates, catalog importers (OpenRouter, Hugging Face, models.dev, Ollama), MCP surface, and the web app (catalog, chat, advisor, Node Builder)",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
package/src/corpus.js
CHANGED
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
// "filler": ["long passages of plain prose"], // the context probes' haystack
|
|
12
12
|
// "needles": [{"fact": "… {n} …", "question": "…"}] // the fact hidden in the haystack ({n}: an 8-digit number)
|
|
13
13
|
// }
|
|
14
|
+
// One request is not a probe and takes no corpus text: the origin comparison behind a CDN
|
|
15
|
+
// (location.js checkOrigins, ONP-3 §6.4) announces itself, so it asks originPrompt() below instead.
|
|
14
16
|
// Identity prompts must read like the chat prompts (same kind of request, length and tone), or be
|
|
15
17
|
// left out so that references are captured from chat prompts: Stage C asks some of them in blind
|
|
16
18
|
// probes (stagec.js), which only work if a node cannot pick them out from the ordinary ones.
|
|
@@ -30,6 +32,26 @@ export const LEGACY_IDENTITY_PROMPTS = Object.freeze([
|
|
|
30
32
|
export const IDENTITY_CAPTURE = 8;
|
|
31
33
|
export const IDENTITY_SAMPLE = 3;
|
|
32
34
|
|
|
35
|
+
/**
|
|
36
|
+
* Prompts for the origin comparison behind a CDN (ONP-3 §6.4). It is labelled and an operator can set
|
|
37
|
+
* it off at will (a card that changes its origin addresses is checked at once), so it must never ask
|
|
38
|
+
* corpus text: that would show the operator the identity references or the blind probes. These are
|
|
39
|
+
* public on purpose, and each carries a random number, so that no reply can be prepared in advance.
|
|
40
|
+
*/
|
|
41
|
+
export const ORIGIN_PROMPT_TEMPLATES = Object.freeze([
|
|
42
|
+
'Write one sentence about the number {n}.',
|
|
43
|
+
'Invent a short name for a shop at number {n} on a high street.',
|
|
44
|
+
'Describe the number {n} in a few words.',
|
|
45
|
+
'Write a short line of a poem that mentions the number {n}.',
|
|
46
|
+
'Say something interesting about the number {n}, in one sentence.',
|
|
47
|
+
]);
|
|
48
|
+
|
|
49
|
+
/** One origin-comparison prompt: a template with a random six-digit number. */
|
|
50
|
+
export function originPrompt(random = Math.random) {
|
|
51
|
+
const template = ORIGIN_PROMPT_TEMPLATES[Math.floor(random() * ORIGIN_PROMPT_TEMPLATES.length)];
|
|
52
|
+
return template.replace('{n}', String(100_000 + Math.floor(random() * 900_000)));
|
|
53
|
+
}
|
|
54
|
+
|
|
33
55
|
const DEFAULT_NEEDLE = Object.freeze({
|
|
34
56
|
fact: 'The magic number is {n}.',
|
|
35
57
|
question: 'What is the magic number mentioned in the text above? Reply with the number only.',
|
|
@@ -144,6 +166,8 @@ export function loadCorpus(source = null, { random = Math.random } = {}) {
|
|
|
144
166
|
/** Prompts for a reference capture. */
|
|
145
167
|
identityPrompts: (k = IDENTITY_CAPTURE) => sample(identity, k, random),
|
|
146
168
|
needle: () => pickFrom(needles, random),
|
|
169
|
+
/** A prompt for the origin comparison: never corpus text (originPrompt above). */
|
|
170
|
+
originPrompt: () => originPrompt(random),
|
|
147
171
|
/** `chars` characters of haystack, from the filler passages in random order. */
|
|
148
172
|
haystack(chars) {
|
|
149
173
|
const n = Math.max(0, Math.floor(chars));
|
package/src/location.js
CHANGED
|
@@ -178,31 +178,53 @@ export function modelIds(body) {
|
|
|
178
178
|
} catch { return null; }
|
|
179
179
|
}
|
|
180
180
|
|
|
181
|
+
/**
|
|
182
|
+
* The reply text of an OpenAI-style chat completion, or null. An empty or whitespace-only reply is no
|
|
183
|
+
* reply: one empty answer matches any other, so a decoy that always answers "" would otherwise pass
|
|
184
|
+
* for models that spend their whole token budget on reasoning.
|
|
185
|
+
*/
|
|
186
|
+
export function chatText(body) {
|
|
187
|
+
try {
|
|
188
|
+
const text = JSON.parse(body)?.choices?.[0]?.message?.content;
|
|
189
|
+
return typeof text === 'string' && text.trim() ? text : null;
|
|
190
|
+
} catch { return null; }
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** The origin comparison asks through the CDN and at each origin like Stage B does: temperature 0, this many tokens. */
|
|
194
|
+
export const ORIGIN_IDENTITY_MAX_TOKENS = 64;
|
|
195
|
+
|
|
181
196
|
/**
|
|
182
197
|
* Ask the server at `ip` for the API, as the API host: it must complete a TLS handshake for `host` (SNI)
|
|
183
198
|
* with a certificate valid for that name under the public CA roots, then answer GET `path` with Host:
|
|
184
199
|
* `host` (and `headers`, such as the registry's probe credential, sent only after the certificate is
|
|
185
200
|
* accepted). Connects to the address itself on port 443: no DNS, no redirects. `ok` when the handshake
|
|
186
201
|
* completes and the status is below 500; `models` is the model list when the answer is 200 with an
|
|
187
|
-
* OpenAI-style list, else null. Used for the CDN front and for each declared origin alike.
|
|
188
|
-
* the
|
|
202
|
+
* OpenAI-style list, else null. Used for the CDN front and for each declared origin alike. With `body`
|
|
203
|
+
* the request is a POST of that JSON instead (a chat completion), and `text` is the reply's text, else
|
|
204
|
+
* null. (`ca` replaces the public roots in tests only.)
|
|
189
205
|
*/
|
|
190
|
-
export function probeOrigin(ip, host, { path = '/', headers = {}, timeoutMs = 10_000, port = 443, ca } = {}) {
|
|
206
|
+
export function probeOrigin(ip, host, { path = '/', headers = {}, body = null, timeoutMs = 10_000, port = 443, ca } = {}) {
|
|
191
207
|
return new Promise((resolve) => {
|
|
192
208
|
// One deadline for the whole exchange: the socket's idle timeout alone would let a server that
|
|
193
209
|
// drips its answer hold the check (and the daily sweep behind it) open.
|
|
194
210
|
let deadline = null;
|
|
195
211
|
const settle = (result) => { clearTimeout(deadline); resolve(result); };
|
|
212
|
+
const payload = body === null ? null : JSON.stringify(body);
|
|
196
213
|
const req = https.request({
|
|
197
|
-
host: ip, port, servername: host, path, method: 'GET', agent: false, timeout: timeoutMs, ...(ca ? { ca } : {}),
|
|
198
|
-
headers: {
|
|
214
|
+
host: ip, port, servername: host, path, method: payload === null ? 'GET' : 'POST', agent: false, timeout: timeoutMs, ...(ca ? { ca } : {}),
|
|
215
|
+
headers: {
|
|
216
|
+
...headers, host, accept: 'application/json', 'user-agent': 'opennodes-registry (origin check)',
|
|
217
|
+
...(payload === null ? {} : { 'content-type': 'application/json', 'content-length': Buffer.byteLength(payload) }),
|
|
218
|
+
},
|
|
199
219
|
}, (res) => {
|
|
200
220
|
const status = res.statusCode;
|
|
201
221
|
const chunks = [];
|
|
202
222
|
let size = 0;
|
|
203
223
|
const done = () => {
|
|
204
|
-
const
|
|
205
|
-
|
|
224
|
+
const raw = status === 200 && size <= MAX_LIST_BYTES ? Buffer.concat(chunks).toString('utf8') : null;
|
|
225
|
+
const models = raw === null ? null : modelIds(raw);
|
|
226
|
+
const reply = payload === null ? {} : { text: raw === null ? null : chatText(raw) }; // chat requests only
|
|
227
|
+
settle(status < 500 ? { ok: true, status, models, ...reply } : { ok: false, status, models: null, ...reply, reason: `HTTP ${status} for ${path}` });
|
|
206
228
|
};
|
|
207
229
|
res.on('data', (chunk) => { size += chunk.length; if (size > MAX_LIST_BYTES) res.destroy(); else chunks.push(chunk); });
|
|
208
230
|
res.on('end', done);
|
|
@@ -211,7 +233,7 @@ export function probeOrigin(ip, host, { path = '/', headers = {}, timeoutMs = 10
|
|
|
211
233
|
deadline = setTimeout(() => { settle({ ok: false, reason: 'timed out' }); req.destroy(); }, timeoutMs);
|
|
212
234
|
req.on('timeout', () => req.destroy(Object.assign(new Error('timed out'), { code: 'timed out' })));
|
|
213
235
|
req.on('error', (err) => settle({ ok: false, reason: err.code === 'ERR_TLS_CERT_ALTNAME_INVALID' ? `certificate not valid for ${host}` : String(err.code ?? err.message) }));
|
|
214
|
-
req.end();
|
|
236
|
+
req.end(payload ?? undefined);
|
|
215
237
|
});
|
|
216
238
|
}
|
|
217
239
|
|
|
@@ -221,6 +243,25 @@ function originProbePath(card) {
|
|
|
221
243
|
return `${api.pathname.replace(/\/$/, '')}/models`;
|
|
222
244
|
}
|
|
223
245
|
|
|
246
|
+
/** The chat-completion path of the card's API, `{api path}/chat/completions`. */
|
|
247
|
+
function originChatPath(card) {
|
|
248
|
+
const api = new URL(card.endpoints.openai);
|
|
249
|
+
return `${api.pathname.replace(/\/$/, '')}/chat/completions`;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* The model an identity comparison asks: the first of the card's offerings that the API lists through
|
|
254
|
+
* the CDN (as the model id it is called by), else the first id of that list.
|
|
255
|
+
*/
|
|
256
|
+
function comparisonModel(card, models) {
|
|
257
|
+
const listed = new Set(models);
|
|
258
|
+
for (const o of card?.offerings ?? []) {
|
|
259
|
+
const id = o?.binding?.model_id ?? o?.offering_id;
|
|
260
|
+
if (typeof id === 'string' && listed.has(id)) return id;
|
|
261
|
+
}
|
|
262
|
+
return models[0];
|
|
263
|
+
}
|
|
264
|
+
|
|
224
265
|
/** How two model lists differ, in words; null when they hold the same ids. */
|
|
225
266
|
function listDifference(origin, front) {
|
|
226
267
|
const have = new Set(origin), want = new Set(front);
|
|
@@ -255,6 +296,38 @@ export async function checkOrigins(card, host, declared, opts = {}) {
|
|
|
255
296
|
return fail(`the API gives the registry no model list through the CDN (${why}), so no origin can be compared with it`,
|
|
256
297
|
{ front: { status: front.status ?? null, models: 0 } });
|
|
257
298
|
}
|
|
299
|
+
// With a comparison prompt (opts.comparisonPrompt: never corpus text, see corpus.js originPrompt),
|
|
300
|
+
// each origin must also answer it as the API does through the CDN: a decoy can copy a model list, not
|
|
301
|
+
// a model's replies. Asked at temperature 0 like Stage B; two servers can still differ now and then,
|
|
302
|
+
// so a mismatch is asked once more on both sides. An empty reply counts as none (chatText). Neither
|
|
303
|
+
// the prompt nor the replies are kept with the result.
|
|
304
|
+
let compare = null;
|
|
305
|
+
if (opts.comparisonPrompt) {
|
|
306
|
+
const chat = {
|
|
307
|
+
path: originChatPath(card), headers: target.headers,
|
|
308
|
+
body: {
|
|
309
|
+
model: comparisonModel(card, front.models), stream: false, temperature: 0, max_tokens: ORIGIN_IDENTITY_MAX_TOKENS,
|
|
310
|
+
messages: [{ role: 'user', content: String(opts.comparisonPrompt) }],
|
|
311
|
+
},
|
|
312
|
+
};
|
|
313
|
+
const ask = async (ip) => {
|
|
314
|
+
const text = (await probe(ip, host, chat).catch(() => ({})))?.text;
|
|
315
|
+
return typeof text === 'string' && text.trim() ? text : null; // empty is no reply (chatText)
|
|
316
|
+
};
|
|
317
|
+
const frontTexts = [await ask(opts.frontIp)].filter((t) => t !== null);
|
|
318
|
+
if (!frontTexts.length) {
|
|
319
|
+
return fail('the API gives the registry no reply through the CDN to compare the origins with',
|
|
320
|
+
{ front: { status: front.status, models: front.models.length }, identity: 'no reply through the CDN' });
|
|
321
|
+
}
|
|
322
|
+
compare = async (ip) => {
|
|
323
|
+
const first = await ask(ip);
|
|
324
|
+
if (first !== null && frontTexts.includes(first)) return { same: true, retried: false };
|
|
325
|
+
if (frontTexts.length < 2) { const again = await ask(opts.frontIp); if (again !== null) frontTexts.push(again); }
|
|
326
|
+
const second = await ask(ip);
|
|
327
|
+
if ([first, second].some((t) => t !== null && frontTexts.includes(t))) return { same: true, retried: true };
|
|
328
|
+
return { same: false, retried: true, no_reply: first === null && second === null };
|
|
329
|
+
};
|
|
330
|
+
}
|
|
258
331
|
const addresses = [];
|
|
259
332
|
for (const address of listed) {
|
|
260
333
|
const ips = net.isIP(address) ? [address] : await (opts.resolve ?? ((h) => dns.resolve4(h)))(address).catch(() => []);
|
|
@@ -265,14 +338,25 @@ export async function checkOrigins(card, host, declared, opts = {}) {
|
|
|
265
338
|
const differs = serves.models ? listDifference(serves.models, front.models)
|
|
266
339
|
: `does not answer like the API through the CDN (HTTP ${serves.status}${serves.status === 200 ? ', no model list' : ''})`;
|
|
267
340
|
if (differs) { addresses.push({ address, ip, verdict: 'unknown', reason: differs }); continue; }
|
|
341
|
+
let identity = null;
|
|
342
|
+
if (compare) {
|
|
343
|
+
identity = await compare(ip);
|
|
344
|
+
if (!identity.same) {
|
|
345
|
+
const reason = identity.no_reply ? 'does not reply to a chat request like the API through the CDN'
|
|
346
|
+
: 'replies to a chat request differently from the API through the CDN';
|
|
347
|
+
addresses.push({ address, ip, verdict: 'unknown', reason, identity: { same: false, retried: true } });
|
|
348
|
+
continue;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
268
351
|
const located = await locateAddress(ip, declared, opts);
|
|
269
|
-
addresses.push({ address, ip, serves: true, server_country: located.server.country, ...located });
|
|
352
|
+
addresses.push({ address, ip, serves: true, ...(identity ? { identity } : {}), server_country: located.server.country, ...located });
|
|
270
353
|
}
|
|
271
354
|
const failed = addresses.find((a) => !SERVER_CHECK_PASSES.includes(a.verdict));
|
|
272
355
|
return {
|
|
273
356
|
declared: listed,
|
|
274
357
|
signed,
|
|
275
358
|
front: { status: front.status, models: front.models.length },
|
|
359
|
+
identity: compare ? 'compared' : 'not compared',
|
|
276
360
|
verdict: failed ? failed.verdict : addresses.every((a) => a.verdict === 'match') ? 'match' : 'same_region',
|
|
277
361
|
addresses,
|
|
278
362
|
};
|
package/src/schedule.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
// Re-verification on the registry's own timetable (ONP-3 §4a):
|
|
2
2
|
// - Stage A at least every 6 h and on every new card revision, for registered nodes from `indexed` up;
|
|
3
|
-
// - Stage B for a node that reaches `community`, at a random time within a day; again
|
|
4
|
-
// change to a tested offering's model, serving or
|
|
5
|
-
// a
|
|
3
|
+
// - Stage B for a node that reaches `community`, at a random time within a day; again at a random time
|
|
4
|
+
// within 3 days of any change to a tested offering's model, serving, hardware or binding block (or a
|
|
5
|
+
// new tested offering), within the hour after a confirmed mismatch in a blind identity check
|
|
6
|
+
// (stagec.js), and on a random timer, 1 to 91 days after a pass, otherwise. That timer is its own
|
|
7
|
+
// row (TIMER) and only a run it set off draws it again: a run set off by a change does not, so an
|
|
8
|
+
// operator who changes the card every day cannot keep pushing the random run away.
|
|
6
9
|
// The operator does not choose when Stage B runs, and no API says when it will: the next run time
|
|
7
10
|
// lives only in the private `schedule` table. The server supplies the stage runs (and their effect
|
|
8
11
|
// on the tier); this module only decides when they are due.
|
|
@@ -21,7 +24,9 @@ export const SCHEDULE_DEFAULTS = Object.freeze({
|
|
|
21
24
|
stageBIntervalMs: 91 * DAY,
|
|
22
25
|
stageBRetryMs: 7 * DAY, // after a Stage B that did not pass (and was not a dispute); 85-100% of it
|
|
23
26
|
stageBFirstMs: [HOUR, DAY], // a node that reaches community: first Stage B in this window
|
|
24
|
-
|
|
27
|
+
// After a change to a tested offering (or a new one): anywhere in three days, so that an operator who
|
|
28
|
+
// changes the card cannot know the hour of the run that follows (ONP-3 §4a, re-verification).
|
|
29
|
+
stageBChangeMs: [0, 72 * HOUR],
|
|
25
30
|
// After a confirmed mismatch in a blind identity check (stagec.js). The upper end leaves room for
|
|
26
31
|
// the tick (at most 1.5 x tickMs late), so the run starts within the hour.
|
|
27
32
|
stageBIdentityMs: [0, 50 * 60_000],
|
|
@@ -34,6 +39,12 @@ export const SCHEDULE_DEFAULTS = Object.freeze({
|
|
|
34
39
|
/** States whose nodes get Stage A on schedule, and the subset that gets Stage B. */
|
|
35
40
|
export const STAGE_A_STATES = ['indexed', 'community', 'verified', 'attested'];
|
|
36
41
|
export const STAGE_B_STATES = ['community', 'verified', 'attested'];
|
|
42
|
+
/**
|
|
43
|
+
* The private schedule row holding a node's random Stage B timer (drawn after a pass). Kept apart
|
|
44
|
+
* from row 'B', whose next_at is the soonest of everything due, so that runs set off by a change or
|
|
45
|
+
* a light-check mismatch never redraw it.
|
|
46
|
+
*/
|
|
47
|
+
export const TIMER = 'B:timer';
|
|
37
48
|
|
|
38
49
|
const iso = (ms) => new Date(ms).toISOString();
|
|
39
50
|
const sha256 = (s) => createHash('sha256').update(s).digest('hex');
|
|
@@ -105,8 +116,17 @@ export function makePlanner(store, options = {}) {
|
|
|
105
116
|
await store.setSchedule(nodeId, 'B', { ...prev, next_at: iso(now + between(o.staleRetryMs, random)), failures: (prev.failures ?? 0) + 1 });
|
|
106
117
|
return;
|
|
107
118
|
}
|
|
119
|
+
// The random timer is drawn again only when it is due or missing: a run that a change or a
|
|
120
|
+
// light-check mismatch set off leaves it where it was, so it still fires (ONP-3 §4a).
|
|
121
|
+
let timer = await store.getSchedule(nodeId, TIMER);
|
|
122
|
+
const timerAt = timer?.next_at ? Date.parse(timer.next_at) : null;
|
|
123
|
+
if (result.ok && !result.identityFailed && (timerAt === null || timerAt <= now)) {
|
|
124
|
+
timer = { last_at: iso(now), next_at: iso(now + between([o.stageBMinGapMs, o.stageBIntervalMs], random)) };
|
|
125
|
+
await store.setSchedule(nodeId, TIMER, timer);
|
|
126
|
+
}
|
|
127
|
+
const pending = timer?.next_at && Date.parse(timer.next_at) > now ? Date.parse(timer.next_at) : Infinity;
|
|
108
128
|
const next = result.identityFailed ? null
|
|
109
|
-
: iso(
|
|
129
|
+
: iso(Math.min(pending, result.ok ? Infinity : now + o.stageBRetryMs * between([0.85, 1], random)));
|
|
110
130
|
await store.setSchedule(nodeId, 'B', {
|
|
111
131
|
last_at: iso(now), next_at: next, ok: result.ok, revision: card?.revision ?? null,
|
|
112
132
|
digest: servingDigest(card), pending_digest: null, failures: result.ok ? 0 : (prev.failures ?? 0) + 1,
|
|
@@ -157,7 +177,8 @@ export function startScheduler(store, planner, { stageA, stageB, random = Math.r
|
|
|
157
177
|
}
|
|
158
178
|
const digest = servingDigest(fresh);
|
|
159
179
|
if (b.digest && digest !== b.digest && digest !== b.pending_digest) {
|
|
160
|
-
// A tested offering's model, serving or
|
|
180
|
+
// A tested offering's model, serving, hardware or binding changed since the last Stage B, or a
|
|
181
|
+
// tested offering is new: run it at a random time in the change window.
|
|
161
182
|
nextAt = Math.min(nextAt, now + between(o.stageBChangeMs, random));
|
|
162
183
|
b = { ...b, pending_digest: digest, next_at: iso(nextAt) };
|
|
163
184
|
await store.setSchedule(node.id, 'B', b);
|
package/src/server.js
CHANGED
|
@@ -294,11 +294,13 @@ export async function startRegistry({
|
|
|
294
294
|
* card, capacity) keeps `community` or demotes `verified` to `community`. Returns null when a
|
|
295
295
|
* run is already in progress for the node.
|
|
296
296
|
*/
|
|
297
|
-
async function stageBFor(nodeId) {
|
|
297
|
+
async function stageBFor(nodeId, { refresh = false } = {}) {
|
|
298
298
|
if (stageBRunning.has(nodeId)) return null;
|
|
299
299
|
stageBRunning.add(nodeId);
|
|
300
300
|
try {
|
|
301
|
-
|
|
301
|
+
// Scheduled runs go out on the card already held: a card fetch just before the battery would
|
|
302
|
+
// tell the operator that Stage B is starting (ONP-3 §4a.9). A 409 still re-fetches (below).
|
|
303
|
+
if (refresh) await refreshCard(nodeId);
|
|
302
304
|
const card = await store.latestCard(nodeId);
|
|
303
305
|
const revision = await store.latestRevision(nodeId);
|
|
304
306
|
// Decided before anything is sent: what counts is the key this run's probes carry.
|
|
@@ -442,7 +444,7 @@ export async function startRegistry({
|
|
|
442
444
|
if (!LISTED.includes(node.state)) {
|
|
443
445
|
return problem(res, 409, 'wrong-state', `Stage B requires community tier, node is ${node.state}`);
|
|
444
446
|
}
|
|
445
|
-
const stageB = await stageBFor(params.id);
|
|
447
|
+
const stageB = await stageBFor(params.id, { refresh: true }); // the admin's request: the latest card
|
|
446
448
|
if (!stageB) return problem(res, 409, 'stage-b-running', `Stage B is already running for ${params.id}`);
|
|
447
449
|
if (stageB.stale) {
|
|
448
450
|
return problem(res, 409, 'stale-card', 'the node changed its card revision during the battery; retry');
|
|
@@ -854,7 +856,11 @@ export async function startRegistry({
|
|
|
854
856
|
// (authFetch), and counts declared origins only in a signed card.
|
|
855
857
|
const key = (await store.getCustomerKey(nodeId)) ?? (await store.getProbeKey(nodeId));
|
|
856
858
|
const signed = Boolean((await store.latestRevision(nodeId))?.sig_ok);
|
|
857
|
-
|
|
859
|
+
// Declared origins must also reply to one prompt as the API does through the CDN (location.js
|
|
860
|
+
// checkOrigins). Never corpus text: the check is labelled and the operator can set it off at will,
|
|
861
|
+
// so a corpus prompt here would show them the identity references (corpus.js originPrompt).
|
|
862
|
+
const comparisonPrompt = corpus.originPrompt();
|
|
863
|
+
const result = await checkNodeLocation(card, { ...location, asHolders, key, signed, comparisonPrompt });
|
|
858
864
|
await store.setObservation(nodeId, '_node', 'location', result);
|
|
859
865
|
return result;
|
|
860
866
|
}
|
|
@@ -892,7 +898,9 @@ export async function startRegistry({
|
|
|
892
898
|
// without one (ONP_SCHEDULE=0) Stage B runs only on admin request, so the mismatch is only recorded.
|
|
893
899
|
const requestStageB = schedule ? (nodeId, card) => planner.stageBSoon(nodeId, card) : null;
|
|
894
900
|
const stageCHandle = stageC ? startStageC(store, { safeFetch, fetchFor: authFetch, refreshCard, requestStageB, corpus, ...stageC }) : null;
|
|
895
|
-
|
|
901
|
+
// Scheduled runs use the card already held when Stage C re-fetches cards on its own timer
|
|
902
|
+
// (stagec.js cardSweep), so no card fetch announces them; without Stage C, Stage A re-fetches.
|
|
903
|
+
const scheduleHandle = schedule ? startScheduler(store, planner, { stageA: (id) => stageAFor(id, { refresh: !stageCHandle }), stageB: (id) => stageBFor(id) }) : null;
|
|
896
904
|
const reimportHandle = reimport ? startReimport(store, { safeFetch, ...reimport }) : null;
|
|
897
905
|
const locationHandle = location ? startLocationSweep() : null;
|
|
898
906
|
const actualPort = await listen(app, port, host);
|
|
@@ -905,6 +913,7 @@ export async function startRegistry({
|
|
|
905
913
|
scheduleTick: scheduleHandle ? () => scheduleHandle.tick() : null,
|
|
906
914
|
/** Run one Stage C blind sweep, or one look for due follow-ups, now (tests); null when Stage C is off. */
|
|
907
915
|
blindSweep: stageCHandle ? () => stageCHandle.blindSweep() : null,
|
|
916
|
+
cardSweep: stageCHandle ? () => stageCHandle.cardSweep() : null,
|
|
908
917
|
followUpTick: stageCHandle ? () => stageCHandle.followUpTick() : null,
|
|
909
918
|
close: async () => {
|
|
910
919
|
stageCHandle?.stop();
|
package/src/stageb.js
CHANGED
|
@@ -89,7 +89,10 @@ export const STAGE_B_409 = 'identity-409';
|
|
|
89
89
|
* (the card the run holds is stale now, so even an honest node refuses what follows).
|
|
90
90
|
*/
|
|
91
91
|
function makeOn409(store, nodeId, card, { revisionMoved, maxExcused409 }) {
|
|
92
|
-
|
|
92
|
+
// `status`: the reply that sent the registry to the card. Since rev. 14 scheduled runs go out on
|
|
93
|
+
// the card already held, so a 404 for a model the node has just dropped gets the same rule as a
|
|
94
|
+
// 409: re-fetched after the reply, excused only if the revision really moved, within the bound.
|
|
95
|
+
return async (offering, status = 409) => {
|
|
93
96
|
const fresh = revisionMoved ? await revisionMoved() : null;
|
|
94
97
|
if (!fresh) return { kind: 'refused' };
|
|
95
98
|
const since = (await store.getSchedule(nodeId, 'B'))?.last_at ?? '';
|
|
@@ -98,7 +101,7 @@ function makeOn409(store, nodeId, card, { revisionMoved, maxExcused409 }) {
|
|
|
98
101
|
return { kind: 'moved', reason: `the card revision moved again during Stage B, after ${excused} such 409s since the last judged run (at most ${maxExcused409} are excused)` };
|
|
99
102
|
}
|
|
100
103
|
await store.recordProbe(nodeId, offering.offering_id, 'B', STAGE_B_409, false,
|
|
101
|
-
|
|
104
|
+
`${status} with revision ${card.revision} pinned; card re-indexed at ${fresh}; Stage B runs again later`);
|
|
102
105
|
return { kind: 'stale' };
|
|
103
106
|
};
|
|
104
107
|
}
|
|
@@ -113,9 +116,11 @@ async function probeIdentity(safeFetch, card, offering, refs, on409) {
|
|
|
113
116
|
let matches = 0, retried = 0, refused = 0, stop = null;
|
|
114
117
|
const ask = async (prompt) => {
|
|
115
118
|
const { status, text } = await chatOnce(safeFetch, card, offering, prompt);
|
|
116
|
-
if (status
|
|
117
|
-
|
|
118
|
-
|
|
119
|
+
if (status !== 200) {
|
|
120
|
+
// A 409, or another failure (a 404 for a model dropped since the card was fetched): only a
|
|
121
|
+
// revision that really moved excuses it; with the current revision pinned it does not match.
|
|
122
|
+
const what = await on409(offering, status);
|
|
123
|
+
if (what.kind === 'refused') { if (status === 409) refused++; } else stop = what;
|
|
119
124
|
return null;
|
|
120
125
|
}
|
|
121
126
|
return status === 200 && text !== null ? sha256(text) : null;
|
|
@@ -293,6 +298,13 @@ export async function runStageB(store, nodeId, card, {
|
|
|
293
298
|
await store.setObservation(nodeId, offering.offering_id, 'context_cap', verdict.context.verified_cap);
|
|
294
299
|
|
|
295
300
|
verdict.capacity = await probeCapacity(safeFetch, card, offering, corpus, capacity);
|
|
301
|
+
if (!verdict.capacity.ok) {
|
|
302
|
+
// A failed ramp on a card that has since moved (the model dropped or changed during the run)
|
|
303
|
+
// is not judged, by the same rule and bound as a 409.
|
|
304
|
+
const what = await on409(offering, 'capacity failure');
|
|
305
|
+
if (what.kind === 'stale') return { ok: false, identityFailed: false, stale: true, verdicts: [...verdicts, verdict], untested };
|
|
306
|
+
if (what.kind === 'moved') return { ok: false, identityFailed: false, reason: `${offering.offering_id}: ${what.reason}`, verdicts: [...verdicts, verdict], untested };
|
|
307
|
+
}
|
|
296
308
|
await store.recordProbe(nodeId, offering.offering_id, 'B', 'capacity', verdict.capacity.ok, null, verdict.capacity);
|
|
297
309
|
if (verdict.capacity.ttft_ms.p50 != null) {
|
|
298
310
|
await store.setObservation(nodeId, offering.offering_id, 'ttft_ms', verdict.capacity.ttft_ms);
|
package/src/stagec.js
CHANGED
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
// - random blind invocations at unpredictable times (anti-"benchmark mode": a node cannot serve the
|
|
5
5
|
// real model only when it detects a test window), worded from the registry's probe corpus like
|
|
6
6
|
// any customer request; repeated failures cost the node its tier
|
|
7
|
+
// - blind invocations use the card the registry already holds: cards are re-fetched on their own
|
|
8
|
+
// jittered timer (cardSweep), never just before a probe, so the card origin's log does not announce
|
|
9
|
+
// the "blind" request that follows (a 409 still re-fetches and retries, below)
|
|
7
10
|
// - an excused 409 is followed by a fresh blind invocation within the hour (ONP-3 §4a.9), so
|
|
8
11
|
// publishing a new card revision to refuse a probe does not buy a quiet stretch
|
|
9
12
|
// - on verified and attested nodes some blind invocations ask an identity prompt instead: a light
|
|
@@ -25,6 +28,11 @@ const MINUTE = 60_000, HOUR = 60 * MINUTE, DAY = 24 * HOUR;
|
|
|
25
28
|
export const LIVENESS_INTERVAL_MS = 300_000;
|
|
26
29
|
/** Mean gap between blind-invocation sweeps: one chat call per node per sweep, same jitter. */
|
|
27
30
|
export const BLIND_INTERVAL_MS = 3_600_000;
|
|
31
|
+
/**
|
|
32
|
+
* Mean gap between card re-fetch sweeps, same jitter. Its own timer, independent of the blind sweeps:
|
|
33
|
+
* a card fetch must not tell a node that a blind invocation is coming.
|
|
34
|
+
*/
|
|
35
|
+
export const CARD_REFRESH_INTERVAL_MS = 3_600_000;
|
|
28
36
|
/** Each gap is the mean times a uniform random factor in this range. */
|
|
29
37
|
export const JITTER = [0.5, 1.5];
|
|
30
38
|
/** Consecutive failed blind invocations (since the node's last state change) that demote it one tier. */
|
|
@@ -70,6 +78,7 @@ export function startStageC(store, {
|
|
|
70
78
|
corpus = loadCorpus(null), // probe prompts (corpus.js)
|
|
71
79
|
livenessIntervalMs = LIVENESS_INTERVAL_MS, // tests shorten this
|
|
72
80
|
blindIntervalMs = BLIND_INTERVAL_MS,
|
|
81
|
+
cardRefreshIntervalMs = CARD_REFRESH_INTERVAL_MS,
|
|
73
82
|
followUpTickMs = FOLLOW_UP_TICK_MS,
|
|
74
83
|
followUpMs = FOLLOW_UP_MS,
|
|
75
84
|
failThreshold = 3,
|
|
@@ -139,7 +148,7 @@ export function startStageC(store, {
|
|
|
139
148
|
for (const node of await store.allNodes()) {
|
|
140
149
|
if (stopped) return;
|
|
141
150
|
if (!OBSERVED_STATES.includes(node.state)) continue;
|
|
142
|
-
|
|
151
|
+
// The card the registry holds, never one fetched just now (cardSweep has its own timer).
|
|
143
152
|
const card = await store.latestCard(node.id);
|
|
144
153
|
if (!card) continue;
|
|
145
154
|
// Blind probes call only offerings the tests can call. A node with none is reported in the
|
|
@@ -160,6 +169,23 @@ export function startStageC(store, {
|
|
|
160
169
|
}
|
|
161
170
|
}
|
|
162
171
|
|
|
172
|
+
/**
|
|
173
|
+
* Re-fetch the cards of observed nodes, in random order, on a timer of its own. A revision the
|
|
174
|
+
* node moved to is picked up here (or on its ping, or by a 409's re-fetch), not just before a probe.
|
|
175
|
+
*/
|
|
176
|
+
async function cardSweep() {
|
|
177
|
+
if (!refreshCard) return;
|
|
178
|
+
const nodes = (await store.allNodes()).filter((n) => OBSERVED_STATES.includes(n.state));
|
|
179
|
+
for (let i = nodes.length - 1; i > 0; i--) {
|
|
180
|
+
const j = Math.floor(random() * (i + 1));
|
|
181
|
+
[nodes[i], nodes[j]] = [nodes[j], nodes[i]];
|
|
182
|
+
}
|
|
183
|
+
for (const node of nodes) {
|
|
184
|
+
if (stopped) return;
|
|
185
|
+
await refreshCard(node.id);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
163
189
|
/**
|
|
164
190
|
* The fresh blind invocations owed after excused 409s: each due one runs now, pinned to the card
|
|
165
191
|
* the registry holds (the revision the node moved to), without fetching the card first. Its 409
|
|
@@ -184,6 +210,7 @@ export function startStageC(store, {
|
|
|
184
210
|
const offering = callable[Math.floor(random() * callable.length)];
|
|
185
211
|
const ref = await identityReference(node, offering);
|
|
186
212
|
const result = await blindProbe(node, card, offering, ref);
|
|
213
|
+
if (result.skipped) return;
|
|
187
214
|
// The record says only whether the reply conformed: never that it carried an identity prompt,
|
|
188
215
|
// nor how that comparison went (node detail publishes the last probe records).
|
|
189
216
|
await store.recordProbe(node.id, result.offeringId, 'C', 'blind', result.ok, result.detail, result.measured);
|
|
@@ -202,6 +229,26 @@ export function startStageC(store, {
|
|
|
202
229
|
return refs.length ? refs[Math.floor(random() * refs.length)] : null;
|
|
203
230
|
}
|
|
204
231
|
|
|
232
|
+
/**
|
|
233
|
+
* Blind probes go out on the card the registry holds, so one can reach an offering the node has
|
|
234
|
+
* since dropped from its card (it answers 404, say, not 409). After such a failure, and never
|
|
235
|
+
* before a probe, the card is re-fetched: when its revision moved and the offering is gone, the
|
|
236
|
+
* failure is not judged. It is excused like a 409, within the same daily bound and with a fresh
|
|
237
|
+
* probe owed within the hour. Null when it counts as a failure.
|
|
238
|
+
*/
|
|
239
|
+
async function droppedOffering(node, card, offering, status) {
|
|
240
|
+
await refreshCard?.(node.id);
|
|
241
|
+
const fresh = await store.latestCard(node.id);
|
|
242
|
+
if (!fresh || fresh.revision === card.revision) return null;
|
|
243
|
+
if (fresh.offerings.some((o) => o.offering_id === offering.offering_id && testable(o))) return null;
|
|
244
|
+
const excused = await store.countProbes(node.id, 'blind-409', iso(Date.now() - DAY));
|
|
245
|
+
if (excused >= maxExcused409) return null;
|
|
246
|
+
await store.recordProbe(node.id, offering.offering_id, 'C', 'blind-409', false,
|
|
247
|
+
`status ${status} for ${offering.offering_id}, which revision ${fresh.revision} no longer offers; a fresh probe due within the hour`);
|
|
248
|
+
await oweFollowUp(node.id, fresh.revision);
|
|
249
|
+
return { skipped: true, offeringId: offering.offering_id };
|
|
250
|
+
}
|
|
251
|
+
|
|
205
252
|
/**
|
|
206
253
|
* One blind chat call, in the identity requests' shape (temperature 0, the same output cap). A fresh
|
|
207
254
|
* 409 is excused within the daily bound: the card is re-indexed, the call retried once at once
|
|
@@ -221,6 +268,7 @@ export function startStageC(store, {
|
|
|
221
268
|
let reply = await ask(card, offering, ref ? ref.prompt : corpus.chatPrompt());
|
|
222
269
|
if (reply.status !== 409) {
|
|
223
270
|
const result = judge(reply, offering);
|
|
271
|
+
if (!result.ok) return (await droppedOffering(node, card, offering, reply.status)) ?? result;
|
|
224
272
|
if (ref && result.ok) result.identity = await lightCheck(reply, () => ask(card, offering, ref.prompt), ref);
|
|
225
273
|
return result;
|
|
226
274
|
}
|
|
@@ -238,7 +286,9 @@ export function startStageC(store, {
|
|
|
238
286
|
await oweFollowUp(node.id, fresh.revision);
|
|
239
287
|
const retryOffering = fresh.offerings.find((o) => o.offering_id === offering.offering_id && testable(o))
|
|
240
288
|
?? fresh.offerings.find(testable);
|
|
241
|
-
|
|
289
|
+
// The node moved to a card with nothing to call (an excused 409, already recorded): nothing
|
|
290
|
+
// was judged, and the next sweep reports it as blind_skipped, as for any such card.
|
|
291
|
+
if (!retryOffering) return { skipped: true, offeringId: offering.offering_id };
|
|
242
292
|
reply = await ask(fresh, retryOffering, corpus.chatPrompt());
|
|
243
293
|
return judge(reply, retryOffering, reply.status === 409 ? 'on the retry with the re-indexed revision' : null);
|
|
244
294
|
} catch (err) {
|
|
@@ -325,12 +375,14 @@ export function startStageC(store, {
|
|
|
325
375
|
};
|
|
326
376
|
loop(livenessSweep, livenessIntervalMs);
|
|
327
377
|
loop(blindSweep, blindIntervalMs);
|
|
378
|
+
loop(cardSweep, cardRefreshIntervalMs);
|
|
328
379
|
loop(followUpTick, followUpTickMs);
|
|
329
380
|
|
|
330
381
|
return {
|
|
331
382
|
stop: () => { stopped = true; },
|
|
332
383
|
/** One blind sweep, or one look for due follow-ups, now (tests). */
|
|
333
384
|
blindSweep,
|
|
385
|
+
cardSweep,
|
|
334
386
|
followUpTick,
|
|
335
387
|
};
|
|
336
388
|
}
|
package/src/web/index.html
CHANGED
|
@@ -663,7 +663,7 @@
|
|
|
663
663
|
<p class="sub">Everything this registry sends to your endpoints, as the code runs today: how much, how often and what starts it, so you can size your probe allowance. A <i>chat offering</i> is one bound to <code>onp.openai.chat/v1</code>; other offerings get only the health and models checks. Probe calls carry your probe key if you gave one at registration, or, once the registry has bought access to your API as a customer, that access instead; the registry does not pay for calls made with your probe key. Their wording comes from a private set of ordinary requests, the same kind your customers send; it is not published.</p>
|
|
664
664
|
<div class="panel pad" style="max-width:56rem" id="probe-load-table">
|
|
665
665
|
<div class="stage"><span class="k">STAGE A</span><span><b>When:</b> when you verify your registration, on each <code>PUT /v0/nodes/{id}/ping</code>, on every new card revision, and at least every 6 hours (each gap is random, 4.5 to 6 hours), each time after a fetch of your card.<br><b>Sends:</b> 1 GET to your health endpoint, 1 GET to <code>/models</code>, and 1 blind chat completion per chat offering (a short request, at most 32 output tokens): about 4 of each a day.</span></div>
|
|
666
|
-
<div class="stage"><span class="k">STAGE B</span><span><b>When:</b> on the registry's schedule, never on request: between 1 and 24 hours after your node reaches community; within
|
|
666
|
+
<div class="stage"><span class="k">STAGE B</span><span><b>When:</b> on the registry's schedule, never on request: between 1 and 24 hours after your node reaches community; at a random time within 72 hours of a change to a chat offering's model, serving, hardware or binding block, a new chat offering, or a change to your API endpoint; within 1 hour of a confirmed identity mismatch in a blind call (below), at most once a day; within 1 hour after a run stopped because your card's revision changed; again after 7 days when a run did not pass; and after a pass at a random time from 1 day on, and at most every 91 days. That random run is set apart: a run that a change brings does not move it. The registry admin can also run it.<br><b>Sends, per chat offering</b> (up to 20 chat completions, plus one repeat for each identity reply that does not match):
|
|
667
667
|
<br>· <b>Fingerprint battery:</b> 3 prompts drawn at random from the 8 reference prompts the registry holds for your model's artefact, at temperature 0, at most 64 output tokens each. With no reference for the artefact nothing is asked, and the offering cannot be verified.
|
|
668
668
|
<br>· <b>Calibration:</b> 1 call with about 4,000 characters of text, at most 4 output tokens, to measure your tokenizer.
|
|
669
669
|
<br>· <b>Context:</b> 3 probes sized at 25, 50 and 90% of the claimed context window, at most 64 output tokens each: about 1.65 times the window in prompt tokens altogether (about 210k tokens for a 128k window).
|