@humwick/runner 0.130.0 → 0.130.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/package.json +12 -16
  2. package/plugins/claude/.claude-plugin/plugin.json +1 -1
  3. package/plugins/claude/hooks/gate-run-guard.provisioned.mjs +31 -1
  4. package/src/adapters/claude-effort.ts +2 -4
  5. package/src/adapters/codex-launch-config.ts +4 -5
  6. package/src/adapters/codex.ts +1 -1
  7. package/src/adapters/opencode-provider.ts +7 -22
  8. package/src/adapters/opencode.ts +4 -4
  9. package/src/agent-runner/credentials.ts +42 -12
  10. package/src/agent-runner/inbox.ts +27 -0
  11. package/src/agent-runner/lifecycle-milestones.ts +0 -2
  12. package/src/bin/claude.ts +4 -0
  13. package/src/bin/codex.ts +4 -0
  14. package/src/bin/opencode.ts +4 -0
  15. package/src/index.ts +5 -2
  16. package/src/provider-setup.ts +34 -0
  17. package/src/providers.ts +2 -1
  18. package/src/runner-core.ts +18 -23
  19. package/src/spawn-input.ts +2 -1
  20. package/src/test-run-dedup.ts +59 -56
  21. package/node_modules/@humwick/offload/LICENSE +0 -167
  22. package/node_modules/@humwick/offload/README.md +0 -57
  23. package/node_modules/@humwick/offload/dist/async-runner.d.ts +0 -18
  24. package/node_modules/@humwick/offload/dist/async-runner.d.ts.map +0 -1
  25. package/node_modules/@humwick/offload/dist/async-runner.js +0 -158
  26. package/node_modules/@humwick/offload/dist/async-runner.js.map +0 -1
  27. package/node_modules/@humwick/offload/dist/envelope.d.ts +0 -25
  28. package/node_modules/@humwick/offload/dist/envelope.d.ts.map +0 -1
  29. package/node_modules/@humwick/offload/dist/envelope.js +0 -80
  30. package/node_modules/@humwick/offload/dist/envelope.js.map +0 -1
  31. package/node_modules/@humwick/offload/dist/fixtures/worker-task.d.ts +0 -10
  32. package/node_modules/@humwick/offload/dist/fixtures/worker-task.d.ts.map +0 -1
  33. package/node_modules/@humwick/offload/dist/fixtures/worker-task.js +0 -59
  34. package/node_modules/@humwick/offload/dist/fixtures/worker-task.js.map +0 -1
  35. package/node_modules/@humwick/offload/dist/index.d.ts +0 -5
  36. package/node_modules/@humwick/offload/dist/index.d.ts.map +0 -1
  37. package/node_modules/@humwick/offload/dist/index.js +0 -5
  38. package/node_modules/@humwick/offload/dist/index.js.map +0 -1
  39. package/node_modules/@humwick/offload/dist/subprocess-runner.d.ts +0 -62
  40. package/node_modules/@humwick/offload/dist/subprocess-runner.d.ts.map +0 -1
  41. package/node_modules/@humwick/offload/dist/subprocess-runner.js +0 -295
  42. package/node_modules/@humwick/offload/dist/subprocess-runner.js.map +0 -1
  43. package/node_modules/@humwick/offload/dist/types.d.ts +0 -111
  44. package/node_modules/@humwick/offload/dist/types.d.ts.map +0 -1
  45. package/node_modules/@humwick/offload/dist/types.js +0 -176
  46. package/node_modules/@humwick/offload/dist/types.js.map +0 -1
  47. package/node_modules/@humwick/offload/dist/worker-pool.d.ts +0 -23
  48. package/node_modules/@humwick/offload/dist/worker-pool.d.ts.map +0 -1
  49. package/node_modules/@humwick/offload/dist/worker-pool.js +0 -435
  50. package/node_modules/@humwick/offload/dist/worker-pool.js.map +0 -1
  51. package/node_modules/@humwick/offload/dist/worker-runtime.d.ts +0 -2
  52. package/node_modules/@humwick/offload/dist/worker-runtime.d.ts.map +0 -1
  53. package/node_modules/@humwick/offload/dist/worker-runtime.js +0 -27
  54. package/node_modules/@humwick/offload/dist/worker-runtime.js.map +0 -1
  55. package/node_modules/@humwick/offload/dist/worker.d.ts +0 -5
  56. package/node_modules/@humwick/offload/dist/worker.d.ts.map +0 -1
  57. package/node_modules/@humwick/offload/dist/worker.js +0 -1
  58. package/node_modules/@humwick/offload/dist/worker.js.map +0 -1
  59. package/node_modules/@humwick/offload/package.json +0 -46
  60. package/node_modules/@humwick/offload/src/async-runner.ts +0 -170
  61. package/node_modules/@humwick/offload/src/envelope.ts +0 -92
  62. package/node_modules/@humwick/offload/src/fixtures/worker-task.ts +0 -49
  63. package/node_modules/@humwick/offload/src/index.ts +0 -4
  64. package/node_modules/@humwick/offload/src/subprocess-runner.ts +0 -334
  65. package/node_modules/@humwick/offload/src/types.ts +0 -235
  66. package/node_modules/@humwick/offload/src/worker-pool.ts +0 -463
  67. package/node_modules/@humwick/offload/src/worker-runtime.ts +0 -32
  68. package/node_modules/@humwick/offload/src/worker.ts +0 -5
  69. package/src/gate-run-lease-probe.ts +0 -38
