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
+46 -1
View File
@@ -2,7 +2,7 @@ import { Buffer } from "node:buffer";
import { existsSync, readFileSync } from "node:fs";
import { type UniDeskConfig, rootPath } from "./config";
import { runSshCommandCapture } from "./ssh";
import { classifySshTcpPoolFailure, runSshCommandCapture, type SshCaptureResult } from "./ssh";
type RemoteGcAction = "plan" | "snapshot" | "trend" | "run" | "status" | "policy-plan" | "policy-install";
@@ -254,14 +254,22 @@ async function runRemoteGc(config: UniDeskConfig, providerId: string, action: Re
const scriptConfig = Buffer.from(JSON.stringify({ providerId, action, options, remoteTarget }), "utf8").toString("base64");
const result = await runSshCommandCapture(config, providerId, ["py"], remoteGcPython(scriptConfig));
if (result.exitCode !== 0) {
const degraded = remoteGcDegradedFailure(providerId, action, result);
return {
ok: false,
error: "gc-remote-command-failed",
providerId,
action: `gc remote ${action}`,
exitCode: result.exitCode,
degradedReason: degraded.degradedReason,
transport: degraded.transport,
safeCandidateCount: null,
runAllowed: false,
mutation: false,
degraded,
stdoutTail: result.stdout.slice(-4000),
stderrTail: result.stderr.slice(-4000),
next: degraded.next,
};
}
try {
@@ -279,6 +287,43 @@ async function runRemoteGc(config: UniDeskConfig, providerId: string, action: Re
}
}
function remoteGcDegradedFailure(providerId: string, action: RemoteGcAction, result: SshCaptureResult): Record<string, unknown> {
const text = `${result.stderr}\n${result.stdout}`;
const failureKind = classifySshTcpPoolFailure(text);
const timeout = result.exitCode === 124 || text.includes("ssh-runtime-timeout");
const providerOffline = text.includes(`provider is not online: ${providerId}`) || text.includes("provider is not online");
const degradedReason = failureKind ?? (providerOffline ? "provider-offline" : timeout ? "ssh-runtime-timeout" : "remote-command-failed");
return {
ok: false,
degraded: true,
providerId,
action: `gc remote ${action}`,
degradedReason,
transport: {
sshTcpPoolFailureKind: failureKind,
providerOffline,
sshRuntimeTimeout: timeout,
exitCode: result.exitCode,
},
safeCandidateCount: null,
runAllowed: false,
mutation: false,
summary: failureKind !== null
? `remote GC could not acquire a provider data channel: ${failureKind}`
: providerOffline
? `provider ${providerId} is offline from the controlled CLI transport view`
: timeout
? "remote GC did not complete before the SSH runtime timeout"
: "remote GC command failed before producing a valid plan",
next: {
sshPool: `bun scripts/cli.ts debug ssh-pool ${providerId}`,
fullHealth: "bun scripts/cli.ts debug health",
smoke: `trans ${providerId} argv true`,
retryPlan: `bun scripts/cli.ts gc remote ${providerId} plan --no-snapshot-save`,
},
};
}
function remoteGcPython(configBase64: string): string {
return String.raw`
import base64