@parcha/agentrun-serve 0.1.0-beta.54 → 0.1.0-beta.55

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 (190) hide show
  1. package/CHANGELOG.md +110 -2
  2. package/README.md +266 -88
  3. package/dist/adapters.d.ts +10 -0
  4. package/dist/adapters.js +46 -0
  5. package/dist/agent-package.d.ts +3 -3
  6. package/dist/agent-package.js +6 -13
  7. package/dist/agents-store.js +6 -5
  8. package/dist/api-only.d.ts +16 -4
  9. package/dist/api-only.js +21 -7
  10. package/dist/cli.js +5 -3
  11. package/dist/composio-made.d.ts +26 -1
  12. package/dist/composio-made.js +39 -2
  13. package/dist/composio-preset.d.ts +3 -2
  14. package/dist/composio-preset.js +46 -14
  15. package/dist/computer-held-routes.js +2 -3
  16. package/dist/computer-setting.d.ts +4 -2
  17. package/dist/computer-setting.js +0 -2
  18. package/dist/computers-running.d.ts +8 -0
  19. package/dist/computers-running.js +27 -0
  20. package/dist/console/assets/backend-D5EmB4N3.js +166 -0
  21. package/dist/console/assets/index-DUYLaqiR.js +746 -0
  22. package/dist/console/assets/index-DYhU4adm.css +1 -0
  23. package/dist/console/index.html +2 -2
  24. package/dist/docker-host-addresses.d.ts +23 -3
  25. package/dist/docker-host-addresses.js +90 -18
  26. package/dist/exa-keyless.d.ts +2 -3
  27. package/dist/exa-keyless.js +43 -127
  28. package/dist/firecrawl-keyless.d.ts +41 -0
  29. package/dist/firecrawl-keyless.js +152 -0
  30. package/dist/handed-secret.d.ts +3 -1
  31. package/dist/handed-secret.js +4 -2
  32. package/dist/harness-keys.d.ts +98 -0
  33. package/dist/harness-keys.js +247 -0
  34. package/dist/harness-recipe-entry.d.ts +14 -9
  35. package/dist/harness-recipe-entry.js +25 -14
  36. package/dist/harness-table.d.ts +16 -1
  37. package/dist/harness-table.js +19 -7
  38. package/dist/harness.d.ts +4 -0
  39. package/dist/harness.js +12 -1
  40. package/dist/host-check.d.ts +2 -0
  41. package/dist/host-check.js +6 -0
  42. package/dist/import-summary.d.ts +1 -1
  43. package/dist/import-summary.js +1 -1
  44. package/dist/import.d.ts +5 -5
  45. package/dist/import.js +54 -67
  46. package/dist/keyless-mcp.d.ts +36 -0
  47. package/dist/keyless-mcp.js +127 -0
  48. package/dist/learn/audit.d.ts +3 -3
  49. package/dist/learn/audit.js +3 -3
  50. package/dist/learn/commit.d.ts +8 -7
  51. package/dist/learn/commit.js +60 -20
  52. package/dist/learn/compile.d.ts +4 -3
  53. package/dist/learn/compile.js +7 -5
  54. package/dist/learn/folder.d.ts +16 -3
  55. package/dist/learn/folder.js +46 -13
  56. package/dist/learn/promote.d.ts +37 -13
  57. package/dist/learn/promote.js +112 -40
  58. package/dist/learn/secrets.js +10 -2
  59. package/dist/learning-routes.d.ts +22 -17
  60. package/dist/learning-routes.js +40 -39
  61. package/dist/learning.js +2 -2
  62. package/dist/manifest.d.ts +10 -0
  63. package/dist/manifest.js +30 -0
  64. package/dist/mcp-pin-first.d.ts +4 -2
  65. package/dist/mcp-pin-first.js +5 -2
  66. package/dist/mcp-secret-writes.d.ts +16 -7
  67. package/dist/mcp-secret-writes.js +35 -27
  68. package/dist/mcp-servers-store.d.ts +30 -6
  69. package/dist/mcp-servers-store.js +112 -28
  70. package/dist/mcp-sources.d.ts +10 -2
  71. package/dist/mcp-sources.js +9 -2
  72. package/dist/mcp-store.d.ts +13 -7
  73. package/dist/mcp-store.js +12 -9
  74. package/dist/model-form.d.ts +3 -2
  75. package/dist/model-form.js +11 -7
  76. package/dist/model.d.ts +20 -4
  77. package/dist/model.js +68 -9
  78. package/dist/native/history.d.ts +1 -1
  79. package/dist/native/history.js +2 -2
  80. package/dist/ollama-provider.d.ts +92 -0
  81. package/dist/ollama-provider.js +495 -0
  82. package/dist/openapi/agentrun-v2.openapi.json +2 -2
  83. package/dist/openapi.js +127 -37
  84. package/dist/page.d.ts +11 -3
  85. package/dist/page.js +22 -7
  86. package/dist/place-offers.d.ts +17 -1
  87. package/dist/place-offers.js +46 -5
  88. package/dist/print.js +1 -1
  89. package/dist/purged-workflow.d.ts +35 -7
  90. package/dist/purged-workflow.js +73 -26
  91. package/dist/run-computer.d.ts +2 -0
  92. package/dist/run-computer.js +2 -0
  93. package/dist/run-files.d.ts +4 -0
  94. package/dist/run-files.js +4 -0
  95. package/dist/run-keys.d.ts +2 -4
  96. package/dist/run-keys.js +6 -7
  97. package/dist/run-launch.d.ts +4 -0
  98. package/dist/run-launch.js +4 -0
  99. package/dist/run-reads-over-store.d.ts +3 -2
  100. package/dist/run-reads-over-store.js +66 -2
  101. package/dist/run-secrets.js +5 -2
  102. package/dist/runner/adapter-loop.d.ts +6 -3
  103. package/dist/runner/adapter-loop.js +34 -15
  104. package/dist/runner/adapter-run-spec.d.ts +3 -0
  105. package/dist/runner/adapter-run-spec.js +5 -3
  106. package/dist/runner/audit.js +8 -4
  107. package/dist/runner/beside.d.ts +2 -1
  108. package/dist/runner/beside.js +6 -2
  109. package/dist/runner/claim-secrets.d.ts +5 -8
  110. package/dist/runner/claim-secrets.js +6 -0
  111. package/dist/runner/cli-run-spec.d.ts +1 -1
  112. package/dist/runner/cli-run-spec.js +38 -6
  113. package/dist/runner/harness-loops.d.ts +22 -9
  114. package/dist/runner/harness-loops.js +21 -11
  115. package/dist/runner/held.d.ts +3 -0
  116. package/dist/runner/learning-end.d.ts +1 -1
  117. package/dist/runner/learning-end.js +8 -3
  118. package/dist/runner/loop-contract.d.ts +5 -4
  119. package/dist/runner/main.js +4 -2
  120. package/dist/runner/mcp-claim.d.ts +3 -0
  121. package/dist/runner/mcp-claim.js +26 -2
  122. package/dist/runner/mcp-run.d.ts +3 -0
  123. package/dist/runner/mcp-run.js +2 -1
  124. package/dist/runner/metrics.d.ts +10 -10
  125. package/dist/runner/metrics.js +19 -38
  126. package/dist/runner/model-route.d.ts +3 -0
  127. package/dist/runner/model-route.js +6 -2
  128. package/dist/runner/promotion.d.ts +15 -9
  129. package/dist/runner/promotion.js +25 -15
  130. package/dist/runner/run-child-host.js +17 -7
  131. package/dist/runner/run-child.js +3 -1
  132. package/dist/runner/sdk-loop.js +2 -0
  133. package/dist/runner/workflow-loop.d.ts +2 -2
  134. package/dist/runner/workflow-loop.js +1 -2
  135. package/dist/runner/workflow-spec.d.ts +1 -1
  136. package/dist/runner/workflow-spec.js +6 -6
  137. package/dist/sdk/check.d.ts +4 -1
  138. package/dist/sdk/check.js +2 -1
  139. package/dist/sdk/runs.d.ts +2 -2
  140. package/dist/sdk/runs.js +8 -6
  141. package/dist/secret-cut.js +2 -1
  142. package/dist/secret-writes.d.ts +3 -2
  143. package/dist/secret-writes.js +1 -1
  144. package/dist/server.d.ts +44 -8
  145. package/dist/server.js +283 -108
  146. package/dist/standard-webhooks.d.ts +11 -0
  147. package/dist/standard-webhooks.js +20 -2
  148. package/dist/store/index.d.ts +1 -1
  149. package/dist/store/schema.js +5 -2
  150. package/dist/store/sqlite/store.js +90 -34
  151. package/dist/store/store.d.ts +54 -14
  152. package/dist/store-reads/journal.d.ts +7 -2
  153. package/dist/store-reads/journal.js +9 -6
  154. package/dist/store-reads/learning.d.ts +12 -9
  155. package/dist/store-reads/learning.js +18 -24
  156. package/dist/store-view.d.ts +0 -5
  157. package/dist/store-view.js +9 -8
  158. package/dist/template-eval.d.ts +49 -4
  159. package/dist/template-eval.js +168 -45
  160. package/dist/template-import.js +4 -2
  161. package/dist/templates.d.ts +5 -3
  162. package/dist/templates.js +19 -40
  163. package/dist/timeline/labels.d.ts +2 -2
  164. package/dist/timeline/labels.js +2 -2
  165. package/dist/timeline/timeline.d.ts +2 -2
  166. package/dist/timeline/timeline.js +1 -1
  167. package/dist/tool-plane.d.ts +17 -9
  168. package/dist/tool-plane.js +38 -17
  169. package/dist/tools.js +2 -2
  170. package/dist/trigger-launch-hook.d.ts +16 -8
  171. package/dist/trigger-launch-hook.js +32 -23
  172. package/dist/trigger-targets.d.ts +18 -8
  173. package/dist/trigger-targets.js +42 -19
  174. package/dist/triggers.d.ts +85 -23
  175. package/dist/triggers.js +303 -96
  176. package/dist/web-fake.js +3 -3
  177. package/dist/web-fetch-direct.d.ts +4 -0
  178. package/dist/web-fetch-direct.js +8 -1
  179. package/dist/web-fetch.d.ts +12 -3
  180. package/dist/web-fetch.js +47 -14
  181. package/dist/web-search.d.ts +33 -4
  182. package/dist/web-search.js +100 -41
  183. package/dist/webhooks.js +4 -5
  184. package/launcher/agentrun-serve +5 -1
  185. package/package.json +17 -13
  186. package/templates/README.md +2 -2
  187. package/dist/console/assets/index-B_85An2t.js +0 -745
  188. package/dist/console/assets/index-n1YsbnYh.css +0 -1
  189. package/dist/import-sources.d.ts +0 -116
  190. package/dist/import-sources.js +0 -693
