@tpsdev-ai/flair 0.62.0 → 0.63.1
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 +14 -13
- package/SECURITY.md +73 -43
- package/config.yaml +11 -11
- package/dist/bridges/runtime/execute.js +1 -0
- package/dist/bridges/runtime/import-runner.js +4 -0
- package/dist/bridges/types.js +1 -0
- package/dist/build-info.json +3 -3
- package/dist/cli.js +309 -205
- package/dist/commands/agent.js +325 -137
- package/dist/commands/attention.js +2 -0
- package/dist/commands/backup-approval.js +218 -0
- package/dist/commands/backup.js +37 -33
- package/dist/commands/bootstrap.js +5 -1
- package/dist/commands/bridge.js +10 -0
- package/dist/commands/deploy.js +37 -7
- package/dist/commands/doctor.js +206 -42
- package/dist/commands/export.js +144 -15
- package/dist/commands/federation.js +653 -68
- package/dist/commands/grant.js +5 -6
- package/dist/commands/help.js +25 -0
- package/dist/commands/idp.js +14 -19
- package/dist/commands/import.js +167 -34
- package/dist/commands/init.js +380 -164
- package/dist/commands/integrity.js +5 -6
- package/dist/commands/keys.js +12 -8
- package/dist/commands/mcp.js +157 -79
- package/dist/commands/memory.js +38 -17
- package/dist/commands/migrate-harness-memory.js +9 -3
- package/dist/commands/orgevent.js +5 -10
- package/dist/commands/principal.js +32 -39
- package/dist/commands/quality.js +26 -3
- package/dist/commands/reembed.js +468 -111
- package/dist/commands/rem.js +484 -65
- package/dist/commands/restore.js +352 -44
- package/dist/commands/search.js +2 -0
- package/dist/commands/service.js +109 -2
- package/dist/commands/soul.js +0 -6
- package/dist/commands/status.js +165 -124
- package/dist/commands/test.js +4 -1
- package/dist/commands/upgrade.js +53 -22
- package/dist/commands/workspace.js +7 -8
- package/dist/deploy.js +59 -3
- package/dist/doctor-client.js +9 -25
- package/dist/fabric-upgrade.js +12 -2
- package/dist/federation/presence-send.js +139 -0
- package/dist/federation/scheduler.js +148 -12
- package/dist/federation-verify.js +269 -177
- package/dist/install/clients.js +171 -35
- package/dist/keystore.js +77 -10
- package/dist/lib/agent-id-rule.js +44 -2
- package/dist/lib/agent-key-file.js +509 -0
- package/dist/lib/agent-rotation-lock.js +249 -0
- package/dist/lib/atomic-write.js +3 -3
- package/dist/lib/auth-resolve.js +1040 -64
- package/dist/lib/backup-approval-store.js +612 -0
- package/dist/lib/backup-artifact.js +343 -0
- package/dist/lib/config-critical-section.js +212 -25
- package/dist/lib/connect-phase.js +33 -0
- package/dist/lib/daemon-liveness.js +2 -1
- package/dist/lib/federation-pair-access.js +4 -0
- package/dist/lib/federation-retry-queue.js +283 -0
- package/dist/lib/federation-retry-row.js +101 -0
- package/dist/lib/instruction-event-contract.js +17 -0
- package/dist/lib/instruction-event-doctor.js +102 -0
- package/dist/lib/key-dir.js +203 -0
- package/dist/lib/launchd-management.js +21 -6
- package/dist/lib/local-instance-pair.js +8 -1
- package/dist/lib/mcp-enable.js +14 -15
- package/dist/lib/memory-attributes.js +2 -0
- package/dist/lib/memory-provider-timeout.js +33 -0
- package/dist/lib/mqtt-config.js +132 -0
- package/dist/lib/mqtt-listener-doctor.js +104 -0
- package/dist/lib/node-alias-path.js +50 -2
- package/dist/lib/open-live-row.js +20 -0
- package/dist/lib/ops-url.js +52 -0
- package/dist/lib/promotion-content-hash.js +20 -0
- package/dist/lib/remote-admin-pass.js +157 -0
- package/dist/lib/restore-archive.js +760 -0
- package/dist/lib/restore-verify.js +1 -1
- package/dist/lib/scheduler-platform.js +13 -0
- package/dist/lib/service-repoint.js +13 -4
- package/dist/lib/skill-assignment-preflight.js +159 -0
- package/dist/lib/skill-seed.js +125 -10
- package/dist/lib/skill-tombstone-doctor.js +133 -0
- package/dist/lib/soul-scope-fields.js +26 -0
- package/dist/lib/terminal-text.js +32 -0
- package/dist/lib/uninstall-purge.js +266 -11
- package/dist/lib/upgrade-prior-liveness.js +2 -1
- package/dist/mcp-client-assertion.js +7 -14
- package/dist/memory-id-checkpoint.js +28 -7
- package/dist/mqtt-off-deploy.js +550 -0
- package/dist/rem/promote-policy.js +3 -3
- package/dist/rem/restore.js +302 -26
- package/dist/rem/runner.js +220 -58
- package/dist/rem/scheduler.js +21 -4
- package/dist/resources/A2AAdapter.js +131 -178
- package/dist/resources/AdminMemory.js +2 -0
- package/dist/resources/AdminMemoryCandidates.js +116 -0
- package/dist/resources/Agent.js +155 -45
- package/dist/resources/AgentCard.js +4 -0
- package/dist/resources/AgentKeyRegister.js +56 -22
- package/dist/resources/AgentReadPosition.js +7 -0
- package/dist/resources/AgentSeed.js +232 -107
- package/dist/resources/AutoPromoteCandidates.js +413 -84
- package/dist/resources/Credential.js +6 -8
- package/dist/resources/Federation.js +219 -57
- package/dist/resources/FederationRetry.js +4 -4
- package/dist/resources/InstructionVersion.js +1 -1
- package/dist/resources/MCPClientMetadata.js +6 -3
- package/dist/resources/Memory.js +1348 -271
- package/dist/resources/MemoryArchive.js +149 -64
- package/dist/resources/MemoryBootstrap.js +12 -22
- package/dist/resources/MemoryCandidate.js +16 -2
- package/dist/resources/MemoryConsolidate.js +2 -2
- package/dist/resources/MemoryFeed.js +360 -147
- package/dist/resources/MemoryMaintenance.js +290 -72
- package/dist/resources/MemoryPurge.js +138 -22
- package/dist/resources/MemoryReflect.js +68 -14
- package/dist/resources/MemoryReindex.js +91 -13
- package/dist/resources/Message.js +11 -2
- package/dist/resources/OAuth.js +156 -39
- package/dist/resources/OAuthClient.js +1 -1
- package/dist/resources/OrgEvent.js +292 -29
- package/dist/resources/OrgEventCatchup.js +7 -0
- package/dist/resources/OrgEventMaintenance.js +48 -10
- package/dist/resources/PairingToken.js +1 -1
- package/dist/resources/Presence.js +31 -11
- package/dist/resources/PromoteMemoryCandidate.js +8 -2
- package/dist/resources/RecordUsage.js +2 -4
- package/dist/resources/Soul.js +2 -0
- package/dist/resources/SoulFeed.js +2 -1
- package/dist/resources/WorkspaceLatest.js +4 -0
- package/dist/resources/XAA.js +36 -10
- package/dist/resources/a2a-stream.js +313 -0
- package/dist/resources/a2a-url.js +4 -5
- package/dist/resources/agent-admin.js +10 -1
- package/dist/resources/agent-auth.js +98 -68
- package/dist/resources/agent-read-position-lib.js +4 -1
- package/dist/resources/agent-status-guard.js +9 -7
- package/dist/resources/auth-middleware.js +166 -42
- package/dist/resources/authority-field-guard.js +9 -11
- package/dist/resources/auto-promote-lib.js +8 -5
- package/dist/resources/basic-auth-header.js +21 -0
- package/dist/resources/bm25-index-service.js +4 -5
- package/dist/resources/dedup-cluster.js +6 -1
- package/dist/resources/embeddings-provider.js +25 -0
- package/dist/resources/federation-classify.js +89 -0
- package/dist/resources/federation-retry-lib.js +6 -81
- package/dist/resources/health.js +75 -19
- package/dist/resources/host-pointer/registry.js +29 -0
- package/dist/resources/host-pointer-adapter.js +1 -0
- package/dist/resources/in-process-api.js +74 -11
- package/dist/resources/in-process.js +24 -22
- package/dist/resources/instruction-version-record.js +251 -7
- package/dist/resources/internal-authority.js +13 -0
- package/dist/resources/mcp-client-metadata-fields.js +4 -0
- package/dist/resources/mcp-handler.js +146 -13
- package/dist/resources/mcp-oauth-flag.js +12 -14
- package/dist/resources/mcp-oauth.js +446 -53
- package/dist/resources/mcp-tool-scopes.js +69 -0
- package/dist/resources/mcp-tools.js +70 -22
- package/dist/resources/memory-declared-attributes.js +1 -0
- package/dist/resources/memory-embed-hash.js +56 -0
- package/dist/resources/memory-host-source.js +5 -2
- package/dist/resources/memory-reflect-lib.js +1 -1
- package/dist/resources/memory-write-lock.js +202 -23
- package/dist/resources/memory-write-response.js +1 -1
- package/dist/resources/memory-write-transaction.js +243 -0
- package/dist/resources/migration-boot.js +17 -12
- package/dist/resources/migrations/boot-progress.js +25 -0
- package/dist/resources/migrations/data-dir.js +16 -3
- package/dist/resources/migrations/dir-safety.js +60 -2
- package/dist/resources/migrations/embedding-stamp.js +315 -49
- package/dist/resources/migrations/graph-heal.js +9 -2
- package/dist/resources/migrations/ledger.js +5 -2
- package/dist/resources/migrations/lock.js +867 -80
- package/dist/resources/migrations/progress.js +71 -10
- package/dist/resources/migrations/runner.js +212 -18
- package/dist/resources/migrations/state.js +36 -1
- package/dist/resources/migrations/status.js +2 -13
- package/dist/resources/migrations/synthetic-test-migration.js +78 -12
- package/dist/resources/migrations/types.js +26 -1
- package/dist/resources/migrations/visibility-backfill.js +111 -70
- package/dist/resources/oauth-discovery.js +0 -5
- package/dist/resources/object-body-guard.js +12 -5
- package/dist/resources/org-event-reserved.js +92 -0
- package/dist/resources/org-event-write-fault.js +19 -0
- package/dist/resources/owner-field-guard.js +1 -1
- package/dist/resources/owner-scoped-write-policy.js +65 -21
- package/dist/resources/owner-scoped-writes.js +37 -6
- package/dist/resources/path-id-rewrite.js +76 -0
- package/dist/resources/presence-internal.js +5 -5
- package/dist/resources/promotion-binding.js +43 -0
- package/dist/resources/promotion-stamp.js +124 -33
- package/dist/resources/protocol-context.js +189 -0
- package/dist/resources/record-type-kit.js +2 -4
- package/dist/resources/request-target.js +28 -1
- package/dist/resources/request-transaction.js +11 -1
- package/dist/resources/seed-reservation.js +1 -2
- package/dist/resources/semantic-retrieval-core.js +7 -6
- package/dist/resources/server-row-validation.js +71 -0
- package/dist/resources/skill-manifest.js +4 -3
- package/dist/resources/skill-version-write.js +400 -27
- package/dist/resources/skill-write-fault.js +6 -3
- package/dist/resources/skill-write-policy.js +2 -1
- package/dist/resources/soul-write-policy.js +26 -7
- package/dist/resources/table-helpers.js +1 -1
- package/dist/resources/table-subscription-policy.js +518 -85
- package/dist/resources/table-subscriptions.js +20 -7
- package/dist/resources/txn-pause-point.js +122 -5
- package/dist/resources/usage-recording.js +54 -46
- package/dist/resources/write-back.js +176 -11
- package/dist/resources/write-journal-context.js +5 -0
- package/dist/resources/write-journal.js +289 -0
- package/dist/src/keystore.js +77 -10
- package/dist/src/lib/agent-id-rule.js +44 -2
- package/dist/src/lib/atomic-write.js +3 -3
- package/dist/src/lib/federation-retry-row.js +101 -0
- package/dist/src/lib/instruction-event-contract.js +17 -0
- package/dist/src/lib/key-dir.js +203 -0
- package/dist/src/lib/memory-attributes.js +2 -0
- package/dist/src/lib/open-live-row.js +20 -0
- package/dist/src/lib/scheduler-platform.js +13 -0
- package/dist/src/lib/soul-scope-fields.js +26 -0
- package/dist/src/rem/promote-policy.js +3 -3
- package/dist/src/rem/scheduler.js +21 -4
- package/docs/access-control.md +39 -21
- package/docs/api-reference.md +161 -52
- package/docs/auth.md +69 -38
- package/docs/claude-code.md +3 -3
- package/docs/deploying-on-fabric.md +118 -2
- package/docs/deployment.md +17 -0
- package/docs/embedding-in-a-harper-app.md +23 -21
- package/docs/entity-vocabulary.md +7 -11
- package/docs/federation.md +29 -2
- package/docs/hosted-on-fabric.md +1 -1
- package/docs/integrations.md +11 -11
- package/docs/mcp-clients.md +7 -5
- package/docs/notes/mcp-agent-auth-consumer.md +4 -9
- package/docs/notes/mcp-oauth-model2.md +6 -6
- package/docs/openclaw.md +1 -1
- package/docs/quickstart-fabric.md +2 -2
- package/docs/quickstart.md +3 -3
- package/docs/releasing.md +13 -13
- package/docs/rem.md +24 -3
- package/docs/secrets-and-keys.md +9 -14
- package/docs/standalone-local.md +29 -2
- package/docs/supply-chain-policy.md +28 -20
- package/docs/the-team.md +2 -2
- package/docs/upgrade.md +29 -5
- package/package.json +18 -11
- package/schemas/agent.graphql +3 -3
- package/schemas/federation.graphql +10 -7
- package/schemas/memory.graphql +7 -2
- package/templates/bin/flair-rem-nightly.sh.tmpl +7 -1
- package/templates/launchd/start-flair-with-admin-pass.sh +188 -10
- package/dist/resources/soul-adk-guard.js +0 -68
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
* Do NOT always exit 0 — a verified-wrong reachable peer still fails.
|
|
20
20
|
*/
|
|
21
21
|
import { encodeRecordId } from "./lib/record-id-path.js";
|
|
22
|
+
import { ApiRequestOutcomeUnknown } from "./lib/auth-resolve.js";
|
|
22
23
|
import { validatePeerEndpoint } from "./fleet-verify.js";
|
|
23
24
|
import { DEFAULT_INTERVAL_SECONDS, freshnessWindowMs, } from "./federation/scheduler.js";
|
|
24
25
|
export const FED_VERIFY_EXIT_OK = 0;
|
|
@@ -156,6 +157,22 @@ export function describeFederationVerify(results) {
|
|
|
156
157
|
export function decideFederationVerifyExitCode(results) {
|
|
157
158
|
return describeFederationVerify(results).exitCode;
|
|
158
159
|
}
|
|
160
|
+
/** A verification that could not complete: not an empty peer set, and not a
|
|
161
|
+
* peer that was verified missing the memory (that is "diverged"). */
|
|
162
|
+
function describeVerificationFailure(message, cleanupUnknownCount) {
|
|
163
|
+
const cleanup = cleanupUnknownCount > 0
|
|
164
|
+
? `; ${cleanupUnknownCount} cleanup request(s) had an unknown outcome`
|
|
165
|
+
: "";
|
|
166
|
+
return {
|
|
167
|
+
kind: "verification-failed",
|
|
168
|
+
exitCode: FED_VERIFY_EXIT_DIVERGED,
|
|
169
|
+
failedCount: 0,
|
|
170
|
+
unverifiableCount: 0,
|
|
171
|
+
okCount: 0,
|
|
172
|
+
summary: `verification failed: ${message}${cleanup}`,
|
|
173
|
+
warning: null,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
159
176
|
export function renderFederationVerifyVerdict(verdict) {
|
|
160
177
|
const lines = [];
|
|
161
178
|
if (verdict.warning) {
|
|
@@ -169,6 +186,9 @@ export function renderFederationVerifyVerdict(verdict) {
|
|
|
169
186
|
lines.push(" flair federation sync # push now (verify also does this itself)");
|
|
170
187
|
lines.push(" curl <peer-endpoint>/Health # raw probe");
|
|
171
188
|
}
|
|
189
|
+
else if (verdict.kind === "verification-failed") {
|
|
190
|
+
lines.push(`── FAIL: ${verdict.summary} ──`);
|
|
191
|
+
}
|
|
172
192
|
else if (verdict.kind !== "empty") {
|
|
173
193
|
lines.push(`── ${verdict.summary} ──`);
|
|
174
194
|
}
|
|
@@ -226,12 +246,17 @@ export async function runFederationVerify(opts, deps) {
|
|
|
226
246
|
log(`1. Wrote local memory: ${memId}`);
|
|
227
247
|
}
|
|
228
248
|
catch (e) {
|
|
249
|
+
// The canary write crossed its deadline: it may have taken effect. That
|
|
250
|
+
// is not a verdict of the check, so let the caller's top-level handler
|
|
251
|
+
// report the unknown outcome and exit 3.
|
|
252
|
+
if (e instanceof ApiRequestOutcomeUnknown)
|
|
253
|
+
throw e;
|
|
229
254
|
const message = e instanceof Error ? e.message : String(e);
|
|
230
255
|
err(`1. Local write FAILED: ${message}`);
|
|
231
256
|
return {
|
|
232
257
|
exitCode: FED_VERIFY_EXIT_DIVERGED,
|
|
233
258
|
verdict: {
|
|
234
|
-
kind: "
|
|
259
|
+
kind: "verification-failed",
|
|
235
260
|
exitCode: FED_VERIFY_EXIT_DIVERGED,
|
|
236
261
|
failedCount: 0,
|
|
237
262
|
unverifiableCount: 0,
|
|
@@ -249,6 +274,17 @@ export async function runFederationVerify(opts, deps) {
|
|
|
249
274
|
}
|
|
250
275
|
let pushed = false;
|
|
251
276
|
let cleanedUp = false;
|
|
277
|
+
// Cleanup runs in a finally, so it must not throw: a throw there would
|
|
278
|
+
// replace an error already in flight from the verification body. Record
|
|
279
|
+
// each unknown outcome and report it after the finally has completed.
|
|
280
|
+
const unknownCleanup = [];
|
|
281
|
+
let bodyFailed = false;
|
|
282
|
+
let bodyError;
|
|
283
|
+
// runFederationSyncOnce reports an ordinary failure by RETURNING { error },
|
|
284
|
+
// so handling a returned error is the ordinary path.
|
|
285
|
+
let syncFailure = null;
|
|
286
|
+
// A --peer that matched no listed row: the requested check never ran.
|
|
287
|
+
let unmatchedPeer = null;
|
|
252
288
|
let result = {
|
|
253
289
|
exitCode: FED_VERIFY_EXIT_OK,
|
|
254
290
|
verdict: describeFederationVerify([]),
|
|
@@ -260,200 +296,215 @@ export async function runFederationVerify(opts, deps) {
|
|
|
260
296
|
tag: opts.tag,
|
|
261
297
|
};
|
|
262
298
|
try {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
pushed
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
}];
|
|
293
|
-
const verdict = describeFederationVerify(peers);
|
|
294
|
-
log(renderFederationVerifyVerdict(verdict));
|
|
295
|
-
result = {
|
|
296
|
-
exitCode: verdict.exitCode,
|
|
297
|
-
verdict,
|
|
298
|
-
peers,
|
|
299
|
-
skippedRevoked: [],
|
|
300
|
-
memId,
|
|
301
|
-
cleanedUp: false,
|
|
302
|
-
pushed,
|
|
303
|
-
tag: opts.tag,
|
|
304
|
-
};
|
|
305
|
-
return result;
|
|
306
|
-
}
|
|
307
|
-
const selected = selectPeersToProbe(listed, opts.peerId);
|
|
308
|
-
const skippedRevoked = selected.skippedRevoked;
|
|
309
|
-
const toProbe = selected.probe;
|
|
310
|
-
const revokedRows = skippedRevoked.map(revokedAsUnverifiable);
|
|
311
|
-
for (const row of revokedRows) {
|
|
312
|
-
log(` ${row.id} UNVERIFIABLE (${row.detail})`);
|
|
313
|
-
}
|
|
314
|
-
if (toProbe.length === 0) {
|
|
315
|
-
if (revokedRows.length === 0)
|
|
316
|
-
log("(no peers to probe)");
|
|
317
|
-
const verdict = describeFederationVerify(revokedRows);
|
|
318
|
-
log(renderFederationVerifyVerdict(verdict));
|
|
319
|
-
result = {
|
|
320
|
-
exitCode: verdict.exitCode,
|
|
321
|
-
verdict,
|
|
322
|
-
peers: revokedRows,
|
|
323
|
-
skippedRevoked,
|
|
324
|
-
memId,
|
|
325
|
-
cleanedUp: false,
|
|
326
|
-
pushed,
|
|
327
|
-
tag: opts.tag,
|
|
328
|
-
};
|
|
329
|
-
return result;
|
|
330
|
-
}
|
|
331
|
-
log(`2. Probing ${toProbe.length} peer(s) over ${opts.waitSeconds}s window…`);
|
|
332
|
-
const started = clock.now();
|
|
333
|
-
const settled = new Map();
|
|
334
|
-
const sawAuthenticatedMissing = new Set();
|
|
335
|
-
const settle = (row) => {
|
|
336
|
-
settled.set(row.id, row);
|
|
337
|
-
const label = row.status === "ok" ? "OK" : row.status === "fail" ? "FAIL" : "UNVERIFIABLE";
|
|
338
|
-
log(` ${row.id} ${label} (${row.detail})`);
|
|
339
|
-
};
|
|
340
|
-
while (clock.now() - started < opts.waitMs && settled.size < toProbe.length) {
|
|
341
|
-
for (const p of toProbe) {
|
|
342
|
-
if (settled.has(p.id))
|
|
343
|
-
continue;
|
|
344
|
-
const endpointCheck = validatePeerEndpoint(p.endpoint);
|
|
345
|
-
if ("error" in endpointCheck) {
|
|
346
|
-
settle({
|
|
347
|
-
id: p.id,
|
|
348
|
-
status: "unverifiable",
|
|
349
|
-
detail: endpointCheck.error,
|
|
350
|
-
lastSyncAt: p.lastSyncAt ?? null,
|
|
351
|
-
authenticated: false,
|
|
352
|
-
});
|
|
353
|
-
continue;
|
|
354
|
-
}
|
|
355
|
-
let probeUrl;
|
|
356
|
-
try {
|
|
357
|
-
probeUrl = new URL("/SemanticSearch", endpointCheck.url);
|
|
358
|
-
}
|
|
359
|
-
catch {
|
|
360
|
-
settle({
|
|
361
|
-
id: p.id,
|
|
299
|
+
verifyBody: {
|
|
300
|
+
log(" Pushing canary via federation sync…");
|
|
301
|
+
const syncResult = await deps.syncOnce(opts.syncOpts);
|
|
302
|
+
if (syncResult.error) {
|
|
303
|
+
// A sync error means the check could not complete; that failure belongs
|
|
304
|
+
// in the verdict rather than being probed past.
|
|
305
|
+
syncFailure = syncResult.error;
|
|
306
|
+
break verifyBody;
|
|
307
|
+
}
|
|
308
|
+
else if (syncResult.pushed > 0) {
|
|
309
|
+
// A no-change sync ({ pushed: 0 }) did not inject the canary — do not
|
|
310
|
+
// treat that as a successful push or a missing-canary probe becomes
|
|
311
|
+
// a false FAIL.
|
|
312
|
+
pushed = true;
|
|
313
|
+
log(` Push: synced ${syncResult.pushed} record(s) (${syncResult.skipped} skipped)`);
|
|
314
|
+
}
|
|
315
|
+
else {
|
|
316
|
+
log(` Push: synced 0 records — canary was not injected; probing with lastSyncAt freshness`);
|
|
317
|
+
}
|
|
318
|
+
let listed = [];
|
|
319
|
+
try {
|
|
320
|
+
const r = await deps.api("GET", "/FederationPeers", undefined, apiOpts);
|
|
321
|
+
listed = r.peers ?? [];
|
|
322
|
+
}
|
|
323
|
+
catch (e) {
|
|
324
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
325
|
+
err(`Failed to list peers: ${message}`);
|
|
326
|
+
const peers = [{
|
|
327
|
+
id: "(peer enumeration)",
|
|
362
328
|
status: "unverifiable",
|
|
363
|
-
detail: `
|
|
364
|
-
lastSyncAt:
|
|
329
|
+
detail: `GET /FederationPeers failed: ${message} — could not check any peer`,
|
|
330
|
+
lastSyncAt: null,
|
|
365
331
|
authenticated: false,
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
332
|
+
}];
|
|
333
|
+
const verdict = describeFederationVerify(peers);
|
|
334
|
+
log(renderFederationVerifyVerdict(verdict));
|
|
335
|
+
result = {
|
|
336
|
+
exitCode: verdict.exitCode,
|
|
337
|
+
verdict,
|
|
338
|
+
peers,
|
|
339
|
+
skippedRevoked: [],
|
|
340
|
+
memId,
|
|
341
|
+
cleanedUp: false,
|
|
342
|
+
pushed,
|
|
343
|
+
tag: opts.tag,
|
|
344
|
+
};
|
|
345
|
+
break verifyBody;
|
|
346
|
+
}
|
|
347
|
+
const selected = selectPeersToProbe(listed, opts.peerId);
|
|
348
|
+
const skippedRevoked = selected.skippedRevoked;
|
|
349
|
+
const toProbe = selected.probe;
|
|
350
|
+
const revokedRows = skippedRevoked.map(revokedAsUnverifiable);
|
|
351
|
+
for (const row of revokedRows) {
|
|
352
|
+
log(` ${row.id} UNVERIFIABLE (${row.detail})`);
|
|
353
|
+
}
|
|
354
|
+
if (opts.peerId && toProbe.length === 0 && revokedRows.length === 0) {
|
|
355
|
+
// A requested peer that matches no listed row is not an empty peer set:
|
|
356
|
+
// the check the operator asked for did not run.
|
|
357
|
+
unmatchedPeer = opts.peerId;
|
|
358
|
+
break verifyBody;
|
|
359
|
+
}
|
|
360
|
+
if (toProbe.length === 0) {
|
|
361
|
+
if (revokedRows.length === 0)
|
|
362
|
+
log("(no peers to probe)");
|
|
363
|
+
const verdict = describeFederationVerify(revokedRows);
|
|
364
|
+
log(renderFederationVerifyVerdict(verdict));
|
|
365
|
+
result = {
|
|
366
|
+
exitCode: verdict.exitCode,
|
|
367
|
+
verdict,
|
|
368
|
+
peers: revokedRows,
|
|
369
|
+
skippedRevoked,
|
|
370
|
+
memId,
|
|
371
|
+
cleanedUp: false,
|
|
372
|
+
pushed,
|
|
373
|
+
tag: opts.tag,
|
|
374
|
+
};
|
|
375
|
+
break verifyBody;
|
|
376
|
+
}
|
|
377
|
+
log(`2. Probing ${toProbe.length} peer(s) over ${opts.waitSeconds}s window…`);
|
|
378
|
+
const started = clock.now();
|
|
379
|
+
const settled = new Map();
|
|
380
|
+
const sawAuthenticatedMissing = new Set();
|
|
381
|
+
const settle = (row) => {
|
|
382
|
+
settled.set(row.id, row);
|
|
383
|
+
const label = row.status === "ok" ? "OK" : row.status === "fail" ? "FAIL" : "UNVERIFIABLE";
|
|
384
|
+
log(` ${row.id} ${label} (${row.detail})`);
|
|
385
|
+
};
|
|
386
|
+
while (clock.now() - started < opts.waitMs && settled.size < toProbe.length) {
|
|
387
|
+
for (const p of toProbe) {
|
|
388
|
+
if (settled.has(p.id))
|
|
389
|
+
continue;
|
|
390
|
+
const endpointCheck = validatePeerEndpoint(p.endpoint);
|
|
391
|
+
if ("error" in endpointCheck) {
|
|
378
392
|
settle({
|
|
379
393
|
id: p.id,
|
|
380
394
|
status: "unverifiable",
|
|
381
|
-
detail:
|
|
395
|
+
detail: endpointCheck.error,
|
|
382
396
|
lastSyncAt: p.lastSyncAt ?? null,
|
|
383
397
|
authenticated: false,
|
|
384
398
|
});
|
|
385
399
|
continue;
|
|
386
400
|
}
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
401
|
+
let probeUrl;
|
|
402
|
+
try {
|
|
403
|
+
probeUrl = new URL("/SemanticSearch", endpointCheck.url);
|
|
390
404
|
}
|
|
391
|
-
|
|
392
|
-
if (canaryContainsTag(data, opts.tag)) {
|
|
393
|
-
const elapsed = Math.floor((clock.now() - started) / 1000);
|
|
405
|
+
catch {
|
|
394
406
|
settle({
|
|
395
407
|
id: p.id,
|
|
396
|
-
status: "
|
|
397
|
-
detail: `
|
|
408
|
+
status: "unverifiable",
|
|
409
|
+
detail: `invalid endpoint URL: ${p.endpoint}`,
|
|
398
410
|
lastSyncAt: p.lastSyncAt ?? null,
|
|
399
|
-
authenticated:
|
|
411
|
+
authenticated: false,
|
|
412
|
+
});
|
|
413
|
+
continue;
|
|
414
|
+
}
|
|
415
|
+
try {
|
|
416
|
+
const res = await deps.fetch(probeUrl, {
|
|
417
|
+
method: "POST",
|
|
418
|
+
headers: { "Content-Type": "application/json" },
|
|
419
|
+
body: JSON.stringify({ q: opts.tag, limit: 5 }),
|
|
420
|
+
signal: AbortSignal.timeout(probeTimeoutMs),
|
|
400
421
|
});
|
|
422
|
+
const kind = classifyProbeHttpStatus(res.status);
|
|
423
|
+
if (kind === "auth") {
|
|
424
|
+
settle({
|
|
425
|
+
id: p.id,
|
|
426
|
+
status: "unverifiable",
|
|
427
|
+
detail: authUnverifiableDetail(res.status),
|
|
428
|
+
lastSyncAt: p.lastSyncAt ?? null,
|
|
429
|
+
authenticated: false,
|
|
430
|
+
});
|
|
431
|
+
continue;
|
|
432
|
+
}
|
|
433
|
+
if (kind !== "found-ok") {
|
|
434
|
+
// Retry 4xx/5xx other than 401/403 — couldn't complete this tick.
|
|
435
|
+
continue;
|
|
436
|
+
}
|
|
437
|
+
const data = await res.json().catch(() => ({}));
|
|
438
|
+
if (canaryContainsTag(data, opts.tag)) {
|
|
439
|
+
const elapsed = Math.floor((clock.now() - started) / 1000);
|
|
440
|
+
settle({
|
|
441
|
+
id: p.id,
|
|
442
|
+
status: "ok",
|
|
443
|
+
detail: `memory found after ${elapsed}s`,
|
|
444
|
+
lastSyncAt: p.lastSyncAt ?? null,
|
|
445
|
+
authenticated: true,
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
else {
|
|
449
|
+
sawAuthenticatedMissing.add(p.id);
|
|
450
|
+
}
|
|
401
451
|
}
|
|
402
|
-
|
|
403
|
-
|
|
452
|
+
catch {
|
|
453
|
+
// Unreachable this tick — retry until the window elapses.
|
|
404
454
|
}
|
|
405
455
|
}
|
|
406
|
-
|
|
407
|
-
|
|
456
|
+
if (settled.size < toProbe.length) {
|
|
457
|
+
await clock.sleep(pollIntervalMs);
|
|
408
458
|
}
|
|
409
459
|
}
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
lastSyncAt: p.lastSyncAt ?? null,
|
|
439
|
-
authenticated: false,
|
|
440
|
-
});
|
|
460
|
+
for (const p of toProbe) {
|
|
461
|
+
if (settled.has(p.id))
|
|
462
|
+
continue;
|
|
463
|
+
if (sawAuthenticatedMissing.has(p.id)) {
|
|
464
|
+
const classified = classifyMissingAfterWindow({
|
|
465
|
+
pushed,
|
|
466
|
+
lastSyncAt: p.lastSyncAt,
|
|
467
|
+
nowMs: clock.now(),
|
|
468
|
+
freshnessMs,
|
|
469
|
+
waitSeconds: opts.waitSeconds,
|
|
470
|
+
});
|
|
471
|
+
settle({
|
|
472
|
+
id: p.id,
|
|
473
|
+
status: classified.status,
|
|
474
|
+
detail: classified.detail,
|
|
475
|
+
lastSyncAt: p.lastSyncAt ?? null,
|
|
476
|
+
authenticated: true,
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
else {
|
|
480
|
+
settle({
|
|
481
|
+
id: p.id,
|
|
482
|
+
status: "unverifiable",
|
|
483
|
+
detail: `unreachable — no successful probe within ${opts.waitSeconds}s (couldn't check, not a sync failure)`,
|
|
484
|
+
lastSyncAt: p.lastSyncAt ?? null,
|
|
485
|
+
authenticated: false,
|
|
486
|
+
});
|
|
487
|
+
}
|
|
441
488
|
}
|
|
489
|
+
const peers = [...revokedRows, ...toProbe.map((p) => settled.get(p.id))];
|
|
490
|
+
const verdict = describeFederationVerify(peers);
|
|
491
|
+
log(renderFederationVerifyVerdict(verdict));
|
|
492
|
+
result = {
|
|
493
|
+
exitCode: verdict.exitCode,
|
|
494
|
+
verdict,
|
|
495
|
+
peers,
|
|
496
|
+
skippedRevoked,
|
|
497
|
+
memId,
|
|
498
|
+
cleanedUp: false,
|
|
499
|
+
pushed,
|
|
500
|
+
tag: opts.tag,
|
|
501
|
+
};
|
|
502
|
+
break verifyBody;
|
|
442
503
|
}
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
exitCode: verdict.exitCode,
|
|
448
|
-
verdict,
|
|
449
|
-
peers,
|
|
450
|
-
skippedRevoked,
|
|
451
|
-
memId,
|
|
452
|
-
cleanedUp: false,
|
|
453
|
-
pushed,
|
|
454
|
-
tag: opts.tag,
|
|
455
|
-
};
|
|
456
|
-
return result;
|
|
504
|
+
}
|
|
505
|
+
catch (e) {
|
|
506
|
+
bodyFailed = true;
|
|
507
|
+
bodyError = e;
|
|
457
508
|
}
|
|
458
509
|
finally {
|
|
459
510
|
// Federation merge is LWW put-by-id — local DELETE never reaches the
|
|
@@ -482,8 +533,13 @@ export async function runFederationVerify(opts, deps) {
|
|
|
482
533
|
}
|
|
483
534
|
}
|
|
484
535
|
catch (e) {
|
|
485
|
-
|
|
486
|
-
|
|
536
|
+
if (e instanceof ApiRequestOutcomeUnknown) {
|
|
537
|
+
unknownCleanup.push(e);
|
|
538
|
+
}
|
|
539
|
+
else {
|
|
540
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
541
|
+
log(`4. Cleanup: could not archive canary for peer cleanup (${message})`);
|
|
542
|
+
}
|
|
487
543
|
}
|
|
488
544
|
}
|
|
489
545
|
try {
|
|
@@ -491,9 +547,45 @@ export async function runFederationVerify(opts, deps) {
|
|
|
491
547
|
cleanedUp = true;
|
|
492
548
|
log(`4. Cleanup: deleted local memory ${memId}`);
|
|
493
549
|
}
|
|
494
|
-
catch {
|
|
495
|
-
|
|
550
|
+
catch (e) {
|
|
551
|
+
if (e instanceof ApiRequestOutcomeUnknown) {
|
|
552
|
+
unknownCleanup.push(e);
|
|
553
|
+
}
|
|
554
|
+
else {
|
|
555
|
+
log(`4. Cleanup: could NOT delete local memory ${memId} (manual cleanup needed)`);
|
|
556
|
+
}
|
|
496
557
|
}
|
|
497
558
|
result.cleanedUp = cleanedUp;
|
|
498
559
|
}
|
|
560
|
+
// A failed verification — a thrown body, a returned sync error, or an
|
|
561
|
+
// unmatched --peer — reports its failure in the returned verdict.
|
|
562
|
+
const cleanupUnknownCount = unknownCleanup.length;
|
|
563
|
+
const failure = bodyFailed
|
|
564
|
+
? bodyError
|
|
565
|
+
: syncFailure ?? (unmatchedPeer === null
|
|
566
|
+
? null
|
|
567
|
+
: new Error(`--peer "${unmatchedPeer}" matched no listed peer`));
|
|
568
|
+
if (bodyFailed || (failure !== null && failure !== undefined)) {
|
|
569
|
+
const failureMessage = failure instanceof Error ? failure.message : String(failure);
|
|
570
|
+
result.verdict = describeVerificationFailure(failureMessage, cleanupUnknownCount);
|
|
571
|
+
result.exitCode = result.verdict.exitCode;
|
|
572
|
+
log(renderFederationVerifyVerdict(result.verdict));
|
|
573
|
+
// The unknown outcome outranks a definite failure: both are printed and
|
|
574
|
+
// the command exits 3.
|
|
575
|
+
if (failure instanceof ApiRequestOutcomeUnknown) {
|
|
576
|
+
unknownCleanup.unshift(failure);
|
|
577
|
+
}
|
|
578
|
+
else {
|
|
579
|
+
err(`Error: ${failureMessage}`);
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
if (unknownCleanup.length > 0) {
|
|
583
|
+
for (const unknown of unknownCleanup) {
|
|
584
|
+
err(`Unknown outcome: ${unknown.message}`);
|
|
585
|
+
err("The request may or may not have taken effect; inspect the target before re-running.");
|
|
586
|
+
}
|
|
587
|
+
result.exitCode = 3;
|
|
588
|
+
result.verdict.exitCode = result.exitCode;
|
|
589
|
+
}
|
|
590
|
+
return result;
|
|
499
591
|
}
|