fix: clarify code queue active diagnostics
This commit is contained in:
+122
-4
@@ -260,6 +260,7 @@ interface CodexPrPreflightOptions {
|
||||
}
|
||||
|
||||
type CodeQueuePrPreflightFailureKind = "auth-missing" | "proxy-gap" | "git-remote-gap" | "control-plane-missing" | "target-stack-not-running";
|
||||
type CodeQueueObservationGapKind = "runner-local-observation-gap" | "control-plane-observation-gap" | null;
|
||||
|
||||
interface CodeQueuePrPreflightTransport {
|
||||
config?: UniDeskConfig | null;
|
||||
@@ -1015,6 +1016,42 @@ function recommendedActionFromDiagnostics(record: Record<string, unknown>): stri
|
||||
return "none";
|
||||
}
|
||||
|
||||
function activeHeartbeatCountFromDiagnostics(record: Record<string, unknown>, activeHeartbeatTaskIds: { count: number }, heartbeatFreshTaskIds: { count: number }): number {
|
||||
const explicit = asNumber(record.activeHeartbeatCount, Number.NaN);
|
||||
return Number.isFinite(explicit) ? explicit : Math.max(activeHeartbeatTaskIds.count, heartbeatFreshTaskIds.count);
|
||||
}
|
||||
|
||||
function compactLivenessDecision(record: Record<string, unknown>, lists: {
|
||||
activeHeartbeatTaskIds: { items: string[]; count: number; truncated: boolean; omitted: number };
|
||||
heartbeatFreshTaskIds: { items: string[]; count: number; truncated: boolean; omitted: number };
|
||||
heartbeatRiskTaskIds: { items: string[]; count: number };
|
||||
databaseActiveTaskIds: { count: number };
|
||||
}): Record<string, unknown> {
|
||||
const splitBrainLive = splitBrainLiveFromDiagnostics(record);
|
||||
const effectiveLiveness = effectiveLivenessFromDiagnostics(record);
|
||||
const recommendedAction = recommendedActionFromDiagnostics(record);
|
||||
const activeHeartbeatCount = activeHeartbeatCountFromDiagnostics(record, lists.activeHeartbeatTaskIds, lists.heartbeatFreshTaskIds);
|
||||
return {
|
||||
effectiveLiveness,
|
||||
recommendedAction,
|
||||
splitBrainLive,
|
||||
activeHeartbeatCount,
|
||||
heartbeatFreshTaskCount: lists.heartbeatFreshTaskIds.count,
|
||||
heartbeatFreshTaskIds: lists.heartbeatFreshTaskIds.items,
|
||||
heartbeatFreshTaskIdsTruncated: lists.heartbeatFreshTaskIds.truncated,
|
||||
databaseActiveTaskCount: asNumber(record.databaseActiveTaskCount, lists.databaseActiveTaskIds.count),
|
||||
schedulerActiveRunSlotCount: record.schedulerActiveRunSlotCount ?? null,
|
||||
heartbeatRiskTaskCount: lists.heartbeatRiskTaskIds.count,
|
||||
interpretation: splitBrainLive
|
||||
? "scheduler heartbeat is fresh; treat active task count from heartbeat as live and continue supervision"
|
||||
: effectiveLiveness === "at-risk"
|
||||
? "heartbeat risk is present; investigate heartbeat freshness before recovery"
|
||||
: effectiveLiveness === "degraded"
|
||||
? "diagnostics are degraded; cross-check heartbeat, trace and control-plane sources"
|
||||
: "diagnostics indicate healthy liveness",
|
||||
};
|
||||
}
|
||||
|
||||
function boundedUniqueStringList(value: unknown, limit = diagnosticsIdPreviewLimit): { items: string[]; count: number; omitted: number; truncated: boolean } {
|
||||
const all = Array.from(new Set(stringList(value))).sort();
|
||||
const items = all.slice(0, limit);
|
||||
@@ -1059,6 +1096,12 @@ function compactExecutionDiagnostics(value: unknown): Record<string, unknown> |
|
||||
const allReasons = stringList(record.reasons);
|
||||
const reasons = allReasons.slice(0, diagnosticsReasonPreviewLimit).map((reason) => boundedInlineString(reason, 240).text).filter((reason): reason is string => reason !== null);
|
||||
const livenessSummary = boundedInlineString(record.livenessSummary, 420);
|
||||
const liveness = compactLivenessDecision(record, {
|
||||
activeHeartbeatTaskIds,
|
||||
heartbeatFreshTaskIds,
|
||||
heartbeatRiskTaskIds,
|
||||
databaseActiveTaskIds,
|
||||
});
|
||||
const omittedCounts = {
|
||||
databaseActiveTaskIds: databaseActiveTaskIds.omitted,
|
||||
schedulerActiveTaskIds: schedulerActiveTaskIds.omitted,
|
||||
@@ -1078,8 +1121,9 @@ function compactExecutionDiagnostics(value: unknown): Record<string, unknown> |
|
||||
degraded: record.degraded ?? null,
|
||||
splitBrain: record.splitBrain ?? null,
|
||||
splitBrainLive: splitBrainLiveFromDiagnostics(record),
|
||||
effectiveLiveness: effectiveLivenessFromDiagnostics({ ...record, heartbeatRiskTaskIds: fullHeartbeatRiskTaskIds }),
|
||||
recommendedAction: recommendedActionFromDiagnostics({ ...record, heartbeatRiskTaskIds: fullHeartbeatRiskTaskIds }),
|
||||
effectiveLiveness: liveness.effectiveLiveness,
|
||||
recommendedAction: liveness.recommendedAction,
|
||||
liveness,
|
||||
livenessSummary: livenessSummary.text,
|
||||
livenessSummaryChars: livenessSummary.chars,
|
||||
livenessSummaryTruncated: livenessSummary.truncated,
|
||||
@@ -1089,7 +1133,7 @@ function compactExecutionDiagnostics(value: unknown): Record<string, unknown> |
|
||||
databaseActiveTaskIds: databaseActiveTaskIds.items,
|
||||
schedulerActiveRunSlotCount: record.schedulerActiveRunSlotCount ?? null,
|
||||
schedulerActiveTaskIds: schedulerActiveTaskIds.items,
|
||||
activeHeartbeatCount: record.activeHeartbeatCount ?? activeHeartbeatTaskIds.count,
|
||||
activeHeartbeatCount: liveness.activeHeartbeatCount,
|
||||
activeHeartbeatTaskIds: activeHeartbeatTaskIds.items,
|
||||
heartbeatFreshTaskIds: heartbeatFreshTaskIds.items,
|
||||
heartbeatExpiredTaskIds: heartbeatExpiredTaskIds.items,
|
||||
@@ -2875,6 +2919,30 @@ function decoratePrPreflightScopeBoundary(record: Record<string, unknown>): Reco
|
||||
};
|
||||
}
|
||||
|
||||
function prPreflightObservationGap(kind: Exclude<CodeQueueObservationGapKind, null>, detail: {
|
||||
reason: string;
|
||||
localBackendCoreMissing?: boolean;
|
||||
remoteFallbackUsed?: boolean;
|
||||
remoteControlPlaneReachable?: boolean | null;
|
||||
}): Record<string, unknown> {
|
||||
const controlPlaneGap = kind === "control-plane-observation-gap";
|
||||
return {
|
||||
kind,
|
||||
blockingDisposition: kind,
|
||||
scope: controlPlaneGap ? "control-plane" : "runner-local",
|
||||
reason: detail.reason,
|
||||
localBackendCoreMissing: detail.localBackendCoreMissing === true,
|
||||
remoteFallbackUsed: detail.remoteFallbackUsed === true,
|
||||
remoteControlPlaneReachable: detail.remoteControlPlaneReachable ?? null,
|
||||
schedulerStoppage: false,
|
||||
schedulerStateMachineChanged: false,
|
||||
recommendedAction: controlPlaneGap ? "cross-check-control-plane" : "retry-from-control-plane-or-remote-fallback",
|
||||
note: controlPlaneGap
|
||||
? "The control-plane observation path is unavailable; this is not evidence that the scheduler stopped executing active tasks."
|
||||
: "The current runner/local backend-core observation path is unavailable; this is not evidence that active Code Queue execution stopped.",
|
||||
};
|
||||
}
|
||||
|
||||
function compactPrRuntimePreflight(preflight: Record<string, unknown>, options: CodexPrPreflightOptions): Record<string, unknown> {
|
||||
const pull = asRecord(preflight.pullRequestDelivery) ?? {};
|
||||
const tools = asRecord(pull.tools) ?? {};
|
||||
@@ -3056,9 +3124,16 @@ function queryRemoteMainServerPrPreflight(optionArgs: string[], config: UniDeskC
|
||||
return {
|
||||
ok: false,
|
||||
runnerDisposition: "infra-blocked",
|
||||
blockingDisposition: "control-plane-observation-gap",
|
||||
failureKind: "control-plane-missing",
|
||||
degradedReason: "remote-control-plane-unreachable",
|
||||
message,
|
||||
observationGap: prPreflightObservationGap("control-plane-observation-gap", {
|
||||
reason: "remote control plane CLI returned a structured error",
|
||||
localBackendCoreMissing: false,
|
||||
remoteFallbackUsed: true,
|
||||
remoteControlPlaneReachable: false,
|
||||
}),
|
||||
controlPlane: {
|
||||
mode: "remote-frontend",
|
||||
host: config.network.publicHost,
|
||||
@@ -3081,9 +3156,16 @@ function queryRemoteMainServerPrPreflight(optionArgs: string[], config: UniDeskC
|
||||
return {
|
||||
ok: false,
|
||||
runnerDisposition: "infra-blocked",
|
||||
blockingDisposition: "control-plane-observation-gap",
|
||||
failureKind: "control-plane-missing",
|
||||
degradedReason: "remote-control-plane-unreachable",
|
||||
message,
|
||||
observationGap: prPreflightObservationGap("control-plane-observation-gap", {
|
||||
reason: "remote control plane CLI could not be reached or returned non-JSON output",
|
||||
localBackendCoreMissing: false,
|
||||
remoteFallbackUsed: true,
|
||||
remoteControlPlaneReachable: false,
|
||||
}),
|
||||
controlPlane: {
|
||||
mode: "remote-frontend",
|
||||
host: config.network.publicHost,
|
||||
@@ -3128,6 +3210,18 @@ function codeQueuePrPreflight(optionArgs: string[] = [], transport: CodeQueuePrP
|
||||
if (remoteRecord.ok === false) {
|
||||
return decoratePrPreflightScopeBoundary({
|
||||
...remoteRecord,
|
||||
observationGap: prPreflightObservationGap(
|
||||
remoteRecord.failureKind === "control-plane-missing" ? "control-plane-observation-gap" : "runner-local-observation-gap",
|
||||
{
|
||||
reason: remoteRecord.failureKind === "control-plane-missing"
|
||||
? "remote control plane could not be observed after local backend-core target-stack absence"
|
||||
: "local backend-core target-stack absence was bypassed by remote fallback, but the remote result still failed",
|
||||
localBackendCoreMissing: true,
|
||||
remoteFallbackUsed: true,
|
||||
remoteControlPlaneReachable: remoteRecord.failureKind === "control-plane-missing" ? false : true,
|
||||
},
|
||||
),
|
||||
blockingDisposition: remoteRecord.failureKind === "control-plane-missing" ? "control-plane-observation-gap" : remoteRecord.blockingDisposition ?? remoteRecord.runnerDisposition ?? "infra-blocked",
|
||||
controlPlane: {
|
||||
...(asRecord(remoteRecord.controlPlane) ?? {}),
|
||||
mode: "remote-frontend",
|
||||
@@ -3142,6 +3236,12 @@ function codeQueuePrPreflight(optionArgs: string[] = [], transport: CodeQueuePrP
|
||||
}
|
||||
return decoratePrPreflightScopeBoundary({
|
||||
...remoteRecord,
|
||||
localObservationGap: prPreflightObservationGap("runner-local-observation-gap", {
|
||||
reason: "local backend-core target-stack absence was bypassed by healthy remote control-plane fallback",
|
||||
localBackendCoreMissing: true,
|
||||
remoteFallbackUsed: true,
|
||||
remoteControlPlaneReachable: true,
|
||||
}),
|
||||
controlPlane: {
|
||||
...(asRecord(remoteRecord.controlPlane) ?? {}),
|
||||
mode: "remote-frontend",
|
||||
@@ -3163,9 +3263,16 @@ function codeQueuePrPreflight(optionArgs: string[] = [], transport: CodeQueuePrP
|
||||
...(localRecord ?? {}),
|
||||
ok: false,
|
||||
runnerDisposition: "infra-blocked",
|
||||
blockingDisposition: "control-plane-observation-gap",
|
||||
failureKind,
|
||||
degradedReason,
|
||||
message: "remote control plane unreachable; local backend-core target-stack absence is evidence only",
|
||||
message: "remote control plane unreachable; local backend-core target-stack absence is observation-gap evidence only",
|
||||
observationGap: prPreflightObservationGap("control-plane-observation-gap", {
|
||||
reason: "local backend-core target stack is missing and no remote control plane could be observed",
|
||||
localBackendCoreMissing: true,
|
||||
remoteFallbackUsed: false,
|
||||
remoteControlPlaneReachable: false,
|
||||
}),
|
||||
controlPlane: {
|
||||
mode: "local-backend-core",
|
||||
localBackendCoreMissing: true,
|
||||
@@ -3183,9 +3290,20 @@ function codeQueuePrPreflight(optionArgs: string[] = [], transport: CodeQueuePrP
|
||||
...(localRecord ?? {}),
|
||||
ok: false,
|
||||
runnerDisposition: localRecord?.runnerDisposition ?? "infra-blocked",
|
||||
blockingDisposition: localTargetStackMissing ? "runner-local-observation-gap" : localRecord?.blockingDisposition ?? localRecord?.runnerDisposition ?? "infra-blocked",
|
||||
failureKind: (localRecord?.failureKind as CodeQueuePrPreflightFailureKind | undefined) ?? "proxy-gap",
|
||||
degradedReason: localRecord?.degradedReason ?? "backend-core-proxy-unavailable",
|
||||
message: localRecord?.message ?? localRecord?.stderrTail ?? localRecord?.stdoutTail ?? "Code Queue runtime preflight could not be observed",
|
||||
...(localTargetStackMissing
|
||||
? {
|
||||
observationGap: prPreflightObservationGap("runner-local-observation-gap", {
|
||||
reason: "local backend-core target stack is missing in this runner observation path",
|
||||
localBackendCoreMissing: true,
|
||||
remoteFallbackUsed: false,
|
||||
remoteControlPlaneReachable: null,
|
||||
}),
|
||||
}
|
||||
: {}),
|
||||
controlPlane: {
|
||||
mode: "local-backend-core",
|
||||
localBackendCoreMissing: localTargetStackMissing,
|
||||
|
||||
Reference in New Issue
Block a user