package/dist/triggers.js CHANGED
@@ -10,19 +10,21 @@
10
10
  // While the trigger's last run is active (working, or waiting on a person), a firing is `skipped`, never queued: a firing
11
11
  // queued behind a run parked on a person would wait for as long as the person does. A source whose adapter says each
12
12
  // firing is its own work (concurrent: a webhook with accept) starts a run per firing instead. With max_active_runs set, a
13
- // firing past it waits for a run of the trigger to end.
13
+ // firing past it waits for a run of the trigger to end. A firing handed to the launch hook's host with no run yet is a run
14
+ // in progress for both, until its run starts or its start_by passes (a host start begun by then holds it through the
15
+ // start), and so is one mid-hand on this server: its hook not answered yet, or its host's start being written.
14
16
  // One retry policy, kept in the store: a failed try (a full server, a thrown error, a store that could not read) keeps
15
17
  // the firing due with its next try in retry_at, after the wait BACKOFF_MS gives for its attempts; past the table it fails.
16
- // Every failed try counts toward the trigger's streak, and FAILURES_TO_PAUSE in a row turn the trigger off. A firing past
17
- // its trigger's max_active_runs is no failure: it waits (waits_on, no try counted) and is driven again once a run of the
18
- // trigger ends, read from the store by one query per tick for every waiting firing (the runner is another process: the
18
+ // Each failed firing counts once toward the trigger's streak, however many tries it took, and FAILURES_TO_PAUSE in a row
19
+ // turn the trigger off. A firing past its trigger's max_active_runs is no failure: it waits (waits_on, no try counted) and
20
+ // is driven again once a run of the trigger ends, read from the store by one query per tick for every waiting firing (the runner is another process: the
19
21
  // store is all the two share). One timer, at the soonest next time of an enabled trigger, next try of a due firing, or
20
22
  // WAIT_POLL_MS while a firing waits, is armed again after each change. A next time is reckoned from the last nominal time, never from the clock, so a
21
23
  // late timer does not drift. Of the times that came while the server was down, or its timer late past LATE_MS, the
22
24
  // latest fires if it is within the trigger's catch-up window and the rest are one `missed` row; the schedule goes on from
23
25
  // now. A failed firing queues a trigger.failed webhook message.
24
26
  // With the launch hook set (trigger-launch-hook.ts), a firing that would start a run goes the same way up to the start,
25
- // then is handed to the host instead: sent when the host takes it, skipped with why when it does not.
27
+ // then is handed to the host instead: sent when the host takes it, a failed try (hook_failed and why) when it does not.
26
28
  import { createHash, randomBytes } from "node:crypto";
27
29
  import { TRIGGER_LABELS } from "./timeline/index.js";
28
30
  import { agentDeleting, purgedAgent } from "./agents.js";
@@ -32,7 +34,7 @@ import { EFFORTS } from "./model.js";
32
34
  import { AgentArchived, StoreConstraint, TriggerFull } from "./store/index.js";
