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.
Files changed (125) hide show
  1. package/CHANGELOG.md +560 -1
  2. package/README.md +74 -43
  3. package/dist/auth.d.ts.map +1 -1
  4. package/dist/auth.js.map +1 -1
  5. package/dist/bin.d.ts.map +1 -1
  6. package/dist/bin.js +166 -29
  7. package/dist/bin.js.map +1 -1
  8. package/dist/config/coercions.d.ts +5 -0
  9. package/dist/config/coercions.d.ts.map +1 -1
  10. package/dist/config/coercions.js +8 -0
  11. package/dist/config/coercions.js.map +1 -1
  12. package/dist/config/protocol.js.map +1 -1
  13. package/dist/config/validation.d.ts.map +1 -1
  14. package/dist/config/validation.js.map +1 -1
  15. package/dist/config.d.ts +11 -3
  16. package/dist/config.d.ts.map +1 -1
  17. package/dist/config.js +111 -148
  18. package/dist/config.js.map +1 -1
  19. package/dist/configure-yaml.d.ts.map +1 -1
  20. package/dist/configure-yaml.js +57 -13
  21. package/dist/configure-yaml.js.map +1 -1
  22. package/dist/dispatch-log.d.ts.map +1 -1
  23. package/dist/dispatch-log.js +3 -1
  24. package/dist/dispatch-log.js.map +1 -1
  25. package/dist/dispatchers/generic-cli.d.ts.map +1 -1
  26. package/dist/dispatchers/generic-cli.js +189 -97
  27. package/dist/dispatchers/generic-cli.js.map +1 -1
  28. package/dist/dispatchers/openai-compatible.d.ts +0 -5
  29. package/dist/dispatchers/openai-compatible.d.ts.map +1 -1
  30. package/dist/dispatchers/openai-compatible.js +129 -82
  31. package/dist/dispatchers/openai-compatible.js.map +1 -1
  32. package/dist/dispatchers/shared/harness-login.d.ts.map +1 -1
  33. package/dist/dispatchers/shared/harness-login.js +7 -2
  34. package/dist/dispatchers/shared/harness-login.js.map +1 -1
  35. package/dist/dispatchers/shared/stream-subprocess.d.ts.map +1 -1
  36. package/dist/dispatchers/shared/stream-subprocess.js +7 -60
  37. package/dist/dispatchers/shared/stream-subprocess.js.map +1 -1
  38. package/dist/file-lock.d.ts.map +1 -1
  39. package/dist/file-lock.js +31 -19
  40. package/dist/file-lock.js.map +1 -1
  41. package/dist/harness-presets.d.ts +51 -0
  42. package/dist/harness-presets.d.ts.map +1 -0
  43. package/dist/harness-presets.js +154 -0
  44. package/dist/harness-presets.js.map +1 -0
  45. package/dist/http/parse.d.ts +8 -1
  46. package/dist/http/parse.d.ts.map +1 -1
  47. package/dist/http/parse.js +10 -3
  48. package/dist/http/parse.js.map +1 -1
  49. package/dist/http/server.d.ts.map +1 -1
  50. package/dist/http/server.js +9 -2
  51. package/dist/http/server.js.map +1 -1
  52. package/dist/job-runner.js +6 -0
  53. package/dist/job-runner.js.map +1 -1
  54. package/dist/jobs/lifecycle.d.ts +100 -0
  55. package/dist/jobs/lifecycle.d.ts.map +1 -0
  56. package/dist/jobs/lifecycle.js +263 -0
  57. package/dist/jobs/lifecycle.js.map +1 -0
  58. package/dist/jobs/read.d.ts +17 -0
  59. package/dist/jobs/read.d.ts.map +1 -0
  60. package/dist/jobs/read.js +103 -0
  61. package/dist/jobs/read.js.map +1 -0
  62. package/dist/jobs/run.d.ts +45 -0
  63. package/dist/jobs/run.d.ts.map +1 -0
  64. package/dist/jobs/run.js +351 -0
  65. package/dist/jobs/run.js.map +1 -0
  66. package/dist/jobs/start.d.ts +9 -0
  67. package/dist/jobs/start.d.ts.map +1 -0
  68. package/dist/jobs/start.js +126 -0
  69. package/dist/jobs/start.js.map +1 -0
  70. package/dist/jobs/store.d.ts.map +1 -1
  71. package/dist/jobs/store.js +13 -3
  72. package/dist/jobs/store.js.map +1 -1
  73. package/dist/jobs/supervisor.d.ts +151 -0
  74. package/dist/jobs/supervisor.d.ts.map +1 -0
  75. package/dist/jobs/supervisor.js +679 -0
  76. package/dist/jobs/supervisor.js.map +1 -0
  77. package/dist/jobs.d.ts +15 -233
  78. package/dist/jobs.d.ts.map +1 -1
  79. package/dist/jobs.js +14 -1409
  80. package/dist/jobs.js.map +1 -1
  81. package/dist/leaderboard.d.ts.map +1 -1
  82. package/dist/leaderboard.js +5 -1
  83. package/dist/leaderboard.js.map +1 -1
  84. package/dist/mcp/config-hot-reload.d.ts.map +1 -1
  85. package/dist/mcp/config-hot-reload.js +4 -1
  86. package/dist/mcp/config-hot-reload.js.map +1 -1
  87. package/dist/mcp/dispatcher-factory.js +1 -1
  88. package/dist/mcp/dispatcher-factory.js.map +1 -1
  89. package/dist/mcp/resources.d.ts.map +1 -1
  90. package/dist/mcp/resources.js +3 -2
  91. package/dist/mcp/resources.js.map +1 -1
  92. package/dist/mcp/tools.d.ts +9 -2
  93. package/dist/mcp/tools.d.ts.map +1 -1
  94. package/dist/mcp/tools.js +45 -6
  95. package/dist/mcp/tools.js.map +1 -1
  96. package/dist/observability/spans.d.ts.map +1 -1
  97. package/dist/observability/spans.js +10 -2
  98. package/dist/observability/spans.js.map +1 -1
  99. package/dist/redaction.d.ts +90 -0
  100. package/dist/redaction.d.ts.map +1 -0
  101. package/dist/redaction.js +221 -0
  102. package/dist/redaction.js.map +1 -0
  103. package/dist/router.d.ts +12 -23
  104. package/dist/router.d.ts.map +1 -1
  105. package/dist/router.js +83 -224
  106. package/dist/router.js.map +1 -1
  107. package/dist/state-dir.d.ts.map +1 -1
  108. package/dist/state-dir.js +15 -1
  109. package/dist/state-dir.js.map +1 -1
  110. package/dist/status.d.ts +14 -3
  111. package/dist/status.d.ts.map +1 -1
  112. package/dist/status.js +36 -3
  113. package/dist/status.js.map +1 -1
  114. package/dist/workspace-lock.d.ts +20 -0
  115. package/dist/workspace-lock.d.ts.map +1 -1
  116. package/dist/workspace-lock.js +63 -0
  117. package/dist/workspace-lock.js.map +1 -1
  118. package/dist/workspace-resolve.d.ts +0 -9
  119. package/dist/workspace-resolve.d.ts.map +1 -1
  120. package/dist/workspace-resolve.js +38 -183
  121. package/dist/workspace-resolve.js.map +1 -1
  122. package/dist/workspaces.d.ts.map +1 -1
  123. package/dist/workspaces.js +63 -139
  124. package/dist/workspaces.js.map +1 -1
  125. 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