@@ -1,41 +1,14 @@
1
1
  import { relayEnv } from "@humwick/sdk/env";
2
- // #2142 — per-agent test-run dedup ("latest wins").
3
- //
4
- // Workers run `bun run test:affected` after every file change. When a change touches something
5
- // broad, a single run takes 10-15 minutes — and the agent starts the NEXT run long before the
6
- // previous one finishes. The stacked runs saturate the host: each one holds a gate slot, forks
7
- // its own shard processes, and the oldest run's result is thrown away the moment it lands.
8
- // Instructions don't fix this (an agent rationalizes around them), so the bound has to be
9
- // structural and live BELOW the agent: the runner watches its own session's process tree and,
10
- // whenever it sees more than one independent test run, kills every run except the newest.
11
- //
12
- // Scoping is per-agent BY CONSTRUCTION: the sweep only ever looks at processes it can PROVE belong
13
- // to this agent — descendants of this session's provider process (the tmux pane pid / direct child
14
- // pid the adapter already resolves for busy-liveness), plus processes carrying this agent's
15
- // AGENT_RELAY_ID in their environment. A sibling agent's runs satisfy neither test, so this can
16
- // never fratricide the fleet the way a host-wide `pkill -f` would (#753). It is also
17
- // provider-agnostic — nothing here knows whether the tree belongs to Claude or Codex.
18
- //
19
- // #2461 — the env-tag half of that ownership test is new, and it is why this file exists at all
20
- // after the lease landed. Ancestry ALONE made this a no-op for the case the issue reports: a
21
- // `relay_run` gate run executes under the ORCHESTRATOR daemon, a tree that shares no ancestor with
22
- // the provider pane, so a descendant-scoped sweep could never see it. The orchestrator now stamps
23
- // AGENT_RELAY_ID onto those children, which is what makes them attributable here.
24
- //
25
- // This sweep is now the BACKSTOP, not the primary mechanism. Kill-replace happens at LAUNCH, in
26
- // sdk/src/gate-run-lease.ts, entered from `scripts/gate-slot` and the orchestrator. What is left
27
- // for the sweep is the residual shape neither front door sees: a gate run started straight from the
28
- // provider shell in a repo that does not route through `gate.sh`. It is 15s-late by construction —
29
- // that is the documented coverage gap, tracked for a launch-exact PATH shim in the follow-up issue.
30
- // When a live lease holder exists it is AUTHORITATIVE: the sweep keeps it and kills the rest, so
31
- // the two mechanisms can never disagree about which run survives.
2
+ // #3754 — the lease owns launch-time replacement. The sweep only deduplicates
3
+ // unleased runs with the same captured checkout/revision; ancestry proves ownership,
4
+ // but cannot prove two commands tested the same tree. Live leases protect whole runs.
32
5
  import { execFile } from "node:child_process";
33
6
  import { readFileSync, readdirSync } from "node:fs";
34
7
  import { promisify } from "node:util";
35
8
  import { errMessage } from "@humwick/sdk";
36
9
  import { killPid, waitForPidsExit } from "@humwick/sdk/process-utils";
37
10
  import { classifyGateRun, isTestRunCommand, type GateRunCommands } from "@humwick/sdk/gate-run-classify";
38
- import { GATE_RUN_AGENT_ENV } from "@humwick/sdk/gate-run-lease";
11
+ import { GATE_RUN_AGENT_ENV, GATE_RUN_CONTEXT_ENV, GATE_RUN_HELD_ENV, readLiveGateRunHolderPids } from "@humwick/sdk/gate-run-lease";
39
12
  import type { ManagedProcess } from "./adapter";
40
13
 
41
14
  // Re-exported so the sweep and both lease front doors share ONE definition of "is this a test run".
@@ -215,6 +188,9 @@ export interface TestRunDedupScope {
215
188
  /** Classifier override. Defaults to the argv-shape heuristic; the sweep passes a classifier bound
216
189
  * to the repo's CONFIGURED gate commands so a foreign runner (`pnpm tier:run …`) is matched too. */
217
190
  isGateRun?: (args: string) => boolean;
191
+ /** Launch-time checkout/revision identity. Missing identity cannot prove a duplicate. */
192
+ contextByPid?: ReadonlyMap<number, string>;
193
+ leasedPids?: readonly number[];
218
194
  }
219
195
 
