@tpsdev-ai/flair 0.59.0 → 0.63.0
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 +10 -10
- package/SECURITY.md +49 -5
- package/config.yaml +23 -12
- package/dist/bridges/builtins/mem0.js +63 -28
- package/dist/bridges/runtime/execute.js +1 -0
- package/dist/bridges/runtime/import-runner.js +12 -0
- package/dist/bridges/runtime/load-plugin.js +42 -13
- package/dist/bridges/runtime/yaml-loader.js +4 -2
- package/dist/bridges/types.js +1 -0
- package/dist/build-info.json +3 -3
- package/dist/cli.js +1054 -367
- package/dist/commands/agent.js +233 -90
- package/dist/commands/attention.js +4 -3
- package/dist/commands/backup-approval.js +218 -0
- package/dist/commands/backup.js +211 -39
- package/dist/commands/bootstrap.js +3 -1
- package/dist/commands/bridge.js +172 -119
- package/dist/commands/deploy.js +71 -8
- package/dist/commands/doctor.js +711 -146
- package/dist/commands/export.js +57 -23
- package/dist/commands/federation.js +787 -82
- package/dist/commands/grant.js +5 -6
- package/dist/commands/help.js +25 -0
- package/dist/commands/hook.js +155 -2
- package/dist/commands/idp.js +27 -19
- package/dist/commands/import.js +136 -20
- package/dist/commands/init.js +469 -200
- package/dist/commands/integrity.js +387 -0
- package/dist/commands/keys.js +247 -58
- package/dist/commands/mcp.js +108 -52
- package/dist/commands/memory.js +203 -35
- package/dist/commands/migrate-harness-memory.js +3 -2
- package/dist/commands/orgevent.js +51 -47
- package/dist/commands/presence.js +4 -3
- package/dist/commands/principal.js +428 -62
- package/dist/commands/quality.js +13 -1
- package/dist/commands/reembed.js +141 -17
- package/dist/commands/relationship.js +2 -1
- package/dist/commands/rem.js +537 -80
- package/dist/commands/restore.js +413 -65
- package/dist/commands/search.js +6 -4
- package/dist/commands/service.js +235 -40
- package/dist/commands/soul.js +4 -9
- package/dist/commands/status.js +94 -38
- package/dist/commands/test.js +7 -3
- package/dist/commands/upgrade.js +77 -23
- package/dist/commands/workspace.js +13 -11
- package/dist/component-env.js +31 -41
- package/dist/deploy.js +136 -4
- package/dist/doctor-client.js +534 -92
- package/dist/engine-version-contract.js +1 -0
- package/dist/engine-version.js +23 -3
- package/dist/fabric-upgrade.js +12 -2
- package/dist/federation/presence-send.js +139 -0
- package/dist/federation-verify.js +273 -180
- package/dist/hook-install.js +670 -6
- package/dist/install/clients.js +171 -35
- package/dist/keystore.js +72 -0
- package/dist/lib/action-recall-runtime.js +328 -0
- package/dist/lib/agent-home-fields.js +132 -0
- package/dist/lib/agent-home.js +427 -0
- package/dist/lib/agent-id-rule.js +88 -0
- package/dist/lib/agent-roster.js +33 -0
- package/dist/lib/atomic-write.js +1 -1
- package/dist/lib/auth-resolve.js +1069 -60
- package/dist/lib/backup-approval-store.js +612 -0
- package/dist/lib/backup-artifact.js +343 -0
- package/dist/lib/capture-runtime.js +124 -0
- package/dist/lib/config-critical-section.js +212 -25
- package/dist/lib/connect-phase.js +33 -0
- package/dist/lib/credential-status-rule.js +78 -0
- package/dist/lib/daemon-liveness.js +43 -11
- package/dist/lib/doctor-run.js +75 -37
- package/dist/lib/durability-copy.js +10 -0
- package/dist/lib/embedding-space-doctor.js +75 -0
- 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/flair-agent-role.js +4 -0
- package/dist/lib/hub-url.js +12 -0
- package/dist/lib/init-admin-pass.js +88 -12
- package/dist/lib/init-listener-environ.js +1 -2
- package/dist/lib/init-occupied-listener.js +15 -111
- package/dist/lib/init-spawn-attribution.js +73 -0
- package/dist/lib/init-tcp-probe.js +33 -0
- package/dist/lib/instance-identity-row.js +20 -0
- package/dist/lib/instruction-event-contract.js +17 -0
- package/dist/lib/instruction-event-doctor.js +102 -0
- package/dist/lib/launchd-management.js +38 -3
- package/dist/lib/listener-table.js +268 -0
- package/dist/lib/local-delete-instance.js +27 -0
- package/dist/lib/local-instance-pair.js +256 -0
- package/dist/lib/mcp-enable.js +1182 -341
- package/dist/lib/mcp-oauth-env-core.js +133 -0
- package/dist/lib/mcp-oauth-env.js +125 -0
- package/dist/lib/mcp-spec.js +17 -1
- package/dist/lib/memory-attributes.js +4 -0
- package/dist/lib/memory-id-policy.js +46 -0
- package/dist/lib/memory-integrity.js +309 -0
- package/dist/lib/memory-provider-timeout.js +33 -0
- package/dist/lib/memory-purge-response.js +20 -0
- package/dist/lib/mqtt-config.js +132 -0
- package/dist/lib/mqtt-listener-doctor.js +104 -0
- package/dist/lib/open-live-row.js +20 -0
- package/dist/lib/ops-table-count.js +25 -0
- package/dist/lib/ops-url.js +52 -0
- package/dist/lib/owned-pins.js +67 -10
- package/dist/lib/peer-status.js +27 -0
- package/dist/lib/principal-status.js +29 -0
- package/dist/lib/process-start-time.js +76 -12
- package/dist/lib/promotion-content-hash.js +20 -0
- package/dist/lib/proto-safe-record.js +42 -0
- package/dist/lib/record-id-path.js +25 -0
- package/dist/lib/reembed-server-support.js +66 -0
- package/dist/lib/restore-archive.js +760 -0
- package/dist/lib/restore-verify.js +104 -0
- package/dist/lib/scheduler-platform.js +10 -6
- package/dist/lib/secret-keys.js +25 -0
- package/dist/lib/secrets-push.js +50 -22
- package/dist/lib/skill-assignment-preflight.js +159 -0
- package/dist/lib/skill-seed-pending.js +24 -0
- package/dist/lib/skill-seed.js +448 -0
- package/dist/lib/skill-tombstone-doctor.js +133 -0
- package/dist/lib/soul-scope-fields.js +26 -0
- package/dist/lib/stop-start-recovery.js +54 -0
- package/dist/lib/uninstall-purge.js +266 -11
- package/dist/lib/upgrade-prior-liveness.js +2 -1
- package/dist/lib/using-flair-skill.js +87 -0
- package/dist/mcp-client-assertion.js +114 -14
- package/dist/memory-id-checkpoint.js +347 -0
- package/dist/memory-node-compare.js +207 -0
- package/dist/mqtt-off-deploy.js +550 -0
- package/dist/packages/flair-mcp/src/secret-redaction.js +113 -0
- package/dist/rem/promote-policy.js +3 -3
- package/dist/rem/restore.js +303 -26
- package/dist/rem/runner.js +317 -96
- 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 +463 -33
- package/dist/resources/AgentCard.js +4 -0
- package/dist/resources/AgentKeyRegister.js +248 -0
- package/dist/resources/AgentKeyRegistration.js +28 -0
- package/dist/resources/AgentReadPosition.js +7 -0
- package/dist/resources/AgentSeed.js +238 -107
- package/dist/resources/AutoPromoteCandidates.js +413 -78
- package/dist/resources/Credential.js +183 -10
- package/dist/resources/Federation.js +915 -145
- package/dist/resources/FederationRetry.js +140 -0
- package/dist/resources/InstructionVersion.js +220 -0
- package/dist/resources/Integration.js +300 -25
- package/dist/resources/MCPClientMetadata.js +6 -3
- package/dist/resources/Memory.js +3300 -758
- package/dist/resources/MemoryArchive.js +171 -53
- package/dist/resources/MemoryBootstrap.js +122 -61
- package/dist/resources/MemoryCandidate.js +37 -3
- package/dist/resources/MemoryConsolidate.js +2 -2
- package/dist/resources/MemoryDedupStats.js +30 -1
- package/dist/resources/MemoryFeed.js +545 -50
- package/dist/resources/MemoryGrant.js +21 -1
- package/dist/resources/MemoryMaintenance.js +368 -46
- package/dist/resources/MemoryPurge.js +348 -0
- package/dist/resources/MemoryReflect.js +71 -12
- package/dist/resources/MemoryReindex.js +111 -17
- package/dist/resources/Message.js +16 -5
- package/dist/resources/OAuth.js +342 -48
- package/dist/resources/OAuthClient.js +1 -1
- package/dist/resources/OrgEvent.js +405 -19
- 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 +166 -51
- package/dist/resources/PromoteMemoryCandidate.js +24 -7
- package/dist/resources/RecordUsage.js +2 -4
- package/dist/resources/Relationship.js +23 -0
- package/dist/resources/SemanticSearch.js +63 -32
- package/dist/resources/Soul.js +191 -76
- package/dist/resources/SoulFeed.js +2 -1
- package/dist/resources/TeamDirectory.js +35 -0
- package/dist/resources/WorkspaceLatest.js +4 -0
- package/dist/resources/WorkspaceState.js +21 -1
- package/dist/resources/XAA.js +207 -63
- 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 +138 -83
- 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 +534 -171
- 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/ed25519-auth.js +1 -1
- package/dist/resources/embedding-space-guard.js +366 -72
- package/dist/resources/embeddings-provider.js +25 -0
- package/dist/resources/engine-version-stamp-boot.js +53 -0
- package/dist/resources/federation-classify.js +161 -0
- package/dist/resources/federation-crypto.js +5 -5
- package/dist/resources/federation-retry-lib.js +60 -0
- package/dist/resources/grant-visibility.js +135 -0
- package/dist/resources/harper-routing.js +83 -0
- package/dist/resources/health.js +163 -22
- package/dist/resources/host-pointer/registry.js +29 -0
- package/dist/resources/host-pointer-adapter.js +1 -0
- package/dist/resources/host-source-citation.js +49 -0
- package/dist/resources/host-source-visibility.js +7 -6
- package/dist/resources/in-process.js +24 -22
- package/dist/resources/instance-create-lock.js +17 -0
- package/dist/resources/instance-identity.js +23 -0
- package/dist/resources/instruction-version-record.js +587 -0
- package/dist/resources/internal-authority.js +13 -0
- package/dist/resources/key-lock.js +3 -3
- package/dist/resources/mcp-handler.js +141 -19
- package/dist/resources/mcp-oauth-env-guard.js +36 -0
- package/dist/resources/mcp-oauth-flag.js +12 -14
- package/dist/resources/mcp-oauth.js +450 -56
- package/dist/resources/mcp-tool-arguments.js +4 -6
- package/dist/resources/mcp-tools.js +187 -40
- package/dist/resources/memory-bootstrap-lib.js +5 -15
- package/dist/resources/memory-declared-attributes.js +4 -1
- package/dist/resources/memory-deletion-history.js +55 -0
- package/dist/resources/memory-durability.js +54 -0
- package/dist/resources/memory-embed-hash.js +144 -0
- package/dist/resources/memory-embedding-value.js +8 -0
- package/dist/resources/memory-host-source.js +32 -7
- package/dist/resources/memory-id-guard.js +75 -0
- package/dist/resources/memory-redaction.js +236 -0
- package/dist/resources/memory-reflect-lib.js +1 -1
- package/dist/resources/memory-supplied-vector.js +72 -0
- package/dist/resources/memory-write-lock.js +489 -0
- package/dist/resources/memory-write-response.js +139 -0
- 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 +90 -19
- package/dist/resources/migrations/dir-safety.js +61 -3
- package/dist/resources/migrations/embedding-stamp.js +462 -82
- package/dist/resources/migrations/export.js +1 -0
- package/dist/resources/migrations/graph-heal.js +27 -27
- package/dist/resources/migrations/ledger.js +5 -2
- package/dist/resources/migrations/lock.js +870 -77
- package/dist/resources/migrations/progress.js +71 -10
- package/dist/resources/migrations/runner.js +212 -18
- package/dist/resources/migrations/snapshot.js +1 -0
- package/dist/resources/migrations/source-fields.js +5 -5
- package/dist/resources/migrations/state.js +36 -1
- package/dist/resources/migrations/status.js +2 -13
- package/dist/resources/migrations/synthetic-test-migration.js +81 -12
- package/dist/resources/migrations/types.js +26 -1
- package/dist/resources/migrations/visibility-backfill.js +113 -72
- package/dist/resources/oauth-discovery.js +0 -5
- package/dist/resources/object-body-guard.js +40 -0
- package/dist/resources/org-event-created-at.js +133 -0
- package/dist/resources/org-event-reserved.js +92 -0
- package/dist/resources/org-event-write-fault.js +19 -0
- package/dist/resources/originator-instance.js +39 -7
- package/dist/resources/owner-delete-recheck.js +78 -0
- package/dist/resources/owner-field-guard.js +39 -5
- package/dist/resources/owner-scoped-write-policy.js +256 -0
- package/dist/resources/owner-scoped-writes.js +89 -0
- package/dist/resources/path-id-rewrite.js +76 -0
- package/dist/resources/presence-internal.js +5 -5
- package/dist/resources/presence-receipt.js +236 -0
- package/dist/resources/promotion-binding.js +43 -0
- package/dist/resources/promotion-stamp.js +143 -17
- package/dist/resources/protocol-context.js +189 -0
- package/dist/resources/record-owner-guard.js +74 -26
- package/dist/resources/record-type-kit.js +2 -4
- package/dist/resources/record-types.js +1 -1
- package/dist/resources/relay-ops.js +78 -6
- package/dist/resources/replay-store.js +96 -19
- package/dist/resources/request-target.js +163 -0
- package/dist/resources/request-transaction.js +46 -1
- package/dist/resources/search-readiness.js +4 -1
- package/dist/resources/seed-ids.js +9 -0
- package/dist/resources/seed-reservation.js +116 -0
- package/dist/resources/semantic-retrieval-core.js +27 -15
- package/dist/resources/server-row-validation.js +71 -0
- package/dist/resources/skill-manifest.js +24 -14
- package/dist/resources/skill-subject.js +53 -0
- package/dist/resources/skill-version-write.js +789 -0
- package/dist/resources/skill-write-fault.js +20 -0
- package/dist/resources/skill-write-policy.js +68 -0
- package/dist/resources/skill-write.js +67 -7
- package/dist/resources/soul-write-policy.js +26 -7
- package/dist/resources/table-helpers.js +10 -7
- package/dist/resources/table-subscription-policy.js +518 -85
- package/dist/resources/table-subscriptions.js +20 -7
- package/dist/resources/team-directory.js +248 -0
- package/dist/resources/tool-descriptors/index.js +69 -8
- package/dist/resources/txn-pause-point.js +235 -0
- package/dist/resources/usage-recording.js +186 -70
- package/dist/resources/write-back.js +383 -0
- package/dist/resources/write-journal-context.js +5 -0
- package/dist/resources/write-journal.js +289 -0
- package/dist/src/engine-version-contract.js +1 -0
- package/dist/src/keystore.js +72 -0
- package/dist/src/lib/agent-home-fields.js +132 -0
- package/dist/src/lib/agent-id-rule.js +88 -0
- package/dist/src/lib/agent-key-register.js +80 -0
- package/dist/src/lib/atomic-write.js +256 -0
- package/dist/src/lib/credential-status-rule.js +78 -0
- package/dist/src/lib/expired-by-agent.js +37 -0
- package/dist/src/lib/federation-retry-row.js +101 -0
- package/dist/src/lib/flair-agent-role.js +4 -0
- package/dist/src/lib/idp-mapping-rule.js +81 -0
- package/dist/src/lib/instance-identity-row.js +20 -0
- package/dist/src/lib/instruction-event-contract.js +17 -0
- package/dist/src/lib/mcp-oauth-env-core.js +133 -0
- package/dist/src/lib/memory-attributes.js +4 -0
- package/dist/src/lib/memory-id-policy.js +46 -0
- package/dist/src/lib/open-live-row.js +20 -0
- package/dist/src/lib/principal-status.js +29 -0
- package/dist/src/lib/proto-safe-record.js +42 -0
- package/dist/src/lib/reembed-server-support.js +66 -0
- package/dist/src/lib/scheduler-platform.js +10 -6
- package/dist/src/lib/soul-scope-fields.js +26 -0
- package/dist/src/lib/systemd-agent-id.js +38 -0
- package/dist/src/rem/promote-policy.js +3 -3
- package/dist/src/rem/scheduler.js +21 -4
- package/docs/access-control.md +164 -54
- package/docs/api-reference.md +165 -32
- package/docs/auth.md +46 -30
- package/docs/bridges.md +11 -0
- package/docs/claude-code.md +37 -7
- package/docs/deploying-on-fabric.md +178 -0
- package/docs/deployment.md +19 -0
- package/docs/embedding-in-a-harper-app.md +17 -15
- package/docs/entity-vocabulary.md +3 -6
- package/docs/federation.md +61 -3
- package/docs/hosted-on-fabric.md +43 -36
- package/docs/integrations.md +14 -14
- package/docs/mcp-clients.md +12 -7
- package/docs/n8n.md +17 -11
- package/docs/notes/mcp-agent-auth-consumer.md +16 -13
- package/docs/notes/mcp-oauth-model2.md +40 -11
- package/docs/openclaw.md +1 -1
- package/docs/quickstart-fabric.md +4 -4
- package/docs/quickstart.md +12 -4
- package/docs/releasing.md +25 -19
- package/docs/rem.md +32 -3
- package/docs/secrets-and-keys.md +21 -4
- package/docs/standalone-local.md +30 -2
- package/docs/supply-chain-policy.md +34 -16
- package/docs/the-team.md +2 -2
- package/docs/upgrade.md +46 -6
- package/package.json +24 -12
- package/schemas/agent-key-registration.graphql +22 -0
- package/schemas/agent.graphql +6 -3
- package/schemas/federation.graphql +41 -1
- package/schemas/memory.graphql +91 -7
- package/schemas/oauth.graphql +19 -0
- package/schemas/schema.graphql +2 -0
- 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
package/dist/rem/runner.js
CHANGED
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
* - Step 6 (dedup-cluster stat, flair-quality Slice 1c): calls
|
|
39
39
|
* `/MemoryDedupStats` after distillation. `dryRun` skips it (persisting
|
|
40
40
|
* the stat file is a side effect); failure (e.g. the caller isn't admin
|
|
41
|
-
* — the resource is admin-gated) is recorded in `errors` and
|
|
42
|
-
*
|
|
41
|
+
* — the resource is admin-gated) is recorded in `errors` and fails
|
|
42
|
+
* the cycle (#809). See resources/MemoryDedupStats.ts for the server-side
|
|
43
43
|
* computation and resources/dedup-cluster.ts for the stat's canonical
|
|
44
44
|
* storage location (NOT this log — see those files' module docs for why).
|
|
45
45
|
* - Step 7 shipped in slice-1 PR-1 (was step 6 before this PR).
|
|
@@ -47,9 +47,8 @@
|
|
|
47
47
|
* The audit row's `slice` field tells readers which steps populated which
|
|
48
48
|
* counts: `slice: "1"` rows have `archived`/`expired` undefined; `slice:
|
|
49
49
|
* "2-maintenance"` rows populate them but distillation didn't run this cycle
|
|
50
|
-
* (dry-run skip); `slice: "2"` rows
|
|
51
|
-
*
|
|
52
|
-
* entry on failure (maintenance results still stand either way).
|
|
50
|
+
* (dry-run skip); `slice: "2"` rows reached the non-dry-run distillation phase.
|
|
51
|
+
* An idle ADK skip can contain no `/ReflectMemories` attempt.
|
|
53
52
|
*
|
|
54
53
|
* Pure dependency injection so the runner is unit-testable without Harper.
|
|
55
54
|
* The CLI wires the real `apiCall` + `pkgVersion`; tests pass stubs.
|
|
@@ -59,6 +58,7 @@ import { dirname, resolve } from "node:path";
|
|
|
59
58
|
import { setImmediate as yieldToEventLoop } from "node:timers/promises";
|
|
60
59
|
import { createSnapshot } from "./snapshot.js";
|
|
61
60
|
import { resolveHome } from "../lib/home.js";
|
|
61
|
+
import { ApiRequestOutcomeUnknown, apiErrorRawBody, boundErrorText } from "../lib/auth-resolve.js";
|
|
62
62
|
export const REM_PAUSE_FLAG = resolve(resolveHome(), ".flair", "rem.paused");
|
|
63
63
|
export const REM_NIGHTLY_LOG = resolve(resolveHome(), ".flair", "logs", "rem-nightly.jsonl");
|
|
64
64
|
// ─── ADK per-tag distillation (#1205b-1) ─────────────────────────────────────
|
|
@@ -198,6 +198,36 @@ export async function runHealthPreflight(apiCall, opts = {}) {
|
|
|
198
198
|
export function formatHealthRefuseMessage(result, timeoutMs = DEFAULT_HEALTH_PREFLIGHT_MS) {
|
|
199
199
|
return `GET /Health could not be served within ${timeoutMs}ms (${result.error ?? "unknown error"}). Refusing to start REM so this run cannot take the instance down. Restore /Health, or \`flair rem pause\` to keep the scheduler from retrying.`;
|
|
200
200
|
}
|
|
201
|
+
export const PENDING_NO_ADMIN_REASON = "no admin credential for the operations API";
|
|
202
|
+
/** A count line's value: the count, `unknown (<reason>)`, or `—` when not reached. */
|
|
203
|
+
export function formatCount(count) {
|
|
204
|
+
if (count === undefined)
|
|
205
|
+
return "—";
|
|
206
|
+
return typeof count === "number" ? String(count) : `unknown (${count.reason})`;
|
|
207
|
+
}
|
|
208
|
+
/** The `Pending:` value run-once prints. */
|
|
209
|
+
export function formatPendingCandidates(count) {
|
|
210
|
+
return formatCount(count);
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* The `Auto-promoted:` line run-once prints for the auto-promote step's
|
|
214
|
+
* outcome. `skipped` is the server's `skipped` list. flair#2714: incomplete
|
|
215
|
+
* promotions (Memory written and stamped, candidate update threw, candidate
|
|
216
|
+
* read back pending) and unconfirmed ones (the same throw, but the read did
|
|
217
|
+
* not confirm the promotion on this row) are named on the line, never folded
|
|
218
|
+
* into the promoted or skipped counts. A log row written before those fields
|
|
219
|
+
* existed reads as 0.
|
|
220
|
+
*/
|
|
221
|
+
export function formatAutoPromoted(outcome) {
|
|
222
|
+
let line = `Auto-promoted: ${outcome.promoted} to own memory (${outcome.skipped} skipped)`;
|
|
223
|
+
const incomplete = outcome.incomplete ?? 0;
|
|
224
|
+
const unconfirmed = outcome.unconfirmed ?? 0;
|
|
225
|
+
if (incomplete > 0)
|
|
226
|
+
line += `; ${incomplete} incomplete (memory written, candidate update threw, candidate read back pending)`;
|
|
227
|
+
if (unconfirmed > 0)
|
|
228
|
+
line += `; ${unconfirmed} unconfirmed (memory written, candidate update threw, promotion on this row not confirmed)`;
|
|
229
|
+
return line;
|
|
230
|
+
}
|
|
201
231
|
function readPauseSentinel(path) {
|
|
202
232
|
try {
|
|
203
233
|
const contents = readFileSync(path, "utf-8");
|
|
@@ -208,11 +238,28 @@ function readPauseSentinel(path) {
|
|
|
208
238
|
return false;
|
|
209
239
|
}
|
|
210
240
|
}
|
|
241
|
+
/**
|
|
242
|
+
* A failed append of the nightly audit row. The row is carried so the CLI can
|
|
243
|
+
* still report an unknown write outcome (exit 3) even though the log failed.
|
|
244
|
+
*/
|
|
245
|
+
export class RunnerLogWriteError extends Error {
|
|
246
|
+
row;
|
|
247
|
+
constructor(row, cause) {
|
|
248
|
+
super(`could not append the nightly log row: ${cause?.message ?? String(cause)}`);
|
|
249
|
+
this.name = "RunnerLogWriteError";
|
|
250
|
+
this.row = row;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
211
253
|
function appendLogRow(logPath, row) {
|
|
212
254
|
const dir = dirname(logPath);
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
255
|
+
try {
|
|
256
|
+
if (!existsSync(dir))
|
|
257
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
258
|
+
appendFileSync(logPath, JSON.stringify(row) + "\n", { mode: 0o600 });
|
|
259
|
+
}
|
|
260
|
+
catch (err) {
|
|
261
|
+
throw new RunnerLogWriteError(row, err);
|
|
262
|
+
}
|
|
216
263
|
}
|
|
217
264
|
/**
|
|
218
265
|
* Coerces a Harper REST list response into a flat array. The /Memory and
|
|
@@ -231,22 +278,50 @@ function asArray(raw) {
|
|
|
231
278
|
}
|
|
232
279
|
return [];
|
|
233
280
|
}
|
|
281
|
+
/**
|
|
282
|
+
* A Memory or Soul read's rows. An unrecognised body is a failed read, not an
|
|
283
|
+
* empty result: `asArray` would report it as 0, which reads as an empty store.
|
|
284
|
+
*/
|
|
285
|
+
function rowsFromRead(raw, label) {
|
|
286
|
+
if (Array.isArray(raw))
|
|
287
|
+
return raw;
|
|
288
|
+
if (raw && typeof raw === "object") {
|
|
289
|
+
const obj = raw;
|
|
290
|
+
if (Array.isArray(obj.results))
|
|
291
|
+
return obj.results;
|
|
292
|
+
if (Array.isArray(obj.items))
|
|
293
|
+
return obj.items;
|
|
294
|
+
}
|
|
295
|
+
throw new Error(`${label} returned an unexpected response shape`);
|
|
296
|
+
}
|
|
234
297
|
/**
|
|
235
298
|
* Best-effort extraction of a readable message out of a thrown API error.
|
|
236
|
-
* `
|
|
237
|
-
*
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
*
|
|
241
|
-
*
|
|
242
|
-
*
|
|
299
|
+
* `api()` (src/cli.ts) throws an ApiHttpError for a non-2xx HTTP response
|
|
300
|
+
* (flair#2764). When that error was built from a non-empty response body
|
|
301
|
+
* (ApiHttpError.fromResponse), its unredacted text is parsed here
|
|
302
|
+
* (apiErrorRawBody); otherwise (the credential-less 403 and a refused redirect
|
|
303
|
+
* carry only a message, as does any other error) the message is parsed
|
|
304
|
+
* instead. /ReflectMemories's 503 (no backend configured) and 502
|
|
305
|
+
* (distillation_failed) bodies are JSON `{ error: string, detail?: string }`.
|
|
306
|
+
* A JSON object with a string `error` becomes one bounded line through
|
|
307
|
+
* boundErrorText, which redacts the credential values read from the request's
|
|
308
|
+
* Authorization header (credentialsInHeader) from the server's text within the
|
|
309
|
+
* scope stated on ApiHttpError, or withholds that text when the header's
|
|
310
|
+
* credential could not be read and the response text was non-empty, even when
|
|
311
|
+
* the text derived from it is empty (a prefix added when the line is written
|
|
312
|
+
* is outside the scope):
|
|
313
|
+
* `error: detail` when `detail` is a non-empty string and `error` alone
|
|
314
|
+
* otherwise, so distinct failure modes read distinctly in the audit log
|
|
315
|
+
* instead of as a raw JSON blob. Text that is not JSON, or JSON without a
|
|
316
|
+
* string `error`, falls back to the error's message.
|
|
243
317
|
*/
|
|
244
318
|
function describeApiError(err) {
|
|
245
319
|
const message = typeof err === "string" ? err : err?.message ?? String(err);
|
|
246
320
|
try {
|
|
247
|
-
const parsed = JSON.parse(message);
|
|
321
|
+
const parsed = JSON.parse(apiErrorRawBody(err) || message);
|
|
248
322
|
if (parsed && typeof parsed === "object" && typeof parsed.error === "string") {
|
|
249
|
-
|
|
323
|
+
const detail = typeof parsed.detail === "string" ? parsed.detail : "";
|
|
324
|
+
return boundErrorText(err, detail ? `${parsed.error}: ${detail}` : parsed.error);
|
|
250
325
|
}
|
|
251
326
|
}
|
|
252
327
|
catch {
|
|
@@ -254,10 +329,26 @@ function describeApiError(err) {
|
|
|
254
329
|
}
|
|
255
330
|
return message;
|
|
256
331
|
}
|
|
257
|
-
|
|
332
|
+
function structuredApiError(err) {
|
|
333
|
+
const message = apiErrorRawBody(err) || (typeof err === "string" ? err : err?.message);
|
|
334
|
+
if (typeof message !== "string")
|
|
335
|
+
return null;
|
|
336
|
+
try {
|
|
337
|
+
const body = JSON.parse(message);
|
|
338
|
+
return body && typeof body.error === "string" ? body.error : null;
|
|
339
|
+
}
|
|
340
|
+
catch {
|
|
341
|
+
return null;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
/** The server's structured pause response. */
|
|
258
345
|
export function isRemAbortedFailure(err) {
|
|
259
|
-
|
|
260
|
-
|
|
346
|
+
return err?.status === 503 && structuredApiError(err) === "rem_aborted";
|
|
347
|
+
}
|
|
348
|
+
/** A missing generative backend alone no longer fails the run (#924). */
|
|
349
|
+
export function isNoBackendConfigured(err) {
|
|
350
|
+
return err?.status === 503
|
|
351
|
+
&& structuredApiError(err) === "No generative backend configured. See the models configuration docs.";
|
|
261
352
|
}
|
|
262
353
|
/**
|
|
263
354
|
* True when this agent owns any `adk:<app>:<user>` tag, regardless of
|
|
@@ -290,22 +381,20 @@ export function hasAdkUserTags(memories, agentId) {
|
|
|
290
381
|
*
|
|
291
382
|
* Uses the ops-API `search_by_conditions` convention (admin-authed) via the
|
|
292
383
|
* injected `opsSearch` helper — the same shape `flair rem candidates` uses.
|
|
293
|
-
*
|
|
294
|
-
* no admin creds) or on any error — the runner should not fail the cycle just
|
|
295
|
-
* because the candidate count couldn't be sampled.
|
|
384
|
+
* A failed query returns `unknown` with the error (flair#2680).
|
|
296
385
|
*/
|
|
297
386
|
async function fetchPendingCandidateCount(opsSearch, agentId) {
|
|
298
|
-
if (!opsSearch)
|
|
299
|
-
return 0;
|
|
300
387
|
try {
|
|
301
388
|
const rows = await opsSearch("MemoryCandidate", [
|
|
302
389
|
{ search_attribute: "agentId", search_type: "equals", search_value: agentId },
|
|
303
390
|
{ search_attribute: "status", search_type: "equals", search_value: "pending" },
|
|
304
391
|
], ["id"]);
|
|
392
|
+
if (!Array.isArray(rows))
|
|
393
|
+
return { state: "unknown", reason: "ops API returned an unexpected response shape" };
|
|
305
394
|
return rows.length;
|
|
306
395
|
}
|
|
307
|
-
catch {
|
|
308
|
-
return
|
|
396
|
+
catch (err) {
|
|
397
|
+
return { state: "unknown", reason: err?.message || String(err) };
|
|
309
398
|
}
|
|
310
399
|
}
|
|
311
400
|
/**
|
|
@@ -454,6 +543,7 @@ export async function runNightlyCycle(opts) {
|
|
|
454
543
|
runAt: startedAt.toISOString(),
|
|
455
544
|
slice: "1",
|
|
456
545
|
errors: [],
|
|
546
|
+
skips: [],
|
|
457
547
|
};
|
|
458
548
|
// Step 1: pre-flight (pause)
|
|
459
549
|
if (envPaused || (existsSync(pauseFlagPath) && readPauseSentinel(pauseFlagPath))) {
|
|
@@ -467,6 +557,18 @@ export async function runNightlyCycle(opts) {
|
|
|
467
557
|
return { status: "paused", logRow: row };
|
|
468
558
|
}
|
|
469
559
|
const errors = [];
|
|
560
|
+
// A deadline expiry on a write can leave an effect behind: it is carried
|
|
561
|
+
// apart from `errors` and makes the cycle `unresolved`.
|
|
562
|
+
const outcomeUnknown = [];
|
|
563
|
+
// flair#924 defect 1: deliberate skips (no backend / idle ADK / operator
|
|
564
|
+
// pause) land here, not in `errors`. Dedup so a per-tag or per-stage repeat
|
|
565
|
+
// of the same reason is recorded once.
|
|
566
|
+
const skips = [];
|
|
567
|
+
const pushSkipOnce = (reason) => {
|
|
568
|
+
if (!skips.includes(reason))
|
|
569
|
+
skips.push(reason);
|
|
570
|
+
};
|
|
571
|
+
const NO_BACKEND_SKIP = "distillation skipped: no generative backend configured";
|
|
470
572
|
const healthTimeoutMs = opts.healthTimeoutMs ?? DEFAULT_HEALTH_PREFLIGHT_MS;
|
|
471
573
|
const health = await runHealthPreflight(opts.apiCall, {
|
|
472
574
|
probe: opts.healthProbe,
|
|
@@ -486,38 +588,71 @@ export async function runNightlyCycle(opts) {
|
|
|
486
588
|
let snapshotPath;
|
|
487
589
|
let memoryCount = 0;
|
|
488
590
|
let soulCount = 0;
|
|
489
|
-
let pendingCandidates
|
|
591
|
+
let pendingCandidates;
|
|
490
592
|
// #1205b-1: the memories fetched here (for the snapshot) are reused by the
|
|
491
593
|
// step-5 tag enumeration — no second fetch. Hoisted so step 5 can read them.
|
|
492
594
|
let fetchedMemories = [];
|
|
595
|
+
let memories;
|
|
596
|
+
let souls;
|
|
597
|
+
let readOrSnapshotFailed = false;
|
|
598
|
+
// The two reads are independent: when one fails the other still reports its
|
|
599
|
+
// exact count, and each failed read is named under `Errors:`.
|
|
493
600
|
try {
|
|
494
|
-
|
|
495
|
-
const memoriesRaw = await opts.apiCall("GET", `/Memory?agentId=${encodeURIComponent(opts.agentId)}`);
|
|
496
|
-
const memories = asArray(memoriesRaw);
|
|
497
|
-
fetchedMemories = memories;
|
|
601
|
+
memories = rowsFromRead(await opts.apiCall("GET", `/Memory?agentId=${encodeURIComponent(opts.agentId)}`), "GET /Memory");
|
|
498
602
|
memoryCount = memories.length;
|
|
499
|
-
|
|
500
|
-
|
|
603
|
+
}
|
|
604
|
+
catch (err) {
|
|
605
|
+
const reason = err?.message ?? String(err);
|
|
606
|
+
memoryCount = { state: "unknown", reason };
|
|
607
|
+
errors.push(`memory-count: ${reason}`);
|
|
608
|
+
readOrSnapshotFailed = true;
|
|
609
|
+
}
|
|
610
|
+
try {
|
|
611
|
+
souls = rowsFromRead(await opts.apiCall("GET", `/Soul?agentId=${encodeURIComponent(opts.agentId)}`), "GET /Soul");
|
|
501
612
|
soulCount = souls.length;
|
|
502
|
-
// For the snapshot's soul.json: keep the full multi-row shape if there
|
|
503
|
-
// are multiple souls (different keys), or unwrap a single-row response.
|
|
504
|
-
const soulForSnapshot = souls.length === 1 ? souls[0] : souls.length > 1 ? souls : null;
|
|
505
|
-
pendingCandidates = await fetchPendingCandidateCount(opts.opsSearch, opts.agentId);
|
|
506
|
-
if (!opts.dryRun) {
|
|
507
|
-
const created = await createSnapshot({
|
|
508
|
-
agentId: opts.agentId,
|
|
509
|
-
flairVersion: opts.flairVersion,
|
|
510
|
-
memories,
|
|
511
|
-
soul: soulForSnapshot,
|
|
512
|
-
pendingCandidateCount: pendingCandidates,
|
|
513
|
-
rootOverride: opts.snapshotRoot,
|
|
514
|
-
nowOverride: opts.nowOverride,
|
|
515
|
-
});
|
|
516
|
-
snapshotPath = created.path;
|
|
517
|
-
}
|
|
518
613
|
}
|
|
519
614
|
catch (err) {
|
|
520
|
-
|
|
615
|
+
const reason = err?.message ?? String(err);
|
|
616
|
+
soulCount = { state: "unknown", reason };
|
|
617
|
+
errors.push(`soul-count: ${reason}`);
|
|
618
|
+
readOrSnapshotFailed = true;
|
|
619
|
+
}
|
|
620
|
+
fetchedMemories = memories ?? [];
|
|
621
|
+
if (memories && souls) {
|
|
622
|
+
try {
|
|
623
|
+
// For the snapshot's soul.json: keep the full multi-row shape if there
|
|
624
|
+
// are multiple souls (different keys), or unwrap a single-row response.
|
|
625
|
+
const soulForSnapshot = souls.length === 1 ? souls[0] : souls.length > 1 ? souls : null;
|
|
626
|
+
// flair#2680: a failed count is a failed check (an `errors` entry), not 0.
|
|
627
|
+
// With no admin credential no query runs; when the cycle reaches this step
|
|
628
|
+
// the count is reported unknown.
|
|
629
|
+
if (opts.opsSearch) {
|
|
630
|
+
pendingCandidates = await fetchPendingCandidateCount(opts.opsSearch, opts.agentId);
|
|
631
|
+
if (typeof pendingCandidates !== "number")
|
|
632
|
+
errors.push(`pending-count: ${pendingCandidates.reason}`);
|
|
633
|
+
}
|
|
634
|
+
else {
|
|
635
|
+
pendingCandidates = { state: "unknown", reason: PENDING_NO_ADMIN_REASON };
|
|
636
|
+
}
|
|
637
|
+
if (!opts.dryRun) {
|
|
638
|
+
const created = await createSnapshot({
|
|
639
|
+
agentId: opts.agentId,
|
|
640
|
+
flairVersion: opts.flairVersion,
|
|
641
|
+
memories,
|
|
642
|
+
soul: soulForSnapshot,
|
|
643
|
+
pendingCandidateCount: typeof pendingCandidates === "number" ? pendingCandidates : null,
|
|
644
|
+
rootOverride: opts.snapshotRoot,
|
|
645
|
+
nowOverride: opts.nowOverride,
|
|
646
|
+
});
|
|
647
|
+
snapshotPath = created.path;
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
catch (err) {
|
|
651
|
+
errors.push(`snapshot: ${err?.message ?? String(err)}`);
|
|
652
|
+
readOrSnapshotFailed = true;
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
if (readOrSnapshotFailed) {
|
|
521
656
|
const row = {
|
|
522
657
|
...baseRow,
|
|
523
658
|
status: "failed",
|
|
@@ -539,10 +674,12 @@ export async function runNightlyCycle(opts) {
|
|
|
539
674
|
let expired = 0;
|
|
540
675
|
let sliceLabel = "2-maintenance";
|
|
541
676
|
try {
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
677
|
+
// Only an id is sent: an empty or absent agentId is omitted rather than
|
|
678
|
+
// sent as an empty string.
|
|
679
|
+
const maintBody = { dryRun: opts.dryRun ?? false };
|
|
680
|
+
if (opts.agentId)
|
|
681
|
+
maintBody.agentId = opts.agentId;
|
|
682
|
+
const maintRaw = await opts.apiCall("POST", "/MemoryMaintenance", maintBody);
|
|
546
683
|
if (maintRaw && typeof maintRaw === "object") {
|
|
547
684
|
const obj = maintRaw;
|
|
548
685
|
if (obj.error) {
|
|
@@ -554,6 +691,26 @@ export async function runNightlyCycle(opts) {
|
|
|
554
691
|
}
|
|
555
692
|
}
|
|
556
693
|
catch (err) {
|
|
694
|
+
if (err instanceof ApiRequestOutcomeUnknown) {
|
|
695
|
+
// The maintenance write may have landed. Do not continue writing state
|
|
696
|
+
// whose order depended on it, and do not report a plain failure.
|
|
697
|
+
outcomeUnknown.push(`maintenance: ${err.message}`);
|
|
698
|
+
const row = {
|
|
699
|
+
...baseRow,
|
|
700
|
+
slice: sliceLabel,
|
|
701
|
+
status: "unresolved",
|
|
702
|
+
snapshotPath,
|
|
703
|
+
memoryCount,
|
|
704
|
+
soulCount,
|
|
705
|
+
pendingCandidates,
|
|
706
|
+
durationMs: Date.now() - startedMs,
|
|
707
|
+
errors,
|
|
708
|
+
outcomeUnknown,
|
|
709
|
+
skips,
|
|
710
|
+
};
|
|
711
|
+
appendLogRow(logPath, row);
|
|
712
|
+
return { status: "unresolved", logRow: row, snapshotPath };
|
|
713
|
+
}
|
|
557
714
|
errors.push(`maintenance: ${err?.message ?? String(err)}`);
|
|
558
715
|
const row = {
|
|
559
716
|
...baseRow,
|
|
@@ -595,10 +752,20 @@ export async function runNightlyCycle(opts) {
|
|
|
595
752
|
// #1515: aggregate gather stats from every /ReflectMemories call this cycle.
|
|
596
753
|
let distill;
|
|
597
754
|
let distillAborted = false;
|
|
755
|
+
let distillRan = false;
|
|
598
756
|
const collectStagedIds = (obj) => asArray(obj.candidates)
|
|
599
757
|
.map((c) => (c && typeof c === "object" ? c.id : c))
|
|
600
758
|
.filter((id) => typeof id === "string");
|
|
601
759
|
const noteGather = (obj, maxMemories) => {
|
|
760
|
+
if (!Array.isArray(obj.candidates) || obj.count !== obj.candidates.length
|
|
761
|
+
|| typeof obj.model !== "string" || !obj.model.trim()
|
|
762
|
+
|| !obj.candidates.every((c) => c && typeof c === "object" && typeof c.id === "string" && c.id.length > 0)
|
|
763
|
+
|| !Number.isInteger(obj.gathered) || obj.gathered < 0
|
|
764
|
+
|| !Number.isInteger(obj.unreflected) || obj.unreflected < 0
|
|
765
|
+
|| (obj.gathered === 0 && obj.candidates.length > 0)) {
|
|
766
|
+
throw new Error("unexpected /ReflectMemories response shape");
|
|
767
|
+
}
|
|
768
|
+
distillRan ||= obj.gathered > 0;
|
|
602
769
|
const gathered = typeof obj.gathered === "number" ? obj.gathered : 0;
|
|
603
770
|
const unreflected = typeof obj.unreflected === "number" ? obj.unreflected : 0;
|
|
604
771
|
if (!distill) {
|
|
@@ -634,7 +801,7 @@ export async function runNightlyCycle(opts) {
|
|
|
634
801
|
for (const tag of tagsToRun) {
|
|
635
802
|
if (cycleIsAborted()) {
|
|
636
803
|
distillAborted = true;
|
|
637
|
-
|
|
804
|
+
skips.push("distillation: aborted by operator (flair rem pause or FLAIR_REM_PAUSE=1)");
|
|
638
805
|
break;
|
|
639
806
|
}
|
|
640
807
|
await yieldToEventLoop();
|
|
@@ -649,22 +816,28 @@ export async function runNightlyCycle(opts) {
|
|
|
649
816
|
const obj = (reflectRaw && typeof reflectRaw === "object") ? reflectRaw : {};
|
|
650
817
|
if (obj.error) {
|
|
651
818
|
errors.push(`distillation[${tag}]: ${describeApiError(obj.error)}`);
|
|
652
|
-
if (isRemAbortedFailure(obj.error)) {
|
|
653
|
-
distillAborted = true;
|
|
654
|
-
break;
|
|
655
|
-
}
|
|
656
819
|
}
|
|
657
820
|
else {
|
|
658
|
-
staged.push(...collectStagedIds(obj));
|
|
659
821
|
noteGather(obj, maxMemories);
|
|
822
|
+
staged.push(...collectStagedIds(obj));
|
|
660
823
|
}
|
|
661
824
|
}
|
|
662
825
|
catch (err) {
|
|
663
|
-
|
|
664
|
-
|
|
826
|
+
if (err instanceof ApiRequestOutcomeUnknown) {
|
|
827
|
+
// May have staged candidates; reported apart from `errors`.
|
|
828
|
+
outcomeUnknown.push(`distillation[${tag}]: ${describeApiError(err)}`);
|
|
829
|
+
continue;
|
|
830
|
+
}
|
|
831
|
+
if (isNoBackendConfigured(err)) {
|
|
832
|
+
pushSkipOnce(NO_BACKEND_SKIP);
|
|
833
|
+
break;
|
|
834
|
+
}
|
|
835
|
+
if (isRemAbortedFailure(err)) {
|
|
836
|
+
pushSkipOnce("distillation: aborted by operator (rem_aborted)");
|
|
665
837
|
distillAborted = true;
|
|
666
838
|
break;
|
|
667
839
|
}
|
|
840
|
+
errors.push(`distillation[${tag}]: ${describeApiError(err)}`);
|
|
668
841
|
}
|
|
669
842
|
}
|
|
670
843
|
// `candidates` is defined (even if empty) whenever distillation was
|
|
@@ -675,7 +848,7 @@ export async function runNightlyCycle(opts) {
|
|
|
675
848
|
// ADK agentId whose users are all idle this window. Do NOT fall through
|
|
676
849
|
// to scope:"all" — that mixes every user's backlog (#1205b bleed).
|
|
677
850
|
// Active tags will be re-selected next cycle when they have recent rows.
|
|
678
|
-
|
|
851
|
+
skips.push("distillation: ADK agent has no active adk tags this cycle; skipped agentId-wide distill to avoid cross-user bleed");
|
|
679
852
|
}
|
|
680
853
|
else {
|
|
681
854
|
// AgentId-only path (non-ADK). scope:"all" + oldest-unreflected cap so
|
|
@@ -691,16 +864,11 @@ export async function runNightlyCycle(opts) {
|
|
|
691
864
|
});
|
|
692
865
|
const obj = (reflectRaw && typeof reflectRaw === "object") ? reflectRaw : {};
|
|
693
866
|
if (obj.error) {
|
|
694
|
-
// Defensive: a 200 response shouldn't carry { error }, since
|
|
695
|
-
// MemoryReflect signals failure via HTTP status (503/502) — apiCall
|
|
696
|
-
// implementations throw for those. Handled the same way regardless.
|
|
697
867
|
errors.push(`distillation: ${describeApiError(obj.error)}`);
|
|
698
|
-
if (isRemAbortedFailure(obj.error))
|
|
699
|
-
distillAborted = true;
|
|
700
868
|
}
|
|
701
869
|
else {
|
|
702
|
-
candidates = collectStagedIds(obj);
|
|
703
870
|
noteGather(obj, maxMemories);
|
|
871
|
+
candidates = collectStagedIds(obj);
|
|
704
872
|
}
|
|
705
873
|
}
|
|
706
874
|
catch (err) {
|
|
@@ -709,9 +877,20 @@ export async function runNightlyCycle(opts) {
|
|
|
709
877
|
// 3). Zero partial candidates is guaranteed server-side (all-or-
|
|
710
878
|
// nothing staging in /ReflectMemories). rem_aborted IS fatal to the
|
|
711
879
|
// rest of this cycle (no auto-promote / dedup).
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
880
|
+
if (err instanceof ApiRequestOutcomeUnknown) {
|
|
881
|
+
outcomeUnknown.push(`distillation: ${describeApiError(err)}`);
|
|
882
|
+
}
|
|
883
|
+
else if (isNoBackendConfigured(err)) {
|
|
884
|
+
pushSkipOnce(NO_BACKEND_SKIP);
|
|
885
|
+
}
|
|
886
|
+
else {
|
|
887
|
+
if (isRemAbortedFailure(err)) {
|
|
888
|
+
pushSkipOnce("distillation: aborted by operator (rem_aborted)");
|
|
889
|
+
distillAborted = true;
|
|
890
|
+
}
|
|
891
|
+
else
|
|
892
|
+
errors.push(`distillation: ${describeApiError(err)}`);
|
|
893
|
+
}
|
|
715
894
|
}
|
|
716
895
|
}
|
|
717
896
|
// ── Step 5a (flair#1257 slice 3): continuity-session distillation ─────────
|
|
@@ -747,7 +926,7 @@ export async function runNightlyCycle(opts) {
|
|
|
747
926
|
for (const tag of continuityToRun) {
|
|
748
927
|
if (distillAborted || cycleIsAborted()) {
|
|
749
928
|
distillAborted = true;
|
|
750
|
-
|
|
929
|
+
skips.push("distillation: aborted by operator (flair rem pause or FLAIR_REM_PAUSE=1)");
|
|
751
930
|
break;
|
|
752
931
|
}
|
|
753
932
|
await yieldToEventLoop();
|
|
@@ -763,23 +942,29 @@ export async function runNightlyCycle(opts) {
|
|
|
763
942
|
const obj = (reflectRaw && typeof reflectRaw === "object") ? reflectRaw : {};
|
|
764
943
|
if (obj.error) {
|
|
765
944
|
errors.push(`distillation[${tag}]: ${describeApiError(obj.error)}`);
|
|
766
|
-
if (isRemAbortedFailure(obj.error)) {
|
|
767
|
-
distillAborted = true;
|
|
768
|
-
break;
|
|
769
|
-
}
|
|
770
945
|
}
|
|
771
946
|
else {
|
|
772
|
-
candidates.push(...collectStagedIds(obj));
|
|
773
947
|
noteGather(obj, maxMemories);
|
|
948
|
+
candidates.push(...collectStagedIds(obj));
|
|
774
949
|
distilled++;
|
|
775
950
|
}
|
|
776
951
|
}
|
|
777
952
|
catch (err) {
|
|
778
|
-
|
|
779
|
-
|
|
953
|
+
if (err instanceof ApiRequestOutcomeUnknown) {
|
|
954
|
+
// May have staged candidates; reported apart from `errors`.
|
|
955
|
+
outcomeUnknown.push(`distillation[${tag}]: ${describeApiError(err)}`);
|
|
956
|
+
continue;
|
|
957
|
+
}
|
|
958
|
+
if (isNoBackendConfigured(err)) {
|
|
959
|
+
pushSkipOnce(NO_BACKEND_SKIP);
|
|
960
|
+
break;
|
|
961
|
+
}
|
|
962
|
+
if (isRemAbortedFailure(err)) {
|
|
963
|
+
pushSkipOnce("distillation: aborted by operator (rem_aborted)");
|
|
780
964
|
distillAborted = true;
|
|
781
965
|
break;
|
|
782
966
|
}
|
|
967
|
+
errors.push(`distillation[${tag}]: ${describeApiError(err)}`);
|
|
783
968
|
}
|
|
784
969
|
}
|
|
785
970
|
continuitySessions = distilled;
|
|
@@ -811,11 +996,21 @@ export async function runNightlyCycle(opts) {
|
|
|
811
996
|
else {
|
|
812
997
|
const promotedCount = typeof obj.count === "number" ? obj.count : asArray(obj.promoted).length;
|
|
813
998
|
const skippedCount = asArray(obj.skipped).length;
|
|
814
|
-
|
|
999
|
+
// flair#2714: a promotion whose candidate update threw is reported
|
|
1000
|
+
// apart from `promoted`; carry its counts instead of dropping them.
|
|
1001
|
+
const incompleteCount = asArray(obj.incomplete).length;
|
|
1002
|
+
const unconfirmedCount = asArray(obj.unconfirmed).length;
|
|
1003
|
+
autoPromoted = { promoted: promotedCount, skipped: skippedCount, incomplete: incompleteCount, unconfirmed: unconfirmedCount };
|
|
815
1004
|
}
|
|
816
1005
|
}
|
|
817
1006
|
catch (err) {
|
|
818
|
-
|
|
1007
|
+
if (err instanceof ApiRequestOutcomeUnknown) {
|
|
1008
|
+
// The sweep may have promoted candidates; its outcome is unknown.
|
|
1009
|
+
outcomeUnknown.push(`auto-promote: ${describeApiError(err)}`);
|
|
1010
|
+
}
|
|
1011
|
+
else {
|
|
1012
|
+
errors.push(`auto-promote: ${describeApiError(err)}`);
|
|
1013
|
+
}
|
|
819
1014
|
}
|
|
820
1015
|
}
|
|
821
1016
|
}
|
|
@@ -838,7 +1033,7 @@ export async function runNightlyCycle(opts) {
|
|
|
838
1033
|
let dedup;
|
|
839
1034
|
if (!opts.dryRun && !distillAborted) {
|
|
840
1035
|
try {
|
|
841
|
-
const dedupRaw = await opts.apiCall("POST", "/MemoryDedupStats", {});
|
|
1036
|
+
const dedupRaw = await (opts.adminApiCall ?? opts.apiCall)("POST", "/MemoryDedupStats", {});
|
|
842
1037
|
const obj = (dedupRaw && typeof dedupRaw === "object") ? dedupRaw : {};
|
|
843
1038
|
if (obj.error) {
|
|
844
1039
|
errors.push(`dedup: ${describeApiError(obj.error)}`);
|
|
@@ -846,7 +1041,8 @@ export async function runNightlyCycle(opts) {
|
|
|
846
1041
|
else if (typeof obj.clusterCount === "number" &&
|
|
847
1042
|
typeof obj.largestClusterSize === "number" &&
|
|
848
1043
|
typeof obj.totalMemoriesInClusters === "number" &&
|
|
849
|
-
typeof obj.computedAt === "string"
|
|
1044
|
+
typeof obj.computedAt === "string" &&
|
|
1045
|
+
obj.embeddingSpace === undefined) {
|
|
850
1046
|
dedup = {
|
|
851
1047
|
clusterCount: obj.clusterCount,
|
|
852
1048
|
largestClusterSize: obj.largestClusterSize,
|
|
@@ -854,12 +1050,43 @@ export async function runNightlyCycle(opts) {
|
|
|
854
1050
|
computedAt: obj.computedAt,
|
|
855
1051
|
};
|
|
856
1052
|
}
|
|
1053
|
+
else if (
|
|
1054
|
+
// Accept the guard's refusal only with null counts and a refusal state: any
|
|
1055
|
+
// non-empty state other than "uniform" (a refusal claiming "uniform" is
|
|
1056
|
+
// contradictory and stays an unexpected shape). Not an enumeration of
|
|
1057
|
+
// today's states, so a new guard state is recorded rather than an error.
|
|
1058
|
+
obj.clusterCount === null &&
|
|
1059
|
+
obj.largestClusterSize === null &&
|
|
1060
|
+
obj.totalMemoriesInClusters === null &&
|
|
1061
|
+
typeof obj.computedAt === "string" &&
|
|
1062
|
+
obj.embeddingSpace !== null && typeof obj.embeddingSpace === "object" &&
|
|
1063
|
+
!Array.isArray(obj.embeddingSpace) &&
|
|
1064
|
+
typeof obj.embeddingSpace.state === "string" &&
|
|
1065
|
+
obj.embeddingSpace.state.length > 0 &&
|
|
1066
|
+
obj.embeddingSpace.state !== "uniform" &&
|
|
1067
|
+
(obj.embeddingSpace.reason === null ||
|
|
1068
|
+
typeof obj.embeddingSpace.reason === "string")) {
|
|
1069
|
+
const space = obj.embeddingSpace;
|
|
1070
|
+
dedup = {
|
|
1071
|
+
clusterCount: null,
|
|
1072
|
+
largestClusterSize: null,
|
|
1073
|
+
totalMemoriesInClusters: null,
|
|
1074
|
+
computedAt: obj.computedAt,
|
|
1075
|
+
embeddingSpace: { state: space.state, reason: space.reason },
|
|
1076
|
+
};
|
|
1077
|
+
}
|
|
857
1078
|
else {
|
|
858
1079
|
errors.push("dedup: unexpected /MemoryDedupStats response shape");
|
|
859
1080
|
}
|
|
860
1081
|
}
|
|
861
1082
|
catch (err) {
|
|
862
|
-
|
|
1083
|
+
if (err instanceof ApiRequestOutcomeUnknown) {
|
|
1084
|
+
// The stat write may have persisted; its outcome is unknown.
|
|
1085
|
+
outcomeUnknown.push(`dedup: ${describeApiError(err)}`);
|
|
1086
|
+
}
|
|
1087
|
+
else {
|
|
1088
|
+
errors.push(`dedup: ${describeApiError(err)}`);
|
|
1089
|
+
}
|
|
863
1090
|
}
|
|
864
1091
|
}
|
|
865
1092
|
// Step 7: log
|
|
@@ -874,16 +1101,7 @@ export async function runNightlyCycle(opts) {
|
|
|
874
1101
|
const row = {
|
|
875
1102
|
...baseRow,
|
|
876
1103
|
slice: sliceLabel,
|
|
877
|
-
|
|
878
|
-
// NOT report success. A core stage that could not run — distillation with
|
|
879
|
-
// no generative backend, a per-tag distill failure, the dedup stat, an
|
|
880
|
-
// operator-aborted distill — is already pushed into `errors`; if any error
|
|
881
|
-
// stands, the run FAILED. Before this, a distillation-disabled cycle logged
|
|
882
|
-
// `status: "completed"` next to a populated `Errors:` block while the CLI
|
|
883
|
-
// exited 1 (src/commands/rem.ts), so the one signal a service manager can
|
|
884
|
-
// act on disagreed with the reported status. A populated errors[] can never
|
|
885
|
-
// coexist with "completed" again (regression-tested in rem-runner.test.ts).
|
|
886
|
-
status: errors.length > 0 ? "failed" : opts.dryRun ? "dry-run" : "completed",
|
|
1104
|
+
status: outcomeUnknown.length > 0 ? "unresolved" : errors.length > 0 ? "failed" : opts.dryRun ? "dry-run" : "completed",
|
|
887
1105
|
dryRun: opts.dryRun || undefined,
|
|
888
1106
|
snapshotPath,
|
|
889
1107
|
memoryCount,
|
|
@@ -898,6 +1116,9 @@ export async function runNightlyCycle(opts) {
|
|
|
898
1116
|
dedup,
|
|
899
1117
|
durationMs: Date.now() - startedMs,
|
|
900
1118
|
errors,
|
|
1119
|
+
outcomeUnknown: outcomeUnknown.length > 0 ? outcomeUnknown : undefined,
|
|
1120
|
+
skips,
|
|
1121
|
+
distilledAt: distillRan && !distillAborted && errors.length === 0 && outcomeUnknown.length === 0 && skips.length === 0 ? baseRow.runAt : undefined,
|
|
901
1122
|
// `consolidated` remains undefined — this runner has no consolidation
|
|
902
1123
|
// step; it's reserved for a future slice that adds one.
|
|
903
1124
|
};
|