fix: compact hwlab node control plane status

This commit is contained in:
Codex
2026-06-17 10:33:41 +00:00
parent 59b20254d4
commit 0836f0dfaf
3 changed files with 188 additions and 6 deletions
+22 -2
View File
@@ -208,18 +208,22 @@ export function jobWithTail(job: JobRecord, maxBytes = 12000): JobRecord & {
const progressTailBytes = Math.max(maxBytes, 96_000);
const stdoutProgressTail = tailFile(job.stdoutFile, progressTailBytes);
const stderrProgressTail = tailFile(job.stderrFile, progressTailBytes);
const progress = summarizeJobProgress(job, progressTailBytes, { stdoutTail: stdoutProgressTail, stderrTail: stderrProgressTail });
const rawStdoutTail = tailTextByBytes(stdoutProgressTail, maxBytes);
const stdoutTail = compactJobStdoutTail(job, progress, rawStdoutTail, maxBytes);
return {
...job,
progress: summarizeJobProgress(job, progressTailBytes, { stdoutTail: stdoutProgressTail, stderrTail: stderrProgressTail }),
progress,
tailPolicy: {
requestedTailBytes: maxBytes,
stdoutBytes,
stderrBytes,
stdoutTruncated: stdoutBytes > maxBytes,
stderrTruncated: stderrBytes > maxBytes,
stdoutCompacted: stdoutTail !== rawStdoutTail,
fullLogPaths: { stdoutFile: job.stdoutFile, stderrFile: job.stderrFile },
},
stdoutTail: tailTextByBytes(stdoutProgressTail, maxBytes),
stdoutTail,
stderrTail: tailTextByBytes(stderrProgressTail, maxBytes),
};
}
@@ -791,6 +795,22 @@ function tailTextByBytes(text: string, maxBytes: number): string {
return buffer.subarray(buffer.length - safeMaxBytes).toString("utf8");
}
function compactJobStdoutTail(job: JobRecord, progress: JobProgressSummary, rawTail: string, requestedTailBytes: number): string {
if (progress.kind !== "hwlab-runtime-lane-trigger") return rawTail;
if (Buffer.byteLength(rawTail, "utf8") <= 4096 && !rawTail.includes("\"expected\"") && !rawTail.includes("stdoutTail")) return rawTail;
const interestingLines = rawTail.split(/\r?\n/u)
.map((line) => line.trimEnd())
.filter((line) => !/"(stdoutTail|stderrTail|expected|result)"\s*:/u.test(line))
.filter((line) => /hwlab\.runtime-lane\.trigger\.progress|sourceCommit|pipelineRun|pipelinerun|degradedReason|next(Command|Action)|statusCommand|created|Completed|failed|succeeded/iu.test(line))
.slice(-80);
const header = [
`[stdout compacted: ${progress.kind}; requestedTailBytes=${requestedTailBytes}]`,
`full stdout: ${job.stdoutFile}`,
].join("\n");
if (interestingLines.length === 0) return `${header}\n${tailTextByBytes(rawTail, Math.min(requestedTailBytes, 3000))}`;
return `${header}\n${interestingLines.join("\n")}\n`;
}
function parseJsonLineEvents(text: string, eventName: string): Record<string, unknown>[] {
const events: Record<string, unknown>[] = [];
for (const line of text.split(/\r?\n/u)) {