+ //# sourceMappingURL=supervisor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"supervisor.d.ts","sourceRoot":"","sources":["../../src/jobs/supervisor.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAWH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAWhD,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AA6BrD;;;;;;;;;;;;GAYG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,YAAY,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAMjF;AAoBD;;;;;;GAMG;AACH;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,GAAG,SAAS,GAAG,MAAM,CAQ7F;AAeD;;;;;GAKG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,KAAK,CAAC;IAAE,MAAM,EAAE,SAAS,CAAA;CAAE,CAAC,EACtC,MAAM,EAAE,YAAY,GAAG,SAAS,GAC/B,MAAM,CAUR;AAOD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,oBAAoB,IAAI,CAAC;AAoBtC;;;;;;;;;;GAUG;AACH,wBAAsB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,CAuCrF;AAwBD;;;;;;GAMG;AACH,wBAAsB,aAAa,CAAC,IAAI,EAAE,OAAO,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAgGvF;AAED;;;;;;;;;;;;;GAaG;AACH;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,uBAAuB,IAAI,OAAO,CAAC,MAAM,CAAC,CAqC/D;AAED,wBAAsB,cAAc,CAClC,MAAM,EAAE,YAAY,GAAG,SAAS,EAChC,UAAU,EAAE,MAAM,GAAG,SAAS,GAC7B,OAAO,CAAC,IAAI,CAAC,CA6Bf;AAkGD;;;;;;;GAOG;AACH,iBAAe,oBAAoB,IAAI,OAAO,CAAC,MAAM,CAAC,CA2CrD;AAED;;;;GAIG;AACH,eAAO,MAAM,2BAA2B,6BAAuB,CAAC;AA0ChE;;;;;;;GAOG;AACH,wBAAsB,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAcjG"}