33
35
  import { carriesPrevious, PAYLOAD_KEPT_BYTES, second, validZone } from "./trigger-adapter.js";
34
36
  import { TRIGGER_ADAPTERS } from "./trigger-adapters.js";
35
- import { handToHost, LAUNCH_HOOK_LATE_START_MS } from "./trigger-launch-hook.js";
37
+ import { handToHost, HookFailed, LAUNCH_HOOK_LATE_START_MS } from "./trigger-launch-hook.js";
36
38
  import { MAX_EVERY_S } from "./trigger-schedule.js";
37
39
  import { ID, IDEMPOTENCY_TTL_S, isObject, unknownFields } from "./validate.js";
38
40
  export { MAX_EVERY_S, MIN_EVERY_S } from "./trigger-schedule.js";
@@ -48,7 +50,8 @@ const FULL_RETRY_S = 30;
48
50
  export const SOURCE_KINDS = TRIGGER_ADAPTERS.map((a) => a.id);
49
51
  export const TARGET_KINDS = ["start_run", "message_run"];
50
52
  export const FIRING_STATUSES = ["due", "started", "sent", "skipped", "failed", "missed"];
51
- /** A firing the launch hook's host took (a 2xx) without starting its run here under the firing (RunCreate trigger_firing). */
53
+ /** The reason of a firing the launch hook's host took (a 2xx) without starting its run here under the firing (RunCreate
54
+ * trigger_firing). */
52
55
  export const HANDED_NO_RUN = "Handed to the host by the launch hook, which started no run here for it.";
53
56
  /** The most of a webhook's payload a firing passes on: the rest is cut, at a character's start (trigger-adapter.ts). */
54
57
  /** How late a missed time may be and still fire once, by default: an hour. */
@@ -208,8 +211,16 @@ const nameTaken = (error, name) => error instanceof StoreConstraint && error.uni
208
211
  const archivedDetail = (name) => `The agent ${name} is archived: unarchive it, then turn the trigger on.`;
209
212
  /** Why a trigger is off when the server turned it off, as its row keeps it (`disabled`, JSON). */
210
213
  const reasonOf = (disabled) => (isObject(disabled) ? disabled.reason : undefined);
