spur-board 0.44.2 → 0.44.3

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 +40 -12
  2. package/package.json +1 -1
package/dist/daemon.mjs CHANGED
@@ -12858,7 +12858,7 @@ function evaluateSessionHealth(input) {
12858
12858
  sessionId: session.id,
12859
12859
  kind: ENDED_WORKER_KINDS[session.endReason]
12860
12860
  };
12861
- (spur.observationComplete ? flags : held).push(flag);
12861
+ (spur.observationComplete && prsPolledSince(task, session.endedAt) ? flags : held).push(flag);
12862
12862
  }
12863
12863
  continue;
12864
12864
  }
@@ -12873,10 +12873,14 @@ function evaluateSessionHealth(input) {
12873
12873
  if (session.role === "other") continue;
12874
12874
  const heldMs = now - Date.parse(session.healthSince);
12875
12875
  let kind = null;
12876
+ let fresh = true;
12876
12877
  if (session.health === "error" && episode === null && heldMs >= config.errorAfterMs) kind = session.role === "worker" ? "stuck_worker" : "stuck_orchestrator";
12877
12878
  else if (session.health === "needs_input" && heldMs >= config.needsInputAfterMs) kind = "needs_input";
12878
- else if (session.health === "waiting" && session.role === "worker" && task !== void 0 && !task.hasOpenPr && heldMs >= config.idleInDevAfterMs) kind = "worker_idle";
12879
- if (kind !== null) flags.push({
12879
+ else if (session.health === "waiting" && session.role === "worker" && task !== void 0 && !task.hasOpenPr && heldMs >= config.idleInDevAfterMs) {
12880
+ kind = "worker_idle";
12881
+ fresh = prsPolledSince(task, session.healthSince);
12882
+ }
12883
+ if (kind !== null) (fresh ? flags : held).push({
12880
12884
  taskId: session.taskId,
12881
12885
  sessionId: session.id,
12882
12886
  kind
@@ -12890,6 +12894,10 @@ function evaluateSessionHealth(input) {
12890
12894
  episode
12891
12895
  };
12892
12896
  }
12897
+ /** Whether every PR source of the task completed a poll that began at or after `since`. */
12898
+ function prsPolledSince(task, since) {
12899
+ return task.prCompleteAt !== null && task.prCompleteAt >= Date.parse(since);
12900
+ }
12893
12901
  //#endregion
12894
12902
  //#region ../core/src/app/fromYou.ts
12895
12903
  const episodeSchema = z.object({ startedAt: z.number() }).nullable();
@@ -13019,12 +13027,14 @@ async function reconcileItems(trx, config, now, spurComplete) {
13019
13027
  "link.number",
13020
13028
  "pr_snapshot.state",
13021
13029
  "pr_snapshot.source",
13022
- "pr_snapshot.observed_at"
13030
+ "pr_snapshot.observed_at",
13031
+ "pr_snapshot.detail"
13023
13032
  ]).where("link.entity", "=", "pr").where("link.banned", "=", 0).where(pastReopenFloor).execute();
13024
13033
  const taskPrs = {};
13025
13034
  for (const task of tasks) taskPrs[String(task.id)] = {
13026
13035
  hasOpenPr: false,
13027
13036
  hasMergedPr: false,
13037
+ prCompleteAt: prCompleteAt(config.projects.find((entry) => entry.id === task.project), sourceById),
13028
13038
  turnSessions: []
13029
13039
  };
13030
13040
  for (const pr of prs) {
@@ -13038,6 +13048,7 @@ async function reconcileItems(trx, config, now, spurComplete) {
13038
13048
  const holder = turn.acked_by === null ? null : parseActorId(turn.acked_by);
13039
13049
  if (holder?.actor === "agent") taskPrs[String(turn.task_id)]?.turnSessions.push(holder.actorRef.session);
13040
13050
  }
13051
+ const heldKeys = [];
13041
13052
  for (const task of tasks) {
13042
13053
  const state = taskPrs[String(task.id)];
13043
13054
  if (state === void 0 || state.hasOpenPr || state.hasMergedPr) continue;
@@ -13047,9 +13058,15 @@ async function reconcileItems(trx, config, now, spurComplete) {
13047
13058
  })).sort((left, right) => left.ref.localeCompare(right.ref));
13048
13059
  const first = closed[0];
13049
13060
  if (first === void 0) continue;
13061
+ const closedAt = Math.max(...closed.map((pr) => pr.detail === null ? NaN : Date.parse(parseJson(prFactsSchema, pr.detail).updatedAt)));
13062
+ const key = `pr-closed:${String(task.id)}`;
13063
+ if (state.prCompleteAt === null || !(state.prCompleteAt >= closedAt)) {
13064
+ heldKeys.push(key);
13065
+ continue;
13066
+ }
13050
13067
  const refs = closed.map((pr) => pr.ref);
13051
13068
  candidates.push({
13052
- key: `pr-closed:${String(task.id)}`,
13069
+ key,
13053
13070
  kind: "anomaly",
13054
13071
  taskId: task.id,
13055
13072
  summary: `${task.key}: linked pull request ${refs.join(", ")} closed without merge, no open PR`,
@@ -13065,7 +13082,6 @@ async function reconcileItems(trx, config, now, spurComplete) {
13065
13082
  "detail",
13066
13083
  "source"
13067
13084
  ]).execute();
13068
- const unpolledTickets = [];
13069
13085
  for (const task of tasks) {
13070
13086
  const state = taskPrs[String(task.id)];
13071
13087
  const project = config.projects.find((entry) => entry.id === task.project);
@@ -13082,13 +13098,11 @@ async function reconcileItems(trx, config, now, spurComplete) {
13082
13098
  });
13083
13099
  if (!closedWhileLive) continue;
13084
13100
  const { updatedAt } = parseJson(ticketFactsSchema, ticket.detail);
13085
- const polled = project.repos.every((repo) => {
13086
- const repoSource = sourceById.get(`github:${project.id}:${repo.toLowerCase()}`);
13087
- return repoSource !== void 0 && repoSource.blind_reason === null && repoSource.last_complete_at !== null && Date.parse(repoSource.last_complete_at) > Date.parse(updatedAt);
13088
- });
13101
+ const polledAt = state.prCompleteAt;
13102
+ const polled = polledAt !== null && polledAt > Date.parse(updatedAt);
13089
13103
  const key = `ticket-closed:${String(task.id)}`;
13090
13104
  if (!polled) {
13091
- unpolledTickets.push(key);
13105
+ heldKeys.push(key);
13092
13106
  continue;
13093
13107
  }
13094
13108
  candidates.push({
@@ -13161,7 +13175,7 @@ async function reconcileItems(trx, config, now, spurComplete) {
13161
13175
  }
13162
13176
  }
13163
13177
  const ordered = orderItems(candidates);
13164
- const seen = /* @__PURE__ */ new Set([...ordered.map((item) => item.key), ...unpolledTickets]);
13178
+ const seen = /* @__PURE__ */ new Set([...ordered.map((item) => item.key), ...heldKeys]);
13165
13179
  for (const flag of health.held) {
13166
13180
  const task = taskById.get(Number(flag.taskId));
13167
13181
  if (task !== void 0) seen.add(healthKey(task.id, flag));
@@ -13215,6 +13229,20 @@ async function reconcileItems(trx, config, now, spurComplete) {
13215
13229
  }
13216
13230
  }
13217
13231
  /**
13232
+ * Start of the oldest last complete poll over the project's GitHub sources, or null while any is
13233
+ * missing, blind or never complete: a replacement PR can be in any of the project's repos.
13234
+ */
13235
+ function prCompleteAt(project, sourceById) {
13236
+ if (project === void 0) return null;
13237
+ let oldest = Infinity;
13238
+ for (const repo of project.repos) {
13239
+ const source = sourceById.get(`github:${project.id}:${repo.toLowerCase()}`);
13240
+ if (source === void 0 || source.blind_reason !== null || source.last_complete_at === null) return null;
13241
+ oldest = Math.min(oldest, Date.parse(source.last_complete_at));
13242
+ }
13243
+ return oldest;
13244
+ }
13245
+ /**
13218
13246
  * Raises a ledger item with the operator block it stands for. An active item of the key is
13219
13247
  * returned as it is, so a repeated raise opens no second block.
13220
13248
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spur-board",
3
- "version": "0.44.2",
3
+ "version": "0.44.3",
4
4
  "license": "MIT",
5
5
  "engines": {
6
6
  "node": "^24.12.0 || ^26.0.0"