fix: expose JD01 transport degraded snapshots

This commit is contained in:
Codex
2026-07-04 20:38:10 +00:00
parent f35fde8f65
commit de984e06f7
2 changed files with 128 additions and 1 deletions
+82
View File
@@ -142,6 +142,85 @@ function stringValue(value: unknown): string | null {
return typeof value === "string" ? value : null;
}
function numberValue(value: unknown): number | null {
const parsed = Number(value);
return Number.isFinite(parsed) ? parsed : null;
}
function rounded(value: number | null): number | null {
return value === null ? null : Math.round(value * 100) / 100;
}
function providerHostPressureSummary(providerId: string): unknown {
const response = coreInternalFetch("/api/nodes/system-status?limit=24");
const body = recordValue(recordValue(response).body);
const systemStatuses = arrayValue(body.systemStatuses);
const item = systemStatuses
.map((entry) => recordValue(entry))
.find((entry) => entry.providerId === providerId) ?? null;
if (item === null) {
return {
ok: false,
degradedReason: "system-status-not-found",
systemStatusFetch: response,
};
}
const current = recordValue(item.current);
if (Object.keys(current).length === 0) {
return {
ok: false,
providerId,
degradedReason: "system-status-current-missing",
updatedAt: item.updatedAt ?? null,
nodeStatus: item.nodeStatus ?? null,
classification: "host-pressure-snapshot-unavailable",
};
}
const cpu = recordValue(current.cpu);
const memory = recordValue(current.memory);
const disk = recordValue(current.disk);
const cores = numberValue(cpu.cores);
const load1 = numberValue(cpu.load1);
const load5 = numberValue(cpu.load5);
const load15 = numberValue(cpu.load15);
const load1PerCore = cores !== null && cores > 0 && load1 !== null ? load1 / cores : null;
const memoryPercent = numberValue(memory.percent);
const memoryAvailableBytes = numberValue(memory.availableBytes);
const swapTotalBytes = numberValue(memory.swapTotalBytes);
const diskPercent = numberValue(disk.percent);
const signals: string[] = [];
if (load1PerCore !== null && load1PerCore >= 4) signals.push("load1-per-core>=4");
if (memoryPercent !== null && memoryPercent >= 90) signals.push("memory-percent>=90");
if (memoryAvailableBytes !== null && memoryAvailableBytes < 512 * 1024 * 1024) signals.push("memory-available<512MiB");
if (swapTotalBytes === 0) signals.push("swap-disabled");
if (diskPercent !== null && diskPercent >= 90) signals.push("disk-percent>=90");
return {
ok: current.ok ?? null,
providerId,
updatedAt: item.updatedAt ?? null,
collectedAt: current.collectedAt ?? null,
cpu: {
cores,
load1,
load5,
load15,
load1PerCore: rounded(load1PerCore),
},
memory: {
percent: memoryPercent,
availableBytes: memoryAvailableBytes,
swapTotalBytes,
},
disk: {
percent: diskPercent,
availableBytes: numberValue(disk.availableBytes),
mount: disk.mount ?? null,
},
signals,
classification: signals.length > 0 ? "host-pressure-signals-present" : "host-pressure-signals-not-observed",
};
}
export async function debugSshPool(_config: UniDeskConfig, providerId: string): Promise<unknown> {
const nodesResponse = await coreInternalFetch("/api/nodes");
const body = recordValue(recordValue(nodesResponse).body);
@@ -185,6 +264,7 @@ export async function debugSshPool(_config: UniDeskConfig, providerId: string):
updatedAt: node.updatedAt ?? null,
},
pool,
hostPressure: providerHostPressureSummary(providerId),
classification: ok
? "ssh-tcp-pool-ready"
: pool.transport !== "tcp-pool"
@@ -195,7 +275,9 @@ export async function debugSshPool(_config: UniDeskConfig, providerId: string):
next: {
smoke: `trans ${providerId} argv true`,
fullHealth: "bun scripts/cli.ts debug health",
gcDegradedSnapshot: `bun scripts/cli.ts gc remote ${providerId} snapshot --no-save`,
},
note: "Pool labels are provider-reported channel state; use the smoke command or gc degraded output to verify execution path.",
};
}