@yankeguo/dsh-devlead 0.4.0-rc.1 → 0.4.1
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 +5 -3
- package/lib/index.js +375 -27
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -59,9 +59,11 @@ dsh plugin --profile desktop add @yankeguo/dsh-devlead-bundle
|
|
|
59
59
|
structured domain errors; no experimental package is imported, injected, or declared.
|
|
60
60
|
- Cold-lead rehydration: at plugin load the hub rebuilds its watch index from durable state
|
|
61
61
|
(`sessionQuery` listing → projection-cache pre-filter → exact fold; unclassified rows are capped
|
|
62
|
-
at 64 full-log reads). Without a projection cache
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
at 64 full-log reads per bounded attempt, with a saved cursor). Without a projection cache every cold
|
|
63
|
+
candidate uses the same bounded exact fold. A precise unknown-non-ignorable legacy event can trigger
|
|
64
|
+
read-only recovery of the complete current v4 JSONL artifact; all DevLead records still use the strict
|
|
65
|
+
fold, and other formats/read failures stay fail closed. A disposed lead keeps observing;
|
|
66
|
+
`wakeColdSession` defaults to `true`, so a queued notification resumes the cold lead before delivering.
|
|
65
67
|
|
|
66
68
|
## Configuration
|
|
67
69
|
|
package/lib/index.js
CHANGED
|
@@ -122,6 +122,302 @@ function readRecord(event) {
|
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
+
// packages/devlead/src/session-log-recovery.ts
|
|
126
|
+
import { open, stat } from "node:fs/promises";
|
|
127
|
+
import { isAbsolute } from "node:path";
|
|
128
|
+
import { promisify } from "node:util";
|
|
129
|
+
import { constants, zstdDecompress } from "node:zlib";
|
|
130
|
+
import { SessionLogOffset } from "@deepseek-ai/dsh-session";
|
|
131
|
+
var decompress = promisify(zstdDecompress);
|
|
132
|
+
var utf8 = new TextDecoder("utf-8", { fatal: true });
|
|
133
|
+
var ZSTD_MAGIC = 4247762216;
|
|
134
|
+
var DEVLEAD_RECORD_PREFIX = "plugin:devlead/";
|
|
135
|
+
var HEADER_REQUIRED = ["type", "version", "id", "createdAt", "isSeeded", "delegationDepth"];
|
|
136
|
+
var HEADER_OPTIONAL = ["cwd", "parentSession", "origin", "agentPreset"];
|
|
137
|
+
var EVENT_REQUIRED = ["type", "seq", "time", "data"];
|
|
138
|
+
var EVENT_OPTIONAL = ["ignorable", "sourceEventSeqs", "surfaceOp"];
|
|
139
|
+
function isUnknownNonIgnorableEventError(error51) {
|
|
140
|
+
for (let current = error51, depth = 0; depth < 8 && current !== void 0 && current !== null; depth += 1) {
|
|
141
|
+
if (typeof current === "object") {
|
|
142
|
+
const candidate = current;
|
|
143
|
+
if (candidate.name === "SessionFormatUnsupportedError" && typeof candidate.message === "string" && candidate.message.includes("unknown to this harness and not marked ignorable")) return true;
|
|
144
|
+
current = candidate.cause;
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
async function recoverUnknownEventSessionLog(ctx, header, signal) {
|
|
152
|
+
const persistence = ctx.get("sessionPersistence");
|
|
153
|
+
const stat2 = persistence?.stat;
|
|
154
|
+
if (typeof stat2 !== "function") {
|
|
155
|
+
throw new Error(`Session "${String(header.id)}" needs read-only log recovery, but the persistence backend exposes no stat()`);
|
|
156
|
+
}
|
|
157
|
+
signal?.throwIfAborted();
|
|
158
|
+
const snapshot = await stat2.call(
|
|
159
|
+
persistence,
|
|
160
|
+
header.id,
|
|
161
|
+
signal === void 0 ? void 0 : { signal }
|
|
162
|
+
);
|
|
163
|
+
signal?.throwIfAborted();
|
|
164
|
+
const location = snapshot?.location;
|
|
165
|
+
const path = location?.path;
|
|
166
|
+
const kind = location?.kind;
|
|
167
|
+
if (kind !== "jsonl" || typeof path !== "string" || !isAbsolute(path)) {
|
|
168
|
+
throw new Error(`Session "${String(header.id)}" has no backend-verified absolute JSONL artifact path for read-only recovery`);
|
|
169
|
+
}
|
|
170
|
+
return await readCurrentJsonlForDevLead(path, header, signal);
|
|
171
|
+
}
|
|
172
|
+
async function readCurrentJsonlForDevLead(path, expectedHeader, signal) {
|
|
173
|
+
if (!isAbsolute(path) || !/session\.v4\.jsonl(?:\.zstd)?$/.test(path)) {
|
|
174
|
+
throw new Error(`read-only DevLead recovery supports only current session.v4.jsonl[.zstd] artifacts: ${path}`);
|
|
175
|
+
}
|
|
176
|
+
signal?.throwIfAborted();
|
|
177
|
+
const beforePath = await stat(path, { bigint: true });
|
|
178
|
+
const handle = await open(path, "r");
|
|
179
|
+
let bytes;
|
|
180
|
+
try {
|
|
181
|
+
const beforeHandle = await handle.stat({ bigint: true });
|
|
182
|
+
assertSamePhysicalFile(beforePath, beforeHandle, path);
|
|
183
|
+
bytes = await handle.readFile(signal === void 0 ? void 0 : { signal });
|
|
184
|
+
const afterHandle = await handle.stat({ bigint: true });
|
|
185
|
+
const afterPath = await stat(path, { bigint: true });
|
|
186
|
+
assertSamePhysicalFile(beforeHandle, afterHandle, path);
|
|
187
|
+
assertSamePhysicalFile(afterHandle, afterPath, path);
|
|
188
|
+
} finally {
|
|
189
|
+
await handle.close();
|
|
190
|
+
}
|
|
191
|
+
signal?.throwIfAborted();
|
|
192
|
+
let plaintext;
|
|
193
|
+
try {
|
|
194
|
+
plaintext = path.endsWith(".zstd") ? await decodeZstdFrames(bytes, signal) : bytes;
|
|
195
|
+
} catch (error51) {
|
|
196
|
+
signal?.throwIfAborted();
|
|
197
|
+
throw new Error(`could not decode Session log ${path}: ${error51 instanceof Error ? error51.message : String(error51)}`, { cause: error51 });
|
|
198
|
+
}
|
|
199
|
+
signal?.throwIfAborted();
|
|
200
|
+
const events = parseCurrentJsonl(plaintext, expectedHeader, path);
|
|
201
|
+
return { path, inheritedEventCount: inheritedCut(events, expectedHeader, path), events };
|
|
202
|
+
}
|
|
203
|
+
function assertSamePhysicalFile(left, right, path) {
|
|
204
|
+
if (left.dev !== right.dev || left.ino !== right.ino || left.size !== right.size || left.mtimeNs !== right.mtimeNs || left.ctimeNs !== right.ctimeNs) {
|
|
205
|
+
throw new Error(`Session log changed during read-only recovery; retry the bounded scan: ${path}`);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
async function decodeZstdFrames(bytes, signal) {
|
|
209
|
+
const { frames, tornStart } = scanFrames(bytes);
|
|
210
|
+
if (frames.length === 0) throw new Error("empty or header-less Zstandard session log");
|
|
211
|
+
const chunks = [];
|
|
212
|
+
for (const frame of frames) {
|
|
213
|
+
signal?.throwIfAborted();
|
|
214
|
+
chunks.push(await decompress(bytes.subarray(frame.start, frame.end)));
|
|
215
|
+
}
|
|
216
|
+
const header = chunks[0];
|
|
217
|
+
if (header.length === 0 || header.indexOf(10) !== header.length - 1) {
|
|
218
|
+
throw new Error("corrupt Zstandard session log: first frame is not exactly one header line");
|
|
219
|
+
}
|
|
220
|
+
const complete = Buffer.concat(chunks);
|
|
221
|
+
if (complete.length === 0 || complete.at(-1) !== 10) {
|
|
222
|
+
throw new Error("corrupt Zstandard session log: complete frame contains a torn JSONL record");
|
|
223
|
+
}
|
|
224
|
+
if (tornStart === void 0) return complete;
|
|
225
|
+
signal?.throwIfAborted();
|
|
226
|
+
try {
|
|
227
|
+
const recovered = await decompress(bytes.subarray(tornStart), {
|
|
228
|
+
finishFlush: constants.ZSTD_e_flush
|
|
229
|
+
});
|
|
230
|
+
return Buffer.concat([complete, recovered]);
|
|
231
|
+
} catch (error51) {
|
|
232
|
+
signal?.throwIfAborted();
|
|
233
|
+
if (error51 instanceof Error && error51.name === "AbortError") throw error51;
|
|
234
|
+
return complete;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
function scanFrames(bytes) {
|
|
238
|
+
const frames = [];
|
|
239
|
+
let offset = 0;
|
|
240
|
+
while (offset < bytes.length) {
|
|
241
|
+
const start = offset;
|
|
242
|
+
if (bytes.length - offset < 4) return { frames, tornStart: start };
|
|
243
|
+
if (bytes.readUInt32LE(offset) !== ZSTD_MAGIC) {
|
|
244
|
+
throw new Error(`corrupt Zstandard session log: invalid frame magic at byte ${offset}`);
|
|
245
|
+
}
|
|
246
|
+
offset += 4;
|
|
247
|
+
if (offset === bytes.length) return { frames, tornStart: start };
|
|
248
|
+
const descriptor = bytes.readUInt8(offset);
|
|
249
|
+
offset += 1;
|
|
250
|
+
if ((descriptor & 24) !== 0) {
|
|
251
|
+
throw new Error(`corrupt Zstandard session log: reserved frame-header bit at byte ${offset - 1}`);
|
|
252
|
+
}
|
|
253
|
+
const contentSizeFlag = descriptor >>> 6;
|
|
254
|
+
const singleSegment = (descriptor & 32) !== 0;
|
|
255
|
+
const checksum = (descriptor & 4) !== 0;
|
|
256
|
+
const dictionaryFlag = descriptor & 3;
|
|
257
|
+
const dictionaryBytes = dictionaryFlag === 3 ? 4 : dictionaryFlag;
|
|
258
|
+
const contentSizeBytes = contentSizeFlag === 0 ? singleSegment ? 1 : 0 : 1 << contentSizeFlag;
|
|
259
|
+
const remainingHeaderBytes = (singleSegment ? 0 : 1) + dictionaryBytes + contentSizeBytes;
|
|
260
|
+
if (bytes.length - offset < remainingHeaderBytes) return { frames, tornStart: start };
|
|
261
|
+
offset += remainingHeaderBytes;
|
|
262
|
+
for (; ; ) {
|
|
263
|
+
if (bytes.length - offset < 3) return { frames, tornStart: start };
|
|
264
|
+
const blockHeader = bytes.readUIntLE(offset, 3);
|
|
265
|
+
offset += 3;
|
|
266
|
+
const lastBlock = (blockHeader & 1) !== 0;
|
|
267
|
+
const blockType = blockHeader >>> 1 & 3;
|
|
268
|
+
const blockSize = blockHeader >>> 3;
|
|
269
|
+
if (blockType === 3) {
|
|
270
|
+
throw new Error(`corrupt Zstandard session log: reserved block type at byte ${offset - 3}`);
|
|
271
|
+
}
|
|
272
|
+
const payloadBytes = blockType === 1 ? 1 : blockSize;
|
|
273
|
+
if (bytes.length - offset < payloadBytes) return { frames, tornStart: start };
|
|
274
|
+
offset += payloadBytes;
|
|
275
|
+
if (lastBlock) break;
|
|
276
|
+
}
|
|
277
|
+
if (checksum) {
|
|
278
|
+
if (bytes.length - offset < 4) return { frames, tornStart: start };
|
|
279
|
+
offset += 4;
|
|
280
|
+
}
|
|
281
|
+
frames.push({ start, end: offset });
|
|
282
|
+
}
|
|
283
|
+
return { frames };
|
|
284
|
+
}
|
|
285
|
+
function parseCurrentJsonl(bytes, expectedHeader, path) {
|
|
286
|
+
const headerEnd = bytes.indexOf(10);
|
|
287
|
+
if (headerEnd < 0) throw new Error(`empty or header-less Session log: ${path}`);
|
|
288
|
+
const header = parseRecord(bytes.subarray(0, headerEnd), "header", path);
|
|
289
|
+
assertExactKeys(header, HEADER_REQUIRED, HEADER_OPTIONAL, "physical Session header", path);
|
|
290
|
+
if (header["type"] !== "session" || header["version"] !== 4 || typeof header["id"] !== "string" || typeof header["isSeeded"] !== "boolean" || header["origin"] !== void 0 && header["origin"] !== "subagent") {
|
|
291
|
+
throw new Error(`invalid physical v4 Session header in ${path}`);
|
|
292
|
+
}
|
|
293
|
+
assertCount(header["createdAt"], "header createdAt", path);
|
|
294
|
+
assertCount(header["delegationDepth"], "header delegationDepth", path);
|
|
295
|
+
for (const key of ["parentSession", "agentPreset"]) {
|
|
296
|
+
if (header[key] !== void 0 && typeof header[key] !== "string") {
|
|
297
|
+
throw new Error(`invalid physical Session header ${key} in ${path}`);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
if (header["cwd"] !== void 0 && (typeof header["cwd"] !== "string" || !isAbsolute(header["cwd"]))) {
|
|
301
|
+
throw new Error(`invalid physical Session header cwd in ${path}`);
|
|
302
|
+
}
|
|
303
|
+
if (header["id"] !== String(expectedHeader.id) || header["createdAt"] !== expectedHeader.createdAt || header["isSeeded"] !== (expectedHeader.isSeeded === true) || header["cwd"] !== expectedHeader.cwd || header["parentSession"] !== expectedHeader.parentSession || header["origin"] !== expectedHeader.origin || header["agentPreset"] !== expectedHeader.agentPreset || header["delegationDepth"] !== (expectedHeader.delegationDepth ?? 0)) {
|
|
304
|
+
throw new Error(`Session log header does not match the validated corpus listing: ${path}`);
|
|
305
|
+
}
|
|
306
|
+
const events = [];
|
|
307
|
+
let lineStart = headerEnd + 1;
|
|
308
|
+
while (lineStart < bytes.length) {
|
|
309
|
+
const newline = bytes.indexOf(10, lineStart);
|
|
310
|
+
if (newline < 0) break;
|
|
311
|
+
const line = bytes.subarray(lineStart, newline);
|
|
312
|
+
lineStart = newline + 1;
|
|
313
|
+
const event = parseRecord(line, `event ${String(events.length)}`, path);
|
|
314
|
+
assertExactKeys(event, EVENT_REQUIRED, EVENT_OPTIONAL, `Session event ${String(events.length)}`, path);
|
|
315
|
+
if (typeof event["type"] !== "string" || event["type"].length === 0) {
|
|
316
|
+
throw new Error(`invalid Session event type at seq ${String(events.length)} in ${path}`);
|
|
317
|
+
}
|
|
318
|
+
assertCount(event["seq"], `Session event ${String(events.length)} seq`, path);
|
|
319
|
+
if (event["seq"] !== events.length) {
|
|
320
|
+
throw new Error(`non-contiguous Session event ${String(events.length)} in ${path}`);
|
|
321
|
+
}
|
|
322
|
+
if (!Number.isSafeInteger(event["time"]) || Object.is(event["time"], -0)) {
|
|
323
|
+
throw new Error(`invalid Session event time at seq ${String(events.length)} in ${path}`);
|
|
324
|
+
}
|
|
325
|
+
if (event["ignorable"] !== void 0 && event["ignorable"] !== true) {
|
|
326
|
+
throw new Error(`Session event ignorable must be true when present at seq ${String(events.length)} in ${path}`);
|
|
327
|
+
}
|
|
328
|
+
if (event["type"] === "session/end-seed") assertEndSeedData(event["data"], events.length, path);
|
|
329
|
+
if (event["type"].startsWith(DEVLEAD_RECORD_PREFIX) && event["ignorable"] !== true) {
|
|
330
|
+
throw new Error(`DevLead record at seq ${String(events.length)} is not marked ignorable in ${path}`);
|
|
331
|
+
}
|
|
332
|
+
const decoded = event["sourceEventSeqs"] === void 0 ? event : {
|
|
333
|
+
...event,
|
|
334
|
+
sourceEventSeqs: decodeSourceEventSeqs(event["sourceEventSeqs"], events.length, path)
|
|
335
|
+
};
|
|
336
|
+
events.push(decoded);
|
|
337
|
+
}
|
|
338
|
+
return events;
|
|
339
|
+
}
|
|
340
|
+
function assertEndSeedData(data, seq, path) {
|
|
341
|
+
if (typeof data !== "object" || data === null || Array.isArray(data)) {
|
|
342
|
+
throw new Error(`session/end-seed data must be an object at seq ${String(seq)} in ${path}`);
|
|
343
|
+
}
|
|
344
|
+
const record2 = data;
|
|
345
|
+
if (Object.keys(record2).some((key) => key !== "inherited") || record2["inherited"] !== void 0 && record2["inherited"] !== true) {
|
|
346
|
+
throw new Error(`invalid session/end-seed data at seq ${String(seq)} in ${path}`);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
function assertExactKeys(record2, required2, optional2, label, path) {
|
|
350
|
+
const allowed = /* @__PURE__ */ new Set([...required2, ...optional2]);
|
|
351
|
+
const missing = required2.find((key) => !Object.hasOwn(record2, key));
|
|
352
|
+
if (missing !== void 0) throw new Error(`${label} lacks required field ${missing} in ${path}`);
|
|
353
|
+
const unexpected = Object.keys(record2).find((key) => !allowed.has(key));
|
|
354
|
+
if (unexpected !== void 0) throw new Error(`${label} has unexpected field ${unexpected} in ${path}`);
|
|
355
|
+
}
|
|
356
|
+
function assertCount(value, label, path) {
|
|
357
|
+
if (!Number.isSafeInteger(value) || value < 0 || Object.is(value, -0)) {
|
|
358
|
+
throw new Error(`${label} must be a non-negative safe integer in ${path}`);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
function decodeSourceEventSeqs(value, maxEntries, path) {
|
|
362
|
+
if (!Array.isArray(value)) throw new Error(`sourceEventSeqs must be an array in ${path}`);
|
|
363
|
+
const output = [];
|
|
364
|
+
let hasRange = false;
|
|
365
|
+
for (const entry of value) {
|
|
366
|
+
if (!Array.isArray(entry)) {
|
|
367
|
+
assertCount(entry, "sourceEventSeqs member", path);
|
|
368
|
+
output.push(entry);
|
|
369
|
+
continue;
|
|
370
|
+
}
|
|
371
|
+
if (entry.length !== 2) throw new Error(`sourceEventSeqs range must be a [start, end] pair in ${path}`);
|
|
372
|
+
assertCount(entry[0], "sourceEventSeqs range start", path);
|
|
373
|
+
assertCount(entry[1], "sourceEventSeqs range end", path);
|
|
374
|
+
const start = entry[0];
|
|
375
|
+
const end = entry[1];
|
|
376
|
+
if (start > end || end >= maxEntries || end - start + 1 > maxEntries - output.length) {
|
|
377
|
+
throw new Error(`sourceEventSeqs range exceeds its event seq in ${path}`);
|
|
378
|
+
}
|
|
379
|
+
for (let current = start; current <= end; current += 1) output.push(current);
|
|
380
|
+
hasRange = true;
|
|
381
|
+
}
|
|
382
|
+
const seen = /* @__PURE__ */ new Set();
|
|
383
|
+
for (const source of output) {
|
|
384
|
+
if (source >= maxEntries || seen.has(source)) {
|
|
385
|
+
throw new Error(`sourceEventSeqs must contain unique earlier seqs in ${path}`);
|
|
386
|
+
}
|
|
387
|
+
seen.add(source);
|
|
388
|
+
}
|
|
389
|
+
if (hasRange && output.some((source, index) => index > 0 && source <= output[index - 1])) {
|
|
390
|
+
throw new Error(`sourceEventSeqs ranges must be strictly increasing in ${path}`);
|
|
391
|
+
}
|
|
392
|
+
return output;
|
|
393
|
+
}
|
|
394
|
+
function parseRecord(line, label, path) {
|
|
395
|
+
let value;
|
|
396
|
+
try {
|
|
397
|
+
value = JSON.parse(utf8.decode(line));
|
|
398
|
+
} catch (error51) {
|
|
399
|
+
throw new Error(`invalid committed ${label} JSON in ${path}`, { cause: error51 });
|
|
400
|
+
}
|
|
401
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
402
|
+
throw new Error(`invalid committed ${label}: expected a JSON object in ${path}`);
|
|
403
|
+
}
|
|
404
|
+
return value;
|
|
405
|
+
}
|
|
406
|
+
function inheritedCut(events, header, path) {
|
|
407
|
+
let inherited;
|
|
408
|
+
for (const event of events) {
|
|
409
|
+
if (event.type !== "session/end-seed") continue;
|
|
410
|
+
const data = event.data;
|
|
411
|
+
if (data?.inherited === true) inherited = event.seq;
|
|
412
|
+
}
|
|
413
|
+
if (header.isSeeded === true) {
|
|
414
|
+
if (inherited === void 0) throw new Error(`seeded Session has no inherited-cut marker: ${path}`);
|
|
415
|
+
return SessionLogOffset(inherited);
|
|
416
|
+
}
|
|
417
|
+
if (inherited !== void 0) throw new Error(`unseeded Session has an inherited-cut marker: ${path}`);
|
|
418
|
+
return SessionLogOffset(0);
|
|
419
|
+
}
|
|
420
|
+
|
|
125
421
|
// packages/devlead/src/index.ts
|
|
126
422
|
import {
|
|
127
423
|
DEVLEAD_DEFAULT_MAX_WATCHED as DEVLEAD_DEFAULT_MAX_WATCHED2,
|
|
@@ -19870,9 +20166,9 @@ var REHYDRATION_FINALIZE_TIMEOUT_MS = 5e3;
|
|
|
19870
20166
|
var MAX_FINALIZE_LISTING_REFRESHES = 2;
|
|
19871
20167
|
var DEFAULT_SUPERVISION_DEGRADED_REASON = "the cold-lead supervisor index is incomplete";
|
|
19872
20168
|
var REHYDRATION_PROBE_MESSAGES = {
|
|
19873
|
-
"corrupt-terminal": "devlead: cold lead rehydration is degraded by a corrupt persisted DevLead replay; ordinary retries are paused and a slow 30s recovery probe retries every 30s.
|
|
19874
|
-
"live-failure": "devlead: a live attached DevLead projection is corrupt, so the supervisor set cannot be proven; prompting stays disabled until it is repaired. Open the affected Session
|
|
19875
|
-
"retry-cap": `devlead: cold lead rehydration failed ${String(MAX_REHYDRATION_RETRY_ATTEMPTS)} bounded retry attempts; prompting stays disabled until a complete scan succeeds. Open (resume) the
|
|
20169
|
+
"corrupt-terminal": "devlead: cold lead rehydration is degraded by a corrupt persisted DevLead replay; ordinary retries are paused and a slow 30s recovery probe retries every 30s. Resolve any raw format/read blocker in the detailed error, then open (resume) the affected DevLead Session and run /devlead reset there; the probe recovers once the cause is removed (a Host restart also rebuilds the index)",
|
|
20170
|
+
"live-failure": "devlead: a live attached DevLead projection is corrupt, so the supervisor set cannot be proven; prompting stays disabled until it is repaired. Open the affected Session and run /devlead reset there; the slow 30s recovery probe retries every 30s and recovers once the cause is removed",
|
|
20171
|
+
"retry-cap": `devlead: cold lead rehydration failed ${String(MAX_REHYDRATION_RETRY_ATTEMPTS)} bounded retry attempts; prompting stays disabled until a complete scan succeeds. Follow the detailed Session/path/cause error: transient causes need no log edits. Open (resume) the named DevLead Session for corrupt DevLead records and run /devlead reset there; raw storage failures require storage/plugin repair or a readable backup; the slow 30s recovery probe retries every 30s and a Host restart also rebuilds the index`
|
|
19876
20172
|
};
|
|
19877
20173
|
var REHYDRATION_DEGRADED_CAUSES = {
|
|
19878
20174
|
list: "the persisted Session corpus could not be listed",
|
|
@@ -20107,6 +20403,8 @@ var DevLeadService = class extends Service {
|
|
|
20107
20403
|
liveAttachFailure = false;
|
|
20108
20404
|
/** Human-readable cause of the current degraded supervision state. */
|
|
20109
20405
|
supervisionDegradedReason = DEFAULT_SUPERVISION_DEGRADED_REASON;
|
|
20406
|
+
/** Latest concrete Session/path/cause; retained when a later retry-cap warning is emitted. */
|
|
20407
|
+
supervisionDegradedDetail;
|
|
20110
20408
|
/** Invalidates every in-flight scan application; bumped by reset and service recomposition. */
|
|
20111
20409
|
rehydrationEpoch = 0;
|
|
20112
20410
|
/** Whether the current attempt reached the corpus scan (early live-only returns do not). */
|
|
@@ -21111,6 +21409,7 @@ var DevLeadService = class extends Service {
|
|
|
21111
21409
|
this.rehydrated = true;
|
|
21112
21410
|
this.corpusWasProven = true;
|
|
21113
21411
|
this.supervisionDegradedReason = DEFAULT_SUPERVISION_DEGRADED_REASON;
|
|
21412
|
+
this.supervisionDegradedDetail = void 0;
|
|
21114
21413
|
this.trustedBindings = this.currentCorpusBindings();
|
|
21115
21414
|
this.observedBindings = this.trustedBindings;
|
|
21116
21415
|
this.coldScan = void 0;
|
|
@@ -21326,6 +21625,7 @@ var DevLeadService = class extends Service {
|
|
|
21326
21625
|
if (this.disposed) return;
|
|
21327
21626
|
this.invalidateCorpusProof();
|
|
21328
21627
|
this.supervisionDegradedReason = reason;
|
|
21628
|
+
this.supervisionDegradedDetail = void 0;
|
|
21329
21629
|
this.requestFreshRehydration();
|
|
21330
21630
|
this.armRehydrationRetry(this.ctx.get("sessionQuery") !== void 0);
|
|
21331
21631
|
void this.rehydrateFromPersistence();
|
|
@@ -21406,8 +21706,8 @@ var DevLeadService = class extends Service {
|
|
|
21406
21706
|
* states and exhausted retry budgets are recoverable without a Host restart:
|
|
21407
21707
|
* the probe re-lists and rescans once every {@link DEGRADED_REHYDRATION_PROBE_MS}.
|
|
21408
21708
|
* The probe itself does not repair anything: it retries every 30s and recovers
|
|
21409
|
-
*
|
|
21410
|
-
* corrupt
|
|
21709
|
+
* after the transient cause clears, a read-only recovery succeeds, a human
|
|
21710
|
+
* resets corrupt DevLead state, or the Host restarts. An explicit reset recovers immediately.
|
|
21411
21711
|
* @param reason - stable warning key and degraded-state cause.
|
|
21412
21712
|
*/
|
|
21413
21713
|
scheduleRehydrationProbe(reason) {
|
|
@@ -21470,8 +21770,10 @@ var DevLeadService = class extends Service {
|
|
|
21470
21770
|
this.rehydrationLifecycle = { queryReady, disposers };
|
|
21471
21771
|
}
|
|
21472
21772
|
/** Emit each rehydration warning reason once per service epoch and track its cause. */
|
|
21473
|
-
warnRehydration(reason, message) {
|
|
21773
|
+
warnRehydration(reason, message, detail) {
|
|
21474
21774
|
this.supervisionDegradedReason = REHYDRATION_DEGRADED_CAUSES[reason] ?? message;
|
|
21775
|
+
if (detail !== void 0) this.supervisionDegradedDetail = detail;
|
|
21776
|
+
else if (reason !== "retry-cap" && reason !== "corrupt-terminal") this.supervisionDegradedDetail = void 0;
|
|
21475
21777
|
if (this.rehydrationWarnings.has(reason)) return;
|
|
21476
21778
|
this.rehydrationWarnings.add(reason);
|
|
21477
21779
|
this.ctx.logger.warn(message);
|
|
@@ -21651,6 +21953,7 @@ var DevLeadService = class extends Service {
|
|
|
21651
21953
|
this.rehydrationProgress = false;
|
|
21652
21954
|
this.liveAttachFailure = false;
|
|
21653
21955
|
this.supervisionDegradedReason = DEFAULT_SUPERVISION_DEGRADED_REASON;
|
|
21956
|
+
this.supervisionDegradedDetail = void 0;
|
|
21654
21957
|
if (this.rehydrationRetryTimer !== void 0) {
|
|
21655
21958
|
clearTimeout(this.rehydrationRetryTimer);
|
|
21656
21959
|
this.rehydrationRetryTimer = void 0;
|
|
@@ -22743,7 +23046,7 @@ var DevLeadService = class extends Service {
|
|
|
22743
23046
|
/** Fail-closed error for an unproven or no-longer-proven supervisor index. */
|
|
22744
23047
|
supervisionUnavailable(targetId) {
|
|
22745
23048
|
return new DevLeadError(
|
|
22746
|
-
`cannot prove the complete DevLead supervisor set for Session "${targetId}" yet; no prompt was delivered \u2014 ${this.supervisionDegradedReason}. Recovery: open (resume)
|
|
23049
|
+
`cannot prove the complete DevLead supervisor set for Session "${targetId}" yet; no prompt was delivered \u2014 ${this.supervisionDegradedDetail ?? this.supervisionDegradedReason}. Recovery: transient I/O, timeout, listing, and torn-tail failures are retried automatically. For corrupt DevLead records, first resolve any raw format/read blocker in the detail (upgrade/repair the owning plugin or restore a readable backup), then open (resume) that named DevLead Session and run /devlead reset there. Do not delete logs merely to bypass this check. The slow recovery probe retries every ${String(DEGRADED_REHYDRATION_PROBE_MS / 1e3)}s, and a Host restart also rebuilds the index`,
|
|
22747
23050
|
"DEVLEAD_SESSION_UNAVAILABLE"
|
|
22748
23051
|
);
|
|
22749
23052
|
}
|
|
@@ -23160,16 +23463,16 @@ var DevLeadService = class extends Service {
|
|
|
23160
23463
|
* reported.
|
|
23161
23464
|
*
|
|
23162
23465
|
* `strict` makes the scan safe for admission: a corpus listing failure, or a
|
|
23163
|
-
* log read failure for
|
|
23164
|
-
*
|
|
23165
|
-
* admitting on an unverifiable
|
|
23466
|
+
* log read/recovery/fold failure for any candidate actually read, is a hard
|
|
23467
|
+
* `DEVLEAD_SESSION_UNAVAILABLE` instead of a best-effort skip, because
|
|
23468
|
+
* admitting on an unverifiable candidate could create a second active lead.
|
|
23166
23469
|
* Reconciliation and status remain best-effort.
|
|
23167
23470
|
* @param signal - caller cancellation threaded through query reads.
|
|
23168
23471
|
* @param includePersisted - whether the persisted corpus is scanned.
|
|
23169
23472
|
* @param strict - whether unknown occupancy is a hard error (admission only).
|
|
23170
23473
|
* @returns every enabled Session, deduplicated by id.
|
|
23171
23474
|
* @throws {@link DevLeadError} `DEVLEAD_SESSION_UNAVAILABLE` when `strict` is
|
|
23172
|
-
* set and a
|
|
23475
|
+
* set and a candidate read/recovery/fold or the corpus listing cannot be proven.
|
|
23173
23476
|
*/
|
|
23174
23477
|
async scanActiveSessions(signal, includePersisted = true, strict = false) {
|
|
23175
23478
|
const active = /* @__PURE__ */ new Map();
|
|
@@ -23240,14 +23543,14 @@ var DevLeadService = class extends Service {
|
|
|
23240
23543
|
let events;
|
|
23241
23544
|
let inheritedEventCount = 0;
|
|
23242
23545
|
try {
|
|
23243
|
-
const snapshot = await
|
|
23546
|
+
const snapshot = await this.readColdSessionForSupervision(query, record2.header, signal);
|
|
23244
23547
|
events = snapshot.events;
|
|
23245
23548
|
inheritedEventCount = snapshot.inheritedEventCount;
|
|
23246
23549
|
} catch (error51) {
|
|
23247
23550
|
if (signal?.aborted === true) throw error51;
|
|
23248
|
-
if (strict
|
|
23551
|
+
if (strict) {
|
|
23249
23552
|
throw new DevLeadError(
|
|
23250
|
-
`could not verify global DevLead occupancy: persisted Session "${sessionId}"
|
|
23553
|
+
`could not verify global DevLead occupancy: persisted Session "${sessionId}" could not be read (${prefilter} cache classification): ${thrownMessage(error51)}`,
|
|
23251
23554
|
"DEVLEAD_SESSION_UNAVAILABLE"
|
|
23252
23555
|
);
|
|
23253
23556
|
}
|
|
@@ -23262,7 +23565,16 @@ var DevLeadService = class extends Service {
|
|
|
23262
23565
|
state = applyDevLeadProjection(state, event);
|
|
23263
23566
|
if (state.failure !== null) break;
|
|
23264
23567
|
}
|
|
23265
|
-
if (state.failure !== null
|
|
23568
|
+
if (state.failure !== null) {
|
|
23569
|
+
if (strict) {
|
|
23570
|
+
throw new DevLeadError(
|
|
23571
|
+
`could not verify global DevLead occupancy: persisted Session "${sessionId}" has a corrupt DevLead replay (${prefilter} cache classification): ${state.failure}`,
|
|
23572
|
+
"DEVLEAD_SESSION_UNAVAILABLE"
|
|
23573
|
+
);
|
|
23574
|
+
}
|
|
23575
|
+
continue;
|
|
23576
|
+
}
|
|
23577
|
+
if (!state.enabled) continue;
|
|
23266
23578
|
active.set(sessionId, {
|
|
23267
23579
|
sessionId,
|
|
23268
23580
|
live: false,
|
|
@@ -23506,6 +23818,29 @@ var DevLeadService = class extends Service {
|
|
|
23506
23818
|
this.replayingOpenQuestions = false;
|
|
23507
23819
|
}
|
|
23508
23820
|
}
|
|
23821
|
+
/**
|
|
23822
|
+
* Read one cold candidate through the Host's replay-validated query path.
|
|
23823
|
+
* Only a precise unknown-non-ignorable-event refusal uses the read-only
|
|
23824
|
+
* current-JSONL recovery: all records are still read and the caller applies
|
|
23825
|
+
* the same strict DevLead fold, so unrelated legacy vocabulary cannot hide a
|
|
23826
|
+
* foreign supervisor or excuse corrupt DevLead state.
|
|
23827
|
+
*/
|
|
23828
|
+
async readColdSessionForSupervision(query, header, signal) {
|
|
23829
|
+
try {
|
|
23830
|
+
const snapshot = await query.readSession(header.id);
|
|
23831
|
+
signal?.throwIfAborted();
|
|
23832
|
+
return snapshot;
|
|
23833
|
+
} catch (error51) {
|
|
23834
|
+
signal?.throwIfAborted();
|
|
23835
|
+
if (!isUnknownNonIgnorableEventError(error51)) throw error51;
|
|
23836
|
+
const recovered = await recoverUnknownEventSessionLog(this.ctx, header, signal);
|
|
23837
|
+
signal?.throwIfAborted();
|
|
23838
|
+
this.ctx.logger.debug(
|
|
23839
|
+
`devlead: recovered a complete current JSONL log for DevLead-only replay after an unrelated unknown event; session=${String(header.id)} path=${recovered.path} events=${String(recovered.events.length)}`
|
|
23840
|
+
);
|
|
23841
|
+
return recovered;
|
|
23842
|
+
}
|
|
23843
|
+
}
|
|
23509
23844
|
/**
|
|
23510
23845
|
* Scan durable state for lead Sessions the hub must index after a restart.
|
|
23511
23846
|
*
|
|
@@ -23524,9 +23859,9 @@ var DevLeadService = class extends Service {
|
|
|
23524
23859
|
* Cheap sources first: a live Session without an Agent has its projection
|
|
23525
23860
|
* folded directly (attach-only leads), then the persisted corpus is filtered
|
|
23526
23861
|
* through the projection cache — a row that positively reports an enabled mode
|
|
23527
|
-
* with a non-empty watch set is a candidate
|
|
23528
|
-
*
|
|
23529
|
-
*
|
|
23862
|
+
* with a non-empty watch set is a candidate; every other non-live, non-subagent
|
|
23863
|
+
* row still pays for a complete full-log exact fold (bounded, because a Host
|
|
23864
|
+
* history is unbounded and a stale-negative cache row is not authorization).
|
|
23530
23865
|
* A corrupt replay skips that candidate with one warning; it must never stop
|
|
23531
23866
|
* the scan, and it must never make the plugin fail to load.
|
|
23532
23867
|
* @param listing - barrier-validated listing; re-verified when omitted.
|
|
@@ -23665,14 +24000,16 @@ var DevLeadService = class extends Service {
|
|
|
23665
24000
|
const prefilter = cache === void 0 ? "unknown" : devLeadActivePrefilterOf(cache, record2.header);
|
|
23666
24001
|
let events;
|
|
23667
24002
|
let inheritedEventCount = 0;
|
|
24003
|
+
let sourcePath;
|
|
23668
24004
|
try {
|
|
23669
|
-
const snapshot = await this.awaitScan(
|
|
24005
|
+
const snapshot = await this.awaitScan(this.readColdSessionForSupervision(query, record2.header, signal), signal);
|
|
23670
24006
|
if (snapshot === SCAN_ABORTED) {
|
|
23671
24007
|
state.complete = false;
|
|
23672
24008
|
return result([...state.leads.values()], state.active, false);
|
|
23673
24009
|
}
|
|
23674
24010
|
events = snapshot.events;
|
|
23675
24011
|
inheritedEventCount = snapshot.inheritedEventCount;
|
|
24012
|
+
sourcePath = snapshot.path;
|
|
23676
24013
|
} catch (error51) {
|
|
23677
24014
|
if (signal?.aborted) {
|
|
23678
24015
|
state.complete = false;
|
|
@@ -23684,7 +24021,8 @@ var DevLeadService = class extends Service {
|
|
|
23684
24021
|
readFailed = true;
|
|
23685
24022
|
this.warnRehydration(
|
|
23686
24023
|
"read",
|
|
23687
|
-
`devlead:
|
|
24024
|
+
`devlead: Session "${sessionId}" stayed unreadable (not found) after re-listing; keeping the cursor for a bounded retry: ${thrownMessage(error51)}`,
|
|
24025
|
+
`Session "${sessionId}" stayed unreadable (not found) after re-listing: ${thrownMessage(error51)}`
|
|
23688
24026
|
);
|
|
23689
24027
|
break;
|
|
23690
24028
|
}
|
|
@@ -23699,7 +24037,8 @@ var DevLeadService = class extends Service {
|
|
|
23699
24037
|
this.rehydrationValidationUnverifiable = true;
|
|
23700
24038
|
this.warnRehydration(
|
|
23701
24039
|
"read",
|
|
23702
|
-
`devlead: could not re-verify the Session corpus after
|
|
24040
|
+
`devlead: could not re-verify the Session corpus after Session "${sessionId}" returned not-found; keeping the trusted cursor for a bounded retry: ${thrownMessage(error51)}`,
|
|
24041
|
+
`Session "${sessionId}" returned not-found and its corpus re-list failed: ${thrownMessage(error51)}`
|
|
23703
24042
|
);
|
|
23704
24043
|
return result([...state.leads.values()], state.active, false);
|
|
23705
24044
|
}
|
|
@@ -23731,7 +24070,11 @@ var DevLeadService = class extends Service {
|
|
|
23731
24070
|
}
|
|
23732
24071
|
state.complete = false;
|
|
23733
24072
|
readFailed = true;
|
|
23734
|
-
this.warnRehydration(
|
|
24073
|
+
this.warnRehydration(
|
|
24074
|
+
"read",
|
|
24075
|
+
`devlead: could not read a cold lead candidate Session log "${sessionId}": ${thrownMessage(error51)}`,
|
|
24076
|
+
`Session "${sessionId}" could not be read: ${thrownMessage(error51)}`
|
|
24077
|
+
);
|
|
23735
24078
|
break;
|
|
23736
24079
|
}
|
|
23737
24080
|
if (prefilter !== "active") reads += 1;
|
|
@@ -23743,7 +24086,12 @@ var DevLeadService = class extends Service {
|
|
|
23743
24086
|
if (folded.failure !== null) {
|
|
23744
24087
|
state.complete = false;
|
|
23745
24088
|
state.corrupt = true;
|
|
23746
|
-
|
|
24089
|
+
const location = sourcePath === void 0 ? "" : ` at ${sourcePath}`;
|
|
24090
|
+
this.warnRehydration(
|
|
24091
|
+
"corrupt",
|
|
24092
|
+
`devlead: skipping cold lead candidate Session "${sessionId}"${location} with a corrupt DevLead replay: ${folded.failure}`,
|
|
24093
|
+
`Session "${sessionId}"${location} has a corrupt DevLead replay: ${folded.failure}`
|
|
24094
|
+
);
|
|
23747
24095
|
state.index += 1;
|
|
23748
24096
|
continue;
|
|
23749
24097
|
}
|
|
@@ -24420,8 +24768,8 @@ ${text}` : text,
|
|
|
24420
24768
|
return record2;
|
|
24421
24769
|
}
|
|
24422
24770
|
/** Lazy TTL: only a still-open question expires; answered is never rewritten. */
|
|
24423
|
-
questionExpired(report, answers, now = Date.now(),
|
|
24424
|
-
return this.resolved.questionTtlMs > 0 && report.kind === "question" &&
|
|
24771
|
+
questionExpired(report, answers, now = Date.now(), open2 = questionStatusOf(answers, report.id) === "open") {
|
|
24772
|
+
return this.resolved.questionTtlMs > 0 && report.kind === "question" && open2 && now - report.at >= this.resolved.questionTtlMs;
|
|
24425
24773
|
}
|
|
24426
24774
|
/**
|
|
24427
24775
|
* Read the derived question/answer state of one question report from the
|
|
@@ -24446,9 +24794,9 @@ ${text}` : text,
|
|
|
24446
24794
|
};
|
|
24447
24795
|
}
|
|
24448
24796
|
const answeredAt = fact.answeredAt ?? (fact.status === "admitted" || fact.status === "claimed" || fact.status === "presented" ? fact.at : void 0);
|
|
24449
|
-
const
|
|
24797
|
+
const open2 = fact.status === "discarded" || fact.status === "failed";
|
|
24450
24798
|
return {
|
|
24451
|
-
questionStatus:
|
|
24799
|
+
questionStatus: open2 && this.questionExpired(report, state.answers, Date.now(), true) ? "expired" : open2 ? "open" : "answered",
|
|
24452
24800
|
answerStatus: fact.status,
|
|
24453
24801
|
answerMessageId: fact.messageId,
|
|
24454
24802
|
...answeredAt === void 0 ? {} : { answeredAt },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yankeguo/dsh-devlead",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "DevLead mode core service for the DeepSeek Harness: durable per-session mode, Workspace and Session orchestration, watched-session notifications, and the `devLead` Session projection.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
}
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@yankeguo/dsh-devlead-protocol": "0.4.
|
|
47
|
+
"@yankeguo/dsh-devlead-protocol": "0.4.1"
|
|
48
48
|
},
|
|
49
49
|
"engines": {
|
|
50
50
|
"dsh": ">=0.2.2-rc.1 <0.3.0"
|