mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-11 05:11:49 +01:00
Preserve raw heartbeat result_json writes
(cherry picked from commit 471d462880eaa33121a7b76cc6ad403b4a971d07)
This commit is contained in:
1 parent
7525550741
commit
5abc8cca8b
2 files changed
+1
-55
No files matched your search
@@ -87,27 +87,4 @@ describe("mergeHeartbeatRunResultJson", () => {
|
||||
stdout: "raw stdout",
|
||||
});
|
||||
});
|
||||
|
||||
it("bounds oversized stdout and stderr fields before persistence", () => {
|
||||
const stdout = "a".repeat(6_000);
|
||||
const stderr = "b".repeat(7_000);
|
||||
|
||||
const merged = mergeHeartbeatRunResultJson(
|
||||
{ stdout, stderr },
|
||||
null,
|
||||
);
|
||||
|
||||
expect(typeof merged?.stdout).toBe("string");
|
||||
expect(typeof merged?.stderr).toBe("string");
|
||||
expect((merged?.stdout as string).length).toBeLessThan(stdout.length);
|
||||
expect((merged?.stderr as string).length).toBeLessThan(stderr.length);
|
||||
expect(merged).toMatchObject({
|
||||
stdoutTruncated: true,
|
||||
stderrTruncated: true,
|
||||
stdoutOriginalLength: stdout.length,
|
||||
stderrOriginalLength: stderr.length,
|
||||
});
|
||||
expect(merged?.stdout).toContain("paperclip truncated adapter output");
|
||||
expect(merged?.stderr).toContain("paperclip truncated adapter output");
|
||||
});
|
||||
});
|
||||
@@ -7,16 +7,6 @@ function truncateSummaryText(value: unknown, maxLength = HEARTBEAT_RUN_RESULT_SU
|
||||
return value.length > maxLength ? value.slice(0, maxLength) : value;
|
||||
}
|
||||
|
||||
function compactOutputText(value: string, maxLength = HEARTBEAT_RUN_RESULT_OUTPUT_MAX_CHARS) {
|
||||
if (value.length <= maxLength) return value;
|
||||
|
||||
const headChars = Math.max(0, Math.floor(maxLength * 0.65));
|
||||
const tailChars = Math.max(0, Math.floor(maxLength * 0.2));
|
||||
const omittedChars = Math.max(0, value.length - headChars - tailChars);
|
||||
const marker = `\n[paperclip truncated adapter output: omitted ${omittedChars} chars]\n`;
|
||||
return `${value.slice(0, headChars)}${marker}${value.slice(value.length - tailChars)}`;
|
||||
}
|
||||
|
||||
function readNumericField(record: Record<string, unknown>, key: string) {
|
||||
return key in record ? record[key] ?? null : undefined;
|
||||
}
|
||||
@@ -27,27 +17,6 @@ function readCommentText(value: unknown) {
|
||||
return trimmed.length > 0 ? trimmed : null;
|
||||
}
|
||||
|
||||
function sanitizeRawOutputFields(record: Record<string, unknown>) {
|
||||
let nextRecord = record;
|
||||
|
||||
for (const key of ["stdout", "stderr"] as const) {
|
||||
const value = record[key];
|
||||
if (typeof value !== "string" || value.length <= HEARTBEAT_RUN_RESULT_OUTPUT_MAX_CHARS) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (nextRecord === record) {
|
||||
nextRecord = { ...record };
|
||||
}
|
||||
|
||||
nextRecord[key] = compactOutputText(value, HEARTBEAT_RUN_RESULT_OUTPUT_MAX_CHARS);
|
||||
nextRecord[`${key}Truncated`] = true;
|
||||
nextRecord[`${key}OriginalLength`] = value.length;
|
||||
}
|
||||
|
||||
return nextRecord;
|
||||
}
|
||||
|
||||
export function mergeHeartbeatRunResultJson(
|
||||
resultJson: Record<string, unknown> | null | undefined,
|
||||
summary: string | null | undefined,
|
||||
@@ -55,7 +24,7 @@ export function mergeHeartbeatRunResultJson(
|
||||
const normalizedSummary = readCommentText(summary);
|
||||
const baseResult =
|
||||
resultJson && typeof resultJson === "object" && !Array.isArray(resultJson)
|
||||
? sanitizeRawOutputFields(resultJson)
|
||||
? resultJson
|
||||
: null;
|
||||
|
||||
if (!baseResult) {
|
||||
|
||||
Reference in new issue
Block a user