@herdingchats/friday 0.1.647 → 0.1.651

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/herd.mjs +27 -10
  2. package/package.json +2 -2
package/herd.mjs CHANGED
@@ -18,7 +18,7 @@ var __export = (target, all) => {
18
18
  var define_HERD_PACKAGE_default;
19
19
  var init_define_HERD_PACKAGE = __esm({
20
20
  "<define:HERD_PACKAGE>"() {
21
- define_HERD_PACKAGE_default = { version: "0.1.647", gitHead: "e6ca40951a8ccd049fe5fa0f192137e4ba76a842" };
21
+ define_HERD_PACKAGE_default = { version: "0.1.651", gitHead: "60dd42f8309cea2c6700c788c92ef3732e1d517c" };
22
22
  }
23
23
  });
24
24
 
@@ -6470,6 +6470,7 @@ import {
6470
6470
  renameSync as renameSync4,
6471
6471
  statSync as statSync6
6472
6472
  } from "node:fs";
6473
+ var RETRY_FAILED_MS = [3e4, 6e4, 12e4, 24e4, 48e4, 6e5];
6473
6474
  var MAX_LOG_BYTES2 = 10 * 1024 * 1024;
6474
6475
  var Supervisor = class {
6475
6476
  constructor(options) {
@@ -6491,8 +6492,13 @@ var Supervisor = class {
6491
6492
  failures = 0;
6492
6493
  restartTimer = null;
6493
6494
  checkTimer = null;
6494
- /** Releases that failed to install, and when, so each is retried rather than tried every check. */
6495
+ /**
6496
+ * Releases that failed to install, when they're next due and how many times they've failed, so
6497
+ * each is retried on its own schedule rather than at every check.
6498
+ */
6495
6499
  failed = /* @__PURE__ */ new Map();
6500
+ /** When the release that last failed is due again, so the next check runs then. */
6501
+ retryAt = null;
6496
6502
  status;
6497
6503
  log;
6498
6504
  /** Starts the daemon and the release checks. */
@@ -6503,11 +6509,18 @@ var Supervisor = class {
6503
6509
  const schedule = (ms2) => {
6504
6510
  this.checkTimer = setTimeout(async () => {
6505
6511
  await this.check().catch((error) => this.log(`The release check failed: ${error}`));
6506
- if (!this.stopping) schedule(this.options.checkMs ?? 12e4);
6512
+ if (!this.stopping) schedule(this.nextCheckMs());
6507
6513
  }, ms2);
6508
6514
  };
6509
6515
  schedule(this.options.firstCheckMs ?? 5e3);
6510
6516
  }
6517
+ /** The regular interval, or sooner when a failed release is due again before then. */
6518
+ nextCheckMs() {
6519
+ const every = this.options.checkMs ?? 12e4;
6520
+ if (this.retryAt === null) return every;
6521
+ const now = this.options.now?.() ?? Date.now();
6522
+ return Math.min(every, Math.max(0, this.retryAt - now));
6523
+ }
6511
6524
  /** Stops the daemon and the checks. */
6512
6525
  async stop() {
6513
6526
  this.stopping = true;
@@ -6634,16 +6647,16 @@ var Supervisor = class {
6634
6647
  }
6635
6648
  const current = currentVersion(paths) ?? this.options.version;
6636
6649
  if (target === current) {
6650
+ this.retryAt = null;
6637
6651
  this.status.problem = null;
6638
6652
  this.save();
6639
6653
  return "none";
6640
6654
  }
6641
6655
  const key = `${target} ${integrity ?? ""}`;
6642
6656
  const now = this.options.now?.() ?? Date.now();
6643
- const failedAt = this.failed.get(key);
6644
- if (failedAt !== void 0 && now - failedAt < (this.options.retryFailedMs ?? 10 * 6e4)) {
6645
- return "failed";
6646
- }
6657
+ const failed = this.failed.get(key);
6658
+ this.retryAt = failed?.dueAt ?? null;
6659
+ if (failed && now < failed.dueAt) return "failed";
6647
6660
  const release = takeLock(paths.updateLock);
6648
6661
  if (!release) return "busy";
6649
6662
  try {
@@ -6653,12 +6666,16 @@ var Supervisor = class {
6653
6666
  log: this.log
6654
6667
  });
6655
6668
  if (!installed.ok) {
6656
- const again = failedAt !== void 0;
6657
- this.failed.set(key, now);
6658
- if (again) return "failed";
6669
+ const failures = (failed?.failures ?? 0) + 1;
6670
+ const waits = this.options.retryFailedMs ?? RETRY_FAILED_MS;
6671
+ const dueAt = now + (waits[Math.min(failures, waits.length) - 1] ?? 0);
6672
+ this.failed.set(key, { dueAt, failures });
6673
+ this.retryAt = dueAt;
6674
+ if (failed) return "failed";
6659
6675
  return this.problem(`Staying on ${current}: ${target} ${installed.reason}`);
6660
6676
  }
6661
6677
  activate(paths, target);
6678
+ this.retryAt = null;
6662
6679
  } finally {
6663
6680
  release();
6664
6681
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@herdingchats/friday",
3
- "version": "0.1.647",
3
+ "version": "0.1.651",
4
4
  "description": "Friday, HerdingChats' agent daemon, and the herd command it runs agents with.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -22,5 +22,5 @@
22
22
  "satori": "0.32.0",
23
23
  "zod": "4.6.7"
24
24
  },
25
- "gitHead": "e6ca40951a8ccd049fe5fa0f192137e4ba76a842"
25
+ "gitHead": "60dd42f8309cea2c6700c788c92ef3732e1d517c"
26
26
  }