fix(logs): report line-limit truncation (#123358)

This commit is contained in:
Peter Steinberger
2026-08-13 16:57:26 -07:00
committed by GitHub
parent 1287befae7
commit cb8e08f536
5 changed files with 31 additions and 4 deletions
+3 -1
View File
@@ -208,7 +208,9 @@ describe("logs cli", () => {
expect(stdoutWrites.join("")).toContain("Log file:");
expect(stdoutWrites.join("")).toContain("raw line");
expect(stderrWrites.join("")).toContain("Log tail truncated");
expect(stderrWrites.join("")).toContain(
"Log tail truncated (increase --limit or --max-bytes).",
);
expect(stderrWrites.join("")).toContain("Log cursor reset");
});
+2 -2
View File
@@ -725,7 +725,7 @@ export function registerLogsCli(program: Command) {
if (
!emitJsonLine({
type: "notice",
message: "Log tail truncated (increase --max-bytes).",
message: "Log tail truncated (increase --limit or --max-bytes).",
})
) {
return;
@@ -785,7 +785,7 @@ export function registerLogsCli(program: Command) {
}
}
if (payload.truncated) {
if (!errorLine("Log tail truncated (increase --max-bytes).")) {
if (!errorLine("Log tail truncated (increase --limit or --max-bytes).")) {
return;
}
}
+20
View File
@@ -85,6 +85,26 @@ describe("readConfiguredLogTail", () => {
expect(result.lines).toEqual(["old line", "recent one", "recent two"]);
});
it("reports truncation when the line limit omits complete records", async () => {
const { readConfiguredLogTail } = await import("./log-tail.js");
const tempDir = tempDirs.make("openclaw-log-tail-");
const file = path.join(tempDir, "openclaw-2026-01-22.log");
const content = "one\ntwo\nthree\n";
await fs.writeFile(file, content);
setLoggerOverride({ file });
const result = await readConfiguredLogTail({ limit: 2, maxBytes: 100 });
expect(result).toMatchObject({
lines: ["two", "three"],
cursor: Buffer.byteLength(content),
size: Buffer.byteLength(content),
truncated: true,
reset: false,
});
});
it("falls back only within the active profile's rolling log family", async () => {
const tempDir = tempDirs.make("openclaw-log-tail-");
const missing = path.join(tempDir, "openclaw-dev-2026-01-22.log");
+1
View File
@@ -138,6 +138,7 @@ async function readLogSlice(params: {
lines = lines.slice(0, -1);
}
if (lines.length > limit) {
truncated = true;
lines = lines.slice(lines.length - limit);
}
@@ -100,7 +100,11 @@ export async function runRemoteLogTailing(repoRoot: string, outputRoot: string)
lines: string[];
truncated: boolean;
};
if (first.lines.length !== 2 || !first.lines.some((line) => line.includes("qa-line-three"))) {
if (
first.lines.length !== 2 ||
!first.lines.some((line) => line.includes("qa-line-three")) ||
!first.truncated
) {
throw new Error(`logs.tail did not honor limit: ${JSON.stringify(first)}`);
}
const bounded = (await gateway.call("logs.tail", { limit: 20, maxBytes: 96 })) as {