spur-board 0.20.1 → 0.20.2

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.
Files changed (2) hide show
  1. package/dist/daemon.mjs +57 -11
  2. package/package.json +1 -1
package/dist/daemon.mjs CHANGED
@@ -7633,7 +7633,12 @@ function checkGatewayStrings(strings) {
7633
7633
  }
7634
7634
  return null;
7635
7635
  }
7636
- /** Replays database-only work after scanning exact strings outside the write transaction. */
7636
+ /**
7637
+ * Replays database-only work after scanning exact strings outside the write transaction.
7638
+ * `fn` must build the same gateway strings on every pass: read a time that lands in one, such as
7639
+ * an outbox payload, before the call, as a time read inside `fn` makes a new string each pass and
7640
+ * the replay never ends. A time kept only in the database may be read inside.
7641
+ */
7637
7642
  async function scanTransaction(store, config, fn) {
7638
7643
  const known = /* @__PURE__ */ new Map();
7639
7644
  for (let pass = 0; pass < MAX_PASSES; pass += 1) {
@@ -12232,6 +12237,7 @@ function createObservationCore(deps) {
12232
12237
  },
12233
12238
  async observe(source, observation) {
12234
12239
  const { batch } = observation;
12240
+ const now = clock.now();
12235
12241
  await scanTransaction(store, config, async (trx) => {
12236
12242
  await sourceState(trx, source, observation.state, batch.observedAt, batch.cursor);
12237
12243
  for (const outcome of observation.outcomes) {
@@ -12325,7 +12331,7 @@ function createObservationCore(deps) {
12325
12331
  const activeTasks = await trx.selectFrom("task").select("id").where("membership", "!=", "archived").execute();
12326
12332
  for (const task of activeTasks) await updateTerminal(trx, config, task.id, batch.observedAt, currentComplete, blind);
12327
12333
  await reconcileMembership(trx, config, currentComplete, batch.observedAt);
12328
- await reconcileItems(trx, config, clock.now(), currentComplete.has("spur"));
12334
+ await reconcileItems(trx, config, now, currentComplete.has("spur"));
12329
12335
  if (deps.productVersion !== void 0) await enqueueLiveAfterFirstPoll(trx, {
12330
12336
  config,
12331
12337
  productVersion: deps.productVersion,
@@ -12337,12 +12343,14 @@ function createObservationCore(deps) {
12337
12343
  if (observation.effectiveComplete) completeSince.set(source, batch.observedAt);
12338
12344
  },
12339
12345
  reportSourceState(source, state) {
12346
+ const now = clock.now();
12340
12347
  return scanTransaction(store, config, async (trx) => {
12341
12348
  await sourceState(trx, source, state);
12342
- await reconcileItems(trx, config, clock.now(), completeSince.has("spur"));
12349
+ await reconcileItems(trx, config, now, completeSince.has("spur"));
12343
12350
  });
12344
12351
  },
12345
12352
  notice(kind, value) {
12353
+ const at = new Date(clock.now()).toISOString();
12346
12354
  return scanTransaction(store, config, async (trx) => {
12347
12355
  const key = `spur-notice:${kind}:${value}`;
12348
12356
  if (await trx.selectFrom("meta").select("key").where("key", "=", key).executeTakeFirst() !== void 0) return;
@@ -12350,7 +12358,7 @@ function createObservationCore(deps) {
12350
12358
  key,
12351
12359
  value: "true"
12352
12360
  }).execute();
12353
- await emit(trx, "spur_unknown_state", RESERVED_PROJECT, null, new Date(clock.now()).toISOString(), {
12361
+ await emit(trx, "spur_unknown_state", RESERVED_PROJECT, null, at, {
12354
12362
  kind,
12355
12363
  value
12356
12364
  });
@@ -15023,6 +15031,18 @@ function runSource(entry, options, runnerStartMs) {
15023
15031
  reason: "stale",
15024
15032
  message: `No complete observation in ${String(staleMultiplier)} poll intervals`
15025
15033
  };
15034
+ function fail(step, error, issues) {
15035
+ const kind = error instanceof AdapterError ? error.kind : "unexpected";
15036
+ try {
15037
+ options.onFailure?.({
15038
+ source,
15039
+ step,
15040
+ kind,
15041
+ error,
15042
+ ...issues === void 0 ? {} : { issues }
15043
+ });
15044
+ } catch {}
15045
+ }
15026
15046
  let stopping = false;
15027
15047
  let failures = 0;
15028
15048
  let lastCompleteMs;
@@ -15057,7 +15077,9 @@ function runSource(entry, options, runnerStartMs) {
15057
15077
  try {
15058
15078
  await core.reportSourceState(source, next);
15059
15079
  lastReported = json;
15060
- } catch {}
15080
+ } catch (error) {
15081
+ fail("report", error);
15082
+ }
15061
15083
  });
15062
15084
  return reports;
15063
15085
  }
@@ -15093,6 +15115,7 @@ function runSource(entry, options, runnerStartMs) {
15093
15115
  controller = abort;
15094
15116
  const startMs = now();
15095
15117
  let outcome;
15118
+ let step = "context";
15096
15119
  try {
15097
15120
  const received = await core.context(source);
15098
15121
  const context = entry.repo === void 0 ? received : {
@@ -15109,20 +15132,31 @@ function runSource(entry, options, runnerStartMs) {
15109
15132
  hydrated = true;
15110
15133
  }
15111
15134
  const requested = [...context.observe.prs, ...context.observe.tickets];
15135
+ step = "poll";
15112
15136
  const batch = await untilAborted(adapter.poll({
15113
15137
  ...context,
15114
15138
  signal: abort.signal
15115
15139
  }), abort.signal);
15116
15140
  if (aborted()) return;
15141
+ step = "batch";
15117
15142
  const parsed = batchSchema.safeParse({
15118
15143
  ...batch,
15119
15144
  observedAt: iso$1(startMs)
15120
15145
  });
15121
- if (!parsed.success || parsed.data.source !== source || !answersRequest(context.observe, parsed.data.entities)) outcome = {
15122
- kind: "failed",
15123
- error: new AdapterError("transient", "Invalid batch")
15124
- };
15125
- else {
15146
+ const invalid = !parsed.success ? void 0 : parsed.data.source !== source ? "names another source" : !answersRequest(context.observe, parsed.data.entities) ? "does not answer the request" : void 0;
15147
+ if (!parsed.success || invalid !== void 0) {
15148
+ const error = new AdapterError("transient", `Invalid batch: ${invalid ?? "fails the batch schema"}`);
15149
+ fail("batch", error, parsed.error?.issues.map((issue) => ({
15150
+ path: issue.path.map(String).join("."),
15151
+ code: issue.code,
15152
+ message: issue.message
15153
+ })));
15154
+ outcome = {
15155
+ kind: "failed",
15156
+ error
15157
+ };
15158
+ } else {
15159
+ step = "outcomes";
15126
15160
  const outcomes = applyEntityOutcomes({
15127
15161
  counts,
15128
15162
  requested,
@@ -15150,6 +15184,7 @@ function runSource(entry, options, runnerStartMs) {
15150
15184
  lastReported = JSON.stringify(proposedState);
15151
15185
  });
15152
15186
  reports = accepted.then(() => void 0, () => void 0);
15187
+ step = "observe";
15153
15188
  await accepted;
15154
15189
  if (aborted()) return;
15155
15190
  outcome = {
@@ -15159,6 +15194,7 @@ function runSource(entry, options, runnerStartMs) {
15159
15194
  }
15160
15195
  } catch (error) {
15161
15196
  if (aborted()) return;
15197
+ fail(step, error);
15162
15198
  if (error instanceof AdapterError && (error.kind === "auth" || error.kind === "config")) errorBlind = {
15163
15199
  reason: error.kind,
15164
15200
  message: error.message
@@ -15544,7 +15580,8 @@ function startAdapters(config, core, options = {}) {
15544
15580
  core,
15545
15581
  config,
15546
15582
  ...options.now === void 0 ? {} : { now: options.now },
15547
- ...options.oneShot === void 0 ? {} : { oneShot: options.oneShot }
15583
+ ...options.oneShot === void 0 ? {} : { oneShot: options.oneShot },
15584
+ onFailure: options.onPollFailure
15548
15585
  });
15549
15586
  return {
15550
15587
  firstAttempts: runner.firstAttempts,
@@ -16646,6 +16683,15 @@ function createBoardModules(ctxFor, options = {}) {
16646
16683
  warn: (message) => {
16647
16684
  adapterCtx.log.warn({ message }, "adapter warning");
16648
16685
  },
16686
+ onPollFailure: ({ source, step, kind, error, issues }) => {
16687
+ adapterCtx.log.warn({
16688
+ source,
16689
+ step,
16690
+ kind,
16691
+ err: error,
16692
+ ...issues === void 0 ? {} : { issues }
16693
+ }, "adapter poll failed");
16694
+ },
16649
16695
  onSpurNotice: async (notice) => {
16650
16696
  if (notice.kind === "restart") adapterCtx.log.info("spur restarted");
16651
16697
  else await core.notice(notice.kind, notice.value);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spur-board",
3
- "version": "0.20.1",
3
+ "version": "0.20.2",
4
4
  "license": "MIT",
5
5
  "engines": {
6
6
  "node": "^24.12.0 || ^26.0.0"