spur-board 0.21.1 → 0.22.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/dist/daemon.mjs +258 -184
- package/package.json +1 -1
package/dist/daemon.mjs
CHANGED
|
@@ -7720,9 +7720,11 @@ function checkGatewayStrings(strings) {
|
|
|
7720
7720
|
}
|
|
7721
7721
|
/**
|
|
7722
7722
|
* Replays database-only work after scanning exact strings outside the write transaction.
|
|
7723
|
-
* `fn` must build the same gateway strings on every pass
|
|
7724
|
-
* an outbox payload, before the call,
|
|
7725
|
-
*
|
|
7723
|
+
* `fn` must build the same gateway strings on every pass. Read a time that lands in one, such as
|
|
7724
|
+
* an outbox payload, before the call, or capture it once on the first pass, after the write lock,
|
|
7725
|
+
* and reuse it on every replay, as `runTick` in `sender.ts` does with the send-time token expiry.
|
|
7726
|
+
* A fresh time read on each pass makes a new string each pass and the replay never ends. A time
|
|
7727
|
+
* kept only in the database may be read inside.
|
|
7726
7728
|
*/
|
|
7727
7729
|
async function scanTransaction(store, config, fn) {
|
|
7728
7730
|
const known = /* @__PURE__ */ new Map();
|
|
@@ -7874,7 +7876,7 @@ async function writeDeniedEvent(trx, denial) {
|
|
|
7874
7876
|
}
|
|
7875
7877
|
//#endregion
|
|
7876
7878
|
//#region ../core/src/app/commands.ts
|
|
7877
|
-
const DAY_MS = 864e5;
|
|
7879
|
+
const DAY_MS$1 = 864e5;
|
|
7878
7880
|
const TASKLESS = [
|
|
7879
7881
|
"task.add",
|
|
7880
7882
|
"item.retry",
|
|
@@ -7997,32 +7999,12 @@ function createApply(deps) {
|
|
|
7997
7999
|
return result;
|
|
7998
8000
|
};
|
|
7999
8001
|
}
|
|
8000
|
-
/**
|
|
8001
|
-
|
|
8002
|
-
|
|
8003
|
-
|
|
8004
|
-
|
|
8005
|
-
|
|
8006
|
-
let timer;
|
|
8007
|
-
let running = Promise.resolve();
|
|
8008
|
-
const run = async () => {
|
|
8009
|
-
const cutoff = (/* @__PURE__ */ new Date(clock.now() - retentionDays * DAY_MS)).toISOString();
|
|
8010
|
-
await store.transaction(async (trx) => {
|
|
8011
|
-
await trx.deleteFrom("command").where("at", "<", cutoff).execute();
|
|
8012
|
-
});
|
|
8013
|
-
};
|
|
8014
|
-
return {
|
|
8015
|
-
async start() {
|
|
8016
|
-
await run();
|
|
8017
|
-
timer = setInterval(() => {
|
|
8018
|
-
running = run().catch(onError);
|
|
8019
|
-
}, DAY_MS);
|
|
8020
|
-
},
|
|
8021
|
-
async stop() {
|
|
8022
|
-
clearInterval(timer);
|
|
8023
|
-
await running;
|
|
8024
|
-
}
|
|
8025
|
-
};
|
|
8002
|
+
/** Deletes command keys older than `retentionDays`; a key exactly at the cutoff stays. */
|
|
8003
|
+
async function purgeExpiredCommands(store, clock, retentionDays) {
|
|
8004
|
+
const cutoff = (/* @__PURE__ */ new Date(clock.now() - retentionDays * DAY_MS$1)).toISOString();
|
|
8005
|
+
await store.transaction(async (trx) => {
|
|
8006
|
+
await trx.deleteFrom("command").where("at", "<", cutoff).execute();
|
|
8007
|
+
});
|
|
8026
8008
|
}
|
|
8027
8009
|
//#endregion
|
|
8028
8010
|
//#region ../core/src/app/queries.ts
|
|
@@ -8738,6 +8720,18 @@ async function expireToken(trx, row, at) {
|
|
|
8738
8720
|
await journalToken(trx, "token_expired", row.name, at);
|
|
8739
8721
|
await clearItem(trx, row.item_id, at);
|
|
8740
8722
|
}
|
|
8723
|
+
/**
|
|
8724
|
+
* Lapses the pending request whose approval item is `itemId` once it has expired at `at`. The
|
|
8725
|
+
* sender calls it before posting the approval line, so a late or failing sweep cannot post it.
|
|
8726
|
+
*/
|
|
8727
|
+
async function expireTokenOfItem(trx, itemId, at) {
|
|
8728
|
+
const row = await trx.selectFrom("operator_token").select([
|
|
8729
|
+
"id",
|
|
8730
|
+
"name",
|
|
8731
|
+
"item_id"
|
|
8732
|
+
]).where("item_id", "=", itemId).where("status", "=", "pending").where("expires_at", "<=", at.toISOString()).executeTakeFirst();
|
|
8733
|
+
if (row !== void 0) await expireToken(trx, row, at);
|
|
8734
|
+
}
|
|
8741
8735
|
/** Register a hash and its approval item together. The raw file secret never reaches this app. */
|
|
8742
8736
|
async function requestToken(store, config, input, at) {
|
|
8743
8737
|
if (!/^[0-9a-f]{64}$/.test(input.hash) || input.name.trim() === "" || input.folder.trim() === "") throw new CommandError("usage", "Provide a name, folder and SHA-256 token hash.");
|
|
@@ -9231,8 +9225,9 @@ async function restartNotification(trx, sourceKey, at) {
|
|
|
9231
9225
|
/**
|
|
9232
9226
|
* Ends a ring Spur will not take (a permanent rejection, or no answer for the retry window): its
|
|
9233
9227
|
* notification stops ringing, the operator gets an item and `doorbell_undelivered` is journalled.
|
|
9234
|
-
* The operator's Retry on the item restarts the series (`restartNotification`).
|
|
9235
|
-
*
|
|
9228
|
+
* The operator's Retry on the item restarts the series (`restartNotification`). A ring that is no
|
|
9229
|
+
* longer its notification's last row (the recipient changed while it was in flight) ends alone. An
|
|
9230
|
+
* inbound author ring has no notification: it ends like an author found unavailable at enqueue.
|
|
9236
9231
|
*/
|
|
9237
9232
|
async function ringUndelivered(trx, input) {
|
|
9238
9233
|
const { at, reason } = input;
|
|
@@ -9255,7 +9250,7 @@ async function ringUndelivered(trx, input) {
|
|
|
9255
9250
|
return;
|
|
9256
9251
|
}
|
|
9257
9252
|
const n = await trx.selectFrom("notification").selectAll().where("id", "=", input.notificationId).executeTakeFirst();
|
|
9258
|
-
if (n === void 0 || n.acked_at !== null || n.exhausted_at !== null) return;
|
|
9253
|
+
if (n === void 0 || n.acked_at !== null || n.exhausted_at !== null || n.last_outbox_id !== input.outboxId) return;
|
|
9259
9254
|
const task = await trx.selectFrom("task").selectAll().where("id", "=", n.task_id).executeTakeFirstOrThrow();
|
|
9260
9255
|
await trx.updateTable("notification").set({ exhausted_at: at.toISOString() }).where("id", "=", n.id).execute();
|
|
9261
9256
|
await raiseItem(trx, {
|
|
@@ -9272,9 +9267,21 @@ async function ringUndelivered(trx, input) {
|
|
|
9272
9267
|
reason
|
|
9273
9268
|
}, at);
|
|
9274
9269
|
}
|
|
9275
|
-
/**
|
|
9270
|
+
/** Notifications reconcile looks at: unacked, not exhausted, due, on a task not archived. */
|
|
9271
|
+
function dueNotifications(db, at) {
|
|
9272
|
+
return db.selectFrom("notification").innerJoin("task", "task.id", "notification.task_id").where("task.membership", "!=", "archived").where("notification.acked_at", "is", null).where("notification.exhausted_at", "is", null).where("notification.next_at", "<=", at.toISOString());
|
|
9273
|
+
}
|
|
9274
|
+
/**
|
|
9275
|
+
* Reconciles due notifications in their own transaction. With none due it opens no transaction;
|
|
9276
|
+
* a due notification waiting on a working recipient or an unsent ring still opens one.
|
|
9277
|
+
*/
|
|
9278
|
+
async function reconcileDueDoorbells(store, config, at) {
|
|
9279
|
+
if (await dueNotifications(store.db, at).select("notification.id").executeTakeFirst() === void 0) return;
|
|
9280
|
+
await scanTransaction(store, config, (trx) => reconcileDoorbells(trx, at, config));
|
|
9281
|
+
}
|
|
9282
|
+
/** Reconcile due semantic notifications in the caller's transaction. */
|
|
9276
9283
|
async function reconcileDoorbells(trx, at, config) {
|
|
9277
|
-
const due = await trx
|
|
9284
|
+
const due = await dueNotifications(trx, at).selectAll("notification").orderBy("notification.id").execute();
|
|
9278
9285
|
for (const n of due) {
|
|
9279
9286
|
const session = await selectNotificationRecipient(trx, n);
|
|
9280
9287
|
if (session === void 0) {
|
|
@@ -10302,7 +10309,6 @@ function createSender(options) {
|
|
|
10302
10309
|
async function claim(trx, at) {
|
|
10303
10310
|
const nowIso = new Date(at).toISOString();
|
|
10304
10311
|
await releaseOrphans(trx, nowIso);
|
|
10305
|
-
await reconcileDoorbells(trx, new Date(at), options.config);
|
|
10306
10312
|
const rows = await trx.selectFrom("outbox").selectAll().where("state", "in", ["pending", "post_failed"]).orderBy("id").execute();
|
|
10307
10313
|
const bodies = /* @__PURE__ */ new Map();
|
|
10308
10314
|
for (const row of rows) {
|
|
@@ -10396,11 +10402,15 @@ function createSender(options) {
|
|
|
10396
10402
|
* Stamps the start of a send, just before its IO: the row's retry window if none is open and,
|
|
10397
10403
|
* for a space, the slot of the next send and, under a health row, the probe clock. A slow
|
|
10398
10404
|
* earlier send in the tick does not age them. The clock is read here, once the write lock is
|
|
10399
|
-
* held, so waiting for the lock does not age them either. Returns the stamp.
|
|
10405
|
+
* held, so waiting for the lock does not age them either. Returns the stamp. `expiredAt` is
|
|
10406
|
+
* read once, on the first pass after the lock is held, and reused on replays: token expiry
|
|
10407
|
+
* writes it into a feed edit, a gateway string, so a fresh read per pass would change it on
|
|
10408
|
+
* every scan replay, and a read before the lock would miss a request that lapses meanwhile.
|
|
10400
10409
|
*/
|
|
10401
|
-
async function start(trx, c) {
|
|
10410
|
+
async function start(trx, c, expiredAt) {
|
|
10402
10411
|
const at = now().getTime();
|
|
10403
10412
|
const sentAtIso = new Date(at).toISOString();
|
|
10413
|
+
if (c.body.kind === "feed.line" && c.body.payload.itemId !== void 0) await expireTokenOfItem(trx, c.body.payload.itemId, expiredAt);
|
|
10404
10414
|
if (c.body.kind === "feed.line" && c.body.payload.itemId !== void 0 && !c.maybeSent) {
|
|
10405
10415
|
const item = await trx.selectFrom("operator_item").select("cleared_at").where("id", "=", c.body.payload.itemId).executeTakeFirst();
|
|
10406
10416
|
if (item !== void 0 && item.cleared_at !== null) {
|
|
@@ -10543,6 +10553,7 @@ function createSender(options) {
|
|
|
10543
10553
|
if (body.kind !== "doorbell") return;
|
|
10544
10554
|
await ringUndelivered(trx, {
|
|
10545
10555
|
notificationId: body.payload.notificationId,
|
|
10556
|
+
outboxId: c.id,
|
|
10546
10557
|
dedupeKey: c.key,
|
|
10547
10558
|
session: body.payload.session,
|
|
10548
10559
|
reason,
|
|
@@ -10669,7 +10680,8 @@ function createSender(options) {
|
|
|
10669
10680
|
})).where("id", "in", ids).where("state", "=", "in_flight").execute());
|
|
10670
10681
|
return;
|
|
10671
10682
|
}
|
|
10672
|
-
|
|
10683
|
+
let expiredAt;
|
|
10684
|
+
const started = await scanTransaction(store, options.config, (trx) => start(trx, c, expiredAt ??= now()));
|
|
10673
10685
|
if (started.skip) continue;
|
|
10674
10686
|
const { outcome, error } = await attempt(c, started.firstDeliveryAt);
|
|
10675
10687
|
const at = now().getTime();
|
|
@@ -12466,10 +12478,23 @@ function createObservationCore(deps) {
|
|
|
12466
12478
|
};
|
|
12467
12479
|
}
|
|
12468
12480
|
//#endregion
|
|
12469
|
-
//#region ../core/src/
|
|
12470
|
-
|
|
12481
|
+
//#region ../core/src/domain/slot.ts
|
|
12482
|
+
const WEEKDAYS = [
|
|
12483
|
+
"sunday",
|
|
12484
|
+
"monday",
|
|
12485
|
+
"tuesday",
|
|
12486
|
+
"wednesday",
|
|
12487
|
+
"thursday",
|
|
12488
|
+
"friday",
|
|
12489
|
+
"saturday"
|
|
12490
|
+
];
|
|
12491
|
+
/**
|
|
12492
|
+
* The UTC instant of local midnight on the latest `weekday` at or before `now` in `tz`.
|
|
12493
|
+
* A day that starts at `now` counts as today.
|
|
12494
|
+
*/
|
|
12495
|
+
function lastLocalSlot(now, tz, weekday) {
|
|
12471
12496
|
const formatter = new Intl.DateTimeFormat("en-US", {
|
|
12472
|
-
timeZone:
|
|
12497
|
+
timeZone: tz,
|
|
12473
12498
|
year: "numeric",
|
|
12474
12499
|
month: "2-digit",
|
|
12475
12500
|
day: "2-digit"
|
|
@@ -12484,15 +12509,7 @@ function lastArchiveSlot(now, config) {
|
|
|
12484
12509
|
};
|
|
12485
12510
|
const [year = 0, month = 0, day = 0] = localDate(now).split("-").map(Number);
|
|
12486
12511
|
const localMidnight = Date.UTC(year, month - 1, day);
|
|
12487
|
-
const targetUtcDate = localMidnight - (new Date(localMidnight).getUTCDay() -
|
|
12488
|
-
"sunday",
|
|
12489
|
-
"monday",
|
|
12490
|
-
"tuesday",
|
|
12491
|
-
"wednesday",
|
|
12492
|
-
"thursday",
|
|
12493
|
-
"friday",
|
|
12494
|
-
"saturday"
|
|
12495
|
-
].indexOf(config.archive.doneWeekday) + 7) % 7 * 864e5;
|
|
12512
|
+
const targetUtcDate = localMidnight - (new Date(localMidnight).getUTCDay() - WEEKDAYS.indexOf(weekday) + 7) % 7 * 864e5;
|
|
12496
12513
|
const targetDate = new Date(targetUtcDate).toISOString().slice(0, 10);
|
|
12497
12514
|
let lower = targetUtcDate - 2 * 864e5;
|
|
12498
12515
|
let upper = targetUtcDate + 2 * 864e5;
|
|
@@ -12503,12 +12520,14 @@ function lastArchiveSlot(now, config) {
|
|
|
12503
12520
|
}
|
|
12504
12521
|
return lower;
|
|
12505
12522
|
}
|
|
12523
|
+
//#endregion
|
|
12524
|
+
//#region ../core/src/app/tick.ts
|
|
12506
12525
|
/** One board tick, including an archive slot missed during downtime. */
|
|
12507
12526
|
async function tickBoard(deps) {
|
|
12508
12527
|
const { store, config, clock, completeSince } = deps;
|
|
12509
12528
|
const now = clock.now();
|
|
12510
12529
|
const at = new Date(now).toISOString();
|
|
12511
|
-
const slot = new Date(
|
|
12530
|
+
const slot = new Date(lastLocalSlot(now, config.digest.tz, config.archive.doneWeekday)).toISOString();
|
|
12512
12531
|
await scanTransaction(store, config, async (trx) => {
|
|
12513
12532
|
const sourceStates = await trx.selectFrom("source_state").select(["source", "blind_reason"]).execute();
|
|
12514
12533
|
const blind = new Set(sourceStates.filter((source) => source.blind_reason !== null).map((source) => source.source));
|
|
@@ -13742,9 +13761,11 @@ function pageQuery(connection, bootstrap = false) {
|
|
|
13742
13761
|
}
|
|
13743
13762
|
var GithubClient = class {
|
|
13744
13763
|
token;
|
|
13764
|
+
now;
|
|
13745
13765
|
fetcher;
|
|
13746
|
-
constructor(token, fetcher = fetch) {
|
|
13766
|
+
constructor(token, now, fetcher = fetch) {
|
|
13747
13767
|
this.token = token;
|
|
13768
|
+
this.now = now;
|
|
13748
13769
|
this.fetcher = fetcher;
|
|
13749
13770
|
}
|
|
13750
13771
|
async query(query, variables, signal) {
|
|
@@ -13771,7 +13792,7 @@ var GithubClient = class {
|
|
|
13771
13792
|
status: response.status,
|
|
13772
13793
|
headers: response.headers,
|
|
13773
13794
|
body: await response.text()
|
|
13774
|
-
},
|
|
13795
|
+
}, this.now());
|
|
13775
13796
|
let body;
|
|
13776
13797
|
try {
|
|
13777
13798
|
body = await response.json();
|
|
@@ -13783,7 +13804,7 @@ var GithubClient = class {
|
|
|
13783
13804
|
if (errors.some((error) => error.type === "RATE_LIMITED" || /rate limit/i.test(error.message))) throw classifyHttpFailure({
|
|
13784
13805
|
status: 429,
|
|
13785
13806
|
headers: response.headers
|
|
13786
|
-
},
|
|
13807
|
+
}, this.now());
|
|
13787
13808
|
if (errors.some((error) => teamScopeDenied(error, query))) throw new AdapterError("auth", "GitHub token needs read:org for team review requests");
|
|
13788
13809
|
if (errors.some((error) => error.type === "INSUFFICIENT_SCOPES")) throw new AdapterError("auth", "GitHub token lacks a required GraphQL read scope");
|
|
13789
13810
|
const data = parseWire(dataWire, wire.data, MALFORMED$3, ["data"]);
|
|
@@ -14170,7 +14191,7 @@ function githubSources(config, options) {
|
|
|
14170
14191
|
if (seen.has(normalized)) throw new AdapterError("config", "Duplicate GitHub repository in project");
|
|
14171
14192
|
seen.add(normalized);
|
|
14172
14193
|
const id = sourceId(project.id, repo);
|
|
14173
|
-
const client = new GithubClient(options.token, options.fetch);
|
|
14194
|
+
const client = new GithubClient(options.token, options.now, options.fetch);
|
|
14174
14195
|
const keys = projectKeyRule(project.tracker, project.link, repo);
|
|
14175
14196
|
sources.push({
|
|
14176
14197
|
repo,
|
|
@@ -14184,6 +14205,7 @@ function githubSources(config, options) {
|
|
|
14184
14205
|
login: project.operatorGithubLogin,
|
|
14185
14206
|
keys,
|
|
14186
14207
|
client,
|
|
14208
|
+
now: options.now,
|
|
14187
14209
|
ctx
|
|
14188
14210
|
})
|
|
14189
14211
|
}
|
|
@@ -14291,8 +14313,8 @@ async function fullPr(client, first, owner, name, number, signal, budget) {
|
|
|
14291
14313
|
pr
|
|
14292
14314
|
};
|
|
14293
14315
|
}
|
|
14294
|
-
async function pollRepository({ id, repo, login, keys, client, ctx }) {
|
|
14295
|
-
const observedAt = sourceCursorSchema.parse(
|
|
14316
|
+
async function pollRepository({ id, repo, login, keys, client, now, ctx }) {
|
|
14317
|
+
const observedAt = sourceCursorSchema.parse(new Date(now()).toISOString());
|
|
14296
14318
|
const bootstrap = ctx.cursor === void 0;
|
|
14297
14319
|
const [owner, name] = repo.split("/");
|
|
14298
14320
|
if (!owner || !name) throw new AdapterError("config", "Invalid repository");
|
|
@@ -14516,7 +14538,7 @@ function createGithubIssuesAdapter(options) {
|
|
|
14516
14538
|
status: response.status,
|
|
14517
14539
|
headers: response.headers,
|
|
14518
14540
|
body: await response.text()
|
|
14519
|
-
},
|
|
14541
|
+
}, options.now());
|
|
14520
14542
|
throw new GithubIssuesHttpError(response.status, failure);
|
|
14521
14543
|
}
|
|
14522
14544
|
let value;
|
|
@@ -14603,7 +14625,7 @@ function createGithubIssuesAdapter(options) {
|
|
|
14603
14625
|
id: options.id,
|
|
14604
14626
|
intervalMs: options.intervalMs,
|
|
14605
14627
|
async poll(ctx) {
|
|
14606
|
-
const observedAt =
|
|
14628
|
+
const observedAt = new Date(options.now()).toISOString();
|
|
14607
14629
|
const milestone = await milestoneNumber(ctx.signal);
|
|
14608
14630
|
const filter = new URL(`${root}/issues`);
|
|
14609
14631
|
filter.searchParams.set("state", "open");
|
|
@@ -14804,7 +14826,7 @@ function createJiraAdapter(options) {
|
|
|
14804
14826
|
if (!response.ok) throw new JiraHttpError(response.status, classifyHttpFailure({
|
|
14805
14827
|
status: response.status,
|
|
14806
14828
|
headers: response.headers
|
|
14807
|
-
},
|
|
14829
|
+
}, options.now()));
|
|
14808
14830
|
try {
|
|
14809
14831
|
return await response.json();
|
|
14810
14832
|
} catch {
|
|
@@ -14924,7 +14946,7 @@ function createJiraAdapter(options) {
|
|
|
14924
14946
|
if (fallbackRequests >= FALLBACK_REQUEST_LIMIT) throw new AdapterError("transient", "Jira key lookup fallback request limit reached");
|
|
14925
14947
|
fallbackRequests += 1;
|
|
14926
14948
|
};
|
|
14927
|
-
const observedAt =
|
|
14949
|
+
const observedAt = new Date(options.now()).toISOString();
|
|
14928
14950
|
const tracker = options.tracker();
|
|
14929
14951
|
await validate(tracker, ctx.signal);
|
|
14930
14952
|
const sprintField = await findSprintField(tracker, ctx.signal);
|
|
@@ -15107,7 +15129,7 @@ function applyEntityOutcomes(input) {
|
|
|
15107
15129
|
//#endregion
|
|
15108
15130
|
//#region ../adapters/src/runner/runner.ts
|
|
15109
15131
|
function startRunner(options) {
|
|
15110
|
-
const startedAt =
|
|
15132
|
+
const startedAt = options.now();
|
|
15111
15133
|
const sources = options.entries.map((entry) => runSource(entry, options, startedAt));
|
|
15112
15134
|
return {
|
|
15113
15135
|
firstAttempts: Promise.all(sources.map(async (source) => ({
|
|
@@ -15122,7 +15144,7 @@ function startRunner(options) {
|
|
|
15122
15144
|
function runSource(entry, options, runnerStartMs) {
|
|
15123
15145
|
const { adapter, reserveRemaining } = entry;
|
|
15124
15146
|
const { core, config } = options;
|
|
15125
|
-
const now = options
|
|
15147
|
+
const { now } = options;
|
|
15126
15148
|
const source = adapter.id;
|
|
15127
15149
|
const { intervalMs } = adapter;
|
|
15128
15150
|
const { staleMultiplier } = config.thresholds;
|
|
@@ -15479,12 +15501,12 @@ function createSpurAdapter(options) {
|
|
|
15479
15501
|
id: "spur",
|
|
15480
15502
|
intervalMs: options.intervalMs,
|
|
15481
15503
|
async poll(ctx) {
|
|
15482
|
-
const observedAt =
|
|
15504
|
+
const observedAt = new Date(options.now()).toISOString();
|
|
15483
15505
|
const { response: listResponse, body: listBody } = await request("sessions", ctx.signal);
|
|
15484
15506
|
if (!listResponse.ok) throw classifyHttpFailure({
|
|
15485
15507
|
status: listResponse.status,
|
|
15486
15508
|
headers: listResponse.headers
|
|
15487
|
-
},
|
|
15509
|
+
}, options.now());
|
|
15488
15510
|
const listed = parseWire(z.array(sessionWire), listBody, "Invalid Spur response");
|
|
15489
15511
|
const byId = new Map(listed.map((wire) => [wire.id, wire]));
|
|
15490
15512
|
const detail = /* @__PURE__ */ new Map();
|
|
@@ -15498,7 +15520,7 @@ function createSpurAdapter(options) {
|
|
|
15498
15520
|
if (!response.ok) throw classifyHttpFailure({
|
|
15499
15521
|
status: response.status,
|
|
15500
15522
|
headers: response.headers
|
|
15501
|
-
},
|
|
15523
|
+
}, options.now());
|
|
15502
15524
|
const wire = parseWire(sessionWire, body, "Invalid Spur response");
|
|
15503
15525
|
if (wire.id !== ref.id) throw new AdapterError("transient", "Unresolved Spur session detail");
|
|
15504
15526
|
detail.set(ref.id, wire);
|
|
@@ -15591,12 +15613,12 @@ function sampleQuery(closing) {
|
|
|
15591
15613
|
* reference is dropped, as the poller does; any other GraphQL error rejects with a transient
|
|
15592
15614
|
* `AdapterError`.
|
|
15593
15615
|
*/
|
|
15594
|
-
async function sampleLinkRules({ repo, login, tracker, link }, { token, fetch: fetcher, signal }) {
|
|
15616
|
+
async function sampleLinkRules({ repo, login, tracker, link }, { token, now, fetch: fetcher, signal }) {
|
|
15595
15617
|
const [owner, name] = repo.split("/");
|
|
15596
15618
|
if (!owner || !name) throw new AdapterError("config", "Invalid repository");
|
|
15597
15619
|
const rule = projectKeyRule(tracker, link, repo);
|
|
15598
15620
|
const closing = rule.type === "issues" && rule.sources.includes("closing");
|
|
15599
|
-
const response = await new GithubClient(token, fetcher).query(sampleQuery(closing), {
|
|
15621
|
+
const response = await new GithubClient(token, now, fetcher).query(sampleQuery(closing), {
|
|
15600
15622
|
owner,
|
|
15601
15623
|
repo: name
|
|
15602
15624
|
}, signal);
|
|
@@ -15622,7 +15644,7 @@ function blindSource(id, intervalMs, message) {
|
|
|
15622
15644
|
};
|
|
15623
15645
|
}
|
|
15624
15646
|
/** Starts polling each configured source. */
|
|
15625
|
-
function startAdapters(config, core, options
|
|
15647
|
+
function startAdapters(config, core, options) {
|
|
15626
15648
|
const secrets = options.secrets ?? {};
|
|
15627
15649
|
const githubToken = secrets["GITHUB_TOKEN"];
|
|
15628
15650
|
const entries = [];
|
|
@@ -15638,6 +15660,7 @@ function startAdapters(config, core, options = {}) {
|
|
|
15638
15660
|
email,
|
|
15639
15661
|
token
|
|
15640
15662
|
},
|
|
15663
|
+
now: options.now,
|
|
15641
15664
|
intervalMs: config.adapters.jira.intervalMs,
|
|
15642
15665
|
...options.fetch === void 0 ? {} : { fetch: options.fetch },
|
|
15643
15666
|
warn: options.warn ?? (() => void 0),
|
|
@@ -15649,12 +15672,14 @@ function startAdapters(config, core, options = {}) {
|
|
|
15649
15672
|
id,
|
|
15650
15673
|
tracker: project.tracker,
|
|
15651
15674
|
token: githubToken,
|
|
15675
|
+
now: options.now,
|
|
15652
15676
|
intervalMs: config.adapters.github.intervalMs,
|
|
15653
15677
|
...options.fetch === void 0 ? {} : { fetch: options.fetch }
|
|
15654
15678
|
}) : blindSource(id, config.adapters.github.intervalMs, "GitHub credential is missing") });
|
|
15655
15679
|
}
|
|
15656
15680
|
if (githubToken) entries.push(...githubSources(config, {
|
|
15657
15681
|
token: githubToken,
|
|
15682
|
+
now: options.now,
|
|
15658
15683
|
...options.fetch === void 0 ? {} : { fetch: options.fetch }
|
|
15659
15684
|
}).map(({ adapter, reserveRemaining, repo }) => ({
|
|
15660
15685
|
adapter,
|
|
@@ -15668,6 +15693,7 @@ function startAdapters(config, core, options = {}) {
|
|
|
15668
15693
|
baseUrl: config.adapters.spur.baseUrl,
|
|
15669
15694
|
intervalMs: config.adapters.spur.intervalMs,
|
|
15670
15695
|
flipSmoothingMs: config.health.flipSmoothingMs,
|
|
15696
|
+
now: options.now,
|
|
15671
15697
|
...options.fetch === void 0 ? {} : { fetch: options.fetch },
|
|
15672
15698
|
onNotice: (notice) => {
|
|
15673
15699
|
const pending = Promise.resolve().then(() => options.onSpurNotice?.(notice));
|
|
@@ -15678,7 +15704,7 @@ function startAdapters(config, core, options = {}) {
|
|
|
15678
15704
|
}) }],
|
|
15679
15705
|
core,
|
|
15680
15706
|
config,
|
|
15681
|
-
|
|
15707
|
+
now: options.now,
|
|
15682
15708
|
...options.oneShot === void 0 ? {} : { oneShot: options.oneShot },
|
|
15683
15709
|
onFailure: options.onPollFailure
|
|
15684
15710
|
});
|
|
@@ -16469,9 +16495,19 @@ function record(value) {
|
|
|
16469
16495
|
function string(value) {
|
|
16470
16496
|
return typeof value === "string" ? value : void 0;
|
|
16471
16497
|
}
|
|
16498
|
+
/** Milliseconds of a Slack ts, read from its digits so float error cannot shift the millisecond. */
|
|
16499
|
+
function tsMillis(ts) {
|
|
16500
|
+
const [seconds = "", fraction = ""] = ts.split(".");
|
|
16501
|
+
if (!/^\d+$/.test(seconds) || !/^\d*$/.test(fraction)) return NaN;
|
|
16502
|
+
return Number(seconds) * 1e3 + Number(fraction.padEnd(3, "0").slice(0, 3));
|
|
16503
|
+
}
|
|
16504
|
+
/**
|
|
16505
|
+
* The bounds are clock readings in whole milliseconds, so a message counts by its millisecond:
|
|
16506
|
+
* one posted later within the millisecond `until` was read in is still inside the window.
|
|
16507
|
+
*/
|
|
16472
16508
|
function inInterval(ts, from, until) {
|
|
16473
16509
|
if (ts === void 0) return false;
|
|
16474
|
-
const at =
|
|
16510
|
+
const at = tsMillis(ts);
|
|
16475
16511
|
return Number.isFinite(at) && at >= from && at <= until;
|
|
16476
16512
|
}
|
|
16477
16513
|
async function readThread(client, channel, threadTs) {
|
|
@@ -16494,8 +16530,8 @@ function gap(conversation) {
|
|
|
16494
16530
|
};
|
|
16495
16531
|
}
|
|
16496
16532
|
/** A scan is driven solely by its request; the core owns cursors and deduplication. */
|
|
16497
|
-
async function* recoverThreads(client, request, botIdentity) {
|
|
16498
|
-
const until =
|
|
16533
|
+
async function* recoverThreads(client, request, botIdentity, now) {
|
|
16534
|
+
const until = now();
|
|
16499
16535
|
const from = request.since.getTime();
|
|
16500
16536
|
if (!Number.isFinite(from) || from > until) return;
|
|
16501
16537
|
const bot = await botIdentity();
|
|
@@ -16694,7 +16730,7 @@ function createSlackGateway(config) {
|
|
|
16694
16730
|
return {
|
|
16695
16731
|
...delivery,
|
|
16696
16732
|
...socket,
|
|
16697
|
-
recover: (request) => recoverThreads(api, request, botIdentity),
|
|
16733
|
+
recover: (request) => recoverThreads(api, request, botIdentity, config.now),
|
|
16698
16734
|
async respond(interaction, text, options) {
|
|
16699
16735
|
const addressed = parseInteractionRef(interaction);
|
|
16700
16736
|
const rendered = renderResponse(text, options.cliHint);
|
|
@@ -16721,6 +16757,62 @@ function createSlackGateway(config) {
|
|
|
16721
16757
|
};
|
|
16722
16758
|
}
|
|
16723
16759
|
//#endregion
|
|
16760
|
+
//#region ../daemon/src/scheduler.ts
|
|
16761
|
+
/**
|
|
16762
|
+
* One recurring job: a `setTimeout` chain armed `intervalMs` plus under `jitterMs` after each
|
|
16763
|
+
* timer run settles. Runs never overlap; `trigger` queues behind the active run. A failed run goes
|
|
16764
|
+
* to `onError`, except a failed `first: 'await'` run, which rejects `start` and arms no timer. A
|
|
16765
|
+
* failing `onError` is dropped, so the chain keeps running.
|
|
16766
|
+
* `stop` clears the timer and awaits the active run; after it, and once the start signal aborts,
|
|
16767
|
+
* nothing new runs. Uses the global timers so `vi.useFakeTimers` controls it.
|
|
16768
|
+
*/
|
|
16769
|
+
function createJob(options) {
|
|
16770
|
+
const { run, intervalMs, jitterMs = 0, first = "background", onError } = options;
|
|
16771
|
+
let timer;
|
|
16772
|
+
let active = Promise.resolve();
|
|
16773
|
+
let stopped = false;
|
|
16774
|
+
let signal;
|
|
16775
|
+
const idle = () => stopped || signal === void 0 || signal.aborted;
|
|
16776
|
+
const enqueue = () => {
|
|
16777
|
+
if (idle()) return active;
|
|
16778
|
+
active = active.then(async () => {
|
|
16779
|
+
if (signal !== void 0 && !idle()) await run(signal);
|
|
16780
|
+
}).catch(async (err) => {
|
|
16781
|
+
await onError(err);
|
|
16782
|
+
}).catch(() => void 0);
|
|
16783
|
+
return active;
|
|
16784
|
+
};
|
|
16785
|
+
const schedule = () => {
|
|
16786
|
+
if (idle()) return;
|
|
16787
|
+
const delay = intervalMs + Math.floor(Math.random() * jitterMs);
|
|
16788
|
+
timer = setTimeout(() => {
|
|
16789
|
+
timer = void 0;
|
|
16790
|
+
enqueue().then(schedule);
|
|
16791
|
+
}, delay);
|
|
16792
|
+
};
|
|
16793
|
+
return {
|
|
16794
|
+
async start(startSignal) {
|
|
16795
|
+
signal = startSignal;
|
|
16796
|
+
if (first === "background") {
|
|
16797
|
+
enqueue().then(schedule);
|
|
16798
|
+
return;
|
|
16799
|
+
}
|
|
16800
|
+
if (idle()) return;
|
|
16801
|
+
const firstRun = run(startSignal);
|
|
16802
|
+
active = firstRun.then(() => void 0, () => void 0);
|
|
16803
|
+
await firstRun;
|
|
16804
|
+
schedule();
|
|
16805
|
+
},
|
|
16806
|
+
async stop() {
|
|
16807
|
+
stopped = true;
|
|
16808
|
+
clearTimeout(timer);
|
|
16809
|
+
await active;
|
|
16810
|
+
},
|
|
16811
|
+
trigger: enqueue,
|
|
16812
|
+
settled: () => active
|
|
16813
|
+
};
|
|
16814
|
+
}
|
|
16815
|
+
//#endregion
|
|
16724
16816
|
//#region ../daemon/src/board-modules.ts
|
|
16725
16817
|
/** Compose the board's timer and adapter runner without adding lifecycle state to main. */
|
|
16726
16818
|
function createBoardModules(ctxFor, options = {}) {
|
|
@@ -16731,45 +16823,27 @@ function createBoardModules(ctxFor, options = {}) {
|
|
|
16731
16823
|
config: coreCtx.config,
|
|
16732
16824
|
clock: coreCtx.clock
|
|
16733
16825
|
});
|
|
16734
|
-
let timer;
|
|
16735
|
-
let active = Promise.resolve();
|
|
16736
|
-
let stopped = false;
|
|
16737
|
-
let signal;
|
|
16738
16826
|
const tick = options.tick ?? tickBoard;
|
|
16739
|
-
const
|
|
16740
|
-
|
|
16741
|
-
|
|
16742
|
-
|
|
16743
|
-
|
|
16744
|
-
|
|
16745
|
-
|
|
16746
|
-
|
|
16747
|
-
|
|
16748
|
-
|
|
16749
|
-
|
|
16750
|
-
|
|
16751
|
-
clock: coreCtx.clock,
|
|
16752
|
-
completeSince: core.completeSince
|
|
16753
|
-
})).then(() => options.onTick?.()).catch((err) => {
|
|
16827
|
+
const boardCore = createJob({
|
|
16828
|
+
run: async () => {
|
|
16829
|
+
await tick({
|
|
16830
|
+
store: coreCtx.store,
|
|
16831
|
+
config: coreCtx.config,
|
|
16832
|
+
clock: coreCtx.clock,
|
|
16833
|
+
completeSince: core.completeSince
|
|
16834
|
+
});
|
|
16835
|
+
options.onTick?.();
|
|
16836
|
+
},
|
|
16837
|
+
intervalMs: BOARD_TICK_MS,
|
|
16838
|
+
onError: (err) => {
|
|
16754
16839
|
coreCtx.log.error({ err }, "board tick failed");
|
|
16755
|
-
}
|
|
16756
|
-
};
|
|
16840
|
+
}
|
|
16841
|
+
});
|
|
16757
16842
|
let runner;
|
|
16758
16843
|
return [{
|
|
16759
16844
|
name: "board-core",
|
|
16760
16845
|
stopStage: "final",
|
|
16761
|
-
module:
|
|
16762
|
-
start(startSignal) {
|
|
16763
|
-
signal = startSignal;
|
|
16764
|
-
runTick();
|
|
16765
|
-
return Promise.resolve();
|
|
16766
|
-
},
|
|
16767
|
-
async stop() {
|
|
16768
|
-
stopped = true;
|
|
16769
|
-
if (timer !== void 0) clearTimeout(timer);
|
|
16770
|
-
await active;
|
|
16771
|
-
}
|
|
16772
|
-
}
|
|
16846
|
+
module: boardCore
|
|
16773
16847
|
}, {
|
|
16774
16848
|
name: "board-adapters",
|
|
16775
16849
|
stopStage: "pollers",
|
|
@@ -16864,7 +16938,7 @@ function createSpurPort(options) {
|
|
|
16864
16938
|
}
|
|
16865
16939
|
//#endregion
|
|
16866
16940
|
//#region ../daemon/src/doctor.ts
|
|
16867
|
-
const
|
|
16941
|
+
const DEADLINE_MS = 5e3;
|
|
16868
16942
|
const SPUR_PROBE_SESSION = "spur-board-doctor-probe";
|
|
16869
16943
|
const SPUR_SEND_UNREACHABLE_FIX = "Start Spur or correct adapters.spur.baseUrl in config.yaml, then restart the service; the daemon sends doorbells to that Spur API.";
|
|
16870
16944
|
const SPUR_SEND_FIX = "The Spur API at adapters.spur.baseUrl did not accept a doorbell send; update Spur or point adapters.spur.baseUrl at the Spur daemon.";
|
|
@@ -16901,11 +16975,11 @@ function scopedGithubError(value) {
|
|
|
16901
16975
|
if (error?.["type"] === "INSUFFICIENT_SCOPES" && fields.includes("reviewRequests") && fields.includes("requestedReviewer") && fields.includes("slug")) return GITHUB_TEAMS_FIX;
|
|
16902
16976
|
return null;
|
|
16903
16977
|
}
|
|
16904
|
-
async function deadlineCall(ctx, name, failure, call) {
|
|
16978
|
+
async function deadlineCall(ctx, deadlineMs, name, failure, call) {
|
|
16905
16979
|
const controller = new AbortController();
|
|
16906
16980
|
const deadline = setTimeout(() => {
|
|
16907
16981
|
controller.abort();
|
|
16908
|
-
},
|
|
16982
|
+
}, deadlineMs);
|
|
16909
16983
|
const aborted = new Promise((_resolve, reject) => {
|
|
16910
16984
|
controller.signal.addEventListener("abort", () => {
|
|
16911
16985
|
reject(/* @__PURE__ */ new Error(`${failure}: timed out`));
|
|
@@ -16925,10 +16999,10 @@ async function deadlineCall(ctx, name, failure, call) {
|
|
|
16925
16999
|
clearTimeout(deadline);
|
|
16926
17000
|
}
|
|
16927
17001
|
}
|
|
16928
|
-
async function githubGraphql(ctx, fetcher, token, repo) {
|
|
17002
|
+
async function githubGraphql(ctx, fetcher, deadlineMs, token, repo) {
|
|
16929
17003
|
const [owner, name] = repo.split("/");
|
|
16930
17004
|
if (!owner || !name) return null;
|
|
16931
|
-
return deadlineCall(ctx, "doctor.github", "GitHub doctor probe failed", async (signal) => {
|
|
17005
|
+
return deadlineCall(ctx, deadlineMs, "doctor.github", "GitHub doctor probe failed", async (signal) => {
|
|
16932
17006
|
const response = await fetcher("https://api.github.com/graphql", {
|
|
16933
17007
|
method: "POST",
|
|
16934
17008
|
headers: {
|
|
@@ -16956,19 +17030,20 @@ const BRANCH_MAX = 40;
|
|
|
16956
17030
|
const NAMED_PRS = 3;
|
|
16957
17031
|
const LINK_RULES_TAIL = "Change projects[].link to the repo's branch and PR title rules.";
|
|
16958
17032
|
const LINK_RULES_TOKEN_FIX = "Add GITHUB_TOKEN to secrets.env, then rerun board doctor to compare projects[].link with recent PRs.";
|
|
16959
|
-
function sampleProject(ctx, fetcher, token, project, repo) {
|
|
16960
|
-
return deadlineCall(ctx, "doctor.link_rules", "GitHub link sample failed", (signal) => sampleLinkRules({
|
|
17033
|
+
function sampleProject(ctx, fetcher, deadlineMs, token, project, repo) {
|
|
17034
|
+
return deadlineCall(ctx, deadlineMs, "doctor.link_rules", "GitHub link sample failed", (signal) => sampleLinkRules({
|
|
16961
17035
|
repo,
|
|
16962
17036
|
login: project.operatorGithubLogin,
|
|
16963
17037
|
tracker: project.tracker,
|
|
16964
17038
|
link: project.link
|
|
16965
17039
|
}, {
|
|
16966
17040
|
token,
|
|
17041
|
+
now: () => ctx.clock.now(),
|
|
16967
17042
|
fetch: fetcher,
|
|
16968
17043
|
signal
|
|
16969
17044
|
}));
|
|
16970
17045
|
}
|
|
16971
|
-
function sampleLinks(ctx, fetcher, token) {
|
|
17046
|
+
function sampleLinks(ctx, fetcher, deadlineMs, token) {
|
|
16972
17047
|
const projects = ctx.config.projects.flatMap((project) => project.tracker.type === "github-issues" ? [{
|
|
16973
17048
|
project,
|
|
16974
17049
|
repo: project.tracker.repo
|
|
@@ -16983,7 +17058,7 @@ function sampleLinks(ctx, fetcher, token) {
|
|
|
16983
17058
|
project,
|
|
16984
17059
|
repo,
|
|
16985
17060
|
polled,
|
|
16986
|
-
sample: await sampleProject(ctx, fetcher, token, project, repo)
|
|
17061
|
+
sample: await sampleProject(ctx, fetcher, deadlineMs, token, project, repo)
|
|
16987
17062
|
} : {
|
|
16988
17063
|
project,
|
|
16989
17064
|
repo,
|
|
@@ -17060,11 +17135,11 @@ function warning(id, fix) {
|
|
|
17060
17135
|
fix
|
|
17061
17136
|
};
|
|
17062
17137
|
}
|
|
17063
|
-
async function request(ctx, fetcher, id, url, init = {}) {
|
|
17138
|
+
async function request(ctx, fetcher, deadlineMs, id, url, init = {}) {
|
|
17064
17139
|
try {
|
|
17065
17140
|
return await ctx.logCall(`doctor.${id}`, () => fetcher(url, {
|
|
17066
17141
|
...init,
|
|
17067
|
-
signal: AbortSignal.timeout(
|
|
17142
|
+
signal: AbortSignal.timeout(deadlineMs)
|
|
17068
17143
|
}));
|
|
17069
17144
|
} catch {
|
|
17070
17145
|
return null;
|
|
@@ -17091,12 +17166,12 @@ async function slackMember(response) {
|
|
|
17091
17166
|
}
|
|
17092
17167
|
}
|
|
17093
17168
|
/** Bounded daemon-side checks; no response body or exception text leaves this module. */
|
|
17094
|
-
async function runDaemonDoctor(ctx, productVersion, fetcher = fetch) {
|
|
17169
|
+
async function runDaemonDoctor(ctx, productVersion, fetcher = fetch, { deadlineMs = DEADLINE_MS } = {}) {
|
|
17095
17170
|
const { config, secrets } = ctx;
|
|
17096
17171
|
const checks = [];
|
|
17097
17172
|
const jiraTrackers = config.projects.flatMap((project) => project.tracker.type === "jira" ? [project.tracker] : []);
|
|
17098
17173
|
const slackConfigured = Boolean(config.slack.channels.feed || config.slack.channels.orchestrators);
|
|
17099
|
-
const linkSamples = sampleLinks(ctx, fetcher, secrets["GITHUB_TOKEN"]);
|
|
17174
|
+
const linkSamples = sampleLinks(ctx, fetcher, deadlineMs, secrets["GITHUB_TOKEN"]);
|
|
17100
17175
|
const missing = requiredSecretKeys(config).filter((name) => !secrets[name]);
|
|
17101
17176
|
checks.push(check("secrets", missing.length === 0, `Add ${missing.join(", ")} to the private secrets.env file.`));
|
|
17102
17177
|
const jiraEmail = secrets["JIRA_EMAIL"];
|
|
@@ -17105,7 +17180,7 @@ async function runDaemonDoctor(ctx, productVersion, fetcher = fetch) {
|
|
|
17105
17180
|
if (jiraTrackers.length > 0 && jiraEmail && jiraToken) {
|
|
17106
17181
|
const credentials = Buffer.from(`${jiraEmail}:${jiraToken}`).toString("base64");
|
|
17107
17182
|
jiraOk = (await Promise.all(jiraTrackers.map(async (tracker) => {
|
|
17108
|
-
return (await request(ctx, fetcher, "jira", new URL("/rest/api/3/myself", tracker.baseUrl), { headers: {
|
|
17183
|
+
return (await request(ctx, fetcher, deadlineMs, "jira", new URL("/rest/api/3/myself", tracker.baseUrl), { headers: {
|
|
17109
17184
|
Authorization: `Basic ${credentials}`,
|
|
17110
17185
|
Accept: "application/json"
|
|
17111
17186
|
} }))?.ok === true;
|
|
@@ -17115,12 +17190,12 @@ async function runDaemonDoctor(ctx, productVersion, fetcher = fetch) {
|
|
|
17115
17190
|
const githubToken = secrets["GITHUB_TOKEN"];
|
|
17116
17191
|
const githubRepos = new Set(config.projects.flatMap((project) => project.repos));
|
|
17117
17192
|
const githubFailure = (githubToken === void 0 ? [GITHUB_FIX] : await Promise.all([...githubRepos].map(async (repo) => {
|
|
17118
|
-
const response = await request(ctx, fetcher, "github", `https://api.github.com/repos/${repo}`, { headers: {
|
|
17193
|
+
const response = await request(ctx, fetcher, deadlineMs, "github", `https://api.github.com/repos/${repo}`, { headers: {
|
|
17119
17194
|
Authorization: `Bearer ${githubToken}`,
|
|
17120
17195
|
Accept: "application/vnd.github+json"
|
|
17121
17196
|
} });
|
|
17122
17197
|
if (response?.ok !== true) return GITHUB_FIX;
|
|
17123
|
-
const probe = await githubGraphql(ctx, fetcher, githubToken, repo);
|
|
17198
|
+
const probe = await githubGraphql(ctx, fetcher, deadlineMs, githubToken, repo);
|
|
17124
17199
|
if (probe?.response.ok !== true) return GITHUB_FIX;
|
|
17125
17200
|
const payload = object(probe.body);
|
|
17126
17201
|
const errors = payload?.["errors"];
|
|
@@ -17139,7 +17214,7 @@ async function runDaemonDoctor(ctx, productVersion, fetcher = fetch) {
|
|
|
17139
17214
|
checks.push(check("github.credentials", githubFailure === null, githubFailure ?? GITHUB_FIX));
|
|
17140
17215
|
checks.push(linkRulesCheck(await linkSamples));
|
|
17141
17216
|
const probe = spurSendRequest(config.adapters.spur.baseUrl, SPUR_PROBE_SESSION, "spur-board doctor probe");
|
|
17142
|
-
const [spur, spurSend] = await Promise.all([request(ctx, fetcher, "spur", new URL("sessions", `${config.adapters.spur.baseUrl.replace(/\/$/, "")}/`)), request(ctx, fetcher, "spur.send", probe.url, probe.init)]);
|
|
17217
|
+
const [spur, spurSend] = await Promise.all([request(ctx, fetcher, deadlineMs, "spur", new URL("sessions", `${config.adapters.spur.baseUrl.replace(/\/$/, "")}/`)), request(ctx, fetcher, deadlineMs, "spur.send", probe.url, probe.init)]);
|
|
17143
17218
|
checks.push(check("spur.api", spur?.ok === true, "Start or correct the configured Spur API."));
|
|
17144
17219
|
const spurSendOk = spurSend?.status === 404 && ((await spurErrorText(spurSend))?.startsWith("Session not found") ?? false);
|
|
17145
17220
|
if (spurSend !== null && spurSend.status !== 404) await spurSend.body?.cancel().catch(() => void 0);
|
|
@@ -17149,7 +17224,7 @@ async function runDaemonDoctor(ctx, productVersion, fetcher = fetch) {
|
|
|
17149
17224
|
const botToken = secrets["SLACK_BOT_TOKEN"];
|
|
17150
17225
|
const slackHeaders = botToken ? { Authorization: `Bearer ${botToken}` } : {};
|
|
17151
17226
|
const slackBase = `${(secrets["SLACK_API_URL"] || "https://slack.com/api/").replace(/\/$/, "")}/`;
|
|
17152
|
-
const auth = botToken ? await request(ctx, fetcher, "slack.auth", new URL("auth.test", slackBase), {
|
|
17227
|
+
const auth = botToken ? await request(ctx, fetcher, deadlineMs, "slack.auth", new URL("auth.test", slackBase), {
|
|
17153
17228
|
method: "POST",
|
|
17154
17229
|
headers: slackHeaders
|
|
17155
17230
|
}) : null;
|
|
@@ -17158,13 +17233,13 @@ async function runDaemonDoctor(ctx, productVersion, fetcher = fetch) {
|
|
|
17158
17233
|
const missingScopes = SLACK_BOT_SCOPES.filter((scope) => !granted.has(scope));
|
|
17159
17234
|
checks.push(check("slack.auth", authorized && missingScopes.length === 0, authorized ? `Add ${missingScopes.join(", ")} to the Slack app and reinstall it.` : "Check the Slack bot token."));
|
|
17160
17235
|
for (const [id, channel] of [["slack.orchestrators_member", config.slack.channels.orchestrators], ["slack.feed_member", config.slack.channels.feed]]) {
|
|
17161
|
-
const response = botToken && channel ? await request(ctx, fetcher, id, new URL(`conversations.info?channel=${encodeURIComponent(channel)}`, slackBase), { headers: slackHeaders }) : null;
|
|
17236
|
+
const response = botToken && channel ? await request(ctx, fetcher, deadlineMs, id, new URL(`conversations.info?channel=${encodeURIComponent(channel)}`, slackBase), { headers: slackHeaders }) : null;
|
|
17162
17237
|
checks.push(check(id, await slackMember(response), "Invite the bot to the configured channel ID."));
|
|
17163
17238
|
}
|
|
17164
17239
|
const configToken = secrets["SLACK_APP_CONFIG_TOKEN"];
|
|
17165
17240
|
if (!configToken || !config.slack.appId) checks.push(warning("slack.command", "Verify the installed Slack slash command against slack.command manually, or provide SLACK_APP_CONFIG_TOKEN and slack.appId."));
|
|
17166
17241
|
else {
|
|
17167
|
-
const response = await request(ctx, fetcher, "slack.command", new URL("apps.manifest.export", slackBase), {
|
|
17242
|
+
const response = await request(ctx, fetcher, deadlineMs, "slack.command", new URL("apps.manifest.export", slackBase), {
|
|
17168
17243
|
method: "POST",
|
|
17169
17244
|
headers: {
|
|
17170
17245
|
Authorization: `Bearer ${configToken}`,
|
|
@@ -17271,36 +17346,20 @@ function createInboundModule(ctx, gateway, registry = {}) {
|
|
|
17271
17346
|
clock: ctx.clock,
|
|
17272
17347
|
registry
|
|
17273
17348
|
});
|
|
17274
|
-
|
|
17275
|
-
|
|
17276
|
-
|
|
17277
|
-
|
|
17278
|
-
const schedule = () => {
|
|
17279
|
-
if (stopped || signal?.aborted) return;
|
|
17280
|
-
timer = setTimeout(() => {
|
|
17281
|
-
timer = void 0;
|
|
17282
|
-
tick();
|
|
17283
|
-
}, RECOVERY_MS);
|
|
17284
|
-
};
|
|
17285
|
-
const tick = () => {
|
|
17286
|
-
if (stopped || signal?.aborted) return;
|
|
17287
|
-
active = ctx.logCall("inbound.recover", () => inbound.recover()).catch((err) => {
|
|
17349
|
+
const recovery = createJob({
|
|
17350
|
+
run: () => ctx.logCall("inbound.recover", () => inbound.recover()),
|
|
17351
|
+
intervalMs: RECOVERY_MS,
|
|
17352
|
+
onError: (err) => {
|
|
17288
17353
|
ctx.log.error({ err }, "inbound recovery failed");
|
|
17289
|
-
}
|
|
17290
|
-
};
|
|
17354
|
+
}
|
|
17355
|
+
});
|
|
17291
17356
|
return {
|
|
17292
17357
|
sink: (event) => inbound.sink(event),
|
|
17293
17358
|
reapply: inbound.reapply,
|
|
17294
|
-
awaitRecovery: () =>
|
|
17295
|
-
start(
|
|
17296
|
-
signal = startSignal;
|
|
17297
|
-
tick();
|
|
17298
|
-
return Promise.resolve();
|
|
17299
|
-
},
|
|
17359
|
+
awaitRecovery: () => recovery.settled(),
|
|
17360
|
+
start: (signal) => recovery.start(signal),
|
|
17300
17361
|
async stop() {
|
|
17301
|
-
|
|
17302
|
-
if (timer !== void 0) clearTimeout(timer);
|
|
17303
|
-
await active;
|
|
17362
|
+
await recovery.stop();
|
|
17304
17363
|
await inbound.stop();
|
|
17305
17364
|
}
|
|
17306
17365
|
};
|
|
@@ -17345,8 +17404,8 @@ function slackSettings(config, secrets) {
|
|
|
17345
17404
|
};
|
|
17346
17405
|
}
|
|
17347
17406
|
/**
|
|
17348
|
-
* Own the
|
|
17349
|
-
* closes.
|
|
17407
|
+
* Own the outbox, token-expiry and doorbell jobs, each logging its own failure, and wait for
|
|
17408
|
+
* their active runs and every queued connection update before the store closes.
|
|
17350
17409
|
*/
|
|
17351
17410
|
function createOutboxModule(ctx, gateway, options = {}) {
|
|
17352
17411
|
const spur = options.spur ?? createSpurPort({ baseUrl: ctx.config.adapters.spur.baseUrl });
|
|
@@ -17357,40 +17416,51 @@ function createOutboxModule(ctx, gateway, options = {}) {
|
|
|
17357
17416
|
spur: { send: (session, text) => ctx.logCall("spur.send", () => spur.send(session, text)) },
|
|
17358
17417
|
now: () => new Date(ctx.clock.now())
|
|
17359
17418
|
});
|
|
17360
|
-
|
|
17361
|
-
|
|
17419
|
+
const every = {
|
|
17420
|
+
intervalMs: options.tickMs ?? TICK_MS,
|
|
17421
|
+
jitterMs: options.jitterMs ?? TICK_JITTER_MS
|
|
17422
|
+
};
|
|
17423
|
+
const outbox = createJob({
|
|
17424
|
+
...every,
|
|
17425
|
+
run: (signal) => ctx.logCall("outbox.tick", () => sender.tick(signal)),
|
|
17426
|
+
onError: () => void 0
|
|
17427
|
+
});
|
|
17428
|
+
const tokens = createJob({
|
|
17429
|
+
...every,
|
|
17430
|
+
run: () => expirePendingTokens(ctx.store, ctx.config, new Date(ctx.clock.now())),
|
|
17431
|
+
onError: (err) => {
|
|
17432
|
+
ctx.log.error({ err }, "token expiry failed");
|
|
17433
|
+
}
|
|
17434
|
+
});
|
|
17435
|
+
const doorbells = createJob({
|
|
17436
|
+
...every,
|
|
17437
|
+
run: () => reconcileDueDoorbells(ctx.store, ctx.config, new Date(ctx.clock.now())),
|
|
17438
|
+
onError: (err) => {
|
|
17439
|
+
ctx.log.error({ err }, "doorbell reconcile failed");
|
|
17440
|
+
}
|
|
17441
|
+
});
|
|
17442
|
+
const jobs = [
|
|
17443
|
+
tokens,
|
|
17444
|
+
doorbells,
|
|
17445
|
+
outbox
|
|
17446
|
+
];
|
|
17362
17447
|
let updating = Promise.resolve();
|
|
17363
17448
|
let stopped = false;
|
|
17364
|
-
let signal;
|
|
17365
|
-
const schedule = () => {
|
|
17366
|
-
if (stopped || signal?.aborted) return;
|
|
17367
|
-
timer = setTimeout(() => {
|
|
17368
|
-
timer = void 0;
|
|
17369
|
-
tick().then(schedule);
|
|
17370
|
-
}, TICK_MS + Math.floor(Math.random() * TICK_JITTER_MS));
|
|
17371
|
-
};
|
|
17372
|
-
const tick = () => {
|
|
17373
|
-
if (stopped || signal?.aborted) return active;
|
|
17374
|
-
active = active.then(() => ctx.logCall("outbox.tick", async () => {
|
|
17375
|
-
await expirePendingTokens(ctx.store, ctx.config, new Date(ctx.clock.now()));
|
|
17376
|
-
if (!signal?.aborted) await sender.tick(signal);
|
|
17377
|
-
})).catch(() => void 0);
|
|
17378
|
-
return active;
|
|
17379
|
-
};
|
|
17380
17449
|
return {
|
|
17381
|
-
async start(
|
|
17382
|
-
signal = startSignal;
|
|
17450
|
+
async start(signal) {
|
|
17383
17451
|
await sender.recover();
|
|
17384
17452
|
if (signal.aborted) return;
|
|
17385
|
-
|
|
17453
|
+
await Promise.all(jobs.map((job) => job.start(signal)));
|
|
17386
17454
|
},
|
|
17387
17455
|
async stop() {
|
|
17388
17456
|
stopped = true;
|
|
17389
|
-
|
|
17390
|
-
await active;
|
|
17457
|
+
await Promise.all(jobs.map((job) => job.stop()));
|
|
17391
17458
|
await updating;
|
|
17392
17459
|
},
|
|
17393
|
-
pulse
|
|
17460
|
+
async pulse() {
|
|
17461
|
+
await doorbells.trigger();
|
|
17462
|
+
await outbox.trigger();
|
|
17463
|
+
},
|
|
17394
17464
|
connection(state) {
|
|
17395
17465
|
if (stopped) return Promise.resolve();
|
|
17396
17466
|
const update = sender.recordConnection(state, new Date(ctx.clock.now())).catch((err) => {
|
|
@@ -17507,6 +17577,7 @@ function createSystemdModule(notifier) {
|
|
|
17507
17577
|
}
|
|
17508
17578
|
//#endregion
|
|
17509
17579
|
//#region ../daemon/src/composition.ts
|
|
17580
|
+
const DAY_MS = 864e5;
|
|
17510
17581
|
/** The production module graph, with replaceable external ports for in-process tests. */
|
|
17511
17582
|
function createDaemonModules(ctxFor, ports = {}) {
|
|
17512
17583
|
const board = ctxFor("board-core");
|
|
@@ -17518,7 +17589,10 @@ function createDaemonModules(ctxFor, ports = {}) {
|
|
|
17518
17589
|
});
|
|
17519
17590
|
const ctx = ctxFor("gateway-slack");
|
|
17520
17591
|
const settings = slackSettings(ctx.config, ctx.secrets);
|
|
17521
|
-
const gateway = ports.gateway ?? (settings === null ? void 0 : createSlackGateway(
|
|
17592
|
+
const gateway = ports.gateway ?? (settings === null ? void 0 : createSlackGateway({
|
|
17593
|
+
...settings,
|
|
17594
|
+
now: () => ctx.clock.now()
|
|
17595
|
+
}));
|
|
17522
17596
|
const registry = createOperationRegistry({
|
|
17523
17597
|
config: board.config,
|
|
17524
17598
|
clock: board.clock,
|
|
@@ -17537,10 +17611,10 @@ function createDaemonModules(ctxFor, ports = {}) {
|
|
|
17537
17611
|
const entries = [{
|
|
17538
17612
|
name: "commands",
|
|
17539
17613
|
stopStage: "final",
|
|
17540
|
-
module:
|
|
17541
|
-
|
|
17542
|
-
|
|
17543
|
-
|
|
17614
|
+
module: createJob({
|
|
17615
|
+
run: () => purgeExpiredCommands(commands.store, commands.clock, commands.config.commands.retentionDays),
|
|
17616
|
+
intervalMs: DAY_MS,
|
|
17617
|
+
first: "await",
|
|
17544
17618
|
onError: (err) => {
|
|
17545
17619
|
commands.log.error({ err }, "command purge failed");
|
|
17546
17620
|
}
|