@opennodes/registry 0.1.57 → 0.1.59
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 +2 -2
- package/src/mcp.js +2 -6
- package/src/schedule.js +48 -0
- package/src/server.js +87 -14
- package/src/stageb.js +105 -28
- package/src/store-pg.js +37 -0
- package/src/store.js +46 -0
- package/src/web/index.html +3 -3
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.59 # web app + API on http://127.0.0.1:4300
|
|
7
|
+
ONP_DB=./registry.db npx @opennodes/registry@0.1.59 # persistent SQLite + persistent signing key
|
|
8
|
+
ONP_DB=postgres://user:pass@host/db npx @opennodes/registry@0.1.59
|
|
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.59",
|
|
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, AI Horde), MCP surface, and the web app (catalog, chat, advisor, Node Builder)",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"access": "public"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@opennodes/core": "0.1.
|
|
46
|
+
"@opennodes/core": "0.1.27",
|
|
47
47
|
"pg": "^8.13.1"
|
|
48
48
|
}
|
|
49
49
|
}
|
package/src/mcp.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// MCP host gets ONP discovery (recommend, search_offerings, get_offering, get_node, estimate,
|
|
4
4
|
// find_locations, find_residency) for free.
|
|
5
5
|
import { readFileSync } from 'node:fs';
|
|
6
|
-
import { readJson, sendJson, problem, estimateBounds, round6, extractFeatures, recommend, MCP_TOOLS, MCP_INSTRUCTIONS, summarizeNode, serverCheckOf } from '@opennodes/core';
|
|
6
|
+
import { readJson, sendJson, problem, estimateBounds, round6, extractFeatures, recommend, MCP_TOOLS, MCP_INSTRUCTIONS, summarizeNode, serverCheckOf, mcpToolResult } from '@opennodes/core';
|
|
7
7
|
import { searchOfferingsPaged, searchOfferings, collectOfferings, pricePublished, locationSummary } from './search.js';
|
|
8
8
|
import { buildLocations, buildResidency } from './locations.js';
|
|
9
9
|
import { nodeIdsIn } from './counts.js';
|
|
@@ -139,11 +139,7 @@ async function handleRpc(store, seeds, msg, onResult, trusted) {
|
|
|
139
139
|
try {
|
|
140
140
|
const result = await runTool(store, seeds, params?.name, params?.arguments, trusted);
|
|
141
141
|
onResult?.(nodesReturned(params.name, result));
|
|
142
|
-
return reply(
|
|
143
|
-
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
|
|
144
|
-
structuredContent: result,
|
|
145
|
-
isError: false,
|
|
146
|
-
});
|
|
142
|
+
return reply(mcpToolResult(result)); // operator text cut and marked untrusted (review 4.11)
|
|
147
143
|
} catch (err) {
|
|
148
144
|
return reply({ content: [{ type: 'text', text: String(err.message) }], isError: true });
|
|
149
145
|
}
|
package/src/schedule.js
CHANGED
|
@@ -45,6 +45,19 @@ export const STAGE_B_STATES = ['community', 'verified', 'attested'];
|
|
|
45
45
|
* a light-check mismatch never redraw it.
|
|
46
46
|
*/
|
|
47
47
|
export const TIMER = 'B:timer';
|
|
48
|
+
/**
|
|
49
|
+
* The private row that holds automatic Stage B after a run ended "identity inconclusive" (ONP-3
|
|
50
|
+
* §4a.4): `digest` lists the artefacts (JSON). With the same references a second run would give the
|
|
51
|
+
* same mismatch and dispute without anyone having looked, so no change, retry or blind check sets
|
|
52
|
+
* Stage B off until the artefact is captured again (reopenAfterCapture) or an admin runs Stage B.
|
|
53
|
+
*/
|
|
54
|
+
export const HOLD = 'B:hold';
|
|
55
|
+
|
|
56
|
+
/** Artefacts a node's Stage B hold waits on ([] when there is no hold). */
|
|
57
|
+
export async function heldArtifacts(store, nodeId) {
|
|
58
|
+
const row = await store.getSchedule(nodeId, HOLD);
|
|
59
|
+
try { return row?.digest ? JSON.parse(row.digest) : []; } catch { return []; }
|
|
60
|
+
}
|
|
48
61
|
|
|
49
62
|
const iso = (ms) => new Date(ms).toISOString();
|
|
50
63
|
const sha256 = (s) => createHash('sha256').update(s).digest('hex');
|
|
@@ -100,6 +113,7 @@ export function makePlanner(store, options = {}) {
|
|
|
100
113
|
*/
|
|
101
114
|
async stageBSoon(nodeId, card) {
|
|
102
115
|
const prev = await store.getSchedule(nodeId, 'B');
|
|
116
|
+
if ((await heldArtifacts(store, nodeId)).length) return prev?.next_at ?? null; // held: see HOLD
|
|
103
117
|
const at = Date.now() + between(o.stageBIdentityMs, random);
|
|
104
118
|
const next = iso(Math.min(prev?.next_at ? Date.parse(prev.next_at) : Infinity, at));
|
|
105
119
|
await store.setSchedule(nodeId, 'B', prev ? { ...prev, next_at: next } : {
|
|
@@ -111,6 +125,16 @@ export function makePlanner(store, options = {}) {
|
|
|
111
125
|
async afterStageB(nodeId, card, result) {
|
|
112
126
|
const prev = await store.getSchedule(nodeId, 'B') ?? {};
|
|
113
127
|
const now = Date.now();
|
|
128
|
+
if (result.inconclusive) {
|
|
129
|
+
// Not passed, not disputed: nothing runs until a recapture or an admin's run (HOLD).
|
|
130
|
+
const artifacts = [...new Set([...await heldArtifacts(store, nodeId), ...result.inconclusive.map((i) => i.artifact)])];
|
|
131
|
+
await store.setSchedule(nodeId, HOLD, { last_at: iso(now), next_at: null, digest: JSON.stringify(artifacts) });
|
|
132
|
+
await store.setSchedule(nodeId, 'B', {
|
|
133
|
+
last_at: iso(now), next_at: null, ok: false, revision: card?.revision ?? null,
|
|
134
|
+
digest: servingDigest(card), pending_digest: null, failures: (prev.failures ?? 0) + 1,
|
|
135
|
+
});
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
114
138
|
if (result.stale) {
|
|
115
139
|
// Unjudged: last_at stays, so the excused 409s since the last judged run keep counting.
|
|
116
140
|
await store.setSchedule(nodeId, 'B', { ...prev, next_at: iso(now + between(o.staleRetryMs, random)), failures: (prev.failures ?? 0) + 1 });
|
|
@@ -131,6 +155,29 @@ export function makePlanner(store, options = {}) {
|
|
|
131
155
|
last_at: iso(now), next_at: next, ok: result.ok, revision: card?.revision ?? null,
|
|
132
156
|
digest: servingDigest(card), pending_digest: null, failures: result.ok ? 0 : (prev.failures ?? 0) + 1,
|
|
133
157
|
});
|
|
158
|
+
// A judged run (an admin's, while held) ends the hold.
|
|
159
|
+
if (await store.getSchedule(nodeId, HOLD)) await store.deleteSchedule(nodeId, HOLD);
|
|
160
|
+
},
|
|
161
|
+
/**
|
|
162
|
+
* The artefact's references were captured again: nodes held on it (HOLD) get Stage B at a random
|
|
163
|
+
* time in the first-run window once nothing else holds them. Returns the node ids reopened.
|
|
164
|
+
*/
|
|
165
|
+
async reopenAfterCapture(artifact) {
|
|
166
|
+
const reopened = [];
|
|
167
|
+
for (const node of await store.allNodes()) {
|
|
168
|
+
const held = await heldArtifacts(store, node.id);
|
|
169
|
+
if (!held.includes(artifact)) continue;
|
|
170
|
+
const rest = held.filter((a) => a !== artifact);
|
|
171
|
+
if (rest.length) {
|
|
172
|
+
const row = await store.getSchedule(node.id, HOLD);
|
|
173
|
+
await store.setSchedule(node.id, HOLD, { ...row, digest: JSON.stringify(rest) });
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
await store.deleteSchedule(node.id, HOLD);
|
|
177
|
+
if (STAGE_B_STATES.includes(node.state)) await this.firstStageB(node.id, await store.latestCard(node.id), 'first');
|
|
178
|
+
reopened.push(node.id);
|
|
179
|
+
}
|
|
180
|
+
return reopened;
|
|
134
181
|
},
|
|
135
182
|
};
|
|
136
183
|
}
|
|
@@ -158,6 +205,7 @@ export function startScheduler(store, planner, { stageA, stageB, random = Math.r
|
|
|
158
205
|
|
|
159
206
|
const current = await store.getNode(node.id);
|
|
160
207
|
if (!STAGE_B_STATES.includes(current?.state)) continue;
|
|
208
|
+
if ((await heldArtifacts(store, node.id)).length) continue; // identity inconclusive: see HOLD
|
|
161
209
|
const fresh = await store.latestCard(node.id);
|
|
162
210
|
let b = await store.getSchedule(node.id, 'B');
|
|
163
211
|
if (!b) {
|
package/src/server.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { randomUUID } from 'node:crypto';
|
|
3
3
|
import {
|
|
4
4
|
createApp, listen, closeApp, sendJson, problem, readJson,
|
|
5
|
-
validateCard,
|
|
5
|
+
validateCard, verifyCardWithJwks, estimateBounds,
|
|
6
6
|
extractFeatures, recommend, trustedView, DEFAULT_TRUSTED_JURISDICTIONS, serverCheckOf,
|
|
7
7
|
} from '@opennodes/core';
|
|
8
8
|
import { resolveTxt } from 'node:dns/promises';
|
|
@@ -11,7 +11,7 @@ import { fileURLToPath } from 'node:url';
|
|
|
11
11
|
import { generateKeypair, keypairFromPem } from '@opennodes/core';
|
|
12
12
|
import { createStore } from './store.js';
|
|
13
13
|
import { runStageA, verificationOf } from './probes.js';
|
|
14
|
-
import { runStageB, captureFingerprints, UNSIGNED_CARD, IDENTITY_CAPTURE, CUSTOMER_ACCESS_NEEDED } from './stageb.js';
|
|
14
|
+
import { runStageB, captureFingerprints, judgeMismatch, STAGE_B_INCONCLUSIVE, UNSIGNED_CARD, IDENTITY_CAPTURE, CUSTOMER_ACCESS_NEEDED } from './stageb.js';
|
|
15
15
|
import { startStageC } from './stagec.js';
|
|
16
16
|
import { loadCorpus } from './corpus.js';
|
|
17
17
|
import { vendorTable, proprietaryVendor, VENDOR_SLUG, NAMESPACE, ARTIFACT } from './vendors.js';
|
|
@@ -32,7 +32,10 @@ import {
|
|
|
32
32
|
HORDE_STATUS_URL, HORDE_TEXT_REFERENCE_URL, HORDE_CLIENT_AGENT,
|
|
33
33
|
} from './importers.js';
|
|
34
34
|
import { locationRoutes, loadLocationSeeds, seedPlacements, seedNodeSites, nodeServes } from './locations.js';
|
|
35
|
-
import { makeRequestCounter, nodeIdsIn } from './counts.js';
|
|
35
|
+
import { makeRequestCounter, nodeIdsIn, isoWeek, recentWeeks, weekStart } from './counts.js';
|
|
36
|
+
|
|
37
|
+
/** Why POST /v0/nodes refused a registration before storing anything (GET /v0/stats/registrations). */
|
|
38
|
+
const REGISTRATION_FAILURES = ['card-unfetchable', 'card-invalid', 'namespace-mismatch'];
|
|
36
39
|
|
|
37
40
|
/** Default basemap. OSM's tile policy asks for attribution and light use; busy registries set their own. */
|
|
38
41
|
export const OSM_TILES = {
|
|
@@ -132,10 +135,7 @@ export async function startRegistry({
|
|
|
132
135
|
jwks = await res.json();
|
|
133
136
|
} catch (err) { return { ok: false, definite: false, error: `jwks fetch failed: ${err.message}` }; }
|
|
134
137
|
try {
|
|
135
|
-
|
|
136
|
-
const jwk = (jwks.keys ?? []).find((k) => !kid || k.kid === kid) ?? jwks.keys?.[0];
|
|
137
|
-
if (!jwk) return { ok: false, definite: true, error: 'no key in jwks' };
|
|
138
|
-
verifyCardSignature(card, keyFromJwk(jwk));
|
|
138
|
+
verifyCardWithJwks(card, jwks); // any signature, by kid first, with a key the origin publishes
|
|
139
139
|
return { ok: true };
|
|
140
140
|
} catch (err) { return { ok: false, definite: true, error: String(err.message ?? err) }; }
|
|
141
141
|
}
|
|
@@ -158,6 +158,11 @@ export async function startRegistry({
|
|
|
158
158
|
* operator's probe key (card-only listings of keyed APIs), and only toward the card's own
|
|
159
159
|
* endpoint origins — never to anything else.
|
|
160
160
|
*/
|
|
161
|
+
/** A registration refused before anything was stored (GET /v0/stats/registrations). Never fails the reply. */
|
|
162
|
+
async function failedRegistration(reason) {
|
|
163
|
+
try { await store.addRegistrationFailure(isoWeek(), reason); } catch { /* counting is best-effort */ }
|
|
164
|
+
}
|
|
165
|
+
|
|
161
166
|
async function authFetch(nodeId, card) {
|
|
162
167
|
const key = (await store.getCustomerKey(nodeId)) ?? (await store.getProbeKey(nodeId));
|
|
163
168
|
if (!key || !card?.endpoints) return safeFetch;
|
|
@@ -316,9 +321,22 @@ export async function startRegistry({
|
|
|
316
321
|
safeFetch: await authFetch(nodeId, card), capacity: stageBCapacity, corpus, vendors: await vendors(), signed: Boolean(revision?.sig_ok), revisionMoved,
|
|
317
322
|
});
|
|
318
323
|
const node = await store.getNode(nodeId);
|
|
324
|
+
let result = stageB;
|
|
319
325
|
if (!stageB.stale && LISTED.includes(node.state)) {
|
|
320
|
-
|
|
321
|
-
|
|
326
|
+
// A confirmed mismatch disputes, except a node's first one for an artefact since its
|
|
327
|
+
// references were captured: "identity inconclusive" (ONP-3 §4a.4), held until a recapture.
|
|
328
|
+
const judged = stageB.identityFailed ? await judgeMismatch(store, nodeId, stageB) : null;
|
|
329
|
+
if (judged?.dispute) {
|
|
330
|
+
await store.setState(nodeId, 'disputed', judged.why);
|
|
331
|
+
} else if (judged) {
|
|
332
|
+
const what = judged.inconclusive.map((i) => `${i.offering_id} (${i.artifact}): ${i.matches}/${i.total} reference matches`).join('; ');
|
|
333
|
+
for (const i of judged.inconclusive) {
|
|
334
|
+
await store.recordInconclusive(nodeId, i.artifact);
|
|
335
|
+
await store.recordProbe(nodeId, i.offering_id, 'B', STAGE_B_INCONCLUSIVE, false,
|
|
336
|
+
`${i.matches}/${i.total} reference matches: identity inconclusive, the node's first mismatch for ${i.artifact} since its references were captured; not passed and not disputed; Stage B runs again after the references are captured again or an admin's review, and another mismatch then disputes`);
|
|
337
|
+
}
|
|
338
|
+
result = { ...stageB, ok: false, identityFailed: false, inconclusive: judged.inconclusive, reason: `identity inconclusive: ${what}` };
|
|
339
|
+
if (node.state !== 'community') await store.setState(nodeId, 'community', `Stage B identity inconclusive: ${what}`);
|
|
322
340
|
} else if (stageB.ok && held) {
|
|
323
341
|
// Passed, but on probes the operator could tell apart: it stays at (or returns to) community.
|
|
324
342
|
stageB.held = CUSTOMER_ACCESS_NEEDED;
|
|
@@ -332,8 +350,8 @@ export async function startRegistry({
|
|
|
332
350
|
await store.setState(nodeId, 'community', `Stage B failed: ${stageB.reason}`);
|
|
333
351
|
}
|
|
334
352
|
}
|
|
335
|
-
await planner.afterStageB(nodeId, card,
|
|
336
|
-
return
|
|
353
|
+
await planner.afterStageB(nodeId, card, result);
|
|
354
|
+
return result;
|
|
337
355
|
} finally {
|
|
338
356
|
stageBRunning.delete(nodeId);
|
|
339
357
|
}
|
|
@@ -346,15 +364,16 @@ export async function startRegistry({
|
|
|
346
364
|
if (probe_key != null && (typeof probe_key !== 'string' || probe_key.length > 4096)) return problem(res, 400, 'bad-probe-key', 'probe_key must be a string');
|
|
347
365
|
if (!card_url) return problem(res, 400, 'missing-card-url', 'body must be {"card_url": "..."}');
|
|
348
366
|
let card;
|
|
349
|
-
try { card = await fetchCard(card_url); } catch (err) { return problem(res, 422, 'card-unfetchable', String(err.message)); }
|
|
367
|
+
try { card = await fetchCard(card_url); } catch (err) { await failedRegistration('card-unfetchable'); return problem(res, 422, 'card-unfetchable', String(err.message)); }
|
|
350
368
|
const errors = validateCard(card);
|
|
351
|
-
if (errors.length) return problem(res, 422, 'card-invalid', errors.slice(0, 10).join('; '));
|
|
369
|
+
if (errors.length) { await failedRegistration('card-invalid'); return problem(res, 422, 'card-invalid', errors.slice(0, 10).join('; ')); }
|
|
352
370
|
|
|
353
371
|
const nodeId = card.node.id;
|
|
354
372
|
const origin = new URL(card_url).origin;
|
|
355
373
|
// The card must be served by a host that controls the claimed id (reverse-DNS). Otherwise anyone
|
|
356
374
|
// could host a card naming someone else's node and pass the HTTP challenge on their own server.
|
|
357
375
|
if (!namespaceOk(origin, nodeId)) {
|
|
376
|
+
await failedRegistration('namespace-mismatch');
|
|
358
377
|
return problem(res, 403, 'namespace-mismatch',
|
|
359
378
|
`node id ${nodeId} maps to ${domainForNodeId(nodeId)}; its card must be served from that host or a parent domain, not ${new URL(origin).hostname}`);
|
|
360
379
|
}
|
|
@@ -474,7 +493,42 @@ export async function startRegistry({
|
|
|
474
493
|
catch (err) { return problem(res, 502, 'capture-failed', String(err.message)); }
|
|
475
494
|
if (replace) await store.clearFingerprints(target);
|
|
476
495
|
await store.addFingerprints(target, refs);
|
|
477
|
-
|
|
496
|
+
await store.recordCapture(target, { how: 'node', node_id, offering_id, host: new URL(card.endpoints.openai).host });
|
|
497
|
+
const reopened = await planner.reopenAfterCapture(target);
|
|
498
|
+
sendJson(res, 200, { artifact: target, references: refs.length, corpus: corpus.private ? 'private' : 'built-in', ...(reopened.length ? { reopened } : {}) });
|
|
499
|
+
}],
|
|
500
|
+
|
|
501
|
+
// Reference capture from an endpoint that is not a registered node (admin): a separate machine
|
|
502
|
+
// serving the public weights, which must not be listed, scheduled or probed. Body {endpoint (its
|
|
503
|
+
// OpenAI base URL, e.g. http://host:11434/v1), model_id, artifact}, optional {key} (sent as a
|
|
504
|
+
// Bearer token to that origin only; never stored, logged or returned), {runtime} (e.g. "ollama
|
|
505
|
+
// 0.12.3, CPU", kept privately with the capture) and {"replace": false}. Same SSRF guard, same
|
|
506
|
+
// private corpus and the same request body as Stage B. Lists nothing.
|
|
507
|
+
['POST', '/v0/fingerprints/capture-endpoint', async (req, res) => {
|
|
508
|
+
if (!adminOk(req, res)) return;
|
|
509
|
+
const { endpoint, model_id, artifact, key, runtime, replace = true } = await readJson(req);
|
|
510
|
+
let url;
|
|
511
|
+
try { url = new URL(endpoint); } catch { return problem(res, 400, 'bad-endpoint', 'endpoint must be an http(s) URL: the OpenAI base URL, e.g. http://host:11434/v1'); }
|
|
512
|
+
if (!['http:', 'https:'].includes(url.protocol) || url.username || url.password || url.search || url.hash || endpoint.length > 500) {
|
|
513
|
+
return problem(res, 400, 'bad-endpoint', 'endpoint must be an http(s) base URL without credentials, query or fragment');
|
|
514
|
+
}
|
|
515
|
+
if (typeof model_id !== 'string' || !model_id || model_id.length > 200) return problem(res, 400, 'bad-model-id', 'model_id must be the model name the endpoint serves');
|
|
516
|
+
if (typeof artifact !== 'string' || !ARTIFACT.test(artifact)) return problem(res, 400, 'bad-artifact', 'artifact must be hf:{org}/{repo}, ollama:{name}[:{tag}] or urn:proprietary:{vendor}:{model}');
|
|
517
|
+
if (key != null && (typeof key !== 'string' || key.length > 4096)) return problem(res, 400, 'bad-key', 'key must be a string');
|
|
518
|
+
if (runtime != null && (typeof runtime !== 'string' || runtime.length > 200)) return problem(res, 400, 'bad-runtime', 'runtime must be a short string');
|
|
519
|
+
const base = url.href.replace(/\/+$/, '');
|
|
520
|
+
const fetcher = key
|
|
521
|
+
? (u, opts = {}, timeoutMs) => safeFetch(u, new URL(u).origin === url.origin ? { ...opts, headers: { ...(opts.headers ?? {}), authorization: `Bearer ${key}` } } : opts, timeoutMs)
|
|
522
|
+
: safeFetch;
|
|
523
|
+
const offering = { offering_id: 'capture', model: { artifact }, binding: { model_id } };
|
|
524
|
+
let refs;
|
|
525
|
+
try { refs = await captureFingerprints(fetcher, { endpoints: { openai: base } }, offering, corpus.identityPrompts(IDENTITY_CAPTURE)); }
|
|
526
|
+
catch (err) { const why = String(err.message); return problem(res, 502, 'capture-failed', key ? why.split(key).join('…') : why); }
|
|
527
|
+
if (replace) await store.clearFingerprints(artifact);
|
|
528
|
+
await store.addFingerprints(artifact, refs);
|
|
529
|
+
await store.recordCapture(artifact, { how: 'endpoint', host: url.host, model_id, ...(runtime ? { runtime } : {}) });
|
|
530
|
+
const reopened = await planner.reopenAfterCapture(artifact);
|
|
531
|
+
sendJson(res, 200, { artifact, references: refs.length, corpus: corpus.private ? 'private' : 'built-in', source: { host: url.host, ...(runtime ? { runtime } : {}) }, ...(reopened.length ? { reopened } : {}) });
|
|
478
532
|
}],
|
|
479
533
|
|
|
480
534
|
// Dispute resolution (admin): the only way out of `disputed`. Body {"resolution": "..."}: what
|
|
@@ -618,6 +672,25 @@ export async function startRegistry({
|
|
|
618
672
|
});
|
|
619
673
|
}],
|
|
620
674
|
|
|
675
|
+
// Failed registrations: per ISO week, how many POST /v0/nodes were refused before anything was
|
|
676
|
+
// stored, by reason. Counts only. ?weeks=1..52 (default 12).
|
|
677
|
+
['GET', '/v0/stats/registrations', async (req, res, { query }) => {
|
|
678
|
+
const weeks = Math.min(52, Math.max(1, Math.floor(Number(query.get('weeks') ?? 12)) || 12));
|
|
679
|
+
const range = recentWeeks(weeks);
|
|
680
|
+
const rows = await store.registrationFailures(range.at(-1));
|
|
681
|
+
const out = new Map(range.map((w) => [w, { week: w, starts: weekStart(w), failed: Object.fromEntries(REGISTRATION_FAILURES.map((r) => [r, 0])), total: 0 }]));
|
|
682
|
+
for (const r of rows) {
|
|
683
|
+
const w = out.get(r.week);
|
|
684
|
+
if (!w || !REGISTRATION_FAILURES.includes(r.reason)) continue;
|
|
685
|
+
w.failed[r.reason] += Number(r.n);
|
|
686
|
+
w.total += Number(r.n);
|
|
687
|
+
}
|
|
688
|
+
sendJson(res, 200, {
|
|
689
|
+
counted: 'registrations (POST /v0/nodes) refused before anything was stored, per ISO week (Monday 00:00 UTC) and reason: card-unfetchable, card-invalid, namespace-mismatch. Counts only: never the card URL, the node id or the client.',
|
|
690
|
+
weeks: [...out.values()],
|
|
691
|
+
});
|
|
692
|
+
}],
|
|
693
|
+
|
|
621
694
|
['GET', '/v0/offerings', async (req, res, { query }) => {
|
|
622
695
|
let page;
|
|
623
696
|
try { page = await searchOfferingsPaged(store, query); }
|
package/src/stageb.js
CHANGED
|
@@ -37,11 +37,12 @@ export async function chatOnce(safeFetch, card, offering, content, maxTokens = I
|
|
|
37
37
|
const t0 = performance.now();
|
|
38
38
|
const { status, body } = await fetchJsonCapped(safeFetch, `${card.endpoints.openai}/chat/completions`, {
|
|
39
39
|
method: 'POST',
|
|
40
|
-
headers
|
|
40
|
+
// A reference capture from an endpoint that is not a node (no card) sends no ONP headers.
|
|
41
|
+
headers: card.node ? {
|
|
41
42
|
'content-type': 'application/json',
|
|
42
43
|
'onp-offering': `${card.node.id}/${offering.offering_id}`,
|
|
43
44
|
'onp-card-revision': card.revision,
|
|
44
|
-
},
|
|
45
|
+
} : { 'content-type': 'application/json' },
|
|
45
46
|
body: JSON.stringify({
|
|
46
47
|
model: offering.binding.model_id,
|
|
47
48
|
messages: [{ role: 'user', content }],
|
|
@@ -71,6 +72,40 @@ export async function captureFingerprints(safeFetch, card, offering, prompts = D
|
|
|
71
72
|
return refs;
|
|
72
73
|
}
|
|
73
74
|
|
|
75
|
+
/**
|
|
76
|
+
* A confirmed identity mismatch in Stage B, judged (ONP-3 §4a.4, first mismatch): `dispute`, or
|
|
77
|
+
* `inconclusive` for the node's first mismatch on an artefact since that artefact's references
|
|
78
|
+
* were last captured, whether or not any reference matched. Only hashes are stored, so a different
|
|
79
|
+
* model cannot be told from the same weights on other hardware, engine version or kernels, and a
|
|
80
|
+
* long-enough reply on other hardware can diverge on every prompt. A model swap gains one
|
|
81
|
+
* inconclusive run per artefact and capture at most, and gets no `verified` from it. Disputes at
|
|
82
|
+
* once: any non-matching prompt that went unanswered on either ask (a refusal or failed reply, so
|
|
83
|
+
* M4's rule that a refusal counts as a non-match keeps its force). Card revisions do not reset the
|
|
84
|
+
* count; only a new capture does.
|
|
85
|
+
* Returns {dispute: true, why} or {dispute: false, inconclusive: [{offering_id, artifact, matches, total}]}.
|
|
86
|
+
*/
|
|
87
|
+
export async function judgeMismatch(store, nodeId, stageB) {
|
|
88
|
+
const failed = (stageB.verdicts ?? []).filter((v) => v.identity && !v.identity.ok && !v.identity.unverified);
|
|
89
|
+
const inconclusive = [];
|
|
90
|
+
for (const v of failed) {
|
|
91
|
+
const id = v.identity;
|
|
92
|
+
const artifact = v.artifact;
|
|
93
|
+
if (!artifact) return { dispute: true, why: IDENTITY_MISMATCH };
|
|
94
|
+
if (id.unanswered || id.moved) return { dispute: true, why: IDENTITY_MISMATCH };
|
|
95
|
+
const since = await store.lastCaptureAt(artifact);
|
|
96
|
+
if (await store.countInconclusive(nodeId, artifact, since) > 0) {
|
|
97
|
+
return { dispute: true, why: IDENTITY_MISMATCH };
|
|
98
|
+
}
|
|
99
|
+
inconclusive.push({ offering_id: v.offering_id, artifact, matches: id.matches, total: id.total });
|
|
100
|
+
}
|
|
101
|
+
return inconclusive.length ? { dispute: false, inconclusive } : { dispute: true, why: IDENTITY_MISMATCH };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** The transition reason of a Stage B dispute (the identity probe record says how many references matched). */
|
|
105
|
+
export const IDENTITY_MISMATCH = 'Stage B identity fingerprint mismatch';
|
|
106
|
+
/** Probe record of a Stage B run that ended identity inconclusive. */
|
|
107
|
+
export const STAGE_B_INCONCLUSIVE = 'identity-inconclusive';
|
|
108
|
+
|
|
74
109
|
/** Whether a reply's text is the reference's: the exact-output comparison of ONP-3 §4a.4. */
|
|
75
110
|
export const matchesReference = (text, ref) => typeof text === 'string' && sha256(text) === ref.expected_hash;
|
|
76
111
|
|
|
@@ -85,10 +120,16 @@ export const STAGE_B_409 = 'identity-409';
|
|
|
85
120
|
* revision, or null when the pinned one is still current.
|
|
86
121
|
* - `stale`: a new revision, within the bound: recorded, the run stops unjudged, the caller retries;
|
|
87
122
|
* - `refused`: the current revision was pinned: a reply that does not match;
|
|
88
|
-
* - `
|
|
89
|
-
*
|
|
123
|
+
* - `repin`, beyond the bound, when the re-fetched card claims the same model for the offering: the run
|
|
124
|
+
* goes on with the re-fetched card pinned (`pin.card`) and asks again; a refusal with that revision
|
|
125
|
+
* pinned then counts as a reply that does not match. Before, the run ended as not passed, never as a
|
|
126
|
+
* dispute, so a node that swapped its model could publish a new revision at every run, reach the
|
|
127
|
+
* bound each time and stay at `community` instead of `disputed` (review M4, 24 Nov). An honest node
|
|
128
|
+
* that re-prices often loses nothing: it answers with the current revision pinned.
|
|
129
|
+
* - `moved`, beyond the bound, when the offering's claimed model or binding changed or is gone: the
|
|
130
|
+
* run ends as not passed (no reply was compared for the new claim; that change brings its own run).
|
|
90
131
|
*/
|
|
91
|
-
function makeOn409(store, nodeId,
|
|
132
|
+
function makeOn409(store, nodeId, pin, { revisionMoved, maxExcused409 }) {
|
|
92
133
|
// `status`: the reply that sent the registry to the card. Since rev. 14 scheduled runs go out on
|
|
93
134
|
// the card already held, so a 404 for a model the node has just dropped gets the same rule as a
|
|
94
135
|
// 409: re-fetched after the reply, excused only if the revision really moved, within the bound.
|
|
@@ -98,40 +139,67 @@ function makeOn409(store, nodeId, card, { revisionMoved, maxExcused409 }) {
|
|
|
98
139
|
const since = (await store.getSchedule(nodeId, 'B'))?.last_at ?? '';
|
|
99
140
|
const excused = await store.countProbes(nodeId, STAGE_B_409, since);
|
|
100
141
|
if (excused >= maxExcused409) {
|
|
101
|
-
|
|
142
|
+
const bound = `after ${excused} excused card changes since the last judged run (at most ${maxExcused409} are excused)`;
|
|
143
|
+
const latest = await store.latestCard(nodeId);
|
|
144
|
+
const now = latest?.revision === fresh ? latest.offerings?.find((o) => o.offering_id === offering.offering_id) : null;
|
|
145
|
+
if (now && testable(now) && sameModelClaim(offering, now)) {
|
|
146
|
+
pin.card = latest;
|
|
147
|
+
return { kind: 'repin', offering: now, beyond: `re-pinned to revision ${fresh} ${bound}` };
|
|
148
|
+
}
|
|
149
|
+
return { kind: 'moved', reason: `the card revision moved again during Stage B ${bound}, and the offering's claimed model or binding changed or is gone` };
|
|
102
150
|
}
|
|
103
151
|
await store.recordProbe(nodeId, offering.offering_id, 'B', STAGE_B_409, false,
|
|
104
|
-
`${status} with revision ${card.revision} pinned; card re-indexed at ${fresh}; Stage B runs again later`);
|
|
152
|
+
`${status} with revision ${pin.card.revision} pinned; card re-indexed at ${fresh}; Stage B runs again later`);
|
|
105
153
|
return { kind: 'stale' };
|
|
106
154
|
};
|
|
107
155
|
}
|
|
108
156
|
|
|
157
|
+
/** Whether two versions of an offering claim the same model behind the same binding. */
|
|
158
|
+
const sameModelClaim = (a, b) => a.model?.artifact === b.model?.artifact
|
|
159
|
+
&& a.binding?.profile === b.binding?.profile && a.binding?.model_id === b.binding?.model_id;
|
|
160
|
+
|
|
109
161
|
/**
|
|
110
162
|
* DS-ADM-02: identity check against stored references. A reply that does not match is asked once
|
|
111
163
|
* more before it counts (ONP-3 §6.3 disputes only a confirmed failure: batching on an engine with
|
|
112
164
|
* parallel slots can change a temperature-0 reply now and then). A 409 counts as a reply that does
|
|
113
165
|
* not match unless `on409` excuses it (makeOn409).
|
|
114
166
|
*/
|
|
115
|
-
async function probeIdentity(safeFetch,
|
|
116
|
-
let matches = 0, retried = 0, refused = 0, stop = null;
|
|
117
|
-
|
|
118
|
-
|
|
167
|
+
async function probeIdentity(safeFetch, pin, offering, refs, on409) {
|
|
168
|
+
let matches = 0, retried = 0, refused = 0, refusedRepinned = 0, repinned = null, stop = null;
|
|
169
|
+
let current = offering;
|
|
170
|
+
const ask = async (prompt, again = true) => {
|
|
171
|
+
const { status, text } = await chatOnce(safeFetch, pin.card, current, prompt);
|
|
119
172
|
if (status !== 200) {
|
|
120
173
|
// A 409, or another failure (a 404 for a model dropped since the card was fetched): only a
|
|
121
174
|
// revision that really moved excuses it; with the current revision pinned it does not match.
|
|
122
|
-
const what = await on409(
|
|
123
|
-
if (what.kind === '
|
|
175
|
+
const what = await on409(current, status);
|
|
176
|
+
if (what.kind === 'repin') {
|
|
177
|
+
// Beyond the bound: ask again with the revision just fetched pinned; a refusal then counts.
|
|
178
|
+
current = what.offering;
|
|
179
|
+
repinned = what.beyond;
|
|
180
|
+
if (again) return ask(prompt, false);
|
|
181
|
+
refusedRepinned++;
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
if (what.kind !== 'refused') stop = what;
|
|
185
|
+
else if (status === 409) refused++;
|
|
124
186
|
return null;
|
|
125
187
|
}
|
|
126
|
-
return
|
|
188
|
+
return text !== null ? sha256(text) : null;
|
|
127
189
|
};
|
|
190
|
+
// Non-matching prompts that got no text on either ask (a refusal or another failure): such a
|
|
191
|
+
// mismatch is never "inconclusive" (judgeMismatch), so a refusal keeps counting against the node.
|
|
192
|
+
let unanswered = 0;
|
|
128
193
|
for (const ref of refs) {
|
|
129
194
|
let hash = await ask(ref.prompt);
|
|
130
|
-
|
|
195
|
+
let noText = hash === null;
|
|
196
|
+
if (hash !== ref.expected_hash && !stop) { retried++; hash = await ask(ref.prompt); noText ||= hash === null; }
|
|
131
197
|
if (hash === ref.expected_hash) matches++;
|
|
198
|
+
else if (noText && !stop) unanswered++;
|
|
132
199
|
if (stop) break;
|
|
133
200
|
}
|
|
134
|
-
const extra = { ...(retried ? { retried } : {}), ...(refused ? { refused } : {}) }
|
|
201
|
+
const extra = { ...(retried ? { retried } : {}), ...(refused ? { refused } : {}), ...(unanswered ? { unanswered } : {}),
|
|
202
|
+
...(repinned ? { repinned, refused_repinned: refusedRepinned } : {}) };
|
|
135
203
|
if (stop?.kind === 'stale') return { ok: false, matches, total: refs.length, ...extra, stale: true };
|
|
136
204
|
if (stop?.kind === 'moved') return { ok: false, matches, total: refs.length, ...extra, moved: true, reason: stop.reason };
|
|
137
205
|
// Deterministic battery: require all prompts to match the reference distribution.
|
|
@@ -237,14 +305,14 @@ async function probeCapacity(safeFetch, card, offering, corpus, { steps = CAPACI
|
|
|
237
305
|
* offering cannot be verified: no usable reference for the artefact, or a proprietary artefact
|
|
238
306
|
* claimed outside the vendor's namespace.
|
|
239
307
|
*/
|
|
240
|
-
async function identityOf(store, nodeId, safeFetch,
|
|
308
|
+
async function identityOf(store, nodeId, safeFetch, pin, offering, { corpus, vendors, identitySample, on409 }) {
|
|
241
309
|
const artifact = offering.model?.artifact;
|
|
242
310
|
const claim = vendorClaim(artifact, nodeId, vendors);
|
|
243
311
|
if (!claim.ok) return { ok: false, unverified: true, reason: `${artifact} is not this node's to claim (vendor namespace)` };
|
|
244
312
|
// References captured with public prompts prove nothing: a node could have recognised them.
|
|
245
313
|
const refs = (await store.getFingerprints(artifact)).filter((r) => corpus.usableReference(r.prompt));
|
|
246
314
|
if (!refs.length) return { ok: false, unverified: true, reason: NO_REFERENCE };
|
|
247
|
-
return probeIdentity(safeFetch,
|
|
315
|
+
return probeIdentity(safeFetch, pin, offering, sample(refs, identitySample), on409);
|
|
248
316
|
}
|
|
249
317
|
|
|
250
318
|
/**
|
|
@@ -260,7 +328,9 @@ export async function runStageB(store, nodeId, card, {
|
|
|
260
328
|
safeFetch, capacity = {}, corpus = DEV_CORPUS, vendors = vendorTable(), signed = true, identitySample = IDENTITY_SAMPLE,
|
|
261
329
|
revisionMoved = null, maxExcused409 = MAX_EXCUSED_409,
|
|
262
330
|
} = {}) {
|
|
263
|
-
|
|
331
|
+
// The card the run pins: the one held, until a refusal beyond the bound re-pins the fetched one.
|
|
332
|
+
const pin = { card };
|
|
333
|
+
const on409 = makeOn409(store, nodeId, pin, { revisionMoved, maxExcused409 });
|
|
264
334
|
const untested = untestedOfferings(card);
|
|
265
335
|
if (!signed) {
|
|
266
336
|
await store.recordProbe(nodeId, null, 'B', 'signature', false, UNSIGNED_CARD);
|
|
@@ -270,26 +340,31 @@ export async function runStageB(store, nodeId, card, {
|
|
|
270
340
|
return { ok: false, identityFailed: false, reason: NO_TESTED_OFFERINGS, verdicts: [], untested };
|
|
271
341
|
}
|
|
272
342
|
const verdicts = [];
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
343
|
+
// The offering as the pinned card lists it now (a re-pin replaces the card mid-run).
|
|
344
|
+
const pinned = (o) => pin.card.offerings.find((p) => p.offering_id === o.offering_id) ?? o;
|
|
345
|
+
for (const listed of card.offerings) {
|
|
346
|
+
if (!testable(listed)) continue;
|
|
347
|
+
let offering = pinned(listed);
|
|
348
|
+
const verdict = { offering_id: offering.offering_id, artifact: offering.model?.artifact ?? null, identity: null, context: null, capacity: null };
|
|
276
349
|
|
|
277
|
-
verdict.identity = await identityOf(store, nodeId, safeFetch,
|
|
350
|
+
verdict.identity = await identityOf(store, nodeId, safeFetch, pin, offering, { corpus, vendors, identitySample, on409 });
|
|
278
351
|
if (verdict.identity.stale) {
|
|
279
352
|
// The card's revision really moved (an excused 409, recorded). Abort without judging: the caller retries.
|
|
280
353
|
return { ok: false, identityFailed: false, stale: true, verdicts: [...verdicts, verdict], untested };
|
|
281
354
|
}
|
|
282
|
-
const { matches, total, refused } = verdict.identity;
|
|
355
|
+
const { matches, total, refused, repinned, refused_repinned: refusedRepinned } = verdict.identity;
|
|
283
356
|
await store.recordProbe(nodeId, offering.offering_id, 'B', 'identity', verdict.identity.ok,
|
|
284
357
|
verdict.identity.unverified ? `identity unverified: ${verdict.identity.reason}`
|
|
285
358
|
: verdict.identity.moved ? `not judged: ${verdict.identity.reason}`
|
|
286
|
-
: `${matches}/${total} reference matches${refused ? `; ${refused} replies refused with 409, the current card revision pinned` : ''}`
|
|
359
|
+
: `${matches}/${total} reference matches${refused ? `; ${refused} replies refused with 409, the current card revision pinned` : ''}`
|
|
360
|
+
+ (repinned ? `; ${repinned}${refusedRepinned ? `, then ${refusedRepinned} refusals with it pinned, counted as replies that do not match` : ''}` : ''));
|
|
287
361
|
if (verdict.identity.moved) {
|
|
288
|
-
// Beyond the bound: not passed, and nothing more is sent
|
|
362
|
+
// Beyond the bound, and the claimed model changed: not passed, and nothing more is sent.
|
|
289
363
|
return { ok: false, identityFailed: false, reason: `${offering.offering_id}: ${verdict.identity.reason}`, verdicts: [...verdicts, verdict], untested };
|
|
290
364
|
}
|
|
365
|
+
offering = pinned(offering);
|
|
291
366
|
|
|
292
|
-
verdict.context = await probeContext(safeFetch, card, offering, corpus);
|
|
367
|
+
verdict.context = await probeContext(safeFetch, pin.card, offering, corpus);
|
|
293
368
|
await store.recordProbe(nodeId, offering.offering_id, 'B', 'context', verdict.context.ok,
|
|
294
369
|
`claimed ${verdict.context.claimed}, verified ${verdict.context.verified_cap}`,
|
|
295
370
|
verdict.context);
|
|
@@ -297,13 +372,15 @@ export async function runStageB(store, nodeId, card, {
|
|
|
297
372
|
// earlier cap; 0 = nothing verified, shown as unverified rather than trusting the claim.
|
|
298
373
|
await store.setObservation(nodeId, offering.offering_id, 'context_cap', verdict.context.verified_cap);
|
|
299
374
|
|
|
300
|
-
verdict.capacity = await probeCapacity(safeFetch, card, offering, corpus, capacity);
|
|
375
|
+
verdict.capacity = await probeCapacity(safeFetch, pin.card, offering, corpus, capacity);
|
|
301
376
|
if (!verdict.capacity.ok) {
|
|
302
377
|
// A failed ramp on a card that has since moved (the model dropped or changed during the run)
|
|
303
378
|
// is not judged, by the same rule and bound as a 409.
|
|
304
379
|
const what = await on409(offering, 'capacity failure');
|
|
305
380
|
if (what.kind === 'stale') return { ok: false, identityFailed: false, stale: true, verdicts: [...verdicts, verdict], untested };
|
|
306
381
|
if (what.kind === 'moved') return { ok: false, identityFailed: false, reason: `${offering.offering_id}: ${what.reason}`, verdicts: [...verdicts, verdict], untested };
|
|
382
|
+
// Beyond the bound, same model: the ramp once more with the fetched card pinned, and that one counts.
|
|
383
|
+
if (what.kind === 'repin') { offering = what.offering; verdict.capacity = await probeCapacity(safeFetch, pin.card, offering, corpus, capacity); }
|
|
307
384
|
}
|
|
308
385
|
await store.recordProbe(nodeId, offering.offering_id, 'B', 'capacity', verdict.capacity.ok, null, verdict.capacity);
|
|
309
386
|
if (verdict.capacity.ttft_ms.p50 != null) {
|
package/src/store-pg.js
CHANGED
|
@@ -54,6 +54,16 @@ const SCHEMA = `
|
|
|
54
54
|
CREATE TABLE IF NOT EXISTS vendor_namespaces (
|
|
55
55
|
vendor TEXT PRIMARY KEY, namespaces TEXT NOT NULL, updated_at TEXT NOT NULL
|
|
56
56
|
);
|
|
57
|
+
CREATE TABLE IF NOT EXISTS fingerprint_captures (
|
|
58
|
+
id SERIAL PRIMARY KEY, artifact TEXT NOT NULL, source TEXT NOT NULL, captured_at TEXT NOT NULL
|
|
59
|
+
);
|
|
60
|
+
CREATE TABLE IF NOT EXISTS identity_inconclusive (
|
|
61
|
+
id SERIAL PRIMARY KEY, node_id TEXT NOT NULL, artifact TEXT NOT NULL, at TEXT NOT NULL
|
|
62
|
+
);
|
|
63
|
+
CREATE TABLE IF NOT EXISTS registration_failures (
|
|
64
|
+
week TEXT NOT NULL, reason TEXT NOT NULL, n INTEGER NOT NULL,
|
|
65
|
+
PRIMARY KEY (week, reason)
|
|
66
|
+
);
|
|
57
67
|
`;
|
|
58
68
|
|
|
59
69
|
const NODE_FLAGS = ['institutional', 'founding']; // same list as store.js
|
|
@@ -215,6 +225,33 @@ export async function createPgStore({ connectionString, pool } = {}) {
|
|
|
215
225
|
? q('SELECT * FROM request_counts WHERE node_id = $1 AND week >= $2 ORDER BY week DESC', [nodeId, sinceWeek])
|
|
216
226
|
: q('SELECT * FROM request_counts WHERE week >= $1 ORDER BY week DESC', [sinceWeek]);
|
|
217
227
|
},
|
|
228
|
+
async deleteSchedule(nodeId, stage) {
|
|
229
|
+
await q('DELETE FROM schedule WHERE node_id = $1 AND stage = $2', [nodeId, stage]);
|
|
230
|
+
},
|
|
231
|
+
async recordCapture(artifact, source) {
|
|
232
|
+
await q('INSERT INTO fingerprint_captures (artifact, source, captured_at) VALUES ($1, $2, $3)', [artifact, JSON.stringify(source), now()]);
|
|
233
|
+
},
|
|
234
|
+
async lastCaptureAt(artifact) {
|
|
235
|
+
return (await q('SELECT MAX(captured_at) AS at FROM fingerprint_captures WHERE artifact = $1', [artifact]))[0]?.at ?? null;
|
|
236
|
+
},
|
|
237
|
+
async captures(artifact) {
|
|
238
|
+
return (await q('SELECT artifact, source, captured_at FROM fingerprint_captures WHERE artifact = $1 ORDER BY id DESC', [artifact]))
|
|
239
|
+
.map((r) => ({ ...r, source: JSON.parse(r.source) }));
|
|
240
|
+
},
|
|
241
|
+
async recordInconclusive(nodeId, artifact) {
|
|
242
|
+
await q('INSERT INTO identity_inconclusive (node_id, artifact, at) VALUES ($1, $2, $3)', [nodeId, artifact, now()]);
|
|
243
|
+
},
|
|
244
|
+
async countInconclusive(nodeId, artifact, since = null) {
|
|
245
|
+
return Number((await q('SELECT COUNT(*) AS n FROM identity_inconclusive WHERE node_id = $1 AND artifact = $2 AND at > $3',
|
|
246
|
+
[nodeId, artifact, since ?? '']))[0].n);
|
|
247
|
+
},
|
|
248
|
+
async addRegistrationFailure(week, reason) {
|
|
249
|
+
await q(`INSERT INTO registration_failures (week, reason, n) VALUES ($1, $2, 1)
|
|
250
|
+
ON CONFLICT (week, reason) DO UPDATE SET n = registration_failures.n + 1`, [week, reason]);
|
|
251
|
+
},
|
|
252
|
+
async registrationFailures(sinceWeek = '0000-W00') {
|
|
253
|
+
return q('SELECT * FROM registration_failures WHERE week >= $1 ORDER BY week DESC', [sinceWeek]);
|
|
254
|
+
},
|
|
218
255
|
async close() { await p.end(); },
|
|
219
256
|
};
|
|
220
257
|
}
|
package/src/store.js
CHANGED
|
@@ -79,6 +79,22 @@ export async function createSqliteStore(path = ':memory:') {
|
|
|
79
79
|
CREATE TABLE IF NOT EXISTS vendor_namespaces (
|
|
80
80
|
vendor TEXT PRIMARY KEY, namespaces TEXT NOT NULL, updated_at TEXT NOT NULL
|
|
81
81
|
);
|
|
82
|
+
-- Each reference capture of an artefact: when, and from where (host, runtime, how), so a later
|
|
83
|
+
-- mismatch can be traced to a hardware or runtime difference. Private: no API or export reads it.
|
|
84
|
+
CREATE TABLE IF NOT EXISTS fingerprint_captures (
|
|
85
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT, artifact TEXT NOT NULL, source TEXT NOT NULL, captured_at TEXT NOT NULL
|
|
86
|
+
);
|
|
87
|
+
-- Stage B runs that ended "identity inconclusive" (ONP-3 §4a.4): a node's first confirmed partial
|
|
88
|
+
-- mismatch for an artefact since that artefact's last capture. The next one disputes.
|
|
89
|
+
CREATE TABLE IF NOT EXISTS identity_inconclusive (
|
|
90
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT, node_id TEXT NOT NULL, artifact TEXT NOT NULL, at TEXT NOT NULL
|
|
91
|
+
);
|
|
92
|
+
-- Registrations refused before anything was stored, per ISO week and reason. Counts only: never
|
|
93
|
+
-- the card URL, the node id or the client.
|
|
94
|
+
CREATE TABLE IF NOT EXISTS registration_failures (
|
|
95
|
+
week TEXT NOT NULL, reason TEXT NOT NULL, n INTEGER NOT NULL,
|
|
96
|
+
PRIMARY KEY (week, reason)
|
|
97
|
+
);
|
|
82
98
|
`);
|
|
83
99
|
// Databases created before the founding mark existed: add the column in place.
|
|
84
100
|
if (!db.prepare('PRAGMA table_info(nodes)').all().some((c) => c.name === 'founding')) {
|
|
@@ -228,6 +244,36 @@ export async function createSqliteStore(path = ':memory:') {
|
|
|
228
244
|
? db.prepare('SELECT * FROM request_counts WHERE node_id = ? AND week >= ? ORDER BY week DESC').all(nodeId, sinceWeek)
|
|
229
245
|
: db.prepare('SELECT * FROM request_counts WHERE week >= ? ORDER BY week DESC').all(sinceWeek);
|
|
230
246
|
},
|
|
247
|
+
async deleteSchedule(nodeId, stage) {
|
|
248
|
+
db.prepare('DELETE FROM schedule WHERE node_id = ? AND stage = ?').run(nodeId, stage);
|
|
249
|
+
},
|
|
250
|
+
/** source: {how, host, runtime?, model_id?, node_id?, offering_id?} — kept private. */
|
|
251
|
+
async recordCapture(artifact, source) {
|
|
252
|
+
db.prepare('INSERT INTO fingerprint_captures (artifact, source, captured_at) VALUES (?, ?, ?)').run(artifact, JSON.stringify(source), now());
|
|
253
|
+
},
|
|
254
|
+
/** ISO time of an artefact's last reference capture, or null. */
|
|
255
|
+
async lastCaptureAt(artifact) {
|
|
256
|
+
return db.prepare('SELECT MAX(captured_at) AS at FROM fingerprint_captures WHERE artifact = ?').get(artifact)?.at ?? null;
|
|
257
|
+
},
|
|
258
|
+
async captures(artifact) {
|
|
259
|
+
return db.prepare('SELECT artifact, source, captured_at FROM fingerprint_captures WHERE artifact = ? ORDER BY id DESC').all(artifact)
|
|
260
|
+
.map((r) => ({ ...r, source: JSON.parse(r.source) }));
|
|
261
|
+
},
|
|
262
|
+
async recordInconclusive(nodeId, artifact) {
|
|
263
|
+
db.prepare('INSERT INTO identity_inconclusive (node_id, artifact, at) VALUES (?, ?, ?)').run(nodeId, artifact, now());
|
|
264
|
+
},
|
|
265
|
+
/** Inconclusive runs for a node and artefact after an ISO time (null: ever). */
|
|
266
|
+
async countInconclusive(nodeId, artifact, since = null) {
|
|
267
|
+
return db.prepare('SELECT COUNT(*) AS n FROM identity_inconclusive WHERE node_id = ? AND artifact = ? AND at > ?')
|
|
268
|
+
.get(nodeId, artifact, since ?? '').n;
|
|
269
|
+
},
|
|
270
|
+
async addRegistrationFailure(week, reason) {
|
|
271
|
+
db.prepare(`INSERT INTO registration_failures (week, reason, n) VALUES (?, ?, 1)
|
|
272
|
+
ON CONFLICT(week, reason) DO UPDATE SET n = registration_failures.n + 1`).run(week, reason);
|
|
273
|
+
},
|
|
274
|
+
async registrationFailures(sinceWeek = '0000-W00') {
|
|
275
|
+
return db.prepare('SELECT * FROM registration_failures WHERE week >= ? ORDER BY week DESC').all(sinceWeek);
|
|
276
|
+
},
|
|
231
277
|
async close() { db.close(); },
|
|
232
278
|
};
|
|
233
279
|
}
|
package/src/web/index.html
CHANGED
|
@@ -655,20 +655,20 @@
|
|
|
655
655
|
<p class="sub">Listing is open; tiers are earned. The registry runs an automated admission battery against your live endpoints — no paperwork, no gatekeepers, no exceptions. Every verdict is recorded and visible in your node's listing history.</p>
|
|
656
656
|
<div class="panel pad" style="max-width:56rem">
|
|
657
657
|
<div class="stage"><span class="k">STAGE A</span><span><b>Conformance</b> — gate to <span class="chip t-community">COMMUNITY</span>, minutes. Health endpoint live; card valid; models list agrees with the card; one blind invocation returns proper usage accounting; a proprietary artefact (<code>urn:proprietary:{vendor}:…</code>) only from that vendor's own namespace, so name open-weight models by their public record (<code>hf:</code>, <code>ollama:</code>). Runs when you verify your registration, on every new card revision, and again at least every 6 hours on the registry's own timer.</span></div>
|
|
658
|
-
<div class="stage"><span class="k">STAGE B</span><span><b>Substance</b> — gate to <span class="chip t-verified">VERIFIED</span>, hours. The registry chooses when it runs; nobody can ask for it. <b>Identity fingerprinting:</b> prompts from a private set, at temperature 0, compared with reference answers the registry captured from a deployment of the same weights it trusts. With no reference for your model's artefact, identity is unverified and the node stays at community. A mismatch marks the node <i>disputed</i> and delists it; registering again does not end a dispute, only a resolution the registry records after review. A 409 to a fingerprint prompt stops the run only when your card's revision really changed (then it runs again within the hour, at most 3 times before a run is judged); with the current revision pinned, a 409 counts as a reply that does not match. <b>Signed card:</b> the verified tier needs a card whose signature verifies against your JWKS. <b>Card-only listings:</b> if you gave a probe key at registration, probes carrying it are easy to pick out, so the node stays at community until the registry has bought access to your API as an ordinary customer; from then on probes use that access, and the next Stage B can verify the node. <b>Context verification:</b> needle-in-haystack probes at 25/50/90% of the claimed window; overclaims are capped to the verified size, visibly. <b>Capacity ramp:</b> stepped concurrent load; measured TTFT/throughput overrides claims in search results.</span></div>
|
|
658
|
+
<div class="stage"><span class="k">STAGE B</span><span><b>Substance</b> — gate to <span class="chip t-verified">VERIFIED</span>, hours. The registry chooses when it runs; nobody can ask for it. <b>Identity fingerprinting:</b> prompts from a private set, at temperature 0, compared with reference answers the registry captured from a deployment of the same weights it trusts. With no reference for your model's artefact, identity is unverified and the node stays at community. A confirmed mismatch marks the node <i>disputed</i> and delists it; registering again does not end a dispute, only a resolution the registry records after review. The exception is a first mismatch: when every prompt got a reply, the run ends <i>identity inconclusive</i> (not passed, not disputed, and a verified node returns to community), even if no reply matched, because exact replies can differ between processors and engine versions. Stage B then waits until the registry has captured the references again or reviewed the case, and a second mismatch disputes. A 409 to a fingerprint prompt stops the run only when your card's revision really changed (then it runs again within the hour, at most 3 times before a run is judged); with the current revision pinned, or beyond those 3, a 409 counts as a reply that does not match. <b>Signed card:</b> the verified tier needs a card whose signature verifies against your JWKS. <b>Card-only listings:</b> if you gave a probe key at registration, probes carrying it are easy to pick out, so the node stays at community until the registry has bought access to your API as an ordinary customer; from then on probes use that access, and the next Stage B can verify the node. <b>Context verification:</b> needle-in-haystack probes at 25/50/90% of the claimed window; overclaims are capped to the verified size, visibly. <b>Capacity ramp:</b> stepped concurrent load; measured TTFT/throughput overrides claims in search results.</span></div>
|
|
659
659
|
<div class="stage"><span class="k">STAGE C</span><span><b>Continuous</b> — keeps the tier honest. Liveness sweeps feed a rolling availability score; random blind invocations at unpredictable times, worded like ordinary requests, defeat "benchmark mode". On verified nodes some of them ask an identity prompt, and a reply that is not the reference's brings Stage B within the hour. Sustained liveness failures suspend the listing; blind invocations that keep failing while the node answers its health checks cost it a tier.</span></div>
|
|
660
660
|
<div class="stage"><span class="k">COVERAGE</span><span><b>What is tested.</b> This registry has tests only for chat offerings (<code>onp.openai.chat/v1</code>). A tier covers only the offerings it could test: speech, embeddings, image or any other offering is listed as <span class="chip untested">UNTESTED</span>, and its tier is capped to <span class="chip t-unverified">UNVERIFIED</span> whatever the node's tier. A node with no chat offering stays unverified, because Stage A has nothing to call.</span></div>
|
|
661
661
|
</div>
|
|
662
662
|
<h2 id="probe-load">Probe load</h2>
|
|
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
|
-
<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)
|
|
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); a scheduled run uses the card the registry already holds.<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
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).
|
|
670
670
|
<br>· <b>Capacity ramp:</b> one batch each of 1, 4 and 8 parallel requests (13 calls, at most 48 output tokens each) inside a 3-second budget; a step that would start after the budget is skipped.</span></div>
|
|
671
|
-
<div class="stage"><span class="k">STAGE C</span><span><b>When:</b> continuously, for community, verified and attested nodes, and for nodes suspended for liveness until they recover.<br><b>Sends:</b> 1 GET to your health endpoint every 5 minutes on average (each gap is random, 2.5 to 7.5 minutes), and 1 blind chat completion per node per hour on average (30 to 90 minutes apart, to a randomly chosen chat offering, at temperature 0 and at most 64 output tokens),
|
|
671
|
+
<div class="stage"><span class="k">STAGE C</span><span><b>When:</b> continuously, for community, verified and attested nodes, and for nodes suspended for liveness until they recover.<br><b>Sends:</b> 1 GET to your health endpoint every 5 minutes on average (each gap is random, 2.5 to 7.5 minutes), and 1 blind chat completion per node per hour on average (30 to 90 minutes apart, to a randomly chosen chat offering, at temperature 0 and at most 64 output tokens), on the card the registry already holds; it fetches your card about once an hour, on a timer of its own. That is about 288 health checks and 24 chat calls a day per node, whatever the number of offerings.<br><b>Identity:</b> on verified and attested nodes, about 1 in 4 of those calls asks one of the identity prompts the registry holds references for, instead of an ordinary request and in the same form. A reply that does not match is asked once more; a second miss makes Stage B due within the hour, at most once a day. It never changes your tier by itself.<br><b>409 answers:</b> excused only when your card's revision really changed, at most 3 a day; the registry then fetches the new card, asks once more at once, and sends one more blind chat completion against the new revision at a random time within the hour. Any other 409 counts as a failed call. When 3 blind calls in a row fail while your health checks pass, the node drops one tier (verified to community, community to unverified); the scheduled stages bring it back.</span></div>
|
|
672
672
|
<div class="stage"><span class="k">REFERENCES</span><span><b>When:</b> when the registry admin captures identity references for a model, from a deployment of the same weights the registry trusts.<br><b>Sends:</b> 8 chat completions at temperature 0, at most 64 output tokens each.</span></div>
|
|
673
673
|
<div class="stage"><span class="k">LOCATION</span><span><b>When:</b> after verification and then daily.<br><b>Sends:</b> 3 TCP connections to port 443 of your API host from each probe site (Nuremberg and Helsinki). No HTTP request.</span></div>
|
|
674
674
|
</div>
|