harness-dispatch 0.9.0 → 0.10.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/CHANGELOG.md +560 -1
- package/README.md +74 -43
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js.map +1 -1
- package/dist/bin.d.ts.map +1 -1
- package/dist/bin.js +166 -29
- package/dist/bin.js.map +1 -1
- package/dist/config/coercions.d.ts +5 -0
- package/dist/config/coercions.d.ts.map +1 -1
- package/dist/config/coercions.js +8 -0
- package/dist/config/coercions.js.map +1 -1
- package/dist/config/protocol.js.map +1 -1
- package/dist/config/validation.d.ts.map +1 -1
- package/dist/config/validation.js.map +1 -1
- package/dist/config.d.ts +11 -3
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +111 -148
- package/dist/config.js.map +1 -1
- package/dist/configure-yaml.d.ts.map +1 -1
- package/dist/configure-yaml.js +57 -13
- package/dist/configure-yaml.js.map +1 -1
- package/dist/dispatch-log.d.ts.map +1 -1
- package/dist/dispatch-log.js +3 -1
- package/dist/dispatch-log.js.map +1 -1
- package/dist/dispatchers/generic-cli.d.ts.map +1 -1
- package/dist/dispatchers/generic-cli.js +189 -97
- package/dist/dispatchers/generic-cli.js.map +1 -1
- package/dist/dispatchers/openai-compatible.d.ts +0 -5
- package/dist/dispatchers/openai-compatible.d.ts.map +1 -1
- package/dist/dispatchers/openai-compatible.js +129 -82
- package/dist/dispatchers/openai-compatible.js.map +1 -1
- package/dist/dispatchers/shared/harness-login.d.ts.map +1 -1
- package/dist/dispatchers/shared/harness-login.js +7 -2
- package/dist/dispatchers/shared/harness-login.js.map +1 -1
- package/dist/dispatchers/shared/stream-subprocess.d.ts.map +1 -1
- package/dist/dispatchers/shared/stream-subprocess.js +7 -60
- package/dist/dispatchers/shared/stream-subprocess.js.map +1 -1
- package/dist/file-lock.d.ts.map +1 -1
- package/dist/file-lock.js +31 -19
- package/dist/file-lock.js.map +1 -1
- package/dist/harness-presets.d.ts +51 -0
- package/dist/harness-presets.d.ts.map +1 -0
- package/dist/harness-presets.js +154 -0
- package/dist/harness-presets.js.map +1 -0
- package/dist/http/parse.d.ts +8 -1
- package/dist/http/parse.d.ts.map +1 -1
- package/dist/http/parse.js +10 -3
- package/dist/http/parse.js.map +1 -1
- package/dist/http/server.d.ts.map +1 -1
- package/dist/http/server.js +9 -2
- package/dist/http/server.js.map +1 -1
- package/dist/job-runner.js +6 -0
- package/dist/job-runner.js.map +1 -1
- package/dist/jobs/lifecycle.d.ts +100 -0
- package/dist/jobs/lifecycle.d.ts.map +1 -0
- package/dist/jobs/lifecycle.js +263 -0
- package/dist/jobs/lifecycle.js.map +1 -0
- package/dist/jobs/read.d.ts +17 -0
- package/dist/jobs/read.d.ts.map +1 -0
- package/dist/jobs/read.js +103 -0
- package/dist/jobs/read.js.map +1 -0
- package/dist/jobs/run.d.ts +45 -0
- package/dist/jobs/run.d.ts.map +1 -0
- package/dist/jobs/run.js +351 -0
- package/dist/jobs/run.js.map +1 -0
- package/dist/jobs/start.d.ts +9 -0
- package/dist/jobs/start.d.ts.map +1 -0
- package/dist/jobs/start.js +126 -0
- package/dist/jobs/start.js.map +1 -0
- package/dist/jobs/store.d.ts.map +1 -1
- package/dist/jobs/store.js +13 -3
- package/dist/jobs/store.js.map +1 -1
- package/dist/jobs/supervisor.d.ts +151 -0
- package/dist/jobs/supervisor.d.ts.map +1 -0
- package/dist/jobs/supervisor.js +679 -0
- package/dist/jobs/supervisor.js.map +1 -0
- package/dist/jobs.d.ts +15 -233
- package/dist/jobs.d.ts.map +1 -1
- package/dist/jobs.js +14 -1409
- package/dist/jobs.js.map +1 -1
- package/dist/leaderboard.d.ts.map +1 -1
- package/dist/leaderboard.js +5 -1
- package/dist/leaderboard.js.map +1 -1
- package/dist/mcp/config-hot-reload.d.ts.map +1 -1
- package/dist/mcp/config-hot-reload.js +4 -1
- package/dist/mcp/config-hot-reload.js.map +1 -1
- package/dist/mcp/dispatcher-factory.js +1 -1
- package/dist/mcp/dispatcher-factory.js.map +1 -1
- package/dist/mcp/resources.d.ts.map +1 -1
- package/dist/mcp/resources.js +3 -2
- package/dist/mcp/resources.js.map +1 -1
- package/dist/mcp/tools.d.ts +9 -2
- package/dist/mcp/tools.d.ts.map +1 -1
- package/dist/mcp/tools.js +45 -6
- package/dist/mcp/tools.js.map +1 -1
- package/dist/observability/spans.d.ts.map +1 -1
- package/dist/observability/spans.js +10 -2
- package/dist/observability/spans.js.map +1 -1
- package/dist/redaction.d.ts +90 -0
- package/dist/redaction.d.ts.map +1 -0
- package/dist/redaction.js +221 -0
- package/dist/redaction.js.map +1 -0
- package/dist/router.d.ts +12 -23
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +83 -224
- package/dist/router.js.map +1 -1
- package/dist/state-dir.d.ts.map +1 -1
- package/dist/state-dir.js +15 -1
- package/dist/state-dir.js.map +1 -1
- package/dist/status.d.ts +14 -3
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +36 -3
- package/dist/status.js.map +1 -1
- package/dist/workspace-lock.d.ts +20 -0
- package/dist/workspace-lock.d.ts.map +1 -1
- package/dist/workspace-lock.js +63 -0
- package/dist/workspace-lock.js.map +1 -1
- package/dist/workspace-resolve.d.ts +0 -9
- package/dist/workspace-resolve.d.ts.map +1 -1
- package/dist/workspace-resolve.js +38 -183
- package/dist/workspace-resolve.js.map +1 -1
- package/dist/workspaces.d.ts.map +1 -1
- package/dist/workspaces.js +63 -139
- package/dist/workspaces.js.map +1 -1
- package/package.json +5 -4
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Admission control and the supervisor pool: who runs, when, and in which
|
|
3
|
+
* process.
|
|
4
|
+
*
|
|
5
|
+
* The concurrency cap here exists because of a measured OOM, and the pool
|
|
6
|
+
* exists because a runner process per job costs ~76 MB of wrapper. Both are
|
|
7
|
+
* load-bearing; see the comments on DEFAULT_MAX_CONCURRENT_RUNS.
|
|
8
|
+
*/
|
|
9
|
+
import type { RouterConfig } from "../types.js";
|
|
10
|
+
import type { JobDeps, JobStatus } from "./types.js";
|
|
11
|
+
/**
|
|
12
|
+
* The cap, or `null` for "no cap".
|
|
13
|
+
*
|
|
14
|
+
* `null` rather than `0`, and rather than `Infinity`, because both of those
|
|
15
|
+
* were wrong in a way that mattered. `0` used to short-circuit the whole slot
|
|
16
|
+
* queue and supervisor pool, so `max_concurrent_runs: 0` — documented as
|
|
17
|
+
* lifting a limit — silently gave every job its own runner process at ~76 MB,
|
|
18
|
+
* which is the per-job cost the pool exists to remove, on the memory-bound
|
|
19
|
+
* machine the cap exists for. And `Infinity` divides badly: the pool sizes
|
|
20
|
+
* itself with `outstanding / jobsPerSupervisor(limit)`, so an infinite limit
|
|
21
|
+
* asked for ZERO supervisors. An explicit `null` makes each site say what it
|
|
22
|
+
* means about the unbounded case.
|
|
23
|
+
*/
|
|
24
|
+
export declare function maxConcurrentRuns(config: RouterConfig | undefined): number | null;
|
|
25
|
+
/**
|
|
26
|
+
* Occupied slots: jobs actually executing right now. Counts `running` (and
|
|
27
|
+
* plain `queued` — a runner spawned but not yet started) only while the
|
|
28
|
+
* heartbeat is fresh, so a crashed runner's slot is reclaimed by the same
|
|
29
|
+
* ORPHAN_THRESHOLD_MS rule that already frees its status. Slot-queued jobs
|
|
30
|
+
* are waiting for a slot, not holding one.
|
|
31
|
+
*/
|
|
32
|
+
/**
|
|
33
|
+
* What one run of a route costs against the concurrency budget.
|
|
34
|
+
*
|
|
35
|
+
* Unknown routes count as a full 1.0 on purpose. A job that has not been
|
|
36
|
+
* routed yet (no forced `service`) has no weight to look up, and this bound
|
|
37
|
+
* exists because a measured burst of 13 concurrent CLIs exhausted memory —
|
|
38
|
+
* so the safe assumption for "might be anything" is "might be heavy".
|
|
39
|
+
*/
|
|
40
|
+
export declare function resourceWeightFor(status: JobStatus, config: RouterConfig | undefined): number;
|
|
41
|
+
/**
|
|
42
|
+
* Capacity currently in use, as a weighted sum rather than a job count.
|
|
43
|
+
*
|
|
44
|
+
* With every weight at 1.0 this is exactly the old count, so an existing
|
|
45
|
+
* `max_concurrent_runs` keeps its previous meaning.
|
|
46
|
+
*/
|
|
47
|
+
export declare function activeCapacity(statuses: Array<{
|
|
48
|
+
status: JobStatus;
|
|
49
|
+
}>, config: RouterConfig | undefined): number;
|
|
50
|
+
/**
|
|
51
|
+
* How many supervisor PROCESSES may exist, regardless of how many jobs run.
|
|
52
|
+
*
|
|
53
|
+
* Previously every job got its own detached Node process. Measured on Windows
|
|
54
|
+
* with Node 24: a bare node process is 52 MB RSS and one that has bootstrapped
|
|
55
|
+
* a runtime is 65 MB, against ~54 MB for the agent CLI it exists to supervise.
|
|
56
|
+
* So more than half the memory of a concurrent run was wrapper, and it scaled
|
|
57
|
+
* linearly — 13 concurrent jobs meant 845 MB of supervision before any agent
|
|
58
|
+
* had read a file. That is the concurrency ceiling.
|
|
59
|
+
*
|
|
60
|
+
* A supervisor is almost entirely idle: it waits on a child process and writes
|
|
61
|
+
* the result. One can watch several at once for the cost of async I/O, so
|
|
62
|
+
* wrapper memory becomes O(1) in the number of jobs instead of O(N), capped
|
|
63
|
+
* here at ~260 MB.
|
|
64
|
+
*
|
|
65
|
+
* Four rather than one purely to bound blast radius: a supervisor crash strands
|
|
66
|
+
* only the jobs it held. Those are recoverable anyway — the job directory is
|
|
67
|
+
* the source of truth and the heartbeat check already marks stranded jobs
|
|
68
|
+
* orphaned — but losing a quarter of in-flight work beats losing all of it.
|
|
69
|
+
*/
|
|
70
|
+
export declare const SUPERVISOR_POOL_SIZE = 4;
|
|
71
|
+
/**
|
|
72
|
+
* Take exclusive ownership of a job directory.
|
|
73
|
+
*
|
|
74
|
+
* `wx` fails if the file exists, atomically, on both Windows and POSIX — which
|
|
75
|
+
* is what stops two supervisors racing onto the same job. A claim left behind
|
|
76
|
+
* by a crashed supervisor is reclaimed once that job's heartbeat has gone
|
|
77
|
+
* stale, by the same ORPHAN_THRESHOLD_MS rule used everywhere else.
|
|
78
|
+
*
|
|
79
|
+
* Exported for tests: the one-winner property under concurrent reclaim is the
|
|
80
|
+
* invariant, and it is only checkable by calling this directly.
|
|
81
|
+
*/
|
|
82
|
+
export declare function claimJobDir(jobDir: string, status: JobStatus): Promise<boolean>;
|
|
83
|
+
/**
|
|
84
|
+
* Supervisor main loop: claim work, run several jobs at once, exit when idle.
|
|
85
|
+
*
|
|
86
|
+
* Exiting on idle keeps the no-jobs steady state at zero processes, same as
|
|
87
|
+
* before — the pool is a way to share supervision cost while work exists, not
|
|
88
|
+
* a daemon.
|
|
89
|
+
*/
|
|
90
|
+
export declare function runSupervisor(deps: JobDeps, supervisorId?: string): Promise<void>;
|
|
91
|
+
/**
|
|
92
|
+
* Start slot-queued jobs, oldest first, until the machine is at its limit.
|
|
93
|
+
*
|
|
94
|
+
* Deliberately has no daemon behind it: this runs on every new dispatch and
|
|
95
|
+
* again as each runner exits, which between them covers every moment a slot
|
|
96
|
+
* can free. The cost of that choice is that if every runner dies while jobs
|
|
97
|
+
* are queued, the queue resumes on the next dispatch rather than immediately.
|
|
98
|
+
* Bounded waiting was the explicit alternative and was not chosen — a queued
|
|
99
|
+
* job keeps its jobId and its artifacts either way, so nothing is lost.
|
|
100
|
+
*
|
|
101
|
+
* NOT called at server start, which was tried and reverted: it silently ran
|
|
102
|
+
* jobs abandoned by a dead session. `orphanStrandedSlotQueue` runs there
|
|
103
|
+
* instead and reports them. See its comment for why reporting beats resuming.
|
|
104
|
+
*/
|
|
105
|
+
/**
|
|
106
|
+
* Mark jobs stranded in the slot queue by a server that is gone.
|
|
107
|
+
*
|
|
108
|
+
* Called once at server start, where the reasoning holds unconditionally: this
|
|
109
|
+
* process has not queued anything yet, so anything still slot-queued was
|
|
110
|
+
* queued by a session that no longer exists and nothing will ever drain it —
|
|
111
|
+
* a new dispatch would, but the caller is asking about THIS job, and until
|
|
112
|
+
* they happen to send unrelated work it reads `queued` forever.
|
|
113
|
+
*
|
|
114
|
+
* Deliberately reports rather than runs. Resuming was tried and is worse: a
|
|
115
|
+
* job queued days ago would execute at the next server start, in its original
|
|
116
|
+
* workingDir, at up to `full_auto`, with nobody watching. The job keeps its id
|
|
117
|
+
* and artifacts, so `retry_job` re-runs it as a decision rather than a side
|
|
118
|
+
* effect of opening an editor.
|
|
119
|
+
*
|
|
120
|
+
* The one status this writes back. Orphan detection elsewhere is
|
|
121
|
+
* compute-on-read and never persists its verdict, because the owner might
|
|
122
|
+
* still be alive; here the owner is definitionally gone.
|
|
123
|
+
*/
|
|
124
|
+
export declare function orphanStrandedSlotQueue(): Promise<number>;
|
|
125
|
+
export declare function drainSlotQueue(config: RouterConfig | undefined, configPath: string | undefined): Promise<void>;
|
|
126
|
+
/**
|
|
127
|
+
* Supervisors currently alive, counted from their heartbeat files.
|
|
128
|
+
*
|
|
129
|
+
* Approximate on purpose: over-counting briefly means the pool runs one short
|
|
130
|
+
* until the next drain, and under-counting means one extra supervisor that
|
|
131
|
+
* finds no work and exits within SUPERVISOR_IDLE_EXIT_MS. Neither warrants a
|
|
132
|
+
* lock, and both self-correct.
|
|
133
|
+
*/
|
|
134
|
+
declare function countLiveSupervisors(): Promise<number>;
|
|
135
|
+
/**
|
|
136
|
+
* Exported for the cleanup test, which must exercise the REAL sweep rather
|
|
137
|
+
* than a copy of its logic — the bug being pinned is that a stale heartbeat
|
|
138
|
+
* was never removed, and a reimplementation in the test would pin nothing.
|
|
139
|
+
*/
|
|
140
|
+
export declare const countLiveSupervisorsForTest: typeof countLiveSupervisors;
|
|
141
|
+
/**
|
|
142
|
+
* Why a detached runner would fail to bootstrap from this config path, if it
|
|
143
|
+
* would. `undefined` means the file loads (or there is none, which is the
|
|
144
|
+
* auto-detect case and always fine).
|
|
145
|
+
*
|
|
146
|
+
* Deliberately re-reads rather than trusting the server's in-memory config:
|
|
147
|
+
* the two disagreeing is exactly the condition being detected.
|
|
148
|
+
*/
|
|
149
|
+
export declare function configLoadError(configPath: string | undefined): Promise<string | undefined>;
|
|
150
|
+
export {};
|
|
151
|
+
//# sourceMappingUR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