@cleocode/core 2026.11.3 → 2026.11.4-rc.ci.719
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/dist/.source-stamp.json +1 -1
- package/dist/build-provenance.json +2 -2
- package/dist/orchestrate/lead-records.d.ts +36 -11
- package/dist/orchestrate/lead-records.js +78 -17
- package/dist/orchestrate/lead-records.js.map +1 -1
- package/dist/orchestrate/lead.d.ts +6 -0
- package/dist/orchestrate/lead.js +32 -4
- package/dist/orchestrate/lead.js.map +1 -1
- package/dist/orchestrate/query-ops.d.ts +2 -1
- package/dist/orchestrate/query-ops.js +26 -9
- package/dist/orchestrate/query-ops.js.map +1 -1
- package/dist/tasks/change-set.d.ts +17 -1
- package/dist/tasks/change-set.js +26 -4
- package/dist/tasks/change-set.js.map +1 -1
- package/dist/tasks/done-plan.js +21 -9
- package/dist/tasks/done-plan.js.map +1 -1
- package/package.json +13 -13
- package/templates/workflows/release-publish.yml.tmpl +3 -0
package/dist/.source-stamp.json
CHANGED
|
@@ -10,11 +10,13 @@
|
|
|
10
10
|
* lease that only mutations renew), and a reused pid, whose start time
|
|
11
11
|
* differs, never blocks the epic.
|
|
12
12
|
*
|
|
13
|
-
* A lead killed before its `SessionEnd` hook ran (SIGKILL, OOM)
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
13
|
+
* A lead killed before its `SessionEnd` hook ran (SIGKILL, OOM), or one whose
|
|
14
|
+
* Orca terminal was closed after its session ended (T14513), leaves its record
|
|
15
|
+
* behind. {@link reapDeadLeads}, run by the next `cleo orchestrate lead` (which
|
|
16
|
+
* reports what it reaped under `data.lead.reaped`) and by `cleo orchestrate
|
|
17
|
+
* status`, releases such a lead's mailbox, ends its CLEO session unless it has
|
|
18
|
+
* already ended (freeing the epic claim), removes its temp directory (which
|
|
19
|
+
* may hold the mbx env) and deletes the record.
|
|
18
20
|
*
|
|
19
21
|
* The file is local runtime state (a pid means nothing on another device).
|
|
20
22
|
*
|
|
@@ -24,6 +26,7 @@
|
|
|
24
26
|
import type { LeadMode } from '@cleocode/contracts';
|
|
25
27
|
import { type OrcaLeadTerminal } from '@cleocode/contracts/orca-execution.js';
|
|
26
28
|
import { type ProcessLiveness } from '@cleocode/worktree';
|
|
29
|
+
import { endSession, getSession } from '../store/session-store.js';
|
|
27
30
|
import { type AgentMbxClient } from './agentmbx.js';
|
|
28
31
|
/** One process of a lead, identified by pid AND start time (pids are reused). */
|
|
29
32
|
export interface LeadProcess {
|
|
@@ -91,8 +94,10 @@ export declare function removeLeadRecord(projectRoot: string, epicId: string): v
|
|
|
91
94
|
export declare function listLeadRecords(projectRoot: string): LeadRecord[];
|
|
92
95
|
/**
|
|
93
96
|
* Whether a lead is alive: ANY of its processes runs with the start time
|
|
94
|
-
* recorded for it. A process whose start time was not recorded
|
|
95
|
-
*
|
|
97
|
+
* recorded for it. A process whose start time was not recorded, or whose
|
|
98
|
+
* current start time cannot be read, counts on its pid alone (never reaped
|
|
99
|
+
* without proof, T14513); a live pid with a different start time is a reused
|
|
100
|
+
* pid.
|
|
96
101
|
*
|
|
97
102
|
* @param record - The lead record.
|
|
98
103
|
* @param probe - Process probe. @defaultValue `probeProcess` (`@cleocode/worktree`)
|
|
@@ -103,8 +108,23 @@ export declare function isLeadAlive(record: LeadRecord, probe?: (pid: number) =>
|
|
|
103
108
|
/** What {@link reapDeadLeads} did for one dead lead. */
|
|
104
109
|
export interface ReapedLead {
|
|
105
110
|
readonly epicId: string;
|
|
111
|
+
/**
|
|
112
|
+
* The record was deleted: its processes are dead AND its session is proven
|
|
113
|
+
* ended (it had already ended, or the reaper's end returned it ended). `false` keeps the
|
|
114
|
+
* record, with the reason in {@link ReapedLead.keptReason} (T14513).
|
|
115
|
+
*/
|
|
116
|
+
readonly recordRemoved: boolean;
|
|
117
|
+
/** Why a dead lead's record was kept, or `null` when it was removed. */
|
|
118
|
+
readonly keptReason: string | null;
|
|
119
|
+
/** Pids the record named, all of them gone (or reused). */
|
|
120
|
+
readonly pids: readonly number[];
|
|
121
|
+
/** The lead's CLEO session. */
|
|
122
|
+
readonly cleoSessionId: string;
|
|
106
123
|
readonly mailboxReleased: boolean;
|
|
124
|
+
/** The reaper ended the lead's session (it was still open). */
|
|
107
125
|
readonly sessionEnded: boolean;
|
|
126
|
+
/** The session had already ended (the lead's `SessionEnd` hook ran); left as it was (T14513). */
|
|
127
|
+
readonly sessionAlreadyEnded: boolean;
|
|
108
128
|
readonly tempDirRemoved: boolean;
|
|
109
129
|
}
|
|
110
130
|
/** Collaborators of {@link reapDeadLeads}, injected in tests. */
|
|
@@ -115,15 +135,20 @@ export interface ReapDeps {
|
|
|
115
135
|
readonly probe?: (pid: number) => ProcessLiveness;
|
|
116
136
|
/** Only this epic's record. */
|
|
117
137
|
readonly epicId?: string;
|
|
138
|
+
/** Session reader. @defaultValue `getSession` (session store) */
|
|
139
|
+
readonly readSession?: typeof getSession;
|
|
140
|
+
/** Session ender. @defaultValue `endSession` (session store) */
|
|
141
|
+
readonly endSession?: typeof endSession;
|
|
118
142
|
}
|
|
119
143
|
/**
|
|
120
|
-
* Release what a dead lead left behind: its
|
|
121
|
-
*
|
|
122
|
-
* never touched
|
|
144
|
+
* Release what a dead lead left behind: its CLEO session (and so its epic
|
|
145
|
+
* claim), its mailbox, its temp directory and its record. A live lead is
|
|
146
|
+
* never touched, and a dead lead whose session cannot be proven ended keeps
|
|
147
|
+
* its record (reported with `recordRemoved: false` and the reason).
|
|
123
148
|
*
|
|
124
149
|
* @param projectRoot - Project root.
|
|
125
150
|
* @param deps - See {@link ReapDeps}.
|
|
126
|
-
* @returns One entry per
|
|
151
|
+
* @returns One entry per dead lead found, removed or kept.
|
|
127
152
|
* @task T14363
|
|
128
153
|
*/
|
|
129
154
|
export declare function reapDeadLeads(projectRoot: string, deps?: ReapDeps): Promise<ReapedLead[]>;
|
|
@@ -10,11 +10,13 @@
|
|
|
10
10
|
* lease that only mutations renew), and a reused pid, whose start time
|
|
11
11
|
* differs, never blocks the epic.
|
|
12
12
|
*
|
|
13
|
-
* A lead killed before its `SessionEnd` hook ran (SIGKILL, OOM)
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
13
|
+
* A lead killed before its `SessionEnd` hook ran (SIGKILL, OOM), or one whose
|
|
14
|
+
* Orca terminal was closed after its session ended (T14513), leaves its record
|
|
15
|
+
* behind. {@link reapDeadLeads}, run by the next `cleo orchestrate lead` (which
|
|
16
|
+
* reports what it reaped under `data.lead.reaped`) and by `cleo orchestrate
|
|
17
|
+
* status`, releases such a lead's mailbox, ends its CLEO session unless it has
|
|
18
|
+
* already ended (freeing the epic claim), removes its temp directory (which
|
|
19
|
+
* may hold the mbx env) and deletes the record.
|
|
18
20
|
*
|
|
19
21
|
* The file is local runtime state (a pid means nothing on another device).
|
|
20
22
|
*
|
|
@@ -26,7 +28,7 @@ import { tmpdir } from 'node:os';
|
|
|
26
28
|
import { basename, dirname, join, relative, resolve } from 'node:path';
|
|
27
29
|
import { orcaLeadTerminalSchema, } from '@cleocode/contracts/orca-execution.js';
|
|
28
30
|
import { probeProcess } from '@cleocode/worktree';
|
|
29
|
-
import { endSession } from '../store/session-store.js';
|
|
31
|
+
import { endSession, getSession } from '../store/session-store.js';
|
|
30
32
|
import { createAgentMbxClient } from './agentmbx.js';
|
|
31
33
|
import { leadRecordsDir } from './lead-records-dir.js';
|
|
32
34
|
/** Task ids are plain words; anything else never reaches a file name. */
|
|
@@ -140,8 +142,10 @@ export function listLeadRecords(projectRoot) {
|
|
|
140
142
|
}
|
|
141
143
|
/**
|
|
142
144
|
* Whether a lead is alive: ANY of its processes runs with the start time
|
|
143
|
-
* recorded for it. A process whose start time was not recorded
|
|
144
|
-
*
|
|
145
|
+
* recorded for it. A process whose start time was not recorded, or whose
|
|
146
|
+
* current start time cannot be read, counts on its pid alone (never reaped
|
|
147
|
+
* without proof, T14513); a live pid with a different start time is a reused
|
|
148
|
+
* pid.
|
|
145
149
|
*
|
|
146
150
|
* @param record - The lead record.
|
|
147
151
|
* @param probe - Process probe. @defaultValue `probeProcess` (`@cleocode/worktree`)
|
|
@@ -151,7 +155,8 @@ export function listLeadRecords(projectRoot) {
|
|
|
151
155
|
export function isLeadAlive(record, probe = probeProcess) {
|
|
152
156
|
return record.processes.some((p) => {
|
|
153
157
|
const live = probe(p.pid);
|
|
154
|
-
return live.alive &&
|
|
158
|
+
return (live.alive &&
|
|
159
|
+
(p.startedAt === null || live.startedAt === null || live.startedAt === p.startedAt));
|
|
155
160
|
});
|
|
156
161
|
}
|
|
157
162
|
/**
|
|
@@ -163,14 +168,53 @@ function isSpawnTempDir(dir) {
|
|
|
163
168
|
const rel = relative(resolve(tmpdir()), resolve(dir));
|
|
164
169
|
return rel === basename(dir) && basename(dir).startsWith('cleo-claude-spawn-');
|
|
165
170
|
}
|
|
171
|
+
/** Proof that a dead lead's session no longer holds its epic claim, or why there is none. */
|
|
172
|
+
async function settleLeadSession(record, projectRoot, deps) {
|
|
173
|
+
const read = deps.readSession ?? getSession;
|
|
174
|
+
const end = deps.endSession ?? endSession;
|
|
175
|
+
let session;
|
|
176
|
+
try {
|
|
177
|
+
session = await read(record.cleoSessionId, projectRoot);
|
|
178
|
+
}
|
|
179
|
+
catch (err) {
|
|
180
|
+
return { alreadyEnded: false, ended: false, keptReason: `session unreadable: ${String(err)}` };
|
|
181
|
+
}
|
|
182
|
+
// No session found is not proof it ended (wrong store, a lagging read): keep the record.
|
|
183
|
+
if (session === null) {
|
|
184
|
+
return {
|
|
185
|
+
alreadyEnded: false,
|
|
186
|
+
ended: false,
|
|
187
|
+
keptReason: `session ${record.cleoSessionId} not found, so not proven ended`,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
// T14513: a session that already ended keeps its own end time and notes.
|
|
191
|
+
if (session.status === 'ended')
|
|
192
|
+
return { alreadyEnded: true, ended: false, keptReason: null };
|
|
193
|
+
try {
|
|
194
|
+
const after = await end(record.cleoSessionId, 'lead died; reaped', projectRoot);
|
|
195
|
+
if (after?.status === 'ended')
|
|
196
|
+
return { alreadyEnded: false, ended: true, keptReason: null };
|
|
197
|
+
return {
|
|
198
|
+
alreadyEnded: false,
|
|
199
|
+
ended: false,
|
|
200
|
+
keptReason: after === null
|
|
201
|
+
? `session ${record.cleoSessionId} end returned no session, so not proven ended`
|
|
202
|
+
: `session ${record.cleoSessionId} is still ${after.status}`,
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
catch (err) {
|
|
206
|
+
return { alreadyEnded: false, ended: false, keptReason: `session end failed: ${String(err)}` };
|
|
207
|
+
}
|
|
208
|
+
}
|
|
166
209
|
/**
|
|
167
|
-
* Release what a dead lead left behind: its
|
|
168
|
-
*
|
|
169
|
-
* never touched
|
|
210
|
+
* Release what a dead lead left behind: its CLEO session (and so its epic
|
|
211
|
+
* claim), its mailbox, its temp directory and its record. A live lead is
|
|
212
|
+
* never touched, and a dead lead whose session cannot be proven ended keeps
|
|
213
|
+
* its record (reported with `recordRemoved: false` and the reason).
|
|
170
214
|
*
|
|
171
215
|
* @param projectRoot - Project root.
|
|
172
216
|
* @param deps - See {@link ReapDeps}.
|
|
173
|
-
* @returns One entry per
|
|
217
|
+
* @returns One entry per dead lead found, removed or kept.
|
|
174
218
|
* @task T14363
|
|
175
219
|
*/
|
|
176
220
|
export async function reapDeadLeads(projectRoot, deps = {}) {
|
|
@@ -181,13 +225,25 @@ export async function reapDeadLeads(projectRoot, deps = {}) {
|
|
|
181
225
|
for (const record of records) {
|
|
182
226
|
if (isLeadAlive(record, deps.probe))
|
|
183
227
|
continue;
|
|
228
|
+
const session = await settleLeadSession(record, projectRoot, deps);
|
|
229
|
+
if (session.keptReason !== null) {
|
|
230
|
+
reaped.push({
|
|
231
|
+
epicId: record.epicId,
|
|
232
|
+
recordRemoved: false,
|
|
233
|
+
keptReason: session.keptReason,
|
|
234
|
+
pids: record.processes.map((p) => p.pid),
|
|
235
|
+
cleoSessionId: record.cleoSessionId,
|
|
236
|
+
mailboxReleased: false,
|
|
237
|
+
sessionEnded: false,
|
|
238
|
+
sessionAlreadyEnded: false,
|
|
239
|
+
tempDirRemoved: false,
|
|
240
|
+
});
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
184
243
|
const client = deps.mbxClient ?? createAgentMbxClient();
|
|
185
244
|
const release = record.mailbox
|
|
186
245
|
? await client.release({ cli: record.providerCli, session: record.providerSessionId })
|
|
187
246
|
: null;
|
|
188
|
-
const ended = await endSession(record.cleoSessionId, 'lead died; reaped', projectRoot)
|
|
189
|
-
.then(() => true)
|
|
190
|
-
.catch(() => false);
|
|
191
247
|
let tempDirRemoved = false;
|
|
192
248
|
if (record.tempDir && isSpawnTempDir(record.tempDir)) {
|
|
193
249
|
rmSync(record.tempDir, { recursive: true, force: true });
|
|
@@ -196,8 +252,13 @@ export async function reapDeadLeads(projectRoot, deps = {}) {
|
|
|
196
252
|
removeLeadRecord(projectRoot, record.epicId);
|
|
197
253
|
reaped.push({
|
|
198
254
|
epicId: record.epicId,
|
|
255
|
+
recordRemoved: true,
|
|
256
|
+
keptReason: null,
|
|
257
|
+
pids: record.processes.map((p) => p.pid),
|
|
258
|
+
cleoSessionId: record.cleoSessionId,
|
|
199
259
|
mailboxReleased: release?.ok === true,
|
|
200
|
-
sessionEnded: ended,
|
|
260
|
+
sessionEnded: session.ended,
|
|
261
|
+
sessionAlreadyEnded: session.alreadyEnded,
|
|
201
262
|
tempDirRemoved,
|
|
202
263
|
});
|
|
203
264
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lead-records.js","sourceRoot":"","sources":["../../src/orchestrate/lead-records.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"lead-records.js","sourceRoot":"","sources":["../../src/orchestrate/lead-records.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAA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AE,EAAE,KAAK,IAAI;YACrC,YAAY,EAAE,OAAO,CAAC,KAAK;YAC3B,mBAAmB,EAAE,OAAO,CAAC,YAAY;YACzC,cAAc;SACf,CAAC,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -26,6 +26,7 @@ import type { OrcaRoutingAdapter } from '@cleocode/contracts/orca-execution.js';
|
|
|
26
26
|
import { type ProcessLiveness } from '@cleocode/worktree';
|
|
27
27
|
import { type EngineResult } from '../engine-result.js';
|
|
28
28
|
import { type AgentMbxClient } from './agentmbx.js';
|
|
29
|
+
import { type ReapedLead } from './lead-records.js';
|
|
29
30
|
import { orchestrateSpawnExecute } from './spawn-ops.js';
|
|
30
31
|
/** Options for {@link orchestrateLead}. */
|
|
31
32
|
export interface OrchestrateLeadOptions {
|
|
@@ -82,6 +83,11 @@ export interface OrchestrateLeadInfo {
|
|
|
82
83
|
readonly mcp: LeadMcpReport | null;
|
|
83
84
|
/** Set when the lead runs without the mbx server: it cannot read worker mail. */
|
|
84
85
|
readonly mcpWarning?: string;
|
|
86
|
+
/**
|
|
87
|
+
* A dead lead's record this call found for the epic and removed before the
|
|
88
|
+
* new lead started (T14513): its processes were gone. Absent when none.
|
|
89
|
+
*/
|
|
90
|
+
readonly reaped?: readonly ReapedLead[];
|
|
85
91
|
}
|
|
86
92
|
/**
|
|
87
93
|
* Spawn the no-hands lead for an epic.
|
package/dist/orchestrate/lead.js
CHANGED
|
@@ -132,7 +132,7 @@ export async function orchestrateLead(epicId, options = {}) {
|
|
|
132
132
|
// T14363 — one lead per epic, for as long as the lead process lives: reap a
|
|
133
133
|
// dead lead's leftovers first, then refuse while a live lead's record stands.
|
|
134
134
|
const client = options.mbxClient ?? createAgentMbxClient();
|
|
135
|
-
await reapDeadLeads(root, {
|
|
135
|
+
const reaped = await reapDeadLeads(root, {
|
|
136
136
|
epicId,
|
|
137
137
|
mbxClient: client,
|
|
138
138
|
...(options.probe ? { probe: options.probe } : {}),
|
|
@@ -147,6 +147,32 @@ export async function orchestrateLead(epicId, options = {}) {
|
|
|
147
147
|
fix: `Wait for the running lead to exit (pid ${pids}); a dead one is reaped on the next cleo orchestrate lead or status.`,
|
|
148
148
|
});
|
|
149
149
|
}
|
|
150
|
+
// T14513 — a dead lead whose session could not be proven ended keeps its
|
|
151
|
+
// record (and its claim); never start a second lead over it.
|
|
152
|
+
const kept = reaped.find((r) => !r.recordRemoved);
|
|
153
|
+
if (kept) {
|
|
154
|
+
// @sync-invariant none:local-only a dead lead's unproven record blocks a new lead before a spawn
|
|
155
|
+
return engineError('E_LEAD_RECORD_KEPT', `The dead lead of ${epicId} keeps its record: ${kept.keptReason ?? 'its session is not proven ended'}`, {
|
|
156
|
+
exitCode: 6,
|
|
157
|
+
details: { epicId, reaped },
|
|
158
|
+
fix: `Run cleo orchestrate lead ${epicId} again once session ${kept.cleoSessionId} can be read and ended.`,
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
/** A failure that carries this call's reap report, so a cleanup never goes unreported. */
|
|
162
|
+
const withReaped = (failure) => failure.success || reaped.length === 0
|
|
163
|
+
? failure
|
|
164
|
+
: {
|
|
165
|
+
...failure,
|
|
166
|
+
error: {
|
|
167
|
+
...failure.error,
|
|
168
|
+
details: {
|
|
169
|
+
...(typeof failure.error.details === 'object' && failure.error.details !== null
|
|
170
|
+
? failure.error.details
|
|
171
|
+
: {}),
|
|
172
|
+
reaped,
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
};
|
|
150
176
|
const mode = options.mode ?? 'interactive';
|
|
151
177
|
const sessionId = randomUUID();
|
|
152
178
|
const state = {
|
|
@@ -212,15 +238,16 @@ export async function orchestrateLead(epicId, options = {}) {
|
|
|
212
238
|
// Refused or failed after admission: the spawn already handed the claim back.
|
|
213
239
|
await settle(false);
|
|
214
240
|
if (!result.success)
|
|
215
|
-
return result;
|
|
241
|
+
return withReaped(result);
|
|
216
242
|
const refusedMcp = leadMcpOf(data);
|
|
217
243
|
if (mode === 'detached' && refusedMcp !== null && refusedMcp.mailbox !== 'loaded') {
|
|
244
|
+
return withReaped(
|
|
218
245
|
// @sync-invariant none:local-only a detached lead with no owner channel never starts
|
|
219
|
-
|
|
246
|
+
engineError(E_LEAD_NO_OWNER_CHANNEL, `A detached lead needs the mbx MCP server to ask the owner, and it is ${refusedMcp.mailbox === 'refused' ? `refused: ${refusedMcp.warning ?? 'it failed the checks'}` : 'not configured'}`, {
|
|
220
247
|
exitCode: 6,
|
|
221
248
|
details: { epicId, mcp: refusedMcp },
|
|
222
249
|
fix: 'Configure the mbx MCP server at user scope in ~/.claude.json (an absolute path to the agentmbx binary, args ["mcp"]), e.g. `agentmbx setup --only claude`; or run the lead interactively (drop --detached), where it asks with AskUserQuestion.',
|
|
223
|
-
});
|
|
250
|
+
}));
|
|
224
251
|
}
|
|
225
252
|
}
|
|
226
253
|
else if (mode === 'interactive' && 'status' in data && data.status === 'completed') {
|
|
@@ -249,6 +276,7 @@ export async function orchestrateLead(epicId, options = {}) {
|
|
|
249
276
|
mode,
|
|
250
277
|
mailbox,
|
|
251
278
|
mcp,
|
|
279
|
+
...(reaped.length > 0 ? { reaped } : {}),
|
|
252
280
|
...(mcp?.mailbox === 'not-configured'
|
|
253
281
|
? {
|
|
254
282
|
mcpWarning: 'No user-level mbx MCP server is configured, so the lead loads only the runner and cannot read worker mail. Configure the mbx server (agentmbx mcp) in ~/.claude.json and re-run.',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lead.js","sourceRoot":"","sources":["../../src/orchestrate/lead.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EACL,uBAAuB,EACvB,aAAa,EACb,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,+CAA+C,CAAC;AAEvD,OAAO,EAAwB,oBAAoB,EAAE,MAAM,oBAAoB,CA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C,CAAC;QAC1E,8EAA8E;aACzE,IAAI,IAAI,KAAK,IAAI;YAAE,gBAAgB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACzD,CAAC;IACD,MAAM,GAAG,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;IAC5B,MAAM,UAAU,GAAG,KAAK,CAAC,KAAK,CAAC;IAC/B,MAAM,OAAO,GAAmC,UAAU,CAAC,EAAE;QAC3D,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,CAAC,KAAK,CAAC,IAAI,EAAE;QAChD,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,CAAC,OAAO,EAAE,CAAC;IACpD,MAAM,IAAI,GAAwB;QAChC,WAAW,EAAE,iBAAiB;QAC9B,UAAU,EAAE,gBAAgB;QAC5B,SAAS;QACT,IAAI;QACJ,OAAO;QACP,GAAG;QACH,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACxC,GAAG,CAAC,GAAG,EAAE,OAAO,KAAK,gBAAgB;YACnC,CAAC,CAAC;gBACE,UAAU,EACR,kLAAkL;aACrL;YACH,CAAC,CAAC,GAAG,EAAE,OAAO,KAAK,SAAS;gBAC1B,CAAC,CAAC;oBACE,UAAU,EAAE,sEAAsE,GAAG,CAAC,OAAO,IAAI,sBAAsB,GAAG;iBAC3H;gBACH,CAAC,CAAC,EAAE,CAAC;KACV,CAAC;IACF,OAAO,aAAa,CAAC,EAAE,GAAG,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;AAC1C,CAAC"}
|
|
@@ -97,7 +97,8 @@ export declare function loadTasks(projectRoot?: string): Promise<Task[]>;
|
|
|
97
97
|
* @param epicId - Optional epic id to scope status to a single epic.
|
|
98
98
|
* @param projectRoot - Optional project root path.
|
|
99
99
|
* @returns Engine result with status data, plus `workers`: the durable worker
|
|
100
|
-
* records (T14359), after emitting SubagentStop for any that have exited
|
|
100
|
+
* records (T14359), after emitting SubagentStop for any that have exited, and
|
|
101
|
+
* `reapedLeads` when a dead lead record was found, removed or kept (T14513).
|
|
101
102
|
* @task T4478
|
|
102
103
|
*/
|
|
103
104
|
export declare function orchestrateStatus(epicId?: string, projectRoot?: string): Promise<EngineResult>;
|
|
@@ -104,10 +104,14 @@ export async function loadTasks(projectRoot) {
|
|
|
104
104
|
}
|
|
105
105
|
/**
|
|
106
106
|
* Close the records of exited workers (emitting their SubagentStop) and reap
|
|
107
|
-
* dead leads (T14363), then list every worker record. Best-effort: a store
|
|
108
|
-
* rather than failing the status read.
|
|
107
|
+
* dead leads (T14363), then list every worker record. Best-effort: a store
|
|
108
|
+
* failure yields an empty list rather than failing the status read.
|
|
109
|
+
*
|
|
110
|
+
* @returns The worker records, and every dead lead record the reap found,
|
|
111
|
+
* removed or kept (T14513), so a cleanup is never silent.
|
|
109
112
|
*/
|
|
110
113
|
async function loadWorkerRecords(root) {
|
|
114
|
+
let reapedLeads = [];
|
|
111
115
|
try {
|
|
112
116
|
await reconcileWorkerExits(root);
|
|
113
117
|
// T14363 — a lead killed before its hooks ran gives back its mailbox,
|
|
@@ -115,22 +119,30 @@ async function loadWorkerRecords(root) {
|
|
|
115
119
|
// Loaded only when a record exists, so status stays inside its gate-39 budget.
|
|
116
120
|
if (hasLeadRecords(root)) {
|
|
117
121
|
const { reapDeadLeads } = await import('./lead-records.js');
|
|
118
|
-
await reapDeadLeads(root).catch((err) =>
|
|
122
|
+
reapedLeads = await reapDeadLeads(root).catch((err) => {
|
|
123
|
+
getLogger('engine:orchestrate').warn({ err: String(err) }, 'lead reap failed');
|
|
124
|
+
return [];
|
|
125
|
+
});
|
|
119
126
|
}
|
|
120
|
-
return await listWorkerRecords(root);
|
|
127
|
+
return { workers: await listWorkerRecords(root), reapedLeads };
|
|
121
128
|
}
|
|
122
129
|
catch (err) {
|
|
123
130
|
getLogger('engine:orchestrate').warn({ err: String(err) }, 'worker records unavailable');
|
|
124
|
-
return [];
|
|
131
|
+
return { workers: [], reapedLeads };
|
|
125
132
|
}
|
|
126
133
|
}
|
|
134
|
+
/** `reapedLeads` for a status payload, only when the reap found a dead lead. */
|
|
135
|
+
function reapReport(reapedLeads) {
|
|
136
|
+
return reapedLeads.length > 0 ? { reapedLeads } : {};
|
|
137
|
+
}
|
|
127
138
|
/**
|
|
128
139
|
* orchestrate.status - Get orchestrator status
|
|
129
140
|
*
|
|
130
141
|
* @param epicId - Optional epic id to scope status to a single epic.
|
|
131
142
|
* @param projectRoot - Optional project root path.
|
|
132
143
|
* @returns Engine result with status data, plus `workers`: the durable worker
|
|
133
|
-
* records (T14359), after emitting SubagentStop for any that have exited
|
|
144
|
+
* records (T14359), after emitting SubagentStop for any that have exited, and
|
|
145
|
+
* `reapedLeads` when a dead lead record was found, removed or kept (T14513).
|
|
134
146
|
* @task T4478
|
|
135
147
|
*/
|
|
136
148
|
export async function orchestrateStatus(epicId, projectRoot) {
|
|
@@ -149,12 +161,17 @@ export async function orchestrateStatus(epicId, projectRoot) {
|
|
|
149
161
|
const { waves } = await planEpicWaves(epicId, await getTaskAccessor(root), [epicId], undefined, root);
|
|
150
162
|
const status = computeEpicStatus(epicId, epic.title, children, waves);
|
|
151
163
|
const childIds = new Set(children.map((t) => t.id));
|
|
152
|
-
const
|
|
153
|
-
|
|
164
|
+
const loaded = await loadWorkerRecords(root);
|
|
165
|
+
const workers = loaded.workers.filter((w) => childIds.has(w.taskId));
|
|
166
|
+
return { success: true, data: { ...status, workers, ...reapReport(loaded.reapedLeads) } };
|
|
154
167
|
}
|
|
155
168
|
// No epicId - return overall status
|
|
156
169
|
const status = computeOverallStatus(tasks);
|
|
157
|
-
|
|
170
|
+
const loaded = await loadWorkerRecords(root);
|
|
171
|
+
return {
|
|
172
|
+
success: true,
|
|
173
|
+
data: { ...status, workers: loaded.workers, ...reapReport(loaded.reapedLeads) },
|
|
174
|
+
};
|
|
158
175
|
});
|
|
159
176
|
}
|
|
160
177
|
catch (err) {
|