211
- /** Why a try failed, as its firing keeps it: an ApiError's code, else internal. */
212
- const errorOf = (error) => ({ code: error instanceof ApiError ? error.code : "internal", message: String(error?.message ?? error) });
214
+ /** Why a try failed, as its firing keeps it: an ApiError's code or a launch hook's (hook_failed), else internal. */
215
+ const errorOf = (error) => ({ code: error instanceof ApiError || error instanceof HookFailed ? error.code : "internal", message: String(error?.message ?? error) });
216
+ /** What a failed firing's reason says of its try: a launch hook's failure and its cause; nothing for the rest. */
217
+ const failedReason = (error) => (error instanceof HookFailed ? error.message : undefined);
218
+ /** A firing its launch hook's host took (a 2xx) with no run yet: sent with no run, and a startBy, which only such a
219
+ * firing has. startBy is kept in the retry_at column: no column of its own, no migration. */
220
+ const tookWithNoRun = (firing) => firing.status === "sent" && firing.runId === null && firing.startBy !== null;
221
+ /** How long a host start of such a firing holds its trigger's room from its check, at least: a startBy sooner than this
222
+ * is pushed out to it before the run is written (handedStart), so the window never closes while the run is written. */
223
+ const START_WINDOW_MS = 60_000;
213
224
  export class Triggers {
214
225
  deps;
215
226
  store;
@@ -224,6 +235,19 @@ export class Triggers {
224
235
  /** Each trigger's firings, driven one after another in the order asked: a firing's overlap check reads what the one
225
236
  * before it settled to. */
226
237
  turns = new Map();
238
+ /** Each trigger's firings mid-hand on this server, by key, with how many hold each: drive found room for it (busy) and
239
+ * has not yet written what came of it (sent, started, a failed try), or a host start is writing its run and has not
240
+ * yet started the firing with it. Either may hold a firing the other holds (its host starts it before its hook
241
+ * answers), so a firing leaves only once both let go. busy counts each here, but the one it checks, once with the
242
+ * store's firings in progress. */
243
+ handing = new Map();
244
+ /** Each trigger's room checks on this server (drive's, a host start's), one after another: a check's hold (handing, a
245
+ * start_by pushed out) is in place before the next one reads, so two never both take the one place. Removed once idle. */
246
+ checks = new Map();
247
+ /** Each firing a host start on this server is writing the run of, by key: that start's run once written, or undefined
248
+ * when it wrote none. Another start of the firing meanwhile answers that run (handedStart), and its drive waits for it
249
+ * rather than handing it again. */
250
+ starting = new Map();
227
251
  /** Each trigger's removals and the edits that name a target (the one way it moves to another agent), one after another
228
252
  * on this server: a move never lands between a template update's delete of its Composio instance and its conditional
229
253
  * delete of the row (remove), so a moved trigger never stands on an instance that delete took. Across servers the
@@ -697,7 +721,7 @@ export class Triggers {
697
721
  else if (firing.waitsOn === null && !this.driving.has(firing.key) && (firing.retryAt === null || firing.retryAt <= now))
698
722
  void this.inTurn(firing.triggerId, firing.key);
699
723
  }
700
- const waiting = await this.store.triggers.waiting();
724
+ const waiting = await this.store.triggers.waiting(now);
701
725
  this.waiting = waiting.length > 0;
702
726
  for (const firing of waiting)
703
727
  if (firing.free && !this.driving.has(firing.key))
@@ -727,6 +751,39 @@ export class Triggers {
727
751
  });
728
752
  return done;
729
753
  }
754
+ /** `check` on trigger `triggerId` once every room check of it asked before has settled (checks). A check reads the store
755
+ * and holds what it found (hold, a start_by pushed out); it never waits on a hook or a start. */
756
+ checked(triggerId, check) {
757
+ const done = (this.checks.get(triggerId) ?? Promise.resolve()).then(check);
758
+ const turn = done.then(() => undefined, () => undefined);
759
+ this.checks.set(triggerId, turn);
760
+ void turn.then(() => {
761
+ if (this.checks.get(triggerId) === turn)
762
+ this.checks.delete(triggerId);
763
+ });
764
+ return done;
765
+ }
766
+ /** Firing `key` of `triggerId` held mid-hand (handing) until the returned release, counted: held while any of its
767
+ * holders has not released. A release lets go once, however often it is called. */
768
+ hold(triggerId, key) {
769
+ let keys = this.handing.get(triggerId);
770
+ if (!keys)
771
+ this.handing.set(triggerId, (keys = new Map()));
772
+ const held = keys;
773
+ held.set(key, (held.get(key) ?? 0) + 1);
774
+ let released = false;
775
+ return () => {
776
+ if (released)
777
+ return;
778
+ released = true;
779
+ const left = held.get(key) - 1;
780
+ if (left > 0)
781
+ return void held.set(key, left);
782
+ held.delete(key);
783
+ if (held.size === 0 && this.handing.get(triggerId) === held)
784
+ this.handing.delete(triggerId);
785
+ };
786
+ }
730
787
  /** `key`'s firing driven after every firing of its trigger asked before it. */
731
788
  inTurn(triggerId, key) {
732
789
  const known = this.driving.get(key);
@@ -990,47 +1047,69 @@ export class Triggers {
990
1047
  return void (await this.store.triggers.settle(triggerId, key, { status: "skipped", reason: archived }));
991
1048
  if (trigger.target.kind === "message_run")
992
1049
  return void (await this.send(trigger, firing));
993
- const busy = await this.busy(trigger, firing);
994
- if (this.closed)
995
- return;
996
- if (busy && "skipped" in busy)
997
- return void (await this.store.triggers.settle(triggerId, key, { status: "skipped", reason: busy.skipped }));
998
- if (busy && "waitsOn" in busy)
999
- return void (await this.wait(triggerId, key, busy.waitsOn, busy.reason));
1000
- // The target as it is now: an edit during the overlap check may have made it a message.
1001
- const now = await this.find(triggerId);
1002
- if (!now)
1003
- return;
1004
- if (now.target.kind === "message_run")
1005
- return void (await this.send(now, firing));
1006
- if (this.deps.launchHook)
1007
- return void (await this.handed(now, firing, this.deps.launchHook));
1008
- let started;
1050
+ // Room found is held (handing) until what came of it is written: a host start meanwhile counts this firing. The
1051
+ // firing is read again in the check: a host start may have started it since, or be writing its run. One being
1052
+ // written is left as it is (its retry kept, no wait written): that start starts it, or, writing no run, arms the
1053
+ // timer again for its retry (startHold).
1054
+ const claimed = await this.checked(triggerId, async () => {
1055
+ const now = await this.store.triggers.firing(triggerId, key);
1056
+ if (!now || now.status !== "due" || this.starting.has(key))
1057
+ return { gone: true };
1058
+ return (await this.busy(trigger, now)) ?? this.hold(triggerId, key);
1059
+ });
1060
+ if (typeof claimed !== "function") {
1061
+ if (this.closed || "gone" in claimed)
1062
+ return;
1063
+ if ("skipped" in claimed)
1064
+ return void (await this.store.triggers.settle(triggerId, key, { status: "skipped", reason: claimed.skipped }));
1065
+ return void (await this.wait(triggerId, key, claimed.waitsOn, claimed.reason));
1066
+ }
1009
1067
  try {
1010
- const attrs = firing.attrs;
1011
- started = await this.deps.start(now.target, this.inputOf(now, firing), { id: triggerId, firing_key: key, name: now.name, ...(attrs && Object.keys(attrs).length ? { attrs } : {}) }, this.originOf(now), this.titleOf(now, firing), carriesPrevious(this.adapter(now.source)));
1068
+ await this.roomFound(triggerId, firing);
1012
1069
  }
1013
- catch (error) {
1014
- // Stopping, the start may have been cut by the close: the firing stays due for the next start, whose origin key
1015
- // finds a run this one made.
1016
- if (this.closed)
1017
- return;
1018
- // The archive committed between the read above and the start, which refused the run (the store's fire reads the
1019
- // archive in its own transaction): skipped, as above, and no failure counted.
1020
- const raced = await this.archivedSkip(now.agentId).catch(() => undefined);
1021
- if (raced)
1022
- return void (await this.store.triggers.settle(triggerId, key, { status: "skipped", reason: raced }));
1023
- return void (await this.answered(triggerId, key, error));
1070
+ finally {
1071
+ claimed();
1024
1072
  }
1073
+ }
1074
+ catch (error) {
1025
1075
  if (this.closed)
1026
1076
  return;
1027
- await this.started(triggerId, key, started.run_id);
1077
+ await this.failedTry(triggerId, key, error);
1078
+ }
1079
+ }
1080
+ /** A start_run firing drive found room for: its run started, or it handed to the launch hook's host, on the target as it
1081
+ * is now (an edit during the overlap check may have made it a message, sent instead). */
1082
+ async roomFound(triggerId, firing) {
1083
+ const { key } = firing;
1084
+ if (this.closed)
1085
+ return;
1086
+ const now = await this.find(triggerId);
1087
+ if (!now)
1088
+ return;
1089
+ if (now.target.kind === "message_run")
1090
+ return void (await this.send(now, firing));
1091
+ if (this.deps.launchHook)
1092
+ return void (await this.handed(now, firing, this.deps.launchHook));
1093
+ let started;
1094
+ try {
1095
+ const attrs = firing.attrs;
1096
+ started = await this.deps.start(now.target, this.inputOf(now, firing), { id: triggerId, firing_key: key, name: now.name, ...(attrs && Object.keys(attrs).length ? { attrs } : {}) }, this.originOf(now), this.titleOf(now, firing), carriesPrevious(this.adapter(now.source)));
1028
1097
  }
1029
1098
  catch (error) {
1099
+ // Stopping, the start may have been cut by the close: the firing stays due for the next start, whose origin key
1100
+ // finds a run this one made.
1030
1101
  if (this.closed)
1031
1102
  return;
1032
- await this.failedTry(triggerId, key, error);
1103
+ // The archive committed between the read above and the start, which refused the run (the store's fire reads the
1104
+ // archive in its own transaction): skipped, as above, and no failure counted.
1105
+ const raced = await this.archivedSkip(now.agentId).catch(() => undefined);
1106
+ if (raced)
1107
+ return void (await this.store.triggers.settle(triggerId, key, { status: "skipped", reason: raced }));
1108
+ return void (await this.answered(triggerId, key, error));
1033
1109
  }
1110
+ if (this.closed)
1111
+ return;
1112
+ await this.started(triggerId, key, started.run_id);
1034
1113
  }
1035
1114
  /** A message_run firing: its message to the target's run, under its key, queued as a command row the run takes at its
1036
1115
  * next safe point, within the bound per (trigger, run): a clock's firings coalesce to one waiting message, a pushed
@@ -1066,7 +1145,7 @@ export class Triggers {
1066
1145
  /** The firing kept due, waiting for its trigger's room (no try counted, no retry time): a tick drives it once the store
1067
1146
  * says a run of its trigger ended. */
1068
1147
  async wait(triggerId, key, runId, reason) {
1069
- await this.store.triggers.settle(triggerId, key, { waitsOn: runId, retryAt: null, reason });
1148
+ await this.store.triggers.settle(triggerId, key, { waitsOn: runId, retryAt: null, reason, from: "due" });
1070
1149
  this.waiting = true;
1071
1150
  }
1072
1151
  async find(triggerId) {
@@ -1077,19 +1156,37 @@ export class Triggers {
1077
1156
  * active), or, with max_active_runs (a pushed trigger's, with or without accept), waiting on the last run while that
1078
1157
  * many of the trigger's runs have not ended: a capped trigger starts a run per firing and never skips. A trigger whose
1079
1158
  * source starts a run per firing (its adapter's concurrent) is never skipped either: with no cap it starts, the server's
1080
- * run limit still holding through retry. */
1081
- async busy(trigger, firing) {
1159
+ * run limit still holding through retry. A firing its launch hook's host took with no run yet holds the room as a run in
1160
+ * progress until it starts or its startBy passes (the store's activeKeys and held): with a cap, a firing waits on it (on
1161
+ * its key while the trigger has no run), and the overlap check skips for it. So does a firing mid-hand on this server
1162
+ * (handing), other than `firing`: one whose hook has not answered yet, or whose host's start is being written. */
1163
+ async busy(given, firing) {
1164
+ const now = this.clock.now();
1165
+ // Read before the store: a firing whose hand ends meanwhile is in the store by then, so it is counted, and counted
1166
+ // once (a key in both is one firing).
1167
+ const mid = [...(this.handing.get(given.id)?.keys() ?? [])].filter((key) => key !== firing.key);
1168
+ // The trigger as it is now, after mid: a firing started since the caller read it is its last run here (its cap, its
1169
+ // last run, as the start of that firing left them).
1170
+ const trigger = (await this.find(given.id)) ?? given;
1082
1171
  if (trigger.maxActiveRuns !== null) {
1083
- const active = await this.store.triggers.activeRuns(trigger.id);
1084
- if (active < trigger.maxActiveRuns || !trigger.lastRunId)
1172
+ const keys = await this.store.triggers.activeKeys(trigger.id, now);
1173
+ const active = new Set([...keys, ...mid]).size;
1174
+ if (active < trigger.maxActiveRuns)
1085
1175
  return undefined;
1086
- return { waitsOn: trigger.lastRunId, reason: `${active} of this trigger's runs have not ended (max_active_runs ${trigger.maxActiveRuns}).` };
1176
+ // Never room at the cap: a firing started after the trigger's read (by another server) is waited on by its key.
1177
+ const on = trigger.lastRunId ?? (await this.store.triggers.held(trigger.id, now)) ?? mid[0] ?? keys[0];
1178
+ return { waitsOn: on, reason: `${active} of this trigger's runs have not ended (max_active_runs ${trigger.maxActiveRuns}).` };
1087
1179
  }
1088
1180
  if (this.adapter(trigger.source)?.concurrent?.(trigger.source))
1089
1181
  return undefined;
1090
1182
  const earlier = (await this.store.triggers.pending()).some((f) => f.triggerId === trigger.id && f.status === "due" && f.key !== firing.key && f.at < firing.at);
1091
1183
  if (earlier)
1092
1184
  return { skipped: "An earlier firing is still waiting to start its run." };
1185
+ if (mid.length)
1186
+ return { skipped: `The firing ${mid[0]} is being handed to the launch hook's host, or started by it.` };
1187
+ const held = await this.store.triggers.held(trigger.id, now);
1188
+ if (held)
1189
+ return { skipped: `The last firing, ${held}, was handed to the launch hook's host, which may still start its run.` };
1093
1190
  const last = trigger.lastRunId;
1094
1191
  if (!last)
1095
1192
  return undefined;
@@ -1099,8 +1196,9 @@ export class Triggers {
1099
1196
  return { skipped: status === "input_required" ? `The last run, ${last}, is waiting for a person.` : `The last run, ${last}, is still ${status}.` };
1100
1197
  }
1101
1198
  /** A failed try: kept due with its next try after the backoff table's wait (an answer's own Retry-After when longer), or,
1102
- * past the table, failed. Either way one more in the trigger's streak. A throw that is not a target's answer (a store
1103
- * or a run's status that did not read, a programming error) is a failed try like a busy server's. */
1199
+ * past the table, failed. A try is no failure in the trigger's streak: its firing is one, once it fails, however many
1200
+ * tries it took. A throw that is not a target's answer (a store or a run's status that did not read, a programming
1201
+ * error) is a failed try like a busy server's. */
1104
1202
  async failedTry(triggerId, key, error) {
1105
1203
  try {
1106
1204
  const firing = await this.store.triggers.firing(triggerId, key);
@@ -1109,14 +1207,10 @@ export class Triggers {
1109
1207
  const attempts = firing.attempts + 1;
1110
1208
  if (attempts <= BACKOFF_MS.length) {
1111
1209
  const wait = Math.max(BACKOFF_MS[attempts - 1], error instanceof ApiError ? (error.extra.retry_after_ms ?? 0) : 0);
1112
- const settled = await this.store.triggers.settle(triggerId, key, { attempts, retryAt: this.clock.now() + wait, error: errorOf(error), reason: errorOf(error).message, waitsOn: null }, { failure: true, pauseAt: FAILURES_TO_PAUSE });
1113
- if (settled?.paused) {
1114
- this.deps.say({ condition: "trigger_auto_paused", trigger: triggerId, firing: key });
1115
- await this.pausedThere(triggerId);
1116
- }
1210
+ await this.store.triggers.settle(triggerId, key, { attempts, retryAt: this.clock.now() + wait, error: errorOf(error), reason: errorOf(error).message, waitsOn: null, from: "due" });
1117
1211
  return;
1118
1212
  }
1119
- await this.failed(triggerId, key, errorOf(error));
1213
+ await this.failed(triggerId, key, errorOf(error), undefined, failedReason(error));
1120
1214
  }
1121
1215
  catch (failure) {
1122
1216
  // The store could not keep the failure: said, and the timer tries again after the table's first wait.
@@ -1125,18 +1219,19 @@ export class Triggers {
1125
1219
  this.timer ??= this.clock.arm(() => void this.tick(), BACKOFF_MS[0]);
1126
1220
  }
1127
1221
  }
1128
- /** A target refused the firing: a busy server's answer is a failed try under the table; any other (a refusal, a thrown
1129
- * error) fails the firing at once. Both count toward the streak. */
1222
+ /** A target refused the firing: a busy server's answer, or a launch hook that did not answer (a retryable HookFailed),
1223
+ * is a failed try under the table; any other (a refusal, a hook's other answer, a thrown error) fails the firing at
1224
+ * once. The firing counts toward the streak once it fails. */
1130
1225
  async answered(triggerId, key, error, runId) {
1131
- if (error instanceof ApiError && RETRYABLE.has(error.code))
1226
+ if ((error instanceof ApiError && RETRYABLE.has(error.code)) || (error instanceof HookFailed && error.retryable))
1132
1227
  return this.failedTry(triggerId, key, error);
1133
- await this.failed(triggerId, key, errorOf(error), runId);
1228
+ await this.failed(triggerId, key, errorOf(error), runId, failedReason(error));
1134
1229
  }
1135
1230
  /** A start_run firing handed to the host by the launch hook, never started here. The run the host started for it
1136
1231
  * (handedStart: under the firing's key) makes it started, as a run started here would, whatever the hook answered;
1137
1232
  * else a 2xx makes it sent, with no run (its attrs kept for a run the host starts late: handedRan) and its startBy
1138
- * LAUNCH_HOOK_LATE_START_MS after that answer, and any other answer or none skipped with why. The server's stop leaves
1139
- * it due, so the next start hands it again under the same webhook-id (or finds the run the host started). */
1233
+ * LAUNCH_HOOK_LATE_START_MS after that answer, and any other answer or none is a failed try (answered). The server's
1234
+ * stop leaves it due, so the next start hands it again under the same webhook-id (or finds the run the host started). */
1140
1235
  async handed(trigger, firing, hook) {
1141
1236
  if (trigger.target.kind !== "start_run")
1142
1237
  return;
@@ -1145,35 +1240,34 @@ export class Triggers {
1145
1240
  firing_id: firing.key, trigger_id: trigger.id, agent_id: agentId, revision_id: (await this.store.agents.get(agentId))?.currentRevision ?? null,
1146
1241
  input: this.inputOf(trigger, firing), fired_at: second(firing.nominalAt),
1147
1242
  };
1148
- const handed = await handToHost(hook, sent, this.stopping.signal, () => this.clock.now());
1243
+ const handed = await handToHost(hook, sent, this.stopping.signal, () => this.clock.now()).catch((error) => (error instanceof HookFailed ? error : Promise.reject(error)));
1149
1244
  if (this.closed || "stopped" in handed)
1150
1245
  return;
1246
+ // handedRan starts the firing with its run once: the host's own start may have already.
1151
1247
  const linked = await this.deps.runOf(firing.key);
1152
1248
  if (this.closed)
1153
1249
  return;
1154
1250
  if (linked)
1155
- return void (await this.started(trigger.id, firing.key, linked.run_id));
1156
- if ("skipped" in handed) {
1157
- await this.store.triggers.settle(trigger.id, firing.key, { status: "skipped", reason: handed.skipped });
1158
- this.deps.say({ condition: "trigger_hook_skipped", trigger: trigger.id, firing: firing.key });
1159
- return;
1160
- }
1161
- await this.store.triggers.settle(trigger.id, firing.key, { status: "sent", reason: HANDED_NO_RUN, keepAttrs: true, startBy: this.clock.now() + LAUNCH_HOOK_LATE_START_MS }, { reset: true });
1162
- // The host may start the run right after its answer: one it started between the read above and this write found the
1163
- // firing still due (handedRan left it), so it is read again here.
1251
+ return void (await this.handedRan(trigger.id, firing.key, linked.run_id));
1252
+ if (handed instanceof HookFailed)
1253
+ return void (await this.answered(trigger.id, firing.key, handed));
1254
+ // Sent only while it is due: a host start between the read above and this write left it started with its run.
1255
+ await this.store.triggers.settle(trigger.id, firing.key, { status: "sent", reason: HANDED_NO_RUN, keepAttrs: true, startBy: this.clock.now() + LAUNCH_HOOK_LATE_START_MS, from: "due" }, { reset: true });
1256
+ // The host may start the run right after its answer: one it started after this write is read again here.
1164
1257
  const after = await this.deps.runOf(firing.key);
1165
1258
  if (this.closed)
1166
1259
  return;
1167
1260
  if (after)
1168
- return void (await this.started(trigger.id, firing.key, after.run_id));
1261
+ return void (await this.handedRan(trigger.id, firing.key, after.run_id));
1169
1262
  this.deps.say({ condition: "trigger_handed", trigger: trigger.id, firing: firing.key });
1170
1263
  }
1171
- /** The run the host starts through the API for a firing the launch hook handed it (RunCreate `trigger_firing`): the
1172
- * firing's key (the run's origin key, so the firing finds it), and the trigger, input origin and title its own start
1173
- * would give the run; or the run already started under that key. Refused, in words, unless this server has the hook and
1174
- * the firing, of a start_run trigger on `agentId`, is due (being handed over) or one its host took with no run, up to
1175
- * its startBy (the host may answer first and start the run after). */
1176
- async handedStart(given, agentId) {
1264
+ /** The run the host starts through the API for a firing the launch hook handed it (RunCreate `trigger_firing`),
1265
+ * written by `start` from the firing's key (the run's origin key, so the firing finds it), the trigger, input origin
1266
+ * and title its own start would give the run, and the target and previous-result flag it starts on (the policy's
1267
+ * start, as drive's); then the firing started with it (handedRan). Or the run already started under that key,
1268
+ * `replayed`. Refused, in words, unless this server has the hook and the firing, of a start_run trigger on `agentId`,
1269
+ * may start now (startRoom). */
1270
+ async handedStart(given, agentId, start) {
1177
1271
  const refused = (reason, message, field = "trigger_firing") => invalid([{ field, reason, message }]);
1178
1272
  if (!this.deps.launchHook)
1179
1273
  throw refused("not_allowed", "This server has no launch hook: a run starts as a trigger firing's only when the hook handed that firing to its host.");
@@ -1198,26 +1292,133 @@ export class Triggers {
1198
1292
  const prior = await this.deps.runOf(key);
1199
1293
  if (prior) {
1200
1294
  await this.handedRan(triggerId, key, prior.run_id);
1201
- return prior;
1295
+ return { run_id: prior.run_id, replayed: true };
1202
1296
  }
1203
- const minutes = LAUNCH_HOOK_LATE_START_MS / 60_000;
1204
- const taken = firing.status === "sent" && firing.runId === null && firing.reason === HANDED_NO_RUN;
1205
- if (taken && (firing.startBy === null || this.clock.now() > firing.startBy)) {
1206
- const until = firing.startBy === null ? "" : ` (start_by ${iso(firing.startBy)})`;
1207
- throw refused("not_due", `Firing ${key}'s host answered without starting its run, and the ${minutes} minutes after its host answered in which it may still start it have passed${until}.`, "trigger_firing.firing_id");
1297
+ const room = await this.checked(triggerId, () => this.startRoom(trigger, key));
1298
+ // Its start_by moved under the check (its run started meanwhile, by another start of it): read again from the top.
1299
+ if (!room)
1300
+ return this.handedStart(given, agentId, start);
1301
+ if ("replay" in room) {
1302
+ await this.handedRan(triggerId, key, room.replay);
1303
+ return { run_id: room.replay, replayed: true };
1208
1304
  }
1209
- if (firing.status !== "due" && !taken) {
1210
- throw refused("not_due", `Firing ${key} is ${firing.status}${firing.reason ? ` (${firing.reason})` : ""}: a run starts only for a firing the launch hook is handing over, or one its host took within ${minutes} minutes of its answer.`, "trigger_firing.firing_id");
1305
+ if ("follow" in room) {
1306
+ // Another start of the firing on this server is writing its run: that run is this start's answer. One that wrote
1307
+ // none leaves this start to try on its own.
1308
+ const run = await room.follow;
1309
+ return run ? { run_id: run.run_id, replayed: true } : this.handedStart(given, agentId, start);
1211
1310
  }
1212
- const attrs = firing.attrs;
1213
- return { key, trigger: { id: triggerId, firing_key: key, name: trigger.name, ...(attrs && Object.keys(attrs).length ? { attrs } : {}) }, from: this.originOf(trigger), title: this.titleOf(trigger, firing) };
1311
+ let run;
1312
+ try {
1313
+ const attrs = room.firing.attrs;
1314
+ run = await start({
1315
+ key, trigger: { id: triggerId, firing_key: key, name: trigger.name, ...(attrs && Object.keys(attrs).length ? { attrs } : {}) }, from: this.originOf(trigger), title: this.titleOf(trigger, room.firing),
1316
+ target: trigger.target, previous: carriesPrevious(this.adapter(trigger.source)),
1317
+ });
1318
+ room.ran(run);
1319
+ try {
1320
+ await this.handedRan(triggerId, key, run.run_id);
1321
+ }
1322
+ catch (error) {
1323
+ // Its run is written but the firing's start is not: the firing's next turn starts it with the run under its key,
1324
+ // so the run is counted while it works.
1325
+ void this.inTurn(triggerId, key);
1326
+ throw error;
1327
+ }
1328
+ return { run_id: run.run_id, replayed: false };
1329
+ }
1330
+ finally {
1331
+ // No run written: a start_by this start pushed out goes back, so a host's failed starts never extend its window.
1332
+ if (!run && room.pushed)
1333
+ await this.unpush(triggerId, key, room.firing.reason, room.pushed);
1334
+ room.release();
1335
+ }
1336
+ }
1337
+ /** Firing `key`'s startBy, which a host start pushed out from `pushed.from` to `pushed.to` and then wrote no run, put
1338
+ * back: only while it is still sent with no run at `pushed.to`. A store that does not answer leaves it pushed, a minute
1339
+ * past that start's beginning at most. */
1340
+ async unpush(triggerId, key, reason, pushed) {
1341
+ try {
1342
+ await this.store.triggers.settle(triggerId, key, { status: "sent", reason, keepAttrs: true, startBy: pushed.from, from: "sent", startByWas: pushed.to });
1343
+ }
1344
+ catch (error) {
1345
+ this.deps.say({ condition: "trigger_start_by_kept", trigger: triggerId, firing: key, error: String(error?.message ?? error) });
1346
+ }
1347
+ }
1348
+ /** Firing `key` of `triggerId` held mid-hand (hold) by a host start writing its run, and in starting until `release`:
1349
+ * `ran` gives another start of the firing meanwhile the run written. A start that wrote none arms the timer again on
1350
+ * release, so a retry that came due while it wrote (left to it by drive and arm) is driven at once, and a later one at
1351
+ * its time. */
1352
+ startHold(triggerId, key) {
1353
+ const release = this.hold(triggerId, key);
1354
+ let answer;
1355
+ const run = new Promise((resolve) => (answer = resolve));
1356
+ let written = false;
1357
+ this.starting.set(key, run);
1358
+ return {
1359
+ ran: (done) => {
1360
+ written = true;
1361
+ answer(done);
1362
+ },
1363
+ release: () => {
1364
+ answer(undefined);
1365
+ if (this.starting.get(key) === run)
1366
+ this.starting.delete(key);
1367
+ release();
1368
+ if (!written && !this.closed)
1369
+ void this.arm();
1370
+ },
1371
+ };
1214
1372
  }
1215
- /** Run `runId`, which the host started for firing `key` (handedStart), started: one whose host answered first (sent,
1216
- * with no run) is made started here, as handed() makes it when the run came first, so the overlap check and
1217
- * max_active_runs count it. A firing still being handed is left to handed(), which reads its run after the answer. */
1373
+ /** Whether the host may start firing `key` of `trigger` now, read again within its trigger's room checks (checked), and
1374
+ * what holds its room until `release`. Refused, in words, unless the firing is due (being handed over, or waiting on
1375
+ * its retry) with room by drive's own check (busy: max_active_runs, the overlap, firings mid-hand), then held mid-hand
1376
+ * until its run starts; or is one its host took with no run, up to its startBy (the host may answer first and start
1377
+ * the run after), then held mid-hand the same way, however long its run takes to write. Its startBy is pushed out to
1378
+ * at least START_WINDOW_MS from now if it is sooner, so the store holds its room too, for another server's checks.
1379
+ * Undefined when the push was not written: the firing moved meanwhile. A start that would be refused once its run is
1380
+ * under its key (`replay`) answers that run: another start of the firing (the host's repeat) wrote it since handedStart
1381
+ * read none. One while another start of the firing on this server is writing its run (starting) follows that start. */
1382
+ async startRoom(trigger, key) {
1383
+ const follow = this.starting.get(key);
1384
+ if (follow)
1385
+ return { follow };
1386
+ const refused = (reason, message) => invalid([{ field: "trigger_firing.firing_id", reason, message }]);
1387
+ const notDue = async (message) => {
1388
+ const ran = await this.deps.runOf(key);
1389
+ if (ran)
1390
+ return { replay: ran.run_id };
1391
+ throw refused("not_due", message);
1392
+ };
1393
+ const firing = await this.store.triggers.firing(trigger.id, key);
1394
+ if (!firing)
1395
+ throw refused("not_found", `Trigger ${trigger.id} has no firing ${key}.`);
1396
+ const now = this.clock.now();
1397
+ const minutes = LAUNCH_HOOK_LATE_START_MS / 60_000;
1398
+ if (tookWithNoRun(firing)) {
1399
+ if (now > firing.startBy)
1400
+ return notDue(`Firing ${key}'s host answered without starting its run, and the ${minutes} minutes after its host answered in which it may still start it have passed (start_by ${iso(firing.startBy)}).`);
1401
+ if (firing.startBy >= now + START_WINDOW_MS)
1402
+ return { firing, ...this.startHold(trigger.id, key) };
1403
+ const to = now + START_WINDOW_MS;
1404
+ const pushed = await this.store.triggers.settle(trigger.id, key, { status: "sent", reason: firing.reason, keepAttrs: true, startBy: to, from: "sent", holdsAt: now });
1405
+ return pushed && { firing: pushed.firing, pushed: { from: firing.startBy, to }, ...this.startHold(trigger.id, key) };
1406
+ }
1407
+ if (firing.status !== "due")
1408
+ return notDue(`Firing ${key} is ${firing.status}${firing.reason ? ` (${firing.reason})` : ""}: a run starts only for a firing the launch hook is handing over, or one its host took within ${minutes} minutes of its answer.`);
1409
+ // Another firing's run, or another hand or start on this server, may have taken its trigger's room since it was handed.
1410
+ const busy = await this.busy(trigger, firing);
1411
+ if (busy)
1412
+ return notDue(`Firing ${key} does not start now. ${"skipped" in busy ? busy.skipped : busy.reason}`);
1413
+ return { firing, ...this.startHold(trigger.id, key) };
1414
+ }
1415
+ /** Run `runId`, which the host started for firing `key` (handedStart), started: a firing with no run yet, still due
1416
+ * (being handed, or waiting on its retry after the hook failed) or one its host took first, is made started here, as
1417
+ * handed() makes it when the run came first, so the overlap check, max_active_runs and last_run_id count it. A failed
1418
+ * or settled firing is left as it is. */
1218
1419
  async handedRan(triggerId, key, runId) {
1219
1420
  const firing = await this.store.triggers.firing(triggerId, key);
1220
- if (firing?.status === "sent" && firing.runId === null && firing.reason === HANDED_NO_RUN)
1421
+ if (firing && (firing.status === "due" ? firing.runId === null : tookWithNoRun(firing)))
1221
1422
  await this.started(triggerId, key, runId);
1222
1423
  }
1223
1424
  /** Each sent firing whose host's run is in the store under its key, though the server stopped before the firing was
@@ -1243,12 +1444,17 @@ export class Triggers {
1243
1444
  this.deps.say({ condition: "trigger_fired", trigger: triggerId, firing: key, run: runId });
1244
1445
  }
1245
1446
  /** A failed firing: one more in its trigger's streak, the trigger turned off at FAILURES_TO_PAUSE, and trigger.failed
1246
- * queued (after the firing is written: a start finds one not yet queued and queues it, under the same webhook-id). */
1447
+ * queued (after the firing is written: a start finds one not yet queued and queues it, under the same webhook-id).
1448
+ * Failed only while it is due: one its host's run started meanwhile is left started, with no failure and no message. */
1247
1449
  async failed(triggerId, key, error, runId, reason) {
1248
- const settled = await this.store.triggers.settle(triggerId, key, { status: "failed", error, ...(runId ? { runId } : {}), ...(reason ? { reason } : {}) }, { failure: true, pauseAt: FAILURES_TO_PAUSE });
1450
+ const settled = await this.store.triggers.settle(triggerId, key, { status: "failed", error, ...(runId ? { runId } : {}), ...(reason ? { reason } : {}), from: "due" }, { failure: true, pauseAt: FAILURES_TO_PAUSE });
1451
+ if (!settled)
1452
+ return;
1249
1453
  await this.notifyFailed(triggerId, key);
1250
- if (settled?.paused)
1454
+ if (settled.paused) {
1455
+ this.deps.say({ condition: "trigger_auto_paused", trigger: triggerId, firing: key });
1251
1456
  await this.pausedThere(triggerId);
1457
+ }
1252
1458
  }
1253
1459
  /** Trigger `triggerId`, turned off by its failure streak: off at its sender too (offThere). */
1254
1460
  async pausedThere(triggerId) {
@@ -1338,7 +1544,8 @@ export class Triggers {
1338
1544
  soonest = Math.min(soonest, this.clock.now() + BACKOFF_MS[0]);
1339
1545
  // A due firing not being driven: at its next try; one with none (its last write did not land, so it holds no retry
1340
1546
  // time) after the table's first wait, never left with no time to drive it. A waiting one is the poll's.
1341
- else if (!this.driving.has(f.key) && f.waitsOn === null)
1547
+ // One its host's start is writing is that start's until it ends (startHold arms again then).
1548
+ else if (!this.driving.has(f.key) && !this.starting.has(f.key) && f.waitsOn === null)
1342
1549
  soonest = Math.min(soonest, f.retryAt ?? this.clock.now() + BACKOFF_MS[0]);
1343
1550
  }
1344
1551
  }
package/dist/web-fake.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // A template eval's fake of the web tools for one case (template-eval.ts, `web:` in a case's case.yaml): its runs'
2
2
  // web_search and web_fetch answer from the case, never from the network, in the shapes and through the tool names the
3
- // model sees live. `unavailable`: every search fails as keyless search past its free limit does (exa-keyless.ts
3
+ // model sees live. `unavailable`: every search fails as keyless search past its free limit does (keyless-mcp.ts
4
4
  // RATE_LIMITED), and every page fails as a fetch whose connection is refused does (the guarded direct fetch's own words,
5
5
  // web-fetch-direct.ts readDirect). A fixture: each search answered by the first answer whose `query` (a regular
6
6
  // expression, case-insensitive) matches the query, else its default; each page by the answer for exactly its URL, else
@@ -11,7 +11,7 @@
11
11
  //
12
12
  // Only the eval's own in-process runner binds it (runner/beside.ts `evalFakes`, by the agent the eval made for the run):
13
13
  // no package field, API field, setting or environment variable reaches it, so no other server's runs ever see a fake.
14
- import { RATE_LIMITED } from "./exa-keyless.js";
14
+ import { RATE_LIMITED } from "./keyless-mcp.js";
15
15
  import { clip, partProblem, TITLE_CAP, URL_MAX } from "./web-fetch-direct.js";
16
16
  import { webFetch } from "./web-fetch.js";
17
17
  import { searchArgs, snippetOf } from "./web-search.js";
@@ -135,5 +135,5 @@ export function fakeSaveOptions(fake) {
135
135
  /** A faked run's plane: web_search never a harness's own search (Claude's or Codex's, which would answer in its stead), so
136
136
  * the run's own web_search tool, the one the fake answers through, is the one its harness offers. */
137
137
  export function fakedPlane(plane) {
138
- return plane?.web_search === "native" ? { ...plane, web_search: "exa-keyless" } : plane;
138
+ return plane?.web_search === "native" ? { ...plane, web_search: "firecrawl-keyless" } : plane;
139
139
  }
@@ -104,6 +104,10 @@ export type Unread = Page & {
104
104
  };
105
105
  /** The part `part` names of a page read once, as a Page: the links with its first part only. */
106
106
  export declare function partOfRead({ text, beyond, length, links, links_omitted, html_chars, converted, ...page }: Read, part?: Part): Page;
107
+ /** A page a provider read for us as markdown (Parallel's extract, keyless Firecrawl's scrape, keyless Exa's fetch), as a
108
+ * Read: its url, title and status, the text (`whole`: all of the page's, so its length is the page's) and the links it
109
+ * holds. */
110
+ export declare const markdownRead: (url: string, title: string, text: string, whole: boolean, status?: number) => Read;
107
111
  /** The page at `url`, read once through the guarded direct fetch, or why it was not. The rest of `options` are the
108
112
  * guard's resolver and fetch, for a test; a signal ends it early. */
109
113
  export declare function readDirect(url: unknown, options?: Omit<PublicFetchOptions, "maxBytes">): Promise<Read | Unread>;