@opennodes/registry 0.1.58 → 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 +1 -1
- package/src/schedule.js +48 -0
- package/src/server.js +85 -9
- package/src/stageb.js +45 -5
- package/src/store-pg.js +37 -0
- package/src/store.js +46 -0
- 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.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",
|
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
|
@@ -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 = {
|
|
@@ -155,6 +158,11 @@ export async function startRegistry({
|
|
|
155
158
|
* operator's probe key (card-only listings of keyed APIs), and only toward the card's own
|
|
156
159
|
* endpoint origins — never to anything else.
|
|
157
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
|
+
|
|
158
166
|
async function authFetch(nodeId, card) {
|
|
159
167
|
const key = (await store.getCustomerKey(nodeId)) ?? (await store.getProbeKey(nodeId));
|
|
160
168
|
if (!key || !card?.endpoints) return safeFetch;
|
|
@@ -313,9 +321,22 @@ export async function startRegistry({
|
|
|
313
321
|
safeFetch: await authFetch(nodeId, card), capacity: stageBCapacity, corpus, vendors: await vendors(), signed: Boolean(revision?.sig_ok), revisionMoved,
|
|
314
322
|
});
|
|
315
323
|
const node = await store.getNode(nodeId);
|
|
324
|
+
let result = stageB;
|
|
316
325
|
if (!stageB.stale && LISTED.includes(node.state)) {
|
|
317
|
-
|
|
318
|
-
|
|
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}`);
|
|
319
340
|
} else if (stageB.ok && held) {
|
|
320
341
|
// Passed, but on probes the operator could tell apart: it stays at (or returns to) community.
|
|
321
342
|
stageB.held = CUSTOMER_ACCESS_NEEDED;
|
|
@@ -329,8 +350,8 @@ export async function startRegistry({
|
|
|
329
350
|
await store.setState(nodeId, 'community', `Stage B failed: ${stageB.reason}`);
|
|
330
351
|
}
|
|
331
352
|
}
|
|
332
|
-
await planner.afterStageB(nodeId, card,
|
|
333
|
-
return
|
|
353
|
+
await planner.afterStageB(nodeId, card, result);
|
|
354
|
+
return result;
|
|
334
355
|
} finally {
|
|
335
356
|
stageBRunning.delete(nodeId);
|
|
336
357
|
}
|
|
@@ -343,15 +364,16 @@ export async function startRegistry({
|
|
|
343
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');
|
|
344
365
|
if (!card_url) return problem(res, 400, 'missing-card-url', 'body must be {"card_url": "..."}');
|
|
345
366
|
let card;
|
|
346
|
-
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)); }
|
|
347
368
|
const errors = validateCard(card);
|
|
348
|
-
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('; ')); }
|
|
349
370
|
|
|
350
371
|
const nodeId = card.node.id;
|
|
351
372
|
const origin = new URL(card_url).origin;
|
|
352
373
|
// The card must be served by a host that controls the claimed id (reverse-DNS). Otherwise anyone
|
|
353
374
|
// could host a card naming someone else's node and pass the HTTP challenge on their own server.
|
|
354
375
|
if (!namespaceOk(origin, nodeId)) {
|
|
376
|
+
await failedRegistration('namespace-mismatch');
|
|
355
377
|
return problem(res, 403, 'namespace-mismatch',
|
|
356
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}`);
|
|
357
379
|
}
|
|
@@ -471,7 +493,42 @@ export async function startRegistry({
|
|
|
471
493
|
catch (err) { return problem(res, 502, 'capture-failed', String(err.message)); }
|
|
472
494
|
if (replace) await store.clearFingerprints(target);
|
|
473
495
|
await store.addFingerprints(target, refs);
|
|
474
|
-
|
|
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 } : {}) });
|
|
475
532
|
}],
|
|
476
533
|
|
|
477
534
|
// Dispute resolution (admin): the only way out of `disputed`. Body {"resolution": "..."}: what
|
|
@@ -615,6 +672,25 @@ export async function startRegistry({
|
|
|
615
672
|
});
|
|
616
673
|
}],
|
|
617
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
|
+
|
|
618
694
|
['GET', '/v0/offerings', async (req, res, { query }) => {
|
|
619
695
|
let page;
|
|
620
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
|
|
|
@@ -152,13 +187,18 @@ async function probeIdentity(safeFetch, pin, offering, refs, on409) {
|
|
|
152
187
|
}
|
|
153
188
|
return text !== null ? sha256(text) : null;
|
|
154
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;
|
|
155
193
|
for (const ref of refs) {
|
|
156
194
|
let hash = await ask(ref.prompt);
|
|
157
|
-
|
|
195
|
+
let noText = hash === null;
|
|
196
|
+
if (hash !== ref.expected_hash && !stop) { retried++; hash = await ask(ref.prompt); noText ||= hash === null; }
|
|
158
197
|
if (hash === ref.expected_hash) matches++;
|
|
198
|
+
else if (noText && !stop) unanswered++;
|
|
159
199
|
if (stop) break;
|
|
160
200
|
}
|
|
161
|
-
const extra = { ...(retried ? { retried } : {}), ...(refused ? { refused } : {}),
|
|
201
|
+
const extra = { ...(retried ? { retried } : {}), ...(refused ? { refused } : {}), ...(unanswered ? { unanswered } : {}),
|
|
162
202
|
...(repinned ? { repinned, refused_repinned: refusedRepinned } : {}) };
|
|
163
203
|
if (stop?.kind === 'stale') return { ok: false, matches, total: refs.length, ...extra, stale: true };
|
|
164
204
|
if (stop?.kind === 'moved') return { ok: false, matches, total: refs.length, ...extra, moved: true, reason: stop.reason };
|
|
@@ -305,7 +345,7 @@ export async function runStageB(store, nodeId, card, {
|
|
|
305
345
|
for (const listed of card.offerings) {
|
|
306
346
|
if (!testable(listed)) continue;
|
|
307
347
|
let offering = pinned(listed);
|
|
308
|
-
const verdict = { offering_id: offering.offering_id, identity: null, context: null, capacity: null };
|
|
348
|
+
const verdict = { offering_id: offering.offering_id, artifact: offering.model?.artifact ?? null, identity: null, context: null, capacity: null };
|
|
309
349
|
|
|
310
350
|
verdict.identity = await identityOf(store, nodeId, safeFetch, pin, offering, { corpus, vendors, identitySample, on409 });
|
|
311
351
|
if (verdict.identity.stale) {
|
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,7 +655,7 @@
|
|
|
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, 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>
|
|
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>
|