220
196
  export function planTestRunDedup(
@@ -278,29 +254,34 @@ export function planTestRunDedup(
278
254
  }
279
255
  if (runRoots.length < 2) return EMPTY_PLAN;
280
256
 
281
- // Lower elapsed = started later = the run the agent actually wants. `ps etime` only has
282
- // second precision, though, and a Codex agent can launch two commands within that second.
283
- // Pids are allocated in start order within the host pid namespace, so the higher pid is the
284
- // newer root for this otherwise-unresolvable tie. Without this deterministic tie-breaker, two
285
- // same-second delivery runs remain tied forever and #2142 fails to bound the exact burst it
286
- // was added for. The scope is still this session's process tree only.
287
- // A live lease holder wins outright — it is the run the launch-time mechanism already chose. Only
288
- // when there is none (an ungated run in a repo without gate.sh) does newest-wins decide.
289
- const leaseKeep = scope.keepPid !== undefined && runRoots.includes(scope.keepPid) ? scope.keepPid : undefined;
290
- const keptPid = leaseKeep ?? runRoots.reduce((newest, pid) => {
291
- const candidate = byPid.get(pid)!;
292
- const current = byPid.get(newest)!;
293
- return candidate.elapsedSeconds < current.elapsedSeconds
294
- || (candidate.elapsedSeconds === current.elapsedSeconds && pid > newest)
295
- ? pid
296
- : newest;
297
- });
298
- const newestElapsed = byPid.get(keptPid)!.elapsedSeconds;
299
- const staleRoots = runRoots
300
- // With a lease holder the age comparison is meaningless — the holder may be the OLDER run, and
301
- // it still wins. Without one, keep the original guard so a mis-ranked row is never killed.
302
- .filter((pid) => pid !== keptPid && (leaseKeep !== undefined || byPid.get(pid)!.elapsedSeconds >= newestElapsed))
303
- .sort((a, b) => a - b);
257
+ // A lease may belong to a child of the outer shell. Spare the WHOLE run, including
258
+ // ancestors and descendants, rather than signalling its owner indirectly (#3754).
259
+ const leased = new Set(scope.leasedPids ?? []);
260
+ const groups = new Map<string, number[]>();
261
+ const leasedRoots = new Set<number>();
262
+ for (const pid of runRoots) {
263
+ if (subtree(pid).some((child) => leased.has(child))) leasedRoots.add(pid);
264
+ const context = scope.contextByPid ? scope.contextByPid.get(pid) : "legacy";
265
+ if (!context) continue;
266
+ const group = groups.get(context) ?? [];
267
+ group.push(pid);
268
+ groups.set(context, group);
269
+ }
270
+ const staleRoots: number[] = [];
271
+ let keptPid: number | undefined;
272
+ for (const group of groups.values()) {
273
+ if (group.length < 2) continue;
274
+ const leaseKeep = scope.keepPid !== undefined && group.includes(scope.keepPid) ? scope.keepPid : undefined;
275
+ const newest = group.find((pid) => leasedRoots.has(pid)) ?? leaseKeep ?? group.reduce((current, pid) => {
276
+ const candidate = byPid.get(pid)!;
277
+ const prior = byPid.get(current)!;
278
+ return candidate.elapsedSeconds < prior.elapsedSeconds
279
+ || (candidate.elapsedSeconds === prior.elapsedSeconds && pid > current) ? pid : current;
280
+ });
281
+ keptPid = newest;
282
+ staleRoots.push(...group.filter((pid) => pid !== newest && !leasedRoots.has(pid)));
283
+ }
284
+ staleRoots.sort((a, b) => a - b);
304
285
  if (staleRoots.length === 0) return EMPTY_PLAN;
305
286
 
306
287
  const protectedSet = new Set([rootPid, ...protectedPids]);
@@ -334,6 +315,17 @@ export async function readProcessTable(timeoutMs: number = PROCESS_TABLE_TIMEOUT
334
315
  return stdout;
335
316
  }
336
317
 
318
+ /** Only launch-time metadata can distinguish revisions; today's HEAD cannot (#3754). */
319
+ export function readTestRunContext(pid: number): { context?: string; leased?: boolean } {
320
+ try {
321
+ const env = Object.fromEntries(readFileSync(`/proc/${pid}/environ`, "utf8").split("\0").map((entry) => {
322
+ const equals = entry.indexOf("=");
323
+ return [entry.slice(0, equals), entry.slice(equals + 1)];
324
+ }));
325
+ return { context: relayEnv(env, GATE_RUN_CONTEXT_ENV), leased: !!relayEnv(env, GATE_RUN_HELD_ENV) };
326
+ } catch { return {}; }
327
+ }
328
+
337
329
  export interface TestRunDedupDeps {
338
330
  /** Resolve this session's provider pid. undefined ⇒ ancestry proves nothing; the env tag may. */
339
331
  rootPid: () => number | undefined;
@@ -344,6 +336,8 @@ export interface TestRunDedupDeps {
344
336
  gateCommands?: () => GateRunCommands;
345
337
  /** The live lease holder pid, when one exists — authoritative over newest-wins. */
346
338
  leaseHolderPid?: () => number | undefined;
339
+ readRunContext?: (pid: number) => { context?: string; leased?: boolean };
340
+ liveLeasePids?: () => Promise<number[]>;
347
341
  collectOwnedPids?: (agentId: string) => Promise<number[]>;
348
342
  readProcessTable?: () => Promise<string>;
349
343
  kill?: (pid: number, signal: "SIGTERM" | "SIGKILL") => void;
@@ -374,8 +368,17 @@ export async function runTestRunDedupSweep(deps: TestRunDedupDeps): Promise<numb
374
368
  }
375
369
 
376
370
  const gateCommands = deps.gateCommands?.() ?? {};
377
- const plan = planTestRunDedup(parseProcessTable(table), rootPid, deps.protectedPids?.() ?? [], {
378
- ownedPids,
371
+ const rows = parseProcessTable(table);
372
+ const contextByPid = new Map<number, string>();
373
+ const leasedPids = await (deps.liveLeasePids ?? (() => agentId ? readLiveGateRunHolderPids(agentId) : Promise.resolve([])))();
374
+ for (const row of rows) {
375
+ if (classifyGateRun(row.args, gateCommands) === null) continue;
376
+ const context = (deps.readRunContext ?? readTestRunContext)(row.pid);
377
+ if (context.context) contextByPid.set(row.pid, context.context);
378
+ if (context.leased) leasedPids.push(row.pid);
379
+ }
380
+ const plan = planTestRunDedup(rows, rootPid, deps.protectedPids?.() ?? [], {
381
+ ownedPids, contextByPid, leasedPids,
379
382
  keepPid: deps.leaseHolderPid?.(),
380
383
  isGateRun: (args) => classifyGateRun(args, gateCommands) !== null,
381
384
  });
@@ -1,167 +0,0 @@
1
- # PolyForm Shield License 1.0.0
2
-
3
- <https://polyformproject.org/licenses/shield/1.0.0>
4
-
5
- ## Acceptance
6
-
7
- In order to get any license under these terms, you must agree
8
- to them as both strict obligations and conditions to all
9
- your licenses.
10
-
11
- ## Copyright License
12
-
13
- The licensor grants you a copyright license for the
14
- software to do everything you might do with the software
15
- that would otherwise infringe the licensor's copyright
16
- in it for any permitted purpose. However, you may
17
- only distribute the software according to [Distribution
18
- License](#distribution-license) and make changes or new works
19
- based on the software according to [Changes and New Works
20
- License](#changes-and-new-works-license).
21
-
22
- ## Distribution License
23
-
24
- The licensor grants you an additional copyright license
25
- to distribute copies of the software. Your license
26
- to distribute covers distributing the software with
27
- changes and new works permitted by [Changes and New Works
28
- License](#changes-and-new-works-license).
29
-
30
- ## Notices
31
-
32
- You must ensure that anyone who gets a copy of any part of
33
- the software from you also gets a copy of these terms or the
34
- URL for them above, as well as copies of any plain-text lines
35
- beginning with `Required Notice:` that the licensor provided
36
- with the software. For example:
37
-
38
- > Required Notice: Copyright Yoyodyne, Inc. (http://example.com)
39
-
40
- ## Changes and New Works License
41
-
42
- The licensor grants you an additional copyright license to
43
- make changes and new works based on the software for any
44
- permitted purpose.
45
-
46
- ## Patent License
47
-
48
- The licensor grants you a patent license for the software that
49
- covers patent claims the licensor can license, or becomes able
50
- to license, that you would infringe by using the software.
51
-
52
- ## Noncompete
53
-
54
- Any purpose is a permitted purpose, except for providing any
55
- product that competes with the software or any product the
56
- licensor or any of its affiliates provides using the software.
57
-
58
- ## Competition
59
-
60
- Goods and services compete even when they provide functionality
61
- through different kinds of interfaces or for different technical
62
- platforms. Applications can compete with services, libraries
63
- with plugins, frameworks with development tools, and so on,
64
- even if they're written in different programming languages
65
- or for different computer architectures. Goods and services
66
- compete even when provided free of charge. If you market a
67
- product as a practical substitute for the software or another
68
- product, it definitely competes.
69
-
70
- ## New Products
71
-
72
- If you are using the software to provide a product that does
73
- not compete, but the licensor or any of its affiliates brings
74
- your product into competition by providing a new version of
75
- the software or another product using the software, you may
76
- continue using versions of the software available under these
77
- terms beforehand to provide your competing product, but not
78
- any later versions.
79
-
80
- ## Discontinued Products
81
-
82
- You may begin using the software to compete with a product
83
- or service that the licensor or any of its affiliates has
84
- stopped providing, unless the licensor includes a plain-text
85
- line beginning with `Licensor Line of Business:` with the
86
- software that mentions that line of business. For example:
87
-
88
- > Licensor Line of Business: YoyodyneCMS Content Management
89
- System (http://example.com/cms)
90
-
91
- ## Sales of Business
92
-
93
- If the licensor or any of its affiliates sells a line of
94
- business developing the software or using the software
95
- to provide a product, the buyer can also enforce
96
- [Noncompete](#noncompete) for that product.
97
-
98
- ## Fair Use
99
-
100
- You may have "fair use" rights for the software under the
101
- law. These terms do not limit them.
102
-
103
- ## No Other Rights
104
-
105
- These terms do not allow you to sublicense or transfer any of
106
- your licenses to anyone else, or prevent the licensor from
107
- granting licenses to anyone else. These terms do not imply
108
- any other licenses.
109
-
110
- ## Patent Defense
111
-
112
- If you make any written claim that the software infringes or
113
- contributes to infringement of any patent, your patent license
114
- for the software granted under these terms ends immediately. If
115
- your company makes such a claim, your patent license ends
116
- immediately for work on behalf of your company.
117
-
118
- ## Violations
119
-
120
- The first time you are notified in writing that you have
121
- violated any of these terms, or done anything with the software
122
- not covered by your licenses, your licenses can nonetheless
123
- continue if you come into full compliance with these terms,
124
- and take practical steps to correct past violations, within
125
- 32 days of receiving notice. Otherwise, all your licenses
126
- end immediately.
127
-
128
- ## No Liability
129
-
130
- ***As far as the law allows, the software comes as is, without
131
- any warranty or condition, and the licensor will not be liable
132
- to you for any damages arising out of these terms or the use
133
- or nature of the software, under any kind of legal claim.***
134
-
135
- ## Definitions
136
-
137
- The **licensor** is the individual or entity offering these
138
- terms, and the **software** is the software the licensor makes
139
- available under these terms.
140
-
141
- A **product** can be a good or service, or a combination
142
- of them.
143
-
144
- **You** refers to the individual or entity agreeing to these
145
- terms.
146
-
147
- **Your company** is any legal entity, sole proprietorship,
148
- or other kind of organization that you work for, plus all
149
- its affiliates.
150
-
151
- **Affiliates** means the other organizations than an
152
- organization has control over, is under the control of, or is
153
- under common control with.
154
-
155
- **Control** means ownership of substantially all the assets of
156
- an entity, or the power to direct its management and policies
157
- by vote, contract, or otherwise. Control can be direct or
158
- indirect.
159
-
160
- **Your licenses** are all the licenses granted to you for the
161
- software under these terms.
162
-
163
- **Use** means anything you do with the software requiring one
164
- of your licenses.
165
-
166
- Required Notice: Copyright 2026 Exelerus AB
167
- Licensor Line of Business: provider-independent runtimes and coordination software for teams of AI agents
@@ -1,57 +0,0 @@
1
- # @humwick/offload
2
-
3
- Bounded execution primitives for CPU workers, cooperative async I/O, and subprocesses.
4
- All runners use `OffloadEnvelope` for timeout, abort, structured logging, labels, typed
5
- `OffloadError`, and injected escalation.
6
-
7
- ## Maintenance adoption
8
-
9
- `WorkerPool` and `SubprocessRunner` expose `offThread: true`; this is an intentional
10
- marker, not an automatic scheduler integration. A maintenance job that hands its heavy
11
- work to either runner must explicitly wire the existing #1757 seam immediately after
12
- starting it:
13
-
14
- ```ts
15
- const work = runner.run("heavy-job", input, { signal: context.signal });
16
- if (runner.offThread) context.markOffThread?.();
17
- await work;
18
- ```
19
-
20
- `AsyncRunner` is bounded but stays on the process event loop, so it does not advertise
21
- `offThread`.
22
-
23
- ## Shutdown
24
-
25
- Every runner has a teardown that cancels rather than waits: `WorkerPool.destroy()`,
26
- `AsyncRunner.destroy()` and `SubprocessRunner.destroy()` reject outstanding work with an
27
- `aborted` `OffloadError`, kill live subprocess groups, and refuse new work. `drain()` is
28
- the opposite — it waits for accepted work to finish and cancels nothing.
29
-
30
- Because subprocess children run in their own process group, they are reparented rather
31
- than reaped when the host dies; the runner installs a single process `exit` hook that
32
- SIGKILLs any group still alive. A host killed with SIGKILL cannot run that hook, so a
33
- supervisor is still the only guarantee there.
34
-
35
- ## Bounds worth knowing
36
-
37
- - `timeoutMs` (and abort) are hard for subprocesses: SIGTERM, then SIGKILL to the process
38
- group after `killGraceMs` (default 2s), so a child that traps SIGTERM cannot outlive
39
- its deadline. The concurrency slot is held until the child is actually reaped, so
40
- `stats` never reports a slot as free while its work is still running.
41
- - A non-zero exit is a failure by default (it rejects and takes an escalation strike). Probe
42
- callers whose answer *is* the exit code — `tmux has-session`, `which`, `git rev-parse`, a
43
- land gate — must declare it with `okExitCodes` (`[0, 1]`, or `"any"` when the failing codes
44
- are not enumerable). Without it the escalation signal inverts: the sink pages on a healthy
45
- fleet and then latches, so the real outage goes unreported.
46
- **`"any"` also accepts signal deaths** — 137 (SIGKILL, typically the OOM killer) and 139
47
- (SIGSEGV) come back as successes and re-arm the strike counter. That is deliberate for a
48
- land gate, where an OOM-killed gate is just a failed gate, but it means an infrastructure
49
- death reads as a healthy answer and never escalates. Prefer an explicit code list unless
50
- the failing codes genuinely cannot be enumerated; timeout and abort still throw either way.
51
- - Subprocess output is captured up to `maxOutputBytes` per stream (default 8 MiB) and the
52
- result carries `truncated`. The stream is still drained past the cap so a chatty child
53
- never blocks on a full pipe.
54
- - `AsyncRunner` work that ignores its signal keeps its slot until it returns: the cap
55
- degrades toward serial rather than over-admitting. `destroy()` still returns promptly.
56
- - A worker round-trip costs ~110µs, so tasks below roughly 1ms of CPU are not worth
57
- offloading. `run()` has no backpressure: the queue is unbounded by design.
@@ -1,18 +0,0 @@
1
- import { type OffloadDefaults, type OffloadEnvelope } from "./types.js";
2
- export interface AsyncRunnerOptions extends OffloadDefaults {
3
- concurrency: number;
4
- }
5
- export interface AsyncRunner {
6
- run<T>(taskName: string, fn: (signal: AbortSignal) => Promise<T> | T, env?: OffloadEnvelope): Promise<T>;
7
- readonly stats: {
8
- active: number;
9
- queued: number;
10
- };
11
- /** Resolves when everything accepted so far has finished. Does not cancel anything. */
12
- drain(): Promise<void>;
13
- /** Cancels in-flight work, settles every outstanding caller, and refuses new work. */
14
- destroy(): Promise<void>;
15
- }
16
- /** Bounded I/O runner. Work receives the composed signal and must cooperate with aborts. */
17
- export declare function createAsyncRunner(options: AsyncRunnerOptions): AsyncRunner;
18
- //# sourceMappingURL=async-runner.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"async-runner.d.ts","sourceRoot":"","sources":["../src/async-runner.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgE,KAAK,eAAe,EAAE,KAAK,eAAe,EAAE,MAAM,YAAY,CAAC;AAEtI,MAAM,WAAW,kBAAmB,SAAQ,eAAe;IACzD,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,WAAW;IAC1B,GAAG,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACzG,QAAQ,CAAC,KAAK,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IACnD,uFAAuF;IACvF,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,sFAAsF;IACtF,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B;AAYD,4FAA4F;AAC5F,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,kBAAkB,GAAG,WAAW,CA6I1E"}
@@ -1,158 +0,0 @@
1
- import PQueue from "p-queue";
2
- import { beginRun, finishLog, recordResult, startLog } from "./envelope.js";
3
- import { OffloadError, StrikeCounter, normalizeError, validateTimeout } from "./types.js";
4
- /** Bounded I/O runner. Work receives the composed signal and must cooperate with aborts. */
5
- export function createAsyncRunner(options) {
6
- if (!Number.isSafeInteger(options.concurrency) || options.concurrency < 1)
7
- throw new RangeError("concurrency must be a positive integer");
8
- const queue = new PQueue({ concurrency: options.concurrency });
9
- const counter = new StrikeCounter(options.escalationThreshold, options.escalationWindowAttempts);
10
- const live = new Set();
11
- let destroyed = false;
12
- const abortedError = (taskName, cause) => new OffloadError({ kind: "aborted", taskName, message: `${taskName} was aborted`, cause });
13
- const destroyedError = (taskName) => new OffloadError({ kind: "aborted", taskName, message: `${taskName} was cancelled: async runner destroyed` });
14
- return {
15
- get stats() { return { active: queue.pending, queued: queue.size }; },
16
- async run(taskName, fn, env) {
17
- const labels = env?.labels ?? {};
18
- const logger = env?.logger ?? options.logger;
19
- const sink = env?.onEscalate ?? options.onEscalate;
20
- const reportRejection = async (error) => {
21
- // Rejecting before the run reaches startLog is still a terminal outcome; without this
22
- // the structured stream shows nothing at all for it.
23
- finishLog(logger, "async", taskName, labels, performance.now(), error);
24
- await recordResult({ counter, taskName, backend: "async", labels, error, sink, logger });
25
- throw error;
26
- };
27
- if (destroyed)
28
- return reportRejection(destroyedError(taskName));
29
- if (env?.signal?.aborted)
30
- return reportRejection(abortedError(taskName, env.signal.reason));
31
- // Eagerly validated so an invalid deadline rejects with an OffloadError rather than
32
- // escaping the queue callback as a raw RangeError (#1809 P0-1, same class).
33
- try {
34
- validateTimeout(env?.timeoutMs ?? options.defaultTimeoutMs);
35
- }
36
- catch (error) {
37
- return reportRejection(normalizeError(taskName, error, "rejected"));
38
- }
39
- let publish;
40
- let published = false;
41
- const outcome = new Promise((resolve) => {
42
- publish = (value) => { if (!published) {
43
- published = true;
44
- resolve(value);
45
- } };
46
- });
47
- let started = false;
48
- let cancelled = false;
49
- const entry = {
50
- taskName,
51
- teardown: new AbortController(),
52
- settled: outcome.then(() => undefined),
53
- cancelIfQueued: (error) => {
54
- if (started || cancelled)
55
- return;
56
- cancelled = true;
57
- // The single funnel for both abort-while-queued and destroy()-cancels-queued, so
58
- // the one line each terminal path owes the structured stream is emitted here. The
59
- // callback bails on `cancelled` without logging, which keeps it to exactly one.
60
- finishLog(logger, "async", taskName, labels, performance.now(), error);
61
- publish({ ok: false, error });
62
- },
63
- };
64
- live.add(entry);
65
- // p-queue's own `signal` option used to provide this, but it also released the slot
66
- // while the work kept running (#1809 P1-7). Cancelling here keeps abort prompt for
67
- // queued work without lying about occupancy.
68
- const signal = env?.signal;
69
- const onQueuedAbort = signal ? () => entry.cancelIfQueued(abortedError(taskName, signal.reason)) : undefined;
70
- if (signal && onQueuedAbort)
71
- signal.addEventListener("abort", onQueuedAbort, { once: true });
72
- const task = queue.add(async () => {
73
- if (signal && onQueuedAbort)
74
- signal.removeEventListener("abort", onQueuedAbort);
75
- let work;
76
- let context;
77
- let onAbort;
78
- try {
79
- if (cancelled)
80
- return;
81
- if (destroyed || entry.teardown.signal.aborted) {
82
- const error = destroyedError(taskName);
83
- finishLog(logger, "async", taskName, labels, performance.now(), error);
84
- publish({ ok: false, error });
85
- return;
86
- }
87
- started = true;
88
- // Match WorkerPool semantics: a task's deadline starts when it receives a slot,
89
- // not while it is waiting behind unrelated bounded work.
90
- context = beginRun(taskName, env, options, entry.teardown.signal);
91
- const run = context;
92
- const startedAt = startLog(logger, "async", taskName, labels);
93
- try {
94
- if (run.signal.aborted)
95
- throw run.abortError();
96
- const abort = new Promise((_, reject) => {
97
- onAbort = () => reject(run.abortError());
98
- run.signal.addEventListener("abort", onAbort, { once: true });
99
- });
100
- work = Promise.resolve().then(() => fn(run.signal));
101
- const value = await Promise.race([work, abort]);
102
- finishLog(logger, "async", taskName, labels, startedAt);
103
- await recordResult({ counter, taskName, backend: "async", labels, sink, logger });
104
- publish({ ok: true, value });
105
- }
106
- catch (error) {
107
- const normalized = run.signal.aborted ? run.abortError() : normalizeError(taskName, error);
108
- finishLog(logger, "async", taskName, labels, startedAt, normalized);
109
- await recordResult({ counter, taskName, backend: "async", labels, error: normalized, sink, logger });
110
- publish({ ok: false, error: normalized });
111
- }
112
- finally {
113
- // The composite signal stays reachable from the caller's long-lived signal, so an
114
- // un-removed listener retains this closure for the process lifetime (#1809 P0-4).
115
- if (onAbort)
116
- run.signal.removeEventListener("abort", onAbort);
117
- run.cleanup();
118
- }
119
- }
120
- catch (error) {
121
- const normalized = normalizeError(taskName, error, "rejected");
122
- finishLog(logger, "async", taskName, labels, performance.now(), normalized);
123
- await recordResult({ counter, taskName, backend: "async", labels, error: normalized, sink, logger });
124
- publish({ ok: false, error: normalized });
125
- }
126
- finally {
127
- context?.cleanup();
128
- // The caller may already have been settled by the abort race; the slot stays held
129
- // until the work itself finishes, otherwise the cap admits a replacement while the
130
- // aborted task is still running and `stats` under-reports it (#1809 P1-7).
131
- if (work)
132
- await work.catch(() => undefined);
133
- live.delete(entry);
134
- }
135
- });
136
- // The callback settles callers through `publish` and never throws, but a stray
137
- // rejection here would surface as an unhandled rejection rather than a failed run.
138
- void task.catch(() => undefined);
139
- const result = await outcome;
140
- if (!result.ok)
141
- throw result.error;
142
- return result.value;
143
- },
144
- drain: () => queue.onIdle(),
145
- async destroy() {
146
- destroyed = true;
147
- const outstanding = [...live];
148
- for (const entry of outstanding) {
149
- entry.cancelIfQueued(destroyedError(entry.taskName));
150
- entry.teardown.abort(new DOMException("Async runner destroyed", "AbortError"));
151
- }
152
- // Waits on caller settlement rather than `queue.onIdle()`: work that ignores its signal
153
- // must not be able to make teardown hang. Its slot is still held until it finishes.
154
- await Promise.all(outstanding.map((entry) => entry.settled));
155
- },
156
- };
157
- }
158
- //# sourceMappingURL=async-runner.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"async-runner.js","sourceRoot":"","sources":["../src/async-runner.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,SAAS,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,YAAY,EAAE,QAAQ,EAAmB,MAAM,eAAe,CAAC;AAC7F,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,eAAe,EAA8C,MAAM,YAAY,CAAC;AAyBtI,4FAA4F;AAC5F,MAAM,UAAU,iBAAiB,CAAC,OAA2B;IAC3D,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,OAAO,CAAC,WAAW,GAAG,CAAC;QAAE,MAAM,IAAI,UAAU,CAAC,wCAAwC,CAAC,CAAC;IAC1I,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,EAAE,WAAW,EAAE,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;IAC/D,MAAM,OAAO,GAAG,IAAI,aAAa,CAAC,OAAO,CAAC,mBAAmB,EAAE,OAAO,CAAC,wBAAwB,CAAC,CAAC;IACjG,MAAM,IAAI,GAAG,IAAI,GAAG,EAAW,CAAC;IAChC,IAAI,SAAS,GAAG,KAAK,CAAC;IAEtB,MAAM,YAAY,GAAG,CAAC,QAAgB,EAAE,KAAe,EAAgB,EAAE,CACvE,IAAI,YAAY,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,QAAQ,cAAc,EAAE,KAAK,EAAE,CAAC,CAAC;IAC7F,MAAM,cAAc,GAAG,CAAC,QAAgB,EAAg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YACH,CAAC,CAAC,CAAC;YACH,+EAA+E;YAC/E,mFAAmF;YACnF,KAAK,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;YAEjC,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC;YAC7B,IAAI,CAAC,MAAM,CAAC,EAAE;gBAAE,MAAM,MAAM,CAAC,KAAK,CAAC;YACnC,OAAO,MAAM,CAAC,KAAK,CAAC;QACtB,CAAC;QACD,KAAK,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE;QAC3B,KAAK,CAAC,OAAO;YACX,SAAS,GAAG,IAAI,CAAC;YACjB,MAAM,WAAW,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC;YAC9B,KAAK,MAAM,KAAK,IAAI,WAAW,EAAE,CAAC;gBAChC,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;gBACrD,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,YAAY,CAAC,wBAAwB,EAAE,YAAY,CAAC,CAAC,CAAC;YACjF,CAAC;YACD,wFAAwF;YACxF,oFAAoF;YACpF,MAAM,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;QAC/D,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -1,25 +0,0 @@
1
- import { OffloadError, type OffloadDefaults, type OffloadEnvelope, type OffloadLogger, type EscalationEvent, type EscalationSink, type StrikeCounter } from "./types.js";
2
- export interface RunContext {
3
- signal: AbortSignal;
4
- timeoutMs?: number;
5
- cleanup(): void;
6
- abortError(): OffloadError;
7
- }
8
- /**
9
- * `teardown` is the backend's own cancellation channel (runner `destroy()`); it is composed
10
- * with the caller's signal and the deadline so every backend has exactly one signal to observe.
11
- */
12
- export declare function beginRun(taskName: string, env: OffloadEnvelope | undefined, defaults: OffloadDefaults, teardown?: AbortSignal, timeoutMsOverride?: number | null): RunContext;
13
- export declare function startLog(logger: OffloadLogger | undefined, backend: EscalationEvent["backend"], taskName: string, labels: Record<string, string>): number;
14
- export declare function finishLog(logger: OffloadLogger | undefined, backend: EscalationEvent["backend"], taskName: string, labels: Record<string, string>, startedAt: number, error?: OffloadError): void;
15
- export declare function recordResult(options: {
16
- counter: StrikeCounter;
17
- taskName: string;
18
- backend: EscalationEvent["backend"];
19
- labels: Record<string, string>;
20
- error?: OffloadError;
21
- sink?: EscalationSink;
22
- logger?: OffloadLogger;
23
- }): Promise<void>;
24
- export declare function errorForExit(taskName: string, code?: string): OffloadError;
25
- //# sourceMappingURL=envelope.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"envelope.d.ts","sourceRoot":"","sources":["../src/envelope.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,KAAK,eAAe,EAAE,KAAK,eAAe,EAAE,KAAK,aAAa,EAAE,KAAK,eAAe,EAAE,KAAK,cAAc,EAAE,KAAK,aAAa,EAAwB,MAAM,YAAY,CAAC;AAE/L,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,WAAW,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,IAAI,IAAI,CAAC;IAChB,UAAU,IAAI,YAAY,CAAC;CAC5B;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,eAAe,GAAG,SAAS,EAAE,QAAQ,EAAE,eAAe,EAAE,QAAQ,CAAC,EAAE,WAAW,EAAE,iBAAiB,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,UAAU,CA8B7K;AAKD,wBAAgB,QAAQ,CAAC,MAAM,EAAE,aAAa,GAAG,SAAS,EAAE,OAAO,EAAE,eAAe,CAAC,SAAS,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM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