@adhdev/daemon-standalone 1.0.28-rc.24 → 1.0.28-rc.26
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/index.js +472 -53
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -33311,10 +33311,10 @@ var require_dist3 = __commonJS({
|
|
|
33311
33311
|
}
|
|
33312
33312
|
function getDaemonBuildInfo() {
|
|
33313
33313
|
if (cached2) return cached2;
|
|
33314
|
-
const commit = readInjected(true ? "
|
|
33315
|
-
const commitShort = readInjected(true ? "
|
|
33316
|
-
const version2 = readInjected(true ? "1.0.28-rc.
|
|
33317
|
-
const builtAt = readInjected(true ? "2026-07-
|
|
33314
|
+
const commit = readInjected(true ? "6eb8c9b32842573a3be53f868c84feb02358ac43" : void 0) ?? "unknown";
|
|
33315
|
+
const commitShort = readInjected(true ? "6eb8c9b3" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
|
|
33316
|
+
const version2 = readInjected(true ? "1.0.28-rc.26" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
|
|
33317
|
+
const builtAt = readInjected(true ? "2026-07-29T13:55:59.471Z" : void 0);
|
|
33318
33318
|
cached2 = builtAt ? { commit, commitShort, version: version2, builtAt } : { commit, commitShort, version: version2 };
|
|
33319
33319
|
return cached2;
|
|
33320
33320
|
}
|
|
@@ -36902,16 +36902,31 @@ ${error48.message || ""}`;
|
|
|
36902
36902
|
} catch {
|
|
36903
36903
|
}
|
|
36904
36904
|
}
|
|
36905
|
+
function sizeRotationPath(logFile, generation) {
|
|
36906
|
+
return logFile.replace(/\.log$/, `.${generation}.log`);
|
|
36907
|
+
}
|
|
36908
|
+
function rotateSizeGenerations(logFile, maxGenerations = MAX_SIZE_ROTATION_GENERATIONS) {
|
|
36909
|
+
if (maxGenerations < 1) return;
|
|
36910
|
+
const oldest = sizeRotationPath(logFile, maxGenerations);
|
|
36911
|
+
try {
|
|
36912
|
+
fs32.unlinkSync(oldest);
|
|
36913
|
+
} catch {
|
|
36914
|
+
}
|
|
36915
|
+
for (let generation = maxGenerations - 1; generation >= 1; generation--) {
|
|
36916
|
+
const source = sizeRotationPath(logFile, generation);
|
|
36917
|
+
const destination = sizeRotationPath(logFile, generation + 1);
|
|
36918
|
+
try {
|
|
36919
|
+
fs32.renameSync(source, destination);
|
|
36920
|
+
} catch {
|
|
36921
|
+
}
|
|
36922
|
+
}
|
|
36923
|
+
fs32.renameSync(logFile, sizeRotationPath(logFile, 1));
|
|
36924
|
+
}
|
|
36905
36925
|
function rotateSizeIfNeeded() {
|
|
36906
36926
|
try {
|
|
36907
36927
|
const stat2 = fs32.statSync(currentLogFile);
|
|
36908
36928
|
if (stat2.size > MAX_LOG_SIZE) {
|
|
36909
|
-
|
|
36910
|
-
try {
|
|
36911
|
-
fs32.unlinkSync(backup);
|
|
36912
|
-
} catch {
|
|
36913
|
-
}
|
|
36914
|
-
fs32.renameSync(currentLogFile, backup);
|
|
36929
|
+
rotateSizeGenerations(currentLogFile);
|
|
36915
36930
|
}
|
|
36916
36931
|
} catch {
|
|
36917
36932
|
}
|
|
@@ -37020,6 +37035,7 @@ ${error48.message || ""}`;
|
|
|
37020
37035
|
var LOG_DIR;
|
|
37021
37036
|
var MAX_LOG_SIZE;
|
|
37022
37037
|
var MAX_LOG_DAYS;
|
|
37038
|
+
var MAX_SIZE_ROTATION_GENERATIONS;
|
|
37023
37039
|
var currentDate;
|
|
37024
37040
|
var currentLogFile;
|
|
37025
37041
|
var writeCount;
|
|
@@ -37045,6 +37061,7 @@ ${error48.message || ""}`;
|
|
|
37045
37061
|
LOG_DIR = path9.join(ADHDEV_HOME, "logs");
|
|
37046
37062
|
MAX_LOG_SIZE = 5 * 1024 * 1024;
|
|
37047
37063
|
MAX_LOG_DAYS = 7;
|
|
37064
|
+
MAX_SIZE_ROTATION_GENERATIONS = 3;
|
|
37048
37065
|
try {
|
|
37049
37066
|
fs32.mkdirSync(LOG_DIR, { recursive: true });
|
|
37050
37067
|
} catch {
|
|
@@ -43569,8 +43586,8 @@ Next step: ${nextStep}`;
|
|
|
43569
43586
|
}
|
|
43570
43587
|
this.maybeCheckpointWal();
|
|
43571
43588
|
}
|
|
43572
|
-
countTurnOutboxByStatus() {
|
|
43573
|
-
const rows = this.db.prepare("SELECT status, COUNT(*) AS n FROM mesh_turn_outbox GROUP BY status").all();
|
|
43589
|
+
countTurnOutboxByStatus(meshId) {
|
|
43590
|
+
const rows = meshId ? this.db.prepare("SELECT status, COUNT(*) AS n FROM mesh_turn_outbox WHERE mesh_id = ? GROUP BY status").all(meshId) : this.db.prepare("SELECT status, COUNT(*) AS n FROM mesh_turn_outbox GROUP BY status").all();
|
|
43574
43591
|
const out = {};
|
|
43575
43592
|
for (const r of rows) out[r.status] = r.n;
|
|
43576
43593
|
return out;
|
|
@@ -48671,6 +48688,9 @@ ${rendered}`, "utf-8");
|
|
|
48671
48688
|
state: "connected",
|
|
48672
48689
|
transport: transport && transport !== "unknown" ? transport : "direct",
|
|
48673
48690
|
reported: true,
|
|
48691
|
+
directPeerTruthSatisfied: true,
|
|
48692
|
+
authority: "live_peer",
|
|
48693
|
+
cached: false,
|
|
48674
48694
|
reason: "Live peer git snapshot reported by the selected coordinator.",
|
|
48675
48695
|
lastStateChangeAt: readStringValue(connection.lastStateChangeAt) ?? timestamp2
|
|
48676
48696
|
};
|
|
@@ -49344,6 +49364,7 @@ ${rendered}`, "utf-8");
|
|
|
49344
49364
|
const now = args.now ?? Date.now;
|
|
49345
49365
|
const connection = readObjectRecord(status.connection);
|
|
49346
49366
|
const connectionState = readStringValue(connection.state);
|
|
49367
|
+
const directPeerTruthSatisfied = readBooleanValue(connection.directPeerTruthSatisfied);
|
|
49347
49368
|
const git = readObjectRecord(status.git);
|
|
49348
49369
|
const hasGit = readBooleanValue(git.isGitRepo) === true || !!readStringValue(git.branch, git.headCommit, git.head, git.upstream);
|
|
49349
49370
|
const connectionFreshAt = toIsoTimestamp(connection.lastCommandAt ?? connection.lastConnectedAt ?? connection.lastStateChangeAt);
|
|
@@ -49365,12 +49386,12 @@ ${rendered}`, "utf-8");
|
|
|
49365
49386
|
} else if (readBooleanValue(status.gitProbePending) === true) {
|
|
49366
49387
|
dataSource = "pending";
|
|
49367
49388
|
reachable = connectionReachable;
|
|
49389
|
+
} else if (hasGit) {
|
|
49390
|
+
dataSource = "cached";
|
|
49391
|
+
reachable = directTruthUnavailable ? false : connectionReachable;
|
|
49368
49392
|
} else if (directTruthUnavailable) {
|
|
49369
49393
|
dataSource = "unreachable";
|
|
49370
49394
|
reachable = false;
|
|
49371
|
-
} else if (hasGit) {
|
|
49372
|
-
dataSource = "cached";
|
|
49373
|
-
reachable = connectionReachable;
|
|
49374
49395
|
} else if (!daemonId) {
|
|
49375
49396
|
dataSource = "unconfigured";
|
|
49376
49397
|
reachable = null;
|
|
@@ -49392,6 +49413,8 @@ ${rendered}`, "utf-8");
|
|
|
49392
49413
|
dataSource,
|
|
49393
49414
|
probeOk,
|
|
49394
49415
|
reachable,
|
|
49416
|
+
directPeerTruthSatisfied: isSelfNode || liveTruthProbed ? true : directPeerTruthSatisfied ?? false,
|
|
49417
|
+
projection: dataSource === "cached" ? "cached" : "live_or_absent",
|
|
49395
49418
|
lastProbeAt: lastProbeAt ?? null,
|
|
49396
49419
|
ageMs: ageMs2,
|
|
49397
49420
|
staleness
|
|
@@ -57248,6 +57271,126 @@ ${cleanBody}`;
|
|
|
57248
57271
|
recentReadDebugSignatureBySession = /* @__PURE__ */ new Map();
|
|
57249
57272
|
}
|
|
57250
57273
|
});
|
|
57274
|
+
function readRecord6(value) {
|
|
57275
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
57276
|
+
}
|
|
57277
|
+
function readFiniteNumber(value) {
|
|
57278
|
+
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
57279
|
+
}
|
|
57280
|
+
function identitiesMatch(metadataEvent, evidence, attempt, eventSessionId) {
|
|
57281
|
+
const taskId = readNonEmptyString(metadataEvent.taskId);
|
|
57282
|
+
const attemptId = readNonEmptyString(metadataEvent.attemptId);
|
|
57283
|
+
const evidenceTaskId = readNonEmptyString(evidence.taskId);
|
|
57284
|
+
const evidenceAttemptId = readNonEmptyString(evidence.attemptId);
|
|
57285
|
+
const evidenceSessionId = readNonEmptyString(evidence.sessionId);
|
|
57286
|
+
const eventNonce = readFiniteNumber(metadataEvent.dispatchNonce);
|
|
57287
|
+
const evidenceNonce = readFiniteNumber(evidence.dispatchNonce);
|
|
57288
|
+
if (!taskId || !attemptId || !eventSessionId) return false;
|
|
57289
|
+
if (taskId !== attempt.taskId || attemptId !== attempt.attemptId) return false;
|
|
57290
|
+
if (evidenceTaskId !== taskId || evidenceAttemptId !== attemptId) return false;
|
|
57291
|
+
if (!evidenceSessionId || !sessionIdsEquivalent(evidenceSessionId, eventSessionId)) return false;
|
|
57292
|
+
if (!attempt.sessionId || !sessionIdsEquivalent(attempt.sessionId, eventSessionId)) return false;
|
|
57293
|
+
if (typeof attempt.dispatchNonce !== "number" || eventNonce !== attempt.dispatchNonce || evidenceNonce !== attempt.dispatchNonce) return false;
|
|
57294
|
+
return true;
|
|
57295
|
+
}
|
|
57296
|
+
function evaluateAuthoritativeTranscriptCompletion(args) {
|
|
57297
|
+
const { metadataEvent, eventSessionId, attempt } = args;
|
|
57298
|
+
const nowMs = args.nowMs ?? Date.now();
|
|
57299
|
+
if (!attempt || attempt.terminalOutcome || isTerminalTurnStage(attempt.stage)) {
|
|
57300
|
+
return { authoritative: false, reason: "attempt_missing_or_terminal" };
|
|
57301
|
+
}
|
|
57302
|
+
if (isWeakCompletionEvidence(metadataEvent)) {
|
|
57303
|
+
return { authoritative: false, reason: "weak_evidence" };
|
|
57304
|
+
}
|
|
57305
|
+
const diagnostic = readRecord6(metadataEvent.completionDiagnostic);
|
|
57306
|
+
const evidence = readRecord6(diagnostic?.transcriptEvidence);
|
|
57307
|
+
if (diagnostic?.finalAssistantPresent !== true || diagnostic?.cleanPath !== true || diagnostic?.evidenceWeak !== false || !evidence) {
|
|
57308
|
+
return { authoritative: false, reason: "not_clean_strong_evidence" };
|
|
57309
|
+
}
|
|
57310
|
+
if (evidence.version !== 1 || evidence.kind !== "final_assistant" || evidence.cleanPath !== true || evidence.weak !== false) {
|
|
57311
|
+
return { authoritative: false, reason: "invalid_evidence_contract" };
|
|
57312
|
+
}
|
|
57313
|
+
const authorityClass = readNonEmptyString(evidence.authorityClass);
|
|
57314
|
+
const timing = readNonEmptyString(evidence.timing);
|
|
57315
|
+
if (authorityClass !== "native-source" && authorityClass !== "pure-pty" || timing !== "floor" && timing !== "hold" && timing !== "immediate") {
|
|
57316
|
+
return { authoritative: false, reason: "non_transcript_authority_profile" };
|
|
57317
|
+
}
|
|
57318
|
+
const evidenceSource = readNonEmptyString(diagnostic.finalAssistantEvidenceSource);
|
|
57319
|
+
if (authorityClass === "native-source" && evidenceSource !== "external-native" || authorityClass === "pure-pty" && evidenceSource !== "parsed") {
|
|
57320
|
+
return { authoritative: false, reason: "evidence_source_profile_mismatch" };
|
|
57321
|
+
}
|
|
57322
|
+
const finalSummary = readNonEmptyString(metadataEvent.finalSummary);
|
|
57323
|
+
const finalContentLength = readFiniteNumber(evidence.finalContentLength) ?? 0;
|
|
57324
|
+
if (!finalSummary || finalContentLength <= 0) {
|
|
57325
|
+
return { authoritative: false, reason: "empty_final_content" };
|
|
57326
|
+
}
|
|
57327
|
+
if (!identitiesMatch(metadataEvent, evidence, attempt, eventSessionId)) {
|
|
57328
|
+
return { authoritative: false, reason: "causal_identity_mismatch" };
|
|
57329
|
+
}
|
|
57330
|
+
const observedAt = readFiniteNumber(evidence.observedAt);
|
|
57331
|
+
const eventTimestamp = readFiniteNumber(metadataEvent.timestamp);
|
|
57332
|
+
const turnStartedAt = readFiniteNumber(evidence.turnStartedAt);
|
|
57333
|
+
const acceptedAt = Date.parse(attempt.acceptedAt || attempt.createdAt);
|
|
57334
|
+
if (!observedAt || !eventTimestamp || !turnStartedAt) {
|
|
57335
|
+
return { authoritative: false, reason: "missing_evidence_timestamp" };
|
|
57336
|
+
}
|
|
57337
|
+
if (observedAt < turnStartedAt || eventTimestamp < turnStartedAt) {
|
|
57338
|
+
return { authoritative: false, reason: "pre_turn_evidence" };
|
|
57339
|
+
}
|
|
57340
|
+
if (Number.isFinite(acceptedAt) && (observedAt < acceptedAt - 2e3 || eventTimestamp < acceptedAt - 2e3)) {
|
|
57341
|
+
return { authoritative: false, reason: "pre_dispatch_evidence" };
|
|
57342
|
+
}
|
|
57343
|
+
if (observedAt > nowMs + 2e3 || eventTimestamp > nowMs + 2e3 || nowMs - observedAt > AUTHORITATIVE_COMPLETION_MAX_AGE_MS || nowMs - eventTimestamp > AUTHORITATIVE_COMPLETION_MAX_AGE_MS) {
|
|
57344
|
+
return { authoritative: false, reason: "stale_evidence_timestamp" };
|
|
57345
|
+
}
|
|
57346
|
+
const attemptUpdatedAt = Date.parse(attempt.updatedAt);
|
|
57347
|
+
return {
|
|
57348
|
+
authoritative: true,
|
|
57349
|
+
evidenceObservedAt: observedAt,
|
|
57350
|
+
attemptStage: attempt.stage,
|
|
57351
|
+
attemptUpdatedAt: Number.isFinite(attemptUpdatedAt) ? attemptUpdatedAt : null
|
|
57352
|
+
};
|
|
57353
|
+
}
|
|
57354
|
+
function authoritativeEvidenceOutranksLivePending(authority, live) {
|
|
57355
|
+
if (!authority.authoritative || live.pending !== true) return false;
|
|
57356
|
+
if (live.kind !== "modal" && live.kind !== "adapter") return false;
|
|
57357
|
+
if (live.kind === "modal" && (authority.attemptStage === "waiting_approval" || authority.attemptStage === "waiting_choice") && authority.attemptUpdatedAt !== null && authority.attemptUpdatedAt <= authority.evidenceObservedAt) {
|
|
57358
|
+
return true;
|
|
57359
|
+
}
|
|
57360
|
+
return typeof live.observedAt === "number" && Number.isFinite(live.observedAt) && live.observedAt <= authority.evidenceObservedAt;
|
|
57361
|
+
}
|
|
57362
|
+
function completionEligibleForLiveStateRetry(args) {
|
|
57363
|
+
const { metadataEvent, eventSessionId, attempt } = args;
|
|
57364
|
+
const nowMs = args.nowMs ?? Date.now();
|
|
57365
|
+
if (!evaluateAuthoritativeTranscriptCompletion({
|
|
57366
|
+
metadataEvent,
|
|
57367
|
+
eventSessionId,
|
|
57368
|
+
attempt,
|
|
57369
|
+
nowMs
|
|
57370
|
+
}).authoritative) return false;
|
|
57371
|
+
if (!attempt || attempt.terminalOutcome || isTerminalTurnStage(attempt.stage)) return false;
|
|
57372
|
+
const taskId = readNonEmptyString(metadataEvent.taskId);
|
|
57373
|
+
const attemptId = readNonEmptyString(metadataEvent.attemptId);
|
|
57374
|
+
const nonce = readFiniteNumber(metadataEvent.dispatchNonce);
|
|
57375
|
+
if (!taskId || taskId !== attempt.taskId || attemptId !== attempt.attemptId) return false;
|
|
57376
|
+
if (!attempt.sessionId || !sessionIdsEquivalent(attempt.sessionId, eventSessionId)) return false;
|
|
57377
|
+
if (typeof attempt.dispatchNonce !== "number" || nonce !== attempt.dispatchNonce) return false;
|
|
57378
|
+
const eventTimestamp = readFiniteNumber(metadataEvent.timestamp);
|
|
57379
|
+
const acceptedAt = Date.parse(attempt.acceptedAt || attempt.createdAt);
|
|
57380
|
+
if (!eventTimestamp || eventTimestamp > nowMs + 2e3 || nowMs - eventTimestamp > AUTHORITATIVE_COMPLETION_MAX_AGE_MS) return false;
|
|
57381
|
+
if (Number.isFinite(acceptedAt) && eventTimestamp < acceptedAt - 2e3) return false;
|
|
57382
|
+
return true;
|
|
57383
|
+
}
|
|
57384
|
+
var AUTHORITATIVE_COMPLETION_MAX_AGE_MS;
|
|
57385
|
+
var init_mesh_completion_live_gate = __esm2({
|
|
57386
|
+
"src/mesh/mesh-completion-live-gate.ts"() {
|
|
57387
|
+
"use strict";
|
|
57388
|
+
init_dist();
|
|
57389
|
+
init_mesh_turn_ledger();
|
|
57390
|
+
init_mesh_events_utils();
|
|
57391
|
+
AUTHORITATIVE_COMPLETION_MAX_AGE_MS = 6e4;
|
|
57392
|
+
}
|
|
57393
|
+
});
|
|
57251
57394
|
function bootstrapQueueTaskCountsAsHandled(task, bootstrapNodeId, nowMs) {
|
|
57252
57395
|
if (!meshNodeIdMatches({ id: task.targetNodeId }, bootstrapNodeId)) return false;
|
|
57253
57396
|
if (task.status === "assigned") return true;
|
|
@@ -57264,6 +57407,111 @@ ${cleanBody}`;
|
|
|
57264
57407
|
const machineId = readNonEmptyString(loadConfig2().machineId);
|
|
57265
57408
|
return expandDaemonIdForms([statusInstanceId, machineId]);
|
|
57266
57409
|
}
|
|
57410
|
+
function heldCompletionKey(meshId, taskId, attemptId, sessionId, nonce) {
|
|
57411
|
+
return `${meshId}${taskId}${attemptId}${sessionId}${nonce}`;
|
|
57412
|
+
}
|
|
57413
|
+
function readLivePendingEvidence(instance) {
|
|
57414
|
+
try {
|
|
57415
|
+
if (typeof instance?.getLiveTurnPendingEvidence === "function") {
|
|
57416
|
+
const evidence = instance.getLiveTurnPendingEvidence();
|
|
57417
|
+
if (evidence && typeof evidence === "object") {
|
|
57418
|
+
return {
|
|
57419
|
+
pending: evidence.pending === true,
|
|
57420
|
+
...evidence.kind === "adapter" || evidence.kind === "modal" || evidence.kind === "transcript_tool" ? { kind: evidence.kind } : {},
|
|
57421
|
+
...typeof evidence.observedAt === "number" && Number.isFinite(evidence.observedAt) ? { observedAt: evidence.observedAt } : {}
|
|
57422
|
+
};
|
|
57423
|
+
}
|
|
57424
|
+
}
|
|
57425
|
+
if (typeof instance?.hasLiveTurnPendingEvidence === "function") {
|
|
57426
|
+
return { pending: instance.hasLiveTurnPendingEvidence() === true };
|
|
57427
|
+
}
|
|
57428
|
+
} catch {
|
|
57429
|
+
}
|
|
57430
|
+
return { pending: false };
|
|
57431
|
+
}
|
|
57432
|
+
function scheduleHeldLiveStateCompletionDrain() {
|
|
57433
|
+
if (heldLiveStateCompletionTimer || heldLiveStateCompletions.size === 0) return;
|
|
57434
|
+
heldLiveStateCompletionTimer = setTimeout(() => {
|
|
57435
|
+
heldLiveStateCompletionTimer = null;
|
|
57436
|
+
drainHeldLiveStateCompletions();
|
|
57437
|
+
}, MID_TURN_COMPLETION_HOLD_RETRY_MS);
|
|
57438
|
+
heldLiveStateCompletionTimer.unref?.();
|
|
57439
|
+
}
|
|
57440
|
+
function drainHeldLiveStateCompletions(nowMs = Date.now()) {
|
|
57441
|
+
for (const [key2, held] of heldLiveStateCompletions) {
|
|
57442
|
+
if (nowMs < held.nextCheckAt) continue;
|
|
57443
|
+
if (nowMs >= held.expiresAt) {
|
|
57444
|
+
heldLiveStateCompletions.delete(key2);
|
|
57445
|
+
continue;
|
|
57446
|
+
}
|
|
57447
|
+
const attempt = MeshRuntimeStore.getInstance().getCurrentTurnAttempt(held.meshId, held.taskId);
|
|
57448
|
+
const identityStillCurrent = !!attempt && !attempt.terminalOutcome && attempt.attemptId === held.attemptId && sessionIdsEquivalent(attempt.sessionId, held.sessionId) && attempt.dispatchNonce === held.dispatchNonce;
|
|
57449
|
+
if (!identityStillCurrent) {
|
|
57450
|
+
heldLiveStateCompletions.delete(key2);
|
|
57451
|
+
continue;
|
|
57452
|
+
}
|
|
57453
|
+
const liveInstance = held.components.instanceManager?.getInstance?.(held.sessionId);
|
|
57454
|
+
if (!liveInstance) {
|
|
57455
|
+
heldLiveStateCompletions.delete(key2);
|
|
57456
|
+
continue;
|
|
57457
|
+
}
|
|
57458
|
+
const live = readLivePendingEvidence(liveInstance);
|
|
57459
|
+
if (live.pending) {
|
|
57460
|
+
held.nextCheckAt = nowMs + MID_TURN_COMPLETION_HOLD_RETRY_MS;
|
|
57461
|
+
continue;
|
|
57462
|
+
}
|
|
57463
|
+
heldLiveStateCompletions.delete(key2);
|
|
57464
|
+
injectMeshSystemMessage(held.components, {
|
|
57465
|
+
meshId: held.meshId,
|
|
57466
|
+
sourceInstanceId: held.sourceInstanceId,
|
|
57467
|
+
nodeId: held.nodeId,
|
|
57468
|
+
nodeLabel: held.nodeLabel,
|
|
57469
|
+
event: "agent:generating_completed",
|
|
57470
|
+
metadataEvent: {
|
|
57471
|
+
event: "agent:generating_completed",
|
|
57472
|
+
instanceId: held.sessionId,
|
|
57473
|
+
targetSessionId: held.sessionId,
|
|
57474
|
+
taskId: held.taskId,
|
|
57475
|
+
attemptId: held.attemptId,
|
|
57476
|
+
dispatchNonce: held.dispatchNonce,
|
|
57477
|
+
timestamp: held.eventTimestamp,
|
|
57478
|
+
...held.providerType ? { providerType: held.providerType } : {},
|
|
57479
|
+
completionDiagnostic: {
|
|
57480
|
+
source: "mid_turn_live_state_retry",
|
|
57481
|
+
contentFreeRetry: true
|
|
57482
|
+
}
|
|
57483
|
+
}
|
|
57484
|
+
});
|
|
57485
|
+
}
|
|
57486
|
+
scheduleHeldLiveStateCompletionDrain();
|
|
57487
|
+
}
|
|
57488
|
+
function holdCompletionForLiveStateRetry(components, args, eventSessionId, nowMs) {
|
|
57489
|
+
const taskId = readNonEmptyString(args.metadataEvent.taskId);
|
|
57490
|
+
const attemptId = readNonEmptyString(args.metadataEvent.attemptId);
|
|
57491
|
+
const dispatchNonce = typeof args.metadataEvent.dispatchNonce === "number" ? args.metadataEvent.dispatchNonce : NaN;
|
|
57492
|
+
const eventTimestamp = typeof args.metadataEvent.timestamp === "number" ? args.metadataEvent.timestamp : NaN;
|
|
57493
|
+
if (!taskId || !attemptId || !Number.isFinite(dispatchNonce) || !Number.isFinite(eventTimestamp)) return false;
|
|
57494
|
+
const key2 = heldCompletionKey(args.meshId, taskId, attemptId, eventSessionId, dispatchNonce);
|
|
57495
|
+
if (!heldLiveStateCompletions.has(key2)) {
|
|
57496
|
+
heldLiveStateCompletions.set(key2, {
|
|
57497
|
+
components,
|
|
57498
|
+
meshId: args.meshId,
|
|
57499
|
+
sourceInstanceId: args.sourceInstanceId,
|
|
57500
|
+
nodeId: args.nodeId,
|
|
57501
|
+
nodeLabel: args.nodeLabel,
|
|
57502
|
+
sessionId: eventSessionId,
|
|
57503
|
+
taskId,
|
|
57504
|
+
attemptId,
|
|
57505
|
+
dispatchNonce,
|
|
57506
|
+
providerType: readNonEmptyString(args.metadataEvent.providerType) || void 0,
|
|
57507
|
+
eventTimestamp,
|
|
57508
|
+
expiresAt: nowMs + MID_TURN_COMPLETION_HOLD_TTL_MS,
|
|
57509
|
+
nextCheckAt: nowMs + MID_TURN_COMPLETION_HOLD_RETRY_MS
|
|
57510
|
+
});
|
|
57511
|
+
}
|
|
57512
|
+
scheduleHeldLiveStateCompletionDrain();
|
|
57513
|
+
return true;
|
|
57514
|
+
}
|
|
57267
57515
|
function getCachedMeshByWorkspace(workspace) {
|
|
57268
57516
|
const now = Date.now();
|
|
57269
57517
|
const cached4 = meshByWorkspaceCache.get(workspace);
|
|
@@ -57553,19 +57801,38 @@ ${cleanBody}`;
|
|
|
57553
57801
|
}
|
|
57554
57802
|
if (args.event === "agent:generating_completed" && eventSessionId) {
|
|
57555
57803
|
const liveInstance = components.instanceManager?.getInstance?.(eventSessionId);
|
|
57556
|
-
if (typeof liveInstance?.hasLiveTurnPendingEvidence === "function") {
|
|
57557
|
-
|
|
57558
|
-
|
|
57559
|
-
|
|
57560
|
-
|
|
57561
|
-
|
|
57562
|
-
|
|
57563
|
-
|
|
57564
|
-
|
|
57565
|
-
|
|
57566
|
-
|
|
57567
|
-
|
|
57568
|
-
}
|
|
57804
|
+
if (typeof liveInstance?.getLiveTurnPendingEvidence === "function" || typeof liveInstance?.hasLiveTurnPendingEvidence === "function") {
|
|
57805
|
+
const live = readLivePendingEvidence(liveInstance);
|
|
57806
|
+
if (live.pending) {
|
|
57807
|
+
const taskId = readNonEmptyString(args.metadataEvent.taskId);
|
|
57808
|
+
const attempt = taskId ? MeshRuntimeStore.getInstance().getCurrentTurnAttempt(args.meshId, taskId) : null;
|
|
57809
|
+
const authority = evaluateAuthoritativeTranscriptCompletion({
|
|
57810
|
+
metadataEvent: args.metadataEvent,
|
|
57811
|
+
eventSessionId,
|
|
57812
|
+
attempt
|
|
57813
|
+
});
|
|
57814
|
+
if (authoritativeEvidenceOutranksLivePending(authority, live)) {
|
|
57815
|
+
LOG2.info("MeshEvents", `Accepted agent:generating_completed for session ${eventSessionId} (mesh ${args.meshId}): fresh clean-path transcript evidence for the current attempt is newer than the stale ${live.kind ?? "live"} snapshot`);
|
|
57816
|
+
} else {
|
|
57817
|
+
const retryEligible = completionEligibleForLiveStateRetry({
|
|
57818
|
+
metadataEvent: args.metadataEvent,
|
|
57819
|
+
eventSessionId,
|
|
57820
|
+
attempt
|
|
57821
|
+
});
|
|
57822
|
+
const heldForRetry = retryEligible && holdCompletionForLiveStateRetry(components, args, eventSessionId, Date.now());
|
|
57823
|
+
LOG2.info("MeshEvents", `Suppressed agent:generating_completed for session ${eventSessionId} (mesh ${args.meshId}): current live evidence remains pending (${live.kind ?? "unknown"}); transcript authority=${authority.authoritative ? "fresh_but_not_newer" : authority.reason}${heldForRetry ? " \u2014 bounded content-free retry armed" : ""}`);
|
|
57824
|
+
traceMeshEventDrop("mid_turn_live_state_pending", traceCtx, heldForRetry ? "retry_held" : void 0);
|
|
57825
|
+
return {
|
|
57826
|
+
kind: "suppress",
|
|
57827
|
+
result: {
|
|
57828
|
+
success: true,
|
|
57829
|
+
forwarded: 0,
|
|
57830
|
+
suppressed: true,
|
|
57831
|
+
midTurnLiveStatePending: true,
|
|
57832
|
+
...heldForRetry ? { completionRetryHeld: true } : {}
|
|
57833
|
+
}
|
|
57834
|
+
};
|
|
57835
|
+
}
|
|
57569
57836
|
}
|
|
57570
57837
|
}
|
|
57571
57838
|
if (!readNonEmptyString(args.metadataEvent.taskId) && !sessionHasActiveAssignment(args.meshId, eventSessionId) && !findRecentTerminalLedgerEvidence({ meshId: args.meshId, sessionId: eventSessionId, nodeId: eventNodeId || void 0 }) && isWeakCompletionEvidence(args.metadataEvent)) {
|
|
@@ -58467,6 +58734,8 @@ ${cleanBody}`;
|
|
|
58467
58734
|
// keeps event.taskId/meshActiveTaskId for free; this mirrors it for the remote relay.
|
|
58468
58735
|
// Same taskId/meshActiveTaskId ordering the local unroutable trace uses.
|
|
58469
58736
|
taskId: readNonEmptyString(payload.taskId) || readNonEmptyString(payload.meshActiveTaskId),
|
|
58737
|
+
attemptId: readNonEmptyString(payload.attemptId) || readNonEmptyString(payload.meshActiveAttemptId),
|
|
58738
|
+
...typeof payload.dispatchNonce === "number" ? { dispatchNonce: payload.dispatchNonce } : typeof payload.meshActiveDispatchNonce === "number" ? { dispatchNonce: payload.meshActiveDispatchNonce } : {},
|
|
58470
58739
|
targetSessionId: readNonEmptyString(payload.targetSessionId) || readNonEmptyString(payload.sessionId) || readNonEmptyString(payload.instanceId),
|
|
58471
58740
|
providerType: readNonEmptyString(payload.providerType),
|
|
58472
58741
|
providerSessionId: readNonEmptyString(payload.providerSessionId),
|
|
@@ -58493,6 +58762,7 @@ ${cleanBody}`;
|
|
|
58493
58762
|
providerName: readNonEmptyString(payload.providerName),
|
|
58494
58763
|
...payload.sessionSettings && typeof payload.sessionSettings === "object" && !Array.isArray(payload.sessionSettings) ? { sessionSettings: payload.sessionSettings } : {},
|
|
58495
58764
|
finalSummary: readNonEmptyString(payload.finalSummary) || readNonEmptyString(payload.summary),
|
|
58765
|
+
evidenceLevel: readNonEmptyString(payload.evidenceLevel),
|
|
58496
58766
|
// T2: carry the worker's status-snapshot last-message preview across the machine
|
|
58497
58767
|
// boundary so a summary-less completion still surfaces the assistant reply in the
|
|
58498
58768
|
// coordinator's inbox mirror. resolveMeshSurfacedSessionPreview reads these
|
|
@@ -58759,6 +59029,10 @@ ${cleanBody}`;
|
|
|
58759
59029
|
var REMOTE_IDLE_SESSION_TTL_MS;
|
|
58760
59030
|
var meshByWorkspaceCache;
|
|
58761
59031
|
var MESH_WORKSPACE_CACHE_TTL_MS;
|
|
59032
|
+
var MID_TURN_COMPLETION_HOLD_RETRY_MS;
|
|
59033
|
+
var MID_TURN_COMPLETION_HOLD_TTL_MS;
|
|
59034
|
+
var heldLiveStateCompletions;
|
|
59035
|
+
var heldLiveStateCompletionTimer;
|
|
58762
59036
|
var lastPendingEventsPruneAt;
|
|
58763
59037
|
var PENDING_EVENTS_PRUNE_INTERVAL_MS;
|
|
58764
59038
|
var INTENTIONAL_CLEANUP_STOP_SUPPRESSION_MS;
|
|
@@ -58793,9 +59067,14 @@ ${cleanBody}`;
|
|
|
58793
59067
|
init_mesh_turn_ledger();
|
|
58794
59068
|
init_mesh_turn_presentation();
|
|
58795
59069
|
init_mesh_queue_assignment();
|
|
59070
|
+
init_mesh_completion_live_gate();
|
|
58796
59071
|
REMOTE_IDLE_SESSION_TTL_MS = 5 * 60 * 1e3;
|
|
58797
59072
|
meshByWorkspaceCache = /* @__PURE__ */ new Map();
|
|
58798
59073
|
MESH_WORKSPACE_CACHE_TTL_MS = 5e3;
|
|
59074
|
+
MID_TURN_COMPLETION_HOLD_RETRY_MS = 250;
|
|
59075
|
+
MID_TURN_COMPLETION_HOLD_TTL_MS = 5e3;
|
|
59076
|
+
heldLiveStateCompletions = /* @__PURE__ */ new Map();
|
|
59077
|
+
heldLiveStateCompletionTimer = null;
|
|
58799
59078
|
lastPendingEventsPruneAt = 0;
|
|
58800
59079
|
PENDING_EVENTS_PRUNE_INTERVAL_MS = 60 * 60 * 1e3;
|
|
58801
59080
|
INTENTIONAL_CLEANUP_STOP_SUPPRESSION_MS = 30 * 60 * 1e3;
|
|
@@ -67877,6 +68156,7 @@ ${lastSnapshot}`;
|
|
|
67877
68156
|
MAGI_NEEDS_VERIFICATION_PREVIEW_CAP: () => MAGI_NEEDS_VERIFICATION_PREVIEW_CAP,
|
|
67878
68157
|
MAGI_RAW_ANSWER_CAP: () => MAGI_RAW_ANSWER_CAP,
|
|
67879
68158
|
MAX_LEDGER_SLICE_LIMIT: () => MAX_LEDGER_SLICE_LIMIT,
|
|
68159
|
+
MAX_SIZE_ROTATION_GENERATIONS: () => MAX_SIZE_ROTATION_GENERATIONS,
|
|
67880
68160
|
MESH_CONVERGE_FAST_FORWARD_TAG: () => MESH_CONVERGE_FAST_FORWARD_TAG,
|
|
67881
68161
|
MESH_CONVERGE_REFINE_TAG: () => MESH_CONVERGE_REFINE_TAG,
|
|
67882
68162
|
MESH_JSON_CONFIG_LOCATIONS: () => MESH_JSON_CONFIG_LOCATIONS,
|
|
@@ -69800,10 +70080,57 @@ ${lastSnapshot}`;
|
|
|
69800
70080
|
}
|
|
69801
70081
|
return String(error48 || "mesh relay command failed");
|
|
69802
70082
|
}
|
|
70083
|
+
function readStructuredFailure(error48) {
|
|
70084
|
+
if (!error48 || typeof error48 !== "object") return {};
|
|
70085
|
+
const value = error48;
|
|
70086
|
+
return {
|
|
70087
|
+
...typeof value.code === "string" ? { code: value.code } : {},
|
|
70088
|
+
...typeof value.reason === "string" ? { reason: value.reason } : {},
|
|
70089
|
+
...value.transport === "p2p" || value.transport === "unknown" ? { transport: value.transport } : {},
|
|
70090
|
+
...typeof value.recoverable === "boolean" ? { recoverable: value.recoverable } : {},
|
|
70091
|
+
...typeof value.retryRecommended === "boolean" ? { retryRecommended: value.retryRecommended } : {},
|
|
70092
|
+
...typeof value.nextAction === "string" ? { nextAction: value.nextAction } : {},
|
|
70093
|
+
...typeof value.noFallbackReason === "string" ? { noFallbackReason: value.noFallbackReason } : {},
|
|
70094
|
+
...typeof value.meshCode === "string" ? { meshCode: value.meshCode } : {},
|
|
70095
|
+
...typeof value.connectionState === "string" ? { connectionState: value.connectionState } : {},
|
|
70096
|
+
...typeof value.nextRetryAt === "string" ? { nextRetryAt: value.nextRetryAt } : {},
|
|
70097
|
+
...typeof value.authEpoch === "number" ? { authEpoch: value.authEpoch } : {}
|
|
70098
|
+
};
|
|
70099
|
+
}
|
|
70100
|
+
function reasonForCode(code) {
|
|
70101
|
+
switch (code) {
|
|
70102
|
+
case "p2p_timeout":
|
|
70103
|
+
return "daemon_mesh_p2p_timeout";
|
|
70104
|
+
case "p2p_not_connected":
|
|
70105
|
+
return "daemon_mesh_p2p_not_connected";
|
|
70106
|
+
case "p2p_datachannel_closed":
|
|
70107
|
+
return "daemon_mesh_p2p_datachannel_closed";
|
|
70108
|
+
case "p2p_no_route":
|
|
70109
|
+
return "daemon_mesh_p2p_no_route";
|
|
70110
|
+
case "p2p_daemon_offline":
|
|
70111
|
+
return "daemon_mesh_target_offline";
|
|
70112
|
+
case "p2p_unavailable":
|
|
70113
|
+
return "daemon_mesh_p2p_transport_unavailable";
|
|
70114
|
+
case "mesh_logic_or_provider_failure":
|
|
70115
|
+
return "mesh_logic_or_provider_failure";
|
|
70116
|
+
}
|
|
70117
|
+
}
|
|
69803
70118
|
function classifyP2pRelayFailure(error48, _context = {}) {
|
|
69804
70119
|
const message = messageFromError(error48);
|
|
69805
70120
|
const lower = message.toLowerCase();
|
|
69806
|
-
const
|
|
70121
|
+
const structured = readStructuredFailure(error48);
|
|
70122
|
+
if (structured.code && structured.code !== "mesh_logic_or_provider_failure" && structured.transport === "p2p") {
|
|
70123
|
+
return {
|
|
70124
|
+
code: structured.code,
|
|
70125
|
+
reason: structured.reason || reasonForCode(structured.code),
|
|
70126
|
+
transport: "p2p",
|
|
70127
|
+
recoverable: structured.recoverable ?? true,
|
|
70128
|
+
retryRecommended: structured.retryRecommended ?? true,
|
|
70129
|
+
nextAction: structured.nextAction || P2P_NEXT_ACTION,
|
|
70130
|
+
noFallbackReason: structured.noFallbackReason || NO_FALLBACK_REASON
|
|
70131
|
+
};
|
|
70132
|
+
}
|
|
70133
|
+
const hasP2pSignal = /p2p|peer|datachannel|node-datachannel|webrtc|ice|mesh_relay_command|daemon_mesh_p2p_transport/i.test(message);
|
|
69807
70134
|
const hasFailureSignal = /unavailable|missing|failed|failure|timeout|timed out|not connected|closed|disconnected|offline|no route|route unavailable|cannot send|cannot establish/i.test(message);
|
|
69808
70135
|
if (/requires targetdaemonid and command|providerpriority|no inference provider|permission denied|read-only|not a member/i.test(message)) {
|
|
69809
70136
|
return {
|
|
@@ -69830,7 +70157,7 @@ ${lastSnapshot}`;
|
|
|
69830
70157
|
} else if (/closed|disconnected/i.test(message) && (hasP2pSignal || /state changed/i.test(message))) {
|
|
69831
70158
|
code = "p2p_datachannel_closed";
|
|
69832
70159
|
reason = "daemon_mesh_p2p_datachannel_closed";
|
|
69833
|
-
} else if (/not connected|cannot send|cannot establish/i.test(message) && hasP2pSignal) {
|
|
70160
|
+
} else if (/not connected|cannot send|cannot establish|probe gave up/i.test(message) && hasP2pSignal) {
|
|
69834
70161
|
code = "p2p_not_connected";
|
|
69835
70162
|
reason = "daemon_mesh_p2p_not_connected";
|
|
69836
70163
|
} else if (hasP2pSignal && hasFailureSignal) {
|
|
@@ -69863,12 +70190,17 @@ ${lastSnapshot}`;
|
|
|
69863
70190
|
}
|
|
69864
70191
|
function buildP2pRelayFailurePayload(error48, context = {}) {
|
|
69865
70192
|
const classification = classifyP2pRelayFailure(error48, context);
|
|
70193
|
+
const structured = readStructuredFailure(error48);
|
|
69866
70194
|
return {
|
|
69867
70195
|
success: false,
|
|
69868
70196
|
...classification,
|
|
69869
70197
|
error: messageFromError(error48),
|
|
69870
70198
|
...context.command ? { command: context.command } : {},
|
|
69871
|
-
...context.targetDaemonId ? { targetDaemonId: context.targetDaemonId } : {}
|
|
70199
|
+
...context.targetDaemonId ? { targetDaemonId: context.targetDaemonId } : {},
|
|
70200
|
+
...context.meshCode || structured.meshCode ? { meshCode: context.meshCode || structured.meshCode } : {},
|
|
70201
|
+
...context.connectionState || structured.connectionState ? { connectionState: context.connectionState || structured.connectionState } : {},
|
|
70202
|
+
...context.nextRetryAt || structured.nextRetryAt ? { nextRetryAt: context.nextRetryAt || structured.nextRetryAt } : {},
|
|
70203
|
+
...(context.authEpoch ?? structured.authEpoch) !== void 0 ? { authEpoch: context.authEpoch ?? structured.authEpoch } : {}
|
|
69872
70204
|
};
|
|
69873
70205
|
}
|
|
69874
70206
|
var P2pRelayFailureError = class extends Error {
|
|
@@ -69881,19 +70213,37 @@ ${lastSnapshot}`;
|
|
|
69881
70213
|
noFallbackReason;
|
|
69882
70214
|
command;
|
|
69883
70215
|
targetDaemonId;
|
|
70216
|
+
meshCode;
|
|
70217
|
+
connectionState;
|
|
70218
|
+
nextRetryAt;
|
|
70219
|
+
authEpoch;
|
|
69884
70220
|
constructor(message, context = {}) {
|
|
69885
70221
|
super(message);
|
|
69886
70222
|
this.name = "P2pRelayFailureError";
|
|
69887
|
-
const payload = buildP2pRelayFailurePayload(
|
|
69888
|
-
|
|
70223
|
+
const payload = buildP2pRelayFailurePayload({
|
|
70224
|
+
message,
|
|
70225
|
+
...context.code ? { code: context.code } : {},
|
|
70226
|
+
...context.recoverable !== void 0 ? { recoverable: context.recoverable } : {},
|
|
70227
|
+
...context.retryRecommended !== void 0 ? { retryRecommended: context.retryRecommended } : {},
|
|
70228
|
+
transport: context.code ? "p2p" : void 0,
|
|
70229
|
+
meshCode: context.meshCode,
|
|
70230
|
+
connectionState: context.connectionState,
|
|
70231
|
+
nextRetryAt: context.nextRetryAt,
|
|
70232
|
+
authEpoch: context.authEpoch
|
|
70233
|
+
}, context);
|
|
70234
|
+
this.code = context.code ?? payload.code;
|
|
69889
70235
|
this.reason = payload.reason;
|
|
69890
70236
|
this.transport = payload.transport;
|
|
69891
|
-
this.recoverable = payload.recoverable;
|
|
69892
|
-
this.retryRecommended = payload.retryRecommended;
|
|
70237
|
+
this.recoverable = context.recoverable ?? payload.recoverable;
|
|
70238
|
+
this.retryRecommended = context.retryRecommended ?? payload.retryRecommended;
|
|
69893
70239
|
this.nextAction = payload.nextAction;
|
|
69894
70240
|
this.noFallbackReason = payload.noFallbackReason;
|
|
69895
70241
|
this.command = context.command;
|
|
69896
70242
|
this.targetDaemonId = context.targetDaemonId;
|
|
70243
|
+
this.meshCode = context.meshCode;
|
|
70244
|
+
this.connectionState = context.connectionState;
|
|
70245
|
+
this.nextRetryAt = context.nextRetryAt;
|
|
70246
|
+
this.authEpoch = context.authEpoch;
|
|
69897
70247
|
}
|
|
69898
70248
|
};
|
|
69899
70249
|
init_state_store();
|
|
@@ -81195,6 +81545,12 @@ ${body}
|
|
|
81195
81545
|
}
|
|
81196
81546
|
return getCurrentDaemonLogPath();
|
|
81197
81547
|
}
|
|
81548
|
+
function sizeRotationPaths(primaryPath) {
|
|
81549
|
+
return Array.from(
|
|
81550
|
+
{ length: MAX_SIZE_ROTATION_GENERATIONS },
|
|
81551
|
+
(_, index) => primaryPath.replace(/\.log$/, `.${index + 1}.log`)
|
|
81552
|
+
);
|
|
81553
|
+
}
|
|
81198
81554
|
function clampTailBytes(tailBytes) {
|
|
81199
81555
|
if (!Number.isFinite(tailBytes) || tailBytes <= 0) return DEFAULT_TAIL_BYTES;
|
|
81200
81556
|
return Math.min(Math.floor(tailBytes), MAX_TAIL_BYTES);
|
|
@@ -81303,17 +81659,17 @@ ${body}
|
|
|
81303
81659
|
const platform10 = process.platform;
|
|
81304
81660
|
const limitBytes = clampTailBytes(args.tailBytes);
|
|
81305
81661
|
const primaryPath = resolveLogPath(args.date);
|
|
81306
|
-
const
|
|
81662
|
+
const backupPaths = sizeRotationPaths(primaryPath);
|
|
81307
81663
|
const primaryExists = fs16.existsSync(primaryPath);
|
|
81308
|
-
const
|
|
81309
|
-
if (!primaryExists &&
|
|
81664
|
+
const existingBackupPaths = backupPaths.filter((backupPath) => fs16.existsSync(backupPath));
|
|
81665
|
+
if (!primaryExists && existingBackupPaths.length === 0) {
|
|
81310
81666
|
return errorResult(
|
|
81311
81667
|
`No daemon log file at ${primaryPath} (dir: ${getDaemonLogDir()})`,
|
|
81312
81668
|
primaryPath,
|
|
81313
81669
|
platform10
|
|
81314
81670
|
);
|
|
81315
81671
|
}
|
|
81316
|
-
const logPath = primaryExists ? primaryPath :
|
|
81672
|
+
const logPath = primaryExists ? primaryPath : existingBackupPaths[0];
|
|
81317
81673
|
const hasGrep = typeof args.grep === "string" && args.grep.trim().length > 0;
|
|
81318
81674
|
const hasSince = Number.isFinite(args.sinceMs);
|
|
81319
81675
|
const filterMode = hasGrep || hasSince;
|
|
@@ -81342,7 +81698,7 @@ ${body}
|
|
|
81342
81698
|
let scannedBytes = 0;
|
|
81343
81699
|
let allLines = [];
|
|
81344
81700
|
try {
|
|
81345
|
-
for (const p of [
|
|
81701
|
+
for (const p of [...existingBackupPaths].reverse().concat(primaryExists ? [primaryPath] : [])) {
|
|
81346
81702
|
if (!p) continue;
|
|
81347
81703
|
const buf = fs16.readFileSync(p);
|
|
81348
81704
|
scannedBytes += buf.length;
|
|
@@ -86791,6 +87147,43 @@ ${body}
|
|
|
86791
87147
|
isModalParked() {
|
|
86792
87148
|
return this.resolveModalParkStatus() !== null;
|
|
86793
87149
|
}
|
|
87150
|
+
/**
|
|
87151
|
+
* Provider-agnostic live-state observation for the mesh completion gate.
|
|
87152
|
+
* `observedAt` is the PTY snapshot clock, not the time this accessor ran:
|
|
87153
|
+
* after restart/rebind an old waiting_* frame must remain recognizably
|
|
87154
|
+
* older than a newly-written authoritative transcript final.
|
|
87155
|
+
*/
|
|
87156
|
+
getLiveTurnPendingEvidence() {
|
|
87157
|
+
const adapterPending = this.hasAdapterPendingResponse();
|
|
87158
|
+
const modalParked = this.isModalParked();
|
|
87159
|
+
if (adapterPending || modalParked) {
|
|
87160
|
+
let observedAt;
|
|
87161
|
+
try {
|
|
87162
|
+
const raw = this.adapter.getStatus({ allowParse: false });
|
|
87163
|
+
if (typeof raw?.lastOutputAt === "number" && Number.isFinite(raw.lastOutputAt)) {
|
|
87164
|
+
observedAt = raw.lastOutputAt;
|
|
87165
|
+
}
|
|
87166
|
+
} catch {
|
|
87167
|
+
}
|
|
87168
|
+
return {
|
|
87169
|
+
pending: true,
|
|
87170
|
+
kind: modalParked ? "modal" : "adapter",
|
|
87171
|
+
...observedAt !== void 0 ? { observedAt } : {}
|
|
87172
|
+
};
|
|
87173
|
+
}
|
|
87174
|
+
try {
|
|
87175
|
+
const probe = this.probeNativeTranscriptSignals();
|
|
87176
|
+
if (probe?.snapshot?.available === true && Array.isArray(probe.messages) && hasTrailingToolActivityAfterFinalAssistant(probe.messages)) {
|
|
87177
|
+
return {
|
|
87178
|
+
pending: true,
|
|
87179
|
+
kind: "transcript_tool",
|
|
87180
|
+
observedAt: probe.snapshot.sampledAt
|
|
87181
|
+
};
|
|
87182
|
+
}
|
|
87183
|
+
} catch {
|
|
87184
|
+
}
|
|
87185
|
+
return { pending: false };
|
|
87186
|
+
}
|
|
86794
87187
|
/**
|
|
86795
87188
|
* MID-TURN-LIVE-STATE-GATE (broader false-idle RCA, mid-turn follow-up): a live,
|
|
86796
87189
|
* synchronous re-check of whether this session's CURRENT turn genuinely still has
|
|
@@ -86825,15 +87218,7 @@ ${body}
|
|
|
86825
87218
|
* can never wedge a session as "pending" forever.
|
|
86826
87219
|
*/
|
|
86827
87220
|
hasLiveTurnPendingEvidence() {
|
|
86828
|
-
|
|
86829
|
-
try {
|
|
86830
|
-
const probe = this.probeNativeTranscriptSignals();
|
|
86831
|
-
if (probe?.snapshot?.available === true && Array.isArray(probe.messages)) {
|
|
86832
|
-
if (hasTrailingToolActivityAfterFinalAssistant(probe.messages)) return true;
|
|
86833
|
-
}
|
|
86834
|
-
} catch {
|
|
86835
|
-
}
|
|
86836
|
-
return false;
|
|
87221
|
+
return this.getLiveTurnPendingEvidence().pending;
|
|
86837
87222
|
}
|
|
86838
87223
|
/**
|
|
86839
87224
|
* PTY-OVERTRUST-DRAIN (Defect B). The deliverability/drain status the mesh
|
|
@@ -87522,8 +87907,12 @@ ${body}
|
|
|
87522
87907
|
LOG2.debug("CLI", `[${this.type}] finalAssistantEvidence: present=${finalAssistantEvidence.present} source=${finalAssistantEvidence.source} adapterOwnsMessagesElsewhere=${adapterOwnsMessagesElsewhere} parsedStatus=${parsedStatus}`);
|
|
87523
87908
|
if (finalAssistantEvidence.present && finalAssistantEvidence.source !== "unavailable") {
|
|
87524
87909
|
pending.resolvedFinalMessages = Array.isArray(finalAssistantEvidence.messages) ? finalAssistantEvidence.messages : void 0;
|
|
87910
|
+
pending.resolvedFinalEvidenceSource = finalAssistantEvidence.source;
|
|
87911
|
+
pending.resolvedFinalEvidenceObservedAt = Date.now();
|
|
87525
87912
|
} else {
|
|
87526
87913
|
pending.resolvedFinalMessages = void 0;
|
|
87914
|
+
pending.resolvedFinalEvidenceSource = void 0;
|
|
87915
|
+
pending.resolvedFinalEvidenceObservedAt = void 0;
|
|
87527
87916
|
}
|
|
87528
87917
|
if (!finalAssistantEvidence.present) {
|
|
87529
87918
|
if (adapterOwnsMessagesElsewhere) {
|
|
@@ -88479,12 +88868,40 @@ ${body}
|
|
|
88479
88868
|
duration: pending.duration,
|
|
88480
88869
|
busyEpoch: this.busyEpoch
|
|
88481
88870
|
});
|
|
88871
|
+
const finalSummary = this.cleanCompletionFinalSummary(pending);
|
|
88872
|
+
const transcriptProfile = resolveTranscriptAuthorityProfile(this.provider);
|
|
88873
|
+
const finalContentLength = typeof finalSummary === "string" ? finalSummary.trim().length : 0;
|
|
88482
88874
|
this.emitGeneratingCompleted({
|
|
88483
88875
|
chatTitle: pending.chatTitle,
|
|
88484
88876
|
duration: pending.duration,
|
|
88485
88877
|
timestamp: pending.timestamp,
|
|
88486
88878
|
taskId: pending.taskId,
|
|
88487
|
-
finalSummary
|
|
88879
|
+
finalSummary,
|
|
88880
|
+
evidenceLevel: "transcript",
|
|
88881
|
+
completionDiagnostic: {
|
|
88882
|
+
source: "clean_final_assistant",
|
|
88883
|
+
cleanPath: true,
|
|
88884
|
+
evidenceWeak: false,
|
|
88885
|
+
finalAssistantPresent: true,
|
|
88886
|
+
finalAssistantEvidenceSource: pending.resolvedFinalEvidenceSource ?? "parsed",
|
|
88887
|
+
finalAssistantContentLength: finalContentLength,
|
|
88888
|
+
transcriptEvidence: {
|
|
88889
|
+
version: 1,
|
|
88890
|
+
kind: "final_assistant",
|
|
88891
|
+
cleanPath: true,
|
|
88892
|
+
weak: false,
|
|
88893
|
+
authorityClass: transcriptProfile.class,
|
|
88894
|
+
timing: transcriptProfile.timing,
|
|
88895
|
+
providerOwnsTranscript: transcriptProfile.providerOwnsTranscript,
|
|
88896
|
+
observedAt: pending.resolvedFinalEvidenceObservedAt ?? Date.now(),
|
|
88897
|
+
turnStartedAt: pending.turnStartedAt ?? null,
|
|
88898
|
+
finalContentLength,
|
|
88899
|
+
taskId: pending.taskId ?? null,
|
|
88900
|
+
attemptId: typeof this.settings.meshActiveAttemptId === "string" ? this.settings.meshActiveAttemptId : null,
|
|
88901
|
+
dispatchNonce: typeof this.settings.meshActiveDispatchNonce === "number" ? this.settings.meshActiveDispatchNonce : null,
|
|
88902
|
+
sessionId: this.instanceId
|
|
88903
|
+
}
|
|
88904
|
+
}
|
|
88488
88905
|
});
|
|
88489
88906
|
this.completedDebouncePending = null;
|
|
88490
88907
|
this.completedDebounceTimer = null;
|
|
@@ -100683,7 +101100,7 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
100683
101100
|
return "";
|
|
100684
101101
|
}
|
|
100685
101102
|
}
|
|
100686
|
-
function
|
|
101103
|
+
function readRecord7(repoRoot) {
|
|
100687
101104
|
const path50 = (0, import_node_path3.resolve)(repoRoot, PREVIEW_DEPLOY_RECORD);
|
|
100688
101105
|
if (!(0, import_node_fs4.existsSync)(path50)) return null;
|
|
100689
101106
|
try {
|
|
@@ -100724,7 +101141,7 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
100724
101141
|
function buildPreviewFreshness(repoRoot) {
|
|
100725
101142
|
if (!isPreviewPipelineConfigured(repoRoot)) return null;
|
|
100726
101143
|
const current = readCurrentMainCommit(repoRoot);
|
|
100727
|
-
const record2 =
|
|
101144
|
+
const record2 = readRecord7(repoRoot);
|
|
100728
101145
|
const lastPreviewCommit = normalizeCommit(record2?.lastPreviewCommit);
|
|
100729
101146
|
const targets = readTargetFreshness(record2, current.currentMainCommit);
|
|
100730
101147
|
let status = "unknown";
|
|
@@ -101132,6 +101549,7 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
101132
101549
|
finalizeMeshNodeStatus({ status: fallback, node, daemonId, isSelfNode: false, directTruthUnavailable: directTruthUnavailableNodeIds.has(nodeId) });
|
|
101133
101550
|
return fallback;
|
|
101134
101551
|
});
|
|
101552
|
+
const cachedProjectionNodeIds = nodeStatuses.filter((status) => status?.dataFreshness?.projection === "cached" && status?.dataFreshness?.directPeerTruthSatisfied === false).map((status) => readStringValue(status?.nodeId)).filter(Boolean);
|
|
101135
101553
|
const callerCoordinatorDaemonId = typeof args?.coordinatorDaemonId === "string" && args.coordinatorDaemonId.trim() ? args.coordinatorDaemonId.trim() : ctx.deps.statusInstanceId || void 0;
|
|
101136
101554
|
const pendingCoordinatorEvents = getPendingMeshCoordinatorEvents(meshId, callerCoordinatorDaemonId);
|
|
101137
101555
|
const unroutableDeliveries = getRecentUnroutableDeliveries();
|
|
@@ -101192,7 +101610,8 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
101192
101610
|
peerAttemptedCount: effectiveDirectTruth.peerAttemptedCount,
|
|
101193
101611
|
peerConfirmedCount: effectiveDirectTruth.peerConfirmedCount,
|
|
101194
101612
|
unavailableNodeIds: effectiveDirectTruth.unavailableNodeIds,
|
|
101195
|
-
partialNodeFailures: effectiveDirectTruth.unavailableNodeIds
|
|
101613
|
+
partialNodeFailures: effectiveDirectTruth.unavailableNodeIds,
|
|
101614
|
+
cachedProjectionNodeIds
|
|
101196
101615
|
}
|
|
101197
101616
|
} : {},
|
|
101198
101617
|
historicalEvidenceOnly: ["recoveryHints", "ledger.summary", "queue.summary", "historicalSessions"]
|