parallel-codex-tui 0.3.2 → 0.4.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/README.md +12 -7
- package/dist/cli.js +19 -1
- package/dist/orchestrator/orchestrator.js +26 -4
- package/dist/supervisor/client.js +442 -0
- package/dist/supervisor/protocol.js +177 -0
- package/dist/supervisor/runner.js +238 -0
- package/dist/supervisor/store.js +213 -0
- package/dist/tui/App.js +107 -31
- package/dist/tui/AppShell.js +7 -3
- package/dist/tui/InputBar.js +9 -3
- package/dist/version.js +1 -1
- package/dist/workers/mock-adapter.js +18 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -6,7 +6,11 @@ Built with Codex-assisted development.
|
|
|
6
6
|
|
|
7
7
|
## Current Release
|
|
8
8
|
|
|
9
|
-
`v0.
|
|
9
|
+
`v0.4.0` is available from [npm](https://www.npmjs.com/package/parallel-codex-tui/v/0.4.0) and as a [GitHub Release](https://github.com/allendred/parallel-codex-tui/releases/tag/v0.4.0). Main and parallel executions now run in a detached, per-request Supervisor after the Router resolves in the foreground. `Ctrl+C` closes the outer TUI without stopping an attached run, reopening the same workspace restores its live events or terminal result, and `Esc` remains the explicit cancellation command. One TUI owns the control lease while additional TUIs observe the same run; an observer takes control automatically after the prior controller detaches or exits.
|
|
10
|
+
|
|
11
|
+
Supervisor requests, state, events, commands, controller ownership, acknowledgements, and diagnostic output are retained under `.parallel-codex/supervisor/runs/<run-id>/`. The Supervisor writes the final chat result itself, so completion survives a closed terminal without duplicate history when the TUI is reopened. Unexpected Supervisor exit is converted into a durable failed state instead of leaving an indefinitely running UI.
|
|
12
|
+
|
|
13
|
+
In the Task session center, `Ctrl+F` searches durable evidence across Tasks and Turns, Feature names, roles, Providers, models, Worker states, summaries, and native session ids. Filters such as `turn:"中文输入" role:actor provider:codex state:done` can be combined with ordinary Unicode text; live async results reject stale responses, Enter keeps the filter, Esc restores the previously applied query, and `X` clears it.
|
|
10
14
|
|
|
11
15
|
Every Task export now includes human-readable `report.md` and structured `report.json` beside the complete raw `session/` snapshot. Reports preserve each Turn request and route, Judge requirements/plans/acceptance criteria, supervisor summaries, Feature assignments and latest review evidence, Wave verification results, Worker Provider/model/state, active native session metadata, completion contracts, and final acceptance evidence. Integrated changed paths are compared with the current workspace as `match`, `drift`, `missing`, `unexpected`, or `unavailable`; the newest integrated wave for each path is authoritative, deleted paths are represented correctly, and unsafe or symlink-traversing paths are never read.
|
|
12
16
|
|
|
@@ -33,7 +37,7 @@ Highlights:
|
|
|
33
37
|
- Named Worker Providers support Codex-compatible, Claude-compatible, OpenAI-compatible, Anthropic-compatible, and custom generic commands with independent role, model, environment, permission, resume, and interactive settings.
|
|
34
38
|
- Worker overview, Feature board, collaboration timeline, Task and Main conversation centers, status details, rendered Markdown/Diff/error logs, Unicode search, keyboard navigation, mouse scrolling, and configurable themes share one terminal UI system.
|
|
35
39
|
|
|
36
|
-
Release acceptance includes a real three-Feature Tetris task with parallel Actor/Critic waves and final integration review. A clean `v0.2.5` task also ran Codex Judge and Actor, a buffered Claude Critic that independently executed `node --test` and `npm test`, atomic integration, and a resumed Codex Judge that independently passed all seven acceptance criteria. Real Codex and Claude probes both proved fresh and same-session resume calls; Codex fresh and resume runs executed workspace writes with root-level `-a never`, and Claude automated sessions executed safe Bash tools with `auto` permissions. The semantic Router completed a live classification, and one TUI completed Main calls in two workspaces before restoring the first workspace without leaking chat state. PTY coverage runs in Apple Terminal, tmux, and Zellij profiles at narrow and wide sizes, including status/log equivalence, preserving the native output tail across status-detail round trips, and proving both inline and on-demand file memory after native-session rollover. The deterministic repository suite contains 1,
|
|
40
|
+
Release acceptance includes a real three-Feature Tetris task with parallel Actor/Critic waves and final integration review. A clean `v0.2.5` task also ran Codex Judge and Actor, a buffered Claude Critic that independently executed `node --test` and `npm test`, atomic integration, and a resumed Codex Judge that independently passed all seven acceptance criteria. Real Codex and Claude probes both proved fresh and same-session resume calls; Codex fresh and resume runs executed workspace writes with root-level `-a never`, and Claude automated sessions executed safe Bash tools with `auto` permissions. The semantic Router completed a live classification, and one TUI completed Main calls in two workspaces before restoring the first workspace without leaking chat state. PTY coverage runs in Apple Terminal, tmux, and Zellij profiles at narrow and wide sizes, including status/log equivalence, preserving the native output tail across status-detail round trips, and proving both inline and on-demand file memory after native-session rollover. Supervisor PTY coverage proves detached Main and complex execution, restart recovery, controller/observer takeover, explicit cancellation, and process-owner crash recovery. The deterministic repository suite contains 1,357 tests across 141 files: 1,356 pass by default, while one quota-consuming real-Agent test is skipped and passes through `npm run test:real-agents`.
|
|
37
41
|
|
|
38
42
|
Real Provider probes depend on valid local CLI credentials. In particular, authenticate the Claude CLI before selecting a Claude-compatible Worker, then run `parallel-codex-tui --doctor --probe-agents` to prove fresh and resumed calls on that machine.
|
|
39
43
|
|
|
@@ -250,7 +254,7 @@ The doctor output includes `preview:` and `semantic:` ANSI swatch rows so you ca
|
|
|
250
254
|
- `Ctrl+N` leaves the active complex Task and all Worker logs intact on disk, clears only the live selection and retry state, starts a new Main `conversation_id`, and retires the old Main native session. It works from ordinary chat too, so the next request cannot inherit an unrelated native or file-backed conversation; the next complex request creates an independent Task from turn `0001`.
|
|
251
255
|
- Single-feature follow-ups reuse the same Actor/Critic native sessions when available while moving them to the new turn's isolated workspace. File-backed prompt memory keeps the root Turn and the latest 19 previous Turn summaries within a 12,000-character ceiling; longer histories retain an inline count and path to every immutable Turn summary on disk. A failed follow-up retry reuses a complete saved Judge plan, or restores Judge first when the earlier Judge run never produced one.
|
|
252
256
|
- Automated Judge, Actor, Critic, Wave Actor, and Wave Critic runs enforce process-level isolation: Codex is clamped to root-level `-a never` plus `workspace-write`, and Claude is clamped to non-interactive `auto`, even when private command arguments request manual approval or contain a broader bypass mode. Native attach remains an explicit interactive path.
|
|
253
|
-
-
|
|
257
|
+
- Routing remains in the foreground so fallback choices stay interactive. After a route resolves, Main or parallel execution moves into a detached per-run Supervisor. Pressing `Esc` as the controller cancels the active run and records an interrupted complex task as `cancelled`; pressing `Ctrl+C` detaches and exits the outer TUI while execution continues. Reopening the workspace follows persisted events and restores the final result. A second TUI observes the run and automatically acquires the control lease after the previous controller detaches or exits.
|
|
254
258
|
- Failed and cancelled tasks expose `Ctrl+R` retry. Retry keeps the same task and turn, reuses recorded native worker sessions, preserves prior output behind a retry separator, does not route the request again, and reuses the persisted feature dependency plan. A complete Judge snapshot and fully integrated waves are skipped; an unchanged in-progress wave reuses successful Actor and Critic checkpoints and runs only unfinished workers. If the live workspace no longer matches the saved baseline, the stale wave checkpoint is rejected and rebuilt from the current project before workers continue.
|
|
255
259
|
- The shared Main chat holds its own `sessions/main/run-owner.json` lease across prompt initialization, native-session reuse, and Worker completion. A second TUI is rejected before it can clear or overwrite the active Main prompt, log, status, or native session, and startup native-session reconciliation skips a Main session owned by another live TUI. After a hard exit, startup atomically claims the stale Main lease, terminates every verifiable orphan process group, marks active Main Workers `cancelled`, preserves native session ids, and records recovery before exposing the runtime. An unverifiable or still-running Main process blocks startup without changing its status or checkpoints.
|
|
256
260
|
- Task and Main runs use the same lease finalizer, so a successful run cannot report success until its lease is released. If both the run and lease release fail, the top-level error preserves both causes in an `AggregateError` instead of replacing the original Worker failure.
|
|
@@ -477,7 +481,7 @@ Keep `[router.codex]` on `read-only`; routing only classifies requests and does
|
|
|
477
481
|
|
|
478
482
|
The process adapter sends each role prompt to stdin and records stdout/stderr in `output.log`. Worker success is separate from the operating-system exit code: a total, first-output, idle, or stdin watchdog failure remains failed even when the terminated CLI handles `SIGTERM` and exits with code `0`, so the next role never starts from a timed-out checkpoint. `firstOutputTimeoutMs` owns silent startup, `idleTimeoutMs` starts only after real stdout/stderr activity, and `timeoutMs` remains the hard ceiling; equal or longer secondary watchdogs do not race the total deadline. Claude `--print` with `text` or `json` emits only its final result, so those launches display `working · buffered` and use `timeoutMs` without arming a separate first-output watchdog. Claude `stream-json` remains streaming and retains the configured first-output deadline.
|
|
479
483
|
|
|
480
|
-
In chat, scroll long conversation history with the mouse wheel or PageUp/PageDown; sending a new message returns to the latest reply. A single Up/Down recalls persisted request history, and Ctrl+Up/Down remains an alternative. The outer TUI never enables application mouse tracking, so ordinary left-drag selection and system copy work without Shift while alternate-scroll keeps the wheel active in chat and Worker logs. `Ctrl+Y` also copies the current visible chat, rendered Worker log, native Agent screen, or structured overview without changing terminal modes. macOS uses `pbcopy`; Linux uses `wl-copy`, `xclip`, or `xsel` when available and falls back to OSC 52. After a complex task completes, use the same controls to move through its structured result and press `Ctrl+D` to toggle details. Press `Ctrl+N` to preserve all history and start a fresh conversation, `Ctrl+E` to open runtime role/model control, `Ctrl+W` to open Worker logs, and `Tab` to cycle the selected Worker when Workers exist. `Ctrl+S` opens the same status detail view from chat, logs, Worker overview, or an embedded native session; it keeps the footer compact while exposing the complete route, reason, active Main/Judge/Actor/Critic Provider/model map, selected historical Provider/model, phase, activity timestamp, native session, and config effective/restart state. Press `Ctrl+S` or `Esc` to return without interrupting the underlying Worker. While a request is running, press `Esc` to
|
|
484
|
+
In chat, scroll long conversation history with the mouse wheel or PageUp/PageDown; sending a new message returns to the latest reply. A single Up/Down recalls persisted request history, and Ctrl+Up/Down remains an alternative. The outer TUI never enables application mouse tracking, so ordinary left-drag selection and system copy work without Shift while alternate-scroll keeps the wheel active in chat and Worker logs. `Ctrl+Y` also copies the current visible chat, rendered Worker log, native Agent screen, or structured overview without changing terminal modes. macOS uses `pbcopy`; Linux uses `wl-copy`, `xclip`, or `xsel` when available and falls back to OSC 52. After a complex task completes, use the same controls to move through its structured result and press `Ctrl+D` to toggle details. Press `Ctrl+N` to preserve all history and start a fresh conversation, `Ctrl+E` to open runtime role/model control, `Ctrl+W` to open Worker logs, and `Tab` to cycle the selected Worker when Workers exist. `Ctrl+S` opens the same status detail view from chat, logs, Worker overview, or an embedded native session; it keeps the footer compact while exposing the complete route, reason, active Main/Judge/Actor/Critic Provider/model map, selected historical Provider/model, phase, activity timestamp, native session, and config effective/restart state. Press `Ctrl+S` or `Esc` to return without interrupting the underlying Worker. While a request is running, press `Esc` to cancel it or `Ctrl+C` to close the TUI and leave the Supervisor running. After a failed or cancelled Task, press `Ctrl+R` to retry the same turn or `Ctrl+N` to start independently. In Worker-log views, scroll with the mouse wheel, Up/Down, or PageUp/PageDown, press `Tab` to cycle Workers, `Ctrl+N` to start a fresh conversation, and `Esc` to return to chat.
|
|
481
485
|
|
|
482
486
|
`Ctrl+B` opens a live Worker overview without replacing the `Ctrl+W` log shortcut. It summarizes every Judge, Actor, and Critic by turn, role, named Provider, persisted model, state, phase, latest summary, and native-session availability. The selected active worker gets a live activity line showing its first-output deadline while starting and its idle deadline after output begins. The line stays muted while healthy, changes to warning for the final 20% and danger once overdue. Up/Down, PageUp/PageDown, the mouse wheel, or `Tab` changes the selected worker; Enter or `Ctrl+W` opens its rendered log, `Ctrl+O` attaches to its native session, and `Esc` returns to the originating chat or log view. Router diagnostics and the project picker also return to the overview when opened from there.
|
|
483
487
|
|
|
@@ -497,7 +501,7 @@ The Task detail view reads authoritative task files and presents `Project -> Tas
|
|
|
497
501
|
|
|
498
502
|
In a Worker log, `Ctrl+F` searches the final rendered Worker log rather than raw file offsets. Type Unicode text normally; Enter moves to the next match and Up/Down moves backward or forward. `Esc` closes search. The current match is marked with `>` without shifting Diff or source line-number columns. With search closed, press `E` to cycle rendered error lines or `D` to cycle Diff files and hunks.
|
|
499
503
|
|
|
500
|
-
In chat or worker-log views, press `Ctrl+O` to attach to the selected worker's native session inside `parallel-codex-tui`. Native attach runs through a PTY, so full-screen CLIs such as `codex resume {sessionId}` receive a real terminal instead of pipe stdin. Native attach follows outer terminal resize, updating both the rendered screen and child PTY so Codex or Claude reflows at the current dimensions. Input is forwarded to the configured interactive command and output is shown in the native attach panel. When a Codex feature session needs its recorded worker, turn, or feature directories and the interactive command does not already choose a sandbox, native attach adds `--sandbox workspace-write` before its `--add-dir` arguments; an explicitly configured native sandbox remains unchanged. A non-zero native exit recognizes read-only sandbox/add-dir conflicts, untrusted directories, misplaced `--skip-git-repo-check`, missing PTY input, and host permission failures, then appends the exact configuration or terminal action before the exit line scrolls away. Overlapping attach preparations keep only the latest request. Press `Ctrl+]` to return to worker logs; this and closing the outer App terminate the active PTY. An attach preparation that finishes after App shutdown is discarded instead of starting a detached agent. `Ctrl+C` is forwarded to the native agent while attached. In chat and worker-log views,
|
|
504
|
+
In chat or worker-log views, press `Ctrl+O` to attach to the selected worker's native session inside `parallel-codex-tui`. Native attach runs through a PTY, so full-screen CLIs such as `codex resume {sessionId}` receive a real terminal instead of pipe stdin. Native attach follows outer terminal resize, updating both the rendered screen and child PTY so Codex or Claude reflows at the current dimensions. Input is forwarded to the configured interactive command and output is shown in the native attach panel. When a Codex feature session needs its recorded worker, turn, or feature directories and the interactive command does not already choose a sandbox, native attach adds `--sandbox workspace-write` before its `--add-dir` arguments; an explicitly configured native sandbox remains unchanged. A non-zero native exit recognizes read-only sandbox/add-dir conflicts, untrusted directories, misplaced `--skip-git-repo-check`, missing PTY input, and host permission failures, then appends the exact configuration or terminal action before the exit line scrolls away. Overlapping attach preparations keep only the latest request. Press `Ctrl+]` to return to worker logs; this and closing the outer App terminate the active PTY. An attach preparation that finishes after App shutdown is discarded instead of starting a detached agent. `Ctrl+C` is forwarded to the native agent while attached. In chat and worker-log views, `Ctrl+C` detaches an active Supervisor run and exits the outer TUI; during foreground routing it cancels classification before exiting. A second operating-system SIGINT restores terminal modes and forces exit.
|
|
501
505
|
|
|
502
506
|
If a native resume fails because the underlying CLI reports that its context window is full, configure `fallback = "new"` under `[workers.<engine>.nativeSession]`. The old native session is archived as `native-session.retired.json`, removed from active use, and the worker is retried once with the normal fresh-session command. A valid retirement tombstone is also a cross-turn inheritance barrier: a retry or later turn cannot resurrect the same session from an older worker copy, while a newer replacement session remains reusable. A `process-cleanup-error` or `process-ownership-error` always blocks native-session fallback, even when the CLI output also mentions a full context window, so a fresh Worker cannot overlap an untracked or still-running resume process.
|
|
503
507
|
|
|
@@ -545,12 +549,12 @@ The release job installs npm `^11.5.1`, runs on Node `24.15.x`, publishes the pr
|
|
|
545
549
|
To publish a release, update `package.json` and `src/version.ts` to the same version, then push a matching tag:
|
|
546
550
|
|
|
547
551
|
```bash
|
|
548
|
-
VERSION=0.
|
|
552
|
+
VERSION=0.4.0
|
|
549
553
|
git tag "v$VERSION"
|
|
550
554
|
git push origin "v$VERSION"
|
|
551
555
|
```
|
|
552
556
|
|
|
553
|
-
You can also run the Release workflow manually and enter the same tag value. The release tag must match `package.json`; for example, package version `0.
|
|
557
|
+
You can also run the Release workflow manually and enter the same tag value. The release tag must match `package.json`; for example, package version `0.4.0` requires tag `v0.4.0`. Published tags such as `v0.2.10` are immutable and must not be moved or reused.
|
|
554
558
|
|
|
555
559
|
## Publishing Hygiene
|
|
556
560
|
|
|
@@ -558,6 +562,7 @@ You can also run the Release workflow manually and enter the same tag value. The
|
|
|
558
562
|
- `.parallel-codex/role-configuration.json` and `.parallel-codex/role-configuration.next.json` are local runtime role/model selections and are ignored.
|
|
559
563
|
- `.parallel-codex/last-workspace` and `.parallel-codex/workspaces.json` are local workspace-selection state and are ignored.
|
|
560
564
|
- `.parallel-codex/router/` contains local request classification audit records and is ignored.
|
|
565
|
+
- `.parallel-codex/supervisor/` contains detached-run requests, lifecycle state, control commands, event streams, controller leases, acknowledgements, and Supervisor diagnostics; it is local evidence and is ignored.
|
|
561
566
|
- `.parallel-codex/sessions/` contains the workspace chat transcript, task prompts, logs, native session ids, isolated feature workspaces, and conflict evidence; never commit it.
|
|
562
567
|
- `.parallel-codex/diagnostics/` contains redacted support bundles and is ignored; review a bundle before sharing it.
|
|
563
568
|
- `.parallel-codex/probes/` contains failed live Agent probe evidence and is ignored.
|
package/dist/cli.js
CHANGED
|
@@ -27,6 +27,8 @@ import { formatTuiThemeCatalog } from "./tui/theme-preview.js";
|
|
|
27
27
|
import { configureTuiTheme } from "./tui/theme.js";
|
|
28
28
|
import { routerDiagnosticsPolicy } from "./tui/RouterDiagnosticsView.js";
|
|
29
29
|
import { version } from "./version.js";
|
|
30
|
+
import { SupervisorOrchestrator } from "./supervisor/client.js";
|
|
31
|
+
import { runSupervisorJob } from "./supervisor/runner.js";
|
|
30
32
|
main().catch((error) => {
|
|
31
33
|
if (error instanceof WorkspaceSelectionCancelledError) {
|
|
32
34
|
return;
|
|
@@ -35,6 +37,12 @@ main().catch((error) => {
|
|
|
35
37
|
process.exit(1);
|
|
36
38
|
});
|
|
37
39
|
async function main() {
|
|
40
|
+
const supervisorRunDir = process.env.PCT_SUPERVISOR_RUN_DIR;
|
|
41
|
+
if (supervisorRunDir) {
|
|
42
|
+
delete process.env.PCT_SUPERVISOR_RUN_DIR;
|
|
43
|
+
await runSupervisorJob(supervisorRunDir);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
38
46
|
const rawArgs = process.argv.slice(2);
|
|
39
47
|
const cliArgErrors = validateCliArgs(rawArgs);
|
|
40
48
|
if (cliArgErrors.length > 0) {
|
|
@@ -119,7 +127,7 @@ async function main() {
|
|
|
119
127
|
let instance = null;
|
|
120
128
|
const shutdownController = new AbortController();
|
|
121
129
|
const deferredWorkspaceClosures = new Set();
|
|
122
|
-
const appElement = (state) => (_jsx(App, { config: withUiThemeOverride(state.runtime.config, cliArgs.theme), orchestrator: state.
|
|
130
|
+
const appElement = (state) => (_jsx(App, { config: withUiThemeOverride(state.runtime.config, cliArgs.theme), orchestrator: state.supervisor, cwd: state.runtime.workspaceRoot, initialTaskId: state.initialTaskId, initialRoute: state.initialRoute, initialWorkers: state.initialWorkers, initialCanRetryTask: state.initialCanRetryTask, initialMessages: state.initialMessages, workspaceChoices: state.workspaceChoices, shutdownSignal: shutdownController.signal, loadRouterDiagnostics: async () => {
|
|
123
131
|
const [records, latestConfig] = await Promise.all([
|
|
124
132
|
readRouterAudit(join(state.runtime.routerCwd, "routes.jsonl"), 100),
|
|
125
133
|
loadConfig(cliArgs.appRoot)
|
|
@@ -212,6 +220,7 @@ async function main() {
|
|
|
212
220
|
finally {
|
|
213
221
|
removeSigintHandler();
|
|
214
222
|
restoreInteractiveTerminal();
|
|
223
|
+
closeInteractiveWorkspace(current);
|
|
215
224
|
retryDeferredWorkspaceClosures(deferredWorkspaceClosures);
|
|
216
225
|
}
|
|
217
226
|
}
|
|
@@ -219,6 +228,13 @@ async function main() {
|
|
|
219
228
|
async function loadInteractiveWorkspace(appRoot, workspaceRoot, requestedTaskId) {
|
|
220
229
|
const runtime = await createRuntime(appRoot, workspaceRoot);
|
|
221
230
|
try {
|
|
231
|
+
const supervisor = await SupervisorOrchestrator.open({
|
|
232
|
+
delegate: runtime.orchestrator,
|
|
233
|
+
sessions: runtime.sessions,
|
|
234
|
+
appRoot,
|
|
235
|
+
workspaceRoot: runtime.workspaceRoot,
|
|
236
|
+
dataDir: runtime.config.dataDir
|
|
237
|
+
});
|
|
222
238
|
const preflightPromise = runRuntimePreflight(runtime.config, runtime.workspaceRoot, process.env).catch((error) => ({
|
|
223
239
|
ok: false,
|
|
224
240
|
lines: [`preflight: failed (${error instanceof Error ? error.message : String(error)})`]
|
|
@@ -271,6 +287,7 @@ async function loadInteractiveWorkspace(appRoot, workspaceRoot, requestedTaskId)
|
|
|
271
287
|
const recoveryMessages = startupRecoveryMessages(runtime.recoveredTasks, initialTaskId, runtime.pendingTaskCreations, runtime.index.recovery);
|
|
272
288
|
return {
|
|
273
289
|
runtime,
|
|
290
|
+
supervisor,
|
|
274
291
|
initialTaskId,
|
|
275
292
|
initialRoute,
|
|
276
293
|
initialWorkers,
|
|
@@ -293,6 +310,7 @@ async function loadInteractiveWorkspace(appRoot, workspaceRoot, requestedTaskId)
|
|
|
293
310
|
}
|
|
294
311
|
}
|
|
295
312
|
function closeInteractiveWorkspace(state) {
|
|
313
|
+
state.supervisor.detachBackgroundRuns();
|
|
296
314
|
state.runtime.index.close();
|
|
297
315
|
}
|
|
298
316
|
function retryDeferredWorkspaceClosures(states) {
|
|
@@ -75,10 +75,17 @@ export class Orchestrator {
|
|
|
75
75
|
}
|
|
76
76
|
async handleRequest(input) {
|
|
77
77
|
throwIfCancelled(input.signal);
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
78
|
+
let roleSelection;
|
|
79
|
+
let route;
|
|
80
|
+
if (input.route) {
|
|
81
|
+
roleSelection = input.roleSelection ?? await this.roleConfiguration.selectionForRequest();
|
|
82
|
+
route = routeWithRoleSelection(input.route, roleSelection);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
const routed = await this.routeInitialRequest(input);
|
|
86
|
+
roleSelection = routed.roleSelection;
|
|
87
|
+
route = routed.route;
|
|
88
|
+
}
|
|
82
89
|
throwIfCancelled(input.signal);
|
|
83
90
|
const workers = [];
|
|
84
91
|
const executionInput = { ...input, roleSelection };
|
|
@@ -115,6 +122,21 @@ export class Orchestrator {
|
|
|
115
122
|
await this.roleConfiguration.writeTurnSelection(turn.dir, roleSelectionWithEngines(route, roleSelection));
|
|
116
123
|
return this.withTaskRunLease(task, () => this.runInitialTask(executionInput, task, route, turn, workers));
|
|
117
124
|
}
|
|
125
|
+
async routeInitialRequest(input) {
|
|
126
|
+
throwIfCancelled(input.signal);
|
|
127
|
+
const routed = await this.routeRequest(input.request, input.cwd, input.signal, "initial", input.onRouteStart, input.onRouteFallback, input.onRouteProgress);
|
|
128
|
+
const roleSelection = input.roleSelection ?? await this.roleConfiguration.selectionForRequest();
|
|
129
|
+
const route = routeWithRoleSelection(routed, roleSelection);
|
|
130
|
+
input.onRoute?.(route);
|
|
131
|
+
throwIfCancelled(input.signal);
|
|
132
|
+
return {
|
|
133
|
+
mode: route.mode,
|
|
134
|
+
taskId: null,
|
|
135
|
+
reason: route.reason,
|
|
136
|
+
route,
|
|
137
|
+
roleSelection
|
|
138
|
+
};
|
|
139
|
+
}
|
|
118
140
|
async handleTaskTurn(input) {
|
|
119
141
|
throwIfCancelled(input.signal);
|
|
120
142
|
const task = this.sessions.taskFromId(input.taskId);
|
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
import { closeSync, openSync } from "node:fs";
|
|
4
|
+
import { join, resolve } from "node:path";
|
|
5
|
+
import { asSupervisorRunResult, supervisorEventPayload } from "./protocol.js";
|
|
6
|
+
import { acknowledgeSupervisorRun, appendSupervisorCommand, claimSupervisorController, createSupervisorRun, createSupervisorRunId, listSupervisorRuns, readSupervisorEvents, readSupervisorRunState, supervisorRunIsAcknowledged, supervisorRunIsTerminal, supervisorRunProcessIsActive, writeSupervisorRunState } from "./store.js";
|
|
7
|
+
const RUN_POLL_MS = 100;
|
|
8
|
+
const QUEUED_START_GRACE_MS = 3000;
|
|
9
|
+
export class SupervisorDetachedError extends Error {
|
|
10
|
+
constructor(message = "Background run detached") {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = "SupervisorDetachedError";
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export function isSupervisorDetachedError(error) {
|
|
16
|
+
return error instanceof Error && error.name === "SupervisorDetachedError";
|
|
17
|
+
}
|
|
18
|
+
export class SupervisorOrchestrator {
|
|
19
|
+
options;
|
|
20
|
+
persistsRunResults = true;
|
|
21
|
+
launch;
|
|
22
|
+
now;
|
|
23
|
+
recoverableRun = null;
|
|
24
|
+
currentRun = null;
|
|
25
|
+
settledRun = null;
|
|
26
|
+
detaching = false;
|
|
27
|
+
backgroundRunListeners = new Set();
|
|
28
|
+
constructor(options) {
|
|
29
|
+
this.options = options;
|
|
30
|
+
this.launch = options.launch ?? launchSupervisorProcess;
|
|
31
|
+
this.now = options.now ?? (() => new Date());
|
|
32
|
+
}
|
|
33
|
+
static async open(options) {
|
|
34
|
+
const client = new SupervisorOrchestrator(options);
|
|
35
|
+
client.recoverableRun = await client.findRecoverableRun();
|
|
36
|
+
return client;
|
|
37
|
+
}
|
|
38
|
+
async handleRequest(input) {
|
|
39
|
+
const routed = await this.options.delegate.routeInitialRequest(input);
|
|
40
|
+
return this.startRun({
|
|
41
|
+
kind: "handle-request",
|
|
42
|
+
request: input.request,
|
|
43
|
+
cwd: input.cwd,
|
|
44
|
+
route: routed.route,
|
|
45
|
+
role_selection: routed.roleSelection
|
|
46
|
+
}, input);
|
|
47
|
+
}
|
|
48
|
+
async handleTaskTurn(input) {
|
|
49
|
+
return this.startRun({
|
|
50
|
+
kind: "handle-task-turn",
|
|
51
|
+
request: input.request,
|
|
52
|
+
cwd: input.cwd,
|
|
53
|
+
task_id: input.taskId,
|
|
54
|
+
...(input.route ? { route: input.route } : {}),
|
|
55
|
+
...(input.roleSelection ? { role_selection: input.roleSelection } : {})
|
|
56
|
+
}, input);
|
|
57
|
+
}
|
|
58
|
+
async answerTaskQuestion(input) {
|
|
59
|
+
return this.startRun({
|
|
60
|
+
kind: "answer-task-question",
|
|
61
|
+
request: input.request,
|
|
62
|
+
cwd: input.cwd,
|
|
63
|
+
task_id: input.taskId,
|
|
64
|
+
...(input.route ? { route: input.route } : {}),
|
|
65
|
+
...(input.roleSelection ? { role_selection: input.roleSelection } : {})
|
|
66
|
+
}, input);
|
|
67
|
+
}
|
|
68
|
+
async retryTask(input) {
|
|
69
|
+
return this.startRun({
|
|
70
|
+
kind: "retry-task",
|
|
71
|
+
cwd: input.cwd,
|
|
72
|
+
task_id: input.taskId
|
|
73
|
+
}, input);
|
|
74
|
+
}
|
|
75
|
+
async resumeFeature(input) {
|
|
76
|
+
return this.startRun({
|
|
77
|
+
kind: "resume-feature",
|
|
78
|
+
cwd: input.cwd,
|
|
79
|
+
task_id: input.taskId,
|
|
80
|
+
feature_id: input.featureId
|
|
81
|
+
}, input);
|
|
82
|
+
}
|
|
83
|
+
async restorePendingRun(input) {
|
|
84
|
+
this.detaching = input.signal?.aborted ? this.detaching : false;
|
|
85
|
+
const pending = this.recoverableRun ?? await this.findRecoverableRun();
|
|
86
|
+
this.recoverableRun = null;
|
|
87
|
+
if (!pending) {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
const controller = await claimSupervisorController(pending.files);
|
|
91
|
+
return this.watchRun({
|
|
92
|
+
files: pending.files,
|
|
93
|
+
controller,
|
|
94
|
+
detached: this.detaching,
|
|
95
|
+
cancelSent: false
|
|
96
|
+
}, input);
|
|
97
|
+
}
|
|
98
|
+
detachBackgroundRuns() {
|
|
99
|
+
this.detaching = true;
|
|
100
|
+
const current = this.currentRun;
|
|
101
|
+
if (!current) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
current.detached = true;
|
|
105
|
+
void current.controller?.release();
|
|
106
|
+
current.controller = null;
|
|
107
|
+
this.notifyBackgroundRunState();
|
|
108
|
+
}
|
|
109
|
+
backgroundRunAttached() {
|
|
110
|
+
return this.currentRun !== null;
|
|
111
|
+
}
|
|
112
|
+
backgroundRunControllable() {
|
|
113
|
+
return this.currentRun?.controller !== null && this.currentRun?.controller !== undefined;
|
|
114
|
+
}
|
|
115
|
+
subscribeBackgroundRunState(listener) {
|
|
116
|
+
this.backgroundRunListeners.add(listener);
|
|
117
|
+
return () => this.backgroundRunListeners.delete(listener);
|
|
118
|
+
}
|
|
119
|
+
async acknowledgeBackgroundRun() {
|
|
120
|
+
if (!this.settledRun) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
const files = this.settledRun;
|
|
124
|
+
this.settledRun = null;
|
|
125
|
+
await acknowledgeSupervisorRun(files);
|
|
126
|
+
}
|
|
127
|
+
async cancelFeature(taskId, featureId) {
|
|
128
|
+
if (!this.currentRun) {
|
|
129
|
+
return this.options.delegate.cancelFeature(taskId, featureId);
|
|
130
|
+
}
|
|
131
|
+
if (!this.currentRun.controller) {
|
|
132
|
+
return { requested: false, featureId };
|
|
133
|
+
}
|
|
134
|
+
await appendSupervisorCommand(this.currentRun.files, {
|
|
135
|
+
version: 1,
|
|
136
|
+
id: randomUUID(),
|
|
137
|
+
at: this.now().toISOString(),
|
|
138
|
+
type: "cancel-feature",
|
|
139
|
+
task_id: taskId,
|
|
140
|
+
feature_id: featureId
|
|
141
|
+
});
|
|
142
|
+
return { requested: true, featureId };
|
|
143
|
+
}
|
|
144
|
+
async pauseFeature(taskId, featureId) {
|
|
145
|
+
if (!this.currentRun) {
|
|
146
|
+
return this.options.delegate.pauseFeature(taskId, featureId);
|
|
147
|
+
}
|
|
148
|
+
if (!this.currentRun.controller) {
|
|
149
|
+
return { requested: false, featureId };
|
|
150
|
+
}
|
|
151
|
+
await appendSupervisorCommand(this.currentRun.files, {
|
|
152
|
+
version: 1,
|
|
153
|
+
id: randomUUID(),
|
|
154
|
+
at: this.now().toISOString(),
|
|
155
|
+
type: "pause-feature",
|
|
156
|
+
task_id: taskId,
|
|
157
|
+
feature_id: featureId
|
|
158
|
+
});
|
|
159
|
+
return { requested: true, featureId };
|
|
160
|
+
}
|
|
161
|
+
routeTaskFollowUp(input) {
|
|
162
|
+
return this.options.delegate.routeTaskFollowUp(input);
|
|
163
|
+
}
|
|
164
|
+
canRetryTask(taskId) {
|
|
165
|
+
return this.options.delegate.canRetryTask(taskId);
|
|
166
|
+
}
|
|
167
|
+
listTaskWorkers(taskId) {
|
|
168
|
+
return this.options.delegate.listTaskWorkers(taskId);
|
|
169
|
+
}
|
|
170
|
+
reassignFeature(input) {
|
|
171
|
+
return this.options.delegate.reassignFeature(input);
|
|
172
|
+
}
|
|
173
|
+
roleConfigurationSnapshot(taskId) {
|
|
174
|
+
return this.options.delegate.roleConfigurationSnapshot(taskId);
|
|
175
|
+
}
|
|
176
|
+
updateRoleConfiguration(input) {
|
|
177
|
+
return this.options.delegate.updateRoleConfiguration(input);
|
|
178
|
+
}
|
|
179
|
+
clearRoleConfiguration(scope, taskId) {
|
|
180
|
+
return this.options.delegate.clearRoleConfiguration(scope, taskId);
|
|
181
|
+
}
|
|
182
|
+
validateRoleConfiguration(roles) {
|
|
183
|
+
return this.options.delegate.validateRoleConfiguration(roles);
|
|
184
|
+
}
|
|
185
|
+
async startRun(input, callbacks) {
|
|
186
|
+
this.detaching = callbacks.signal?.aborted ? this.detaching : false;
|
|
187
|
+
if (this.currentRun) {
|
|
188
|
+
throw new Error("A Supervisor run is already attached in this TUI.");
|
|
189
|
+
}
|
|
190
|
+
const active = (await this.reconcileRuns()).filter(({ state }) => !supervisorRunIsTerminal(state));
|
|
191
|
+
if (active.length > 0) {
|
|
192
|
+
throw new Error("A background run is already active in this workspace. Reopen the TUI to attach to it.");
|
|
193
|
+
}
|
|
194
|
+
const createdAt = this.now().toISOString();
|
|
195
|
+
const request = {
|
|
196
|
+
...input,
|
|
197
|
+
version: 1,
|
|
198
|
+
run_id: createSupervisorRunId(this.now()),
|
|
199
|
+
app_root: this.options.appRoot,
|
|
200
|
+
workspace_root: this.options.workspaceRoot,
|
|
201
|
+
data_dir: this.options.dataDir,
|
|
202
|
+
created_at: createdAt
|
|
203
|
+
};
|
|
204
|
+
const files = await createSupervisorRun(this.options.workspaceRoot, this.options.dataDir, request);
|
|
205
|
+
const controller = await claimSupervisorController(files);
|
|
206
|
+
if (!controller) {
|
|
207
|
+
throw new Error("The new Supervisor run was claimed by another TUI before it could start.");
|
|
208
|
+
}
|
|
209
|
+
const watched = {
|
|
210
|
+
files,
|
|
211
|
+
controller,
|
|
212
|
+
detached: this.detaching,
|
|
213
|
+
cancelSent: false
|
|
214
|
+
};
|
|
215
|
+
this.currentRun = watched;
|
|
216
|
+
this.notifyBackgroundRunState();
|
|
217
|
+
try {
|
|
218
|
+
await this.launch(files, request);
|
|
219
|
+
}
|
|
220
|
+
catch (error) {
|
|
221
|
+
if (this.currentRun === watched) {
|
|
222
|
+
this.currentRun = null;
|
|
223
|
+
this.notifyBackgroundRunState();
|
|
224
|
+
}
|
|
225
|
+
await controller.release();
|
|
226
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
227
|
+
const failedAt = this.now().toISOString();
|
|
228
|
+
const state = await readSupervisorRunState(files);
|
|
229
|
+
await writeSupervisorRunState(files, {
|
|
230
|
+
...state,
|
|
231
|
+
status: "failed",
|
|
232
|
+
updated_at: failedAt,
|
|
233
|
+
finished_at: failedAt,
|
|
234
|
+
error: message
|
|
235
|
+
});
|
|
236
|
+
await this.options.sessions.appendChatMessage({ from: "system", text: message });
|
|
237
|
+
this.settledRun = files;
|
|
238
|
+
throw error;
|
|
239
|
+
}
|
|
240
|
+
return this.watchRun(watched, callbacks);
|
|
241
|
+
}
|
|
242
|
+
async watchRun(watched, callbacks) {
|
|
243
|
+
this.currentRun = watched;
|
|
244
|
+
this.notifyBackgroundRunState();
|
|
245
|
+
let nextEventSequence = 0;
|
|
246
|
+
try {
|
|
247
|
+
while (true) {
|
|
248
|
+
if (watched.detached) {
|
|
249
|
+
throw new SupervisorDetachedError();
|
|
250
|
+
}
|
|
251
|
+
if (!watched.controller) {
|
|
252
|
+
watched.controller = await claimSupervisorController(watched.files);
|
|
253
|
+
if (watched.controller) {
|
|
254
|
+
this.notifyBackgroundRunState();
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
const events = await readSupervisorEvents(watched.files);
|
|
258
|
+
for (const event of events) {
|
|
259
|
+
if (event.sequence < nextEventSequence) {
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
nextEventSequence = event.sequence + 1;
|
|
263
|
+
dispatchSupervisorEvent(event, callbacks);
|
|
264
|
+
}
|
|
265
|
+
const state = await readSupervisorRunState(watched.files);
|
|
266
|
+
if (supervisorRunIsTerminal(state)) {
|
|
267
|
+
this.settledRun = watched.files;
|
|
268
|
+
if (state.status === "completed" && state.result) {
|
|
269
|
+
return asSupervisorRunResult(state.result);
|
|
270
|
+
}
|
|
271
|
+
const error = new Error(state.error || `Supervisor run ${state.status}`);
|
|
272
|
+
if (state.status === "cancelled") {
|
|
273
|
+
error.name = "AbortError";
|
|
274
|
+
}
|
|
275
|
+
throw error;
|
|
276
|
+
}
|
|
277
|
+
if (watched.controller && !(await supervisorRunProcessIsActive(state))) {
|
|
278
|
+
const ageMs = this.now().getTime() - Date.parse(state.created_at);
|
|
279
|
+
if (state.status !== "queued" || ageMs >= QUEUED_START_GRACE_MS) {
|
|
280
|
+
const failedAt = this.now().toISOString();
|
|
281
|
+
const summary = `Supervisor exited unexpectedly while ${state.kind} was running.`;
|
|
282
|
+
await writeSupervisorRunState(watched.files, {
|
|
283
|
+
...state,
|
|
284
|
+
status: "failed",
|
|
285
|
+
updated_at: failedAt,
|
|
286
|
+
finished_at: failedAt,
|
|
287
|
+
error: summary
|
|
288
|
+
});
|
|
289
|
+
await this.options.sessions.appendChatMessage({
|
|
290
|
+
from: "system",
|
|
291
|
+
text: summary,
|
|
292
|
+
taskId: state.task_id ?? undefined
|
|
293
|
+
});
|
|
294
|
+
continue;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
if (callbacks.signal?.aborted && !watched.cancelSent) {
|
|
298
|
+
if (!watched.controller) {
|
|
299
|
+
throw new SupervisorDetachedError("Observer detached; the background run is still active");
|
|
300
|
+
}
|
|
301
|
+
watched.cancelSent = true;
|
|
302
|
+
await appendSupervisorCommand(watched.files, {
|
|
303
|
+
version: 1,
|
|
304
|
+
id: randomUUID(),
|
|
305
|
+
at: this.now().toISOString(),
|
|
306
|
+
type: "cancel-run"
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
await delay(RUN_POLL_MS);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
finally {
|
|
313
|
+
if (this.currentRun === watched) {
|
|
314
|
+
this.currentRun = null;
|
|
315
|
+
}
|
|
316
|
+
await watched.controller?.release();
|
|
317
|
+
watched.controller = null;
|
|
318
|
+
this.notifyBackgroundRunState();
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
notifyBackgroundRunState() {
|
|
322
|
+
for (const listener of this.backgroundRunListeners) {
|
|
323
|
+
listener();
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
async findRecoverableRun() {
|
|
327
|
+
const runs = await this.reconcileRuns();
|
|
328
|
+
const active = runs.filter(({ state }) => !supervisorRunIsTerminal(state));
|
|
329
|
+
if (active.length > 0) {
|
|
330
|
+
return active.at(-1) ?? null;
|
|
331
|
+
}
|
|
332
|
+
const unacknowledged = [];
|
|
333
|
+
for (const run of runs) {
|
|
334
|
+
if (supervisorRunIsTerminal(run.state) && !(await supervisorRunIsAcknowledged(run.files))) {
|
|
335
|
+
unacknowledged.push(run);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
return unacknowledged.at(-1) ?? null;
|
|
339
|
+
}
|
|
340
|
+
async reconcileRuns() {
|
|
341
|
+
const runs = await listSupervisorRuns(this.options.workspaceRoot, this.options.dataDir);
|
|
342
|
+
for (const run of runs) {
|
|
343
|
+
if (supervisorRunIsTerminal(run.state) || await supervisorRunProcessIsActive(run.state)) {
|
|
344
|
+
continue;
|
|
345
|
+
}
|
|
346
|
+
const ageMs = this.now().getTime() - Date.parse(run.state.created_at);
|
|
347
|
+
if (run.state.status === "queued" && ageMs < QUEUED_START_GRACE_MS) {
|
|
348
|
+
continue;
|
|
349
|
+
}
|
|
350
|
+
const failedAt = this.now().toISOString();
|
|
351
|
+
const summary = `Supervisor exited unexpectedly while ${run.state.kind} was running.`;
|
|
352
|
+
run.state = {
|
|
353
|
+
...run.state,
|
|
354
|
+
status: "failed",
|
|
355
|
+
updated_at: failedAt,
|
|
356
|
+
finished_at: failedAt,
|
|
357
|
+
error: summary
|
|
358
|
+
};
|
|
359
|
+
await writeSupervisorRunState(run.files, run.state);
|
|
360
|
+
await this.options.sessions.appendChatMessage({
|
|
361
|
+
from: "system",
|
|
362
|
+
text: summary,
|
|
363
|
+
taskId: run.state.task_id ?? undefined
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
return runs;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
function dispatchSupervisorEvent(event, callbacks) {
|
|
370
|
+
const payload = supervisorEventPayload(event);
|
|
371
|
+
switch (event.type) {
|
|
372
|
+
case "route-start":
|
|
373
|
+
callbacks.onRouteStart?.(payload);
|
|
374
|
+
break;
|
|
375
|
+
case "route-progress":
|
|
376
|
+
callbacks.onRouteProgress?.(payload);
|
|
377
|
+
break;
|
|
378
|
+
case "route":
|
|
379
|
+
callbacks.onRoute?.(payload);
|
|
380
|
+
break;
|
|
381
|
+
case "status":
|
|
382
|
+
callbacks.onStatus?.(payload);
|
|
383
|
+
break;
|
|
384
|
+
case "worker":
|
|
385
|
+
callbacks.onWorker?.(payload);
|
|
386
|
+
break;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
async function launchSupervisorProcess(files, request) {
|
|
390
|
+
const entrypoint = process.argv[1] ? resolve(process.argv[1]) : "";
|
|
391
|
+
if (!entrypoint) {
|
|
392
|
+
throw new Error("Cannot locate the parallel-codex-tui CLI entrypoint for Supervisor launch.");
|
|
393
|
+
}
|
|
394
|
+
const errorLog = openSync(join(files.dir, "supervisor.log"), "a");
|
|
395
|
+
const child = spawn(process.execPath, [...process.execArgv, entrypoint], {
|
|
396
|
+
cwd: process.cwd(),
|
|
397
|
+
detached: true,
|
|
398
|
+
env: {
|
|
399
|
+
...process.env,
|
|
400
|
+
PCT_SUPERVISOR_RUN_DIR: files.dir
|
|
401
|
+
},
|
|
402
|
+
stdio: ["ignore", "ignore", errorLog]
|
|
403
|
+
});
|
|
404
|
+
try {
|
|
405
|
+
await new Promise((resolve, reject) => {
|
|
406
|
+
child.once("spawn", resolve);
|
|
407
|
+
child.once("error", reject);
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
finally {
|
|
411
|
+
closeSync(errorLog);
|
|
412
|
+
}
|
|
413
|
+
let exitCode;
|
|
414
|
+
const onExit = (code) => {
|
|
415
|
+
exitCode = code;
|
|
416
|
+
};
|
|
417
|
+
child.once("exit", onExit);
|
|
418
|
+
const deadline = Date.now() + 5000;
|
|
419
|
+
while (Date.now() < deadline) {
|
|
420
|
+
const state = await readSupervisorRunState(files);
|
|
421
|
+
if (state.status !== "queued") {
|
|
422
|
+
child.off("exit", onExit);
|
|
423
|
+
child.unref();
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
if (exitCode !== undefined) {
|
|
427
|
+
throw new Error(`Supervisor process exited before startup (code ${exitCode ?? "signal"}).`);
|
|
428
|
+
}
|
|
429
|
+
await delay(25);
|
|
430
|
+
}
|
|
431
|
+
child.off("exit", onExit);
|
|
432
|
+
try {
|
|
433
|
+
child.kill("SIGTERM");
|
|
434
|
+
}
|
|
435
|
+
catch {
|
|
436
|
+
// The startup failure below remains the useful error when the child already exited.
|
|
437
|
+
}
|
|
438
|
+
throw new Error("Supervisor process did not publish startup state within 5s.");
|
|
439
|
+
}
|
|
440
|
+
function delay(ms) {
|
|
441
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
442
|
+
}
|