mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-04 17:14:07 +00:00
fix(memory): bound session export timestamps
This commit is contained in:
@@ -295,4 +295,22 @@ describe("buildSessionEntry", () => {
|
||||
expect(entry.content).toBe("Assistant: User-facing summary.\nUser: Actual user follow-up.");
|
||||
expect(entry.lineMap).toStrictEqual([2, 3]);
|
||||
});
|
||||
|
||||
it("drops Date-invalid numeric message timestamps", async () => {
|
||||
const jsonlLines = [
|
||||
JSON.stringify({
|
||||
type: "message",
|
||||
message: {
|
||||
role: "user",
|
||||
content: "Hello",
|
||||
timestamp: 8_640_000_000_000_001,
|
||||
},
|
||||
}),
|
||||
];
|
||||
const filePath = path.join(tmpDir, "invalid-timestamp-session.jsonl");
|
||||
fsSync.writeFileSync(filePath, jsonlLines.join("\n"));
|
||||
|
||||
const entry = requireSessionEntry(await buildSessionEntry(filePath));
|
||||
expect(entry.messageTimestampsMs).toStrictEqual([0]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -28,6 +28,7 @@ const DREAMING_NARRATIVE_RUN_PREFIX = "dreaming-narrative-";
|
||||
// This limit applies to content only; the role label adds up to 11 chars.
|
||||
const SESSION_EXPORT_CONTENT_WRAP_CHARS = 800;
|
||||
const SESSION_ENTRY_PARSE_YIELD_LINES = 250;
|
||||
const MAX_DATE_TIMESTAMP_MS = 8_640_000_000_000_000;
|
||||
const DIRECT_CRON_PROMPT_RE = /^\[cron:[^\]]+\]\s*/;
|
||||
|
||||
export type SessionFileEntry = {
|
||||
@@ -509,7 +510,7 @@ function parseSessionTimestampMs(
|
||||
for (const value of candidates) {
|
||||
if (typeof value === "number" && Number.isFinite(value)) {
|
||||
const ms = value > 0 && value < 1e11 ? value * 1000 : value;
|
||||
if (Number.isFinite(ms) && ms > 0) {
|
||||
if (Number.isFinite(ms) && ms > 0 && ms <= MAX_DATE_TIMESTAMP_MS) {
|
||||
return ms;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user