@semiont/make-meaning 0.5.30 → 0.5.31

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.
@@ -1,11 +1,11 @@
1
1
  import { replyChannelsFor, createTomlConfigLoader, accessToken, baseUrl as baseUrl$1, retryWithBackoff, isTransientFetchError, STARTUP_FETCH_RETRY, errField, burstBuffer, busRequest, resourceId, didToAgent, annotationId, findBodyItem } from '@semiont/core';
2
+ import { getGraphDatabase, intendedGraphAnnotation } from '@semiont/graph';
2
3
  import { existsSync, readFileSync, promises } from 'fs';
3
4
  import * as path from 'path';
4
5
  import { join } from 'path';
5
6
  import '@semiont/observability';
6
7
  import '@semiont/ontology';
7
8
  import '@semiont/content';
8
- import { getGraphDatabase } from '@semiont/graph';
9
9
  import '@semiont/vectors';
10
10
  import '@semiont/event-sourcing';
11
11
  import { HttpTransport } from '@semiont/http-transport';
@@ -10081,6 +10081,7 @@ var Weaver = class _Weaver {
10081
10081
  let divergent = 0;
10082
10082
  let healed = 0;
10083
10083
  let healFailures = 0;
10084
+ let orphaned = 0;
10084
10085
  for (const resource of resources) {
10085
10086
  const rid = resource["@id"];
10086
10087
  if (!rid) continue;
@@ -10089,11 +10090,17 @@ var Weaver = class _Weaver {
10089
10090
  divergent++;
10090
10091
  this.logger.warn("Reconcile divergence \u2014 healing from the log", { resourceId: String(rid), reason });
10091
10092
  const result = await this.rebuildResource(resourceId(String(rid)));
10092
- if (result.eventsFailed === 0) healed++;
10093
+ if (result.eventCount === 0) {
10094
+ orphaned++;
10095
+ this.logger.warn(
10096
+ "Reconcile found an orphaned view \u2014 the log has no events for this resource, so healing wrote nothing",
10097
+ { resourceId: String(rid), reason, remedy: "semiont stop && semiont clean --store state && semiont start" }
10098
+ );
10099
+ } else if (result.eventsFailed === 0) healed++;
10093
10100
  else healFailures++;
10094
10101
  }
10095
- const summary = { resourcesChecked: resources.length, divergent, healed, healFailures };
10096
- if (divergent > 0 || healFailures > 0) {
10102
+ const summary = { resourcesChecked: resources.length, divergent, healed, healFailures, orphaned };
10103
+ if (divergent > 0 || healFailures > 0 || orphaned > 0) {
10097
10104
  this.logger.warn("Weaver reconcile found divergence", summary);
10098
10105
  } else {
10099
10106
  this.logger.info("Weaver reconcile complete \u2014 projection matches the catalog", summary);
@@ -10135,13 +10142,13 @@ var Weaver = class _Weaver {
10135
10142
  for (const id of viewIds) {
10136
10143
  if (!graphIds.has(id)) return "annotation-set-mismatch";
10137
10144
  }
10138
- const bodyKey = (a) => _Weaver.canonicalJson(a.body ?? []);
10139
10145
  const viewById = new Map(annotations.map((a) => [String(a.id), a]));
10140
10146
  for (const graphAnnotation of graphAnnotations) {
10141
10147
  const viewAnnotation = viewById.get(String(graphAnnotation.id));
10142
10148
  if (!viewAnnotation) continue;
10143
- if (bodyKey(graphAnnotation) !== bodyKey(viewAnnotation)) {
10144
- return "annotation-body-mismatch";
10149
+ const intended = intendedGraphAnnotation({ ...viewAnnotation, creator: graphAnnotation.creator });
10150
+ if (_Weaver.canonicalJson(graphAnnotation) !== _Weaver.canonicalJson(intended)) {
10151
+ return "annotation-content-mismatch";
10145
10152
  }
10146
10153
  }
10147
10154
  return null;
@@ -10494,7 +10501,7 @@ var Weaver = class _Weaver {
10494
10501
  });
10495
10502
  }
10496
10503
  this.logger.info("Resource rebuild complete", { resourceId: resourceId6, eventCount: events.length, eventsFailed });
10497
- return { eventsApplied: events.length - eventsFailed, eventsFailed };
10504
+ return { eventCount: events.length, eventsApplied: events.length - eventsFailed, eventsFailed };
10498
10505
  }
10499
10506
  /**
10500
10507
  * Rebuild entire GraphDB from all events.
@@ -10651,7 +10658,6 @@ var STOWER_CHANNELS = [
10651
10658
  var BROWSER_CHANNELS = [
10652
10659
  "browse:resource-requested",
10653
10660
  "browse:anchored-text-requested",
10654
- "browse:anchored-text-by-checksum-requested",
10655
10661
  "browse:resources-requested",
10656
10662
  "browse:annotations-requested",
10657
10663
  "browse:annotation-requested",
@@ -10711,6 +10717,19 @@ var ARCHIVIST_OUTBOUND_STRAYS = [
10711
10717
  ...ARCHIVIST_OUTBOUND_STRAYS,
10712
10718
  ...replyChannelsFor(ARCHIVIST_INBOUND_CHANNELS)
10713
10719
  ];
10720
+ async function runBootPass(pass, run, logger2, onState) {
10721
+ onState?.({ phase: "running" });
10722
+ try {
10723
+ const summary = await run();
10724
+ onState?.({ phase: "done", summary });
10725
+ } catch (error) {
10726
+ onState?.({ phase: "failed", error: error instanceof Error ? error.message : String(error) });
10727
+ logger2.error(`Boot pass '${pass}' failed \u2014 continuing with a store that may be behind`, {
10728
+ pass,
10729
+ error: errField(error)
10730
+ });
10731
+ }
10732
+ }
10714
10733
  var configPath = join(homedir(), ".semiontconfig");
10715
10734
  var tomlReader = {
10716
10735
  readIfExists: (p) => existsSync(p) ? readFileSync(p, "utf-8") : null
@@ -10857,22 +10876,12 @@ async function main() {
10857
10876
  };
10858
10877
  process.on("SIGTERM", shutdown);
10859
10878
  process.on("SIGINT", shutdown);
10860
- catchUpState = { phase: "running" };
10861
- try {
10862
- const summary = await weaver.catchUp();
10863
- catchUpState = { phase: "done", summary };
10864
- } catch (error) {
10865
- catchUpState = { phase: "failed", error: error instanceof Error ? error.message : String(error) };
10866
- throw error;
10867
- }
10868
- reconcileState = { phase: "running" };
10869
- try {
10870
- const summary = await weaver.reconcile();
10871
- reconcileState = { phase: "done", summary };
10872
- } catch (error) {
10873
- reconcileState = { phase: "failed", error: error instanceof Error ? error.message : String(error) };
10874
- throw error;
10875
- }
10879
+ await runBootPass("catch-up", () => weaver.catchUp(), logger, (s) => {
10880
+ catchUpState = s;
10881
+ });
10882
+ await runBootPass("reconcile", () => weaver.reconcile(), logger, (s) => {
10883
+ reconcileState = s;
10884
+ });
10876
10885
  }
10877
10886
  main().catch((error) => {
10878
10887
  logger.error("Fatal", { error: error instanceof Error ? error.message : String(error), stack: error instanceof Error ? error.stack : void 0 });