Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(facts): reject a ttl duration past the Date range (#8913)

garrytand9cd9137a6d4
diff --git a/src/core/facts/ttl-parse.ts b/src/core/facts/ttl-parse.ts
index a42fe07657..78e09300a4 100644
--- a/src/core/facts/ttl-parse.ts
+++ b/src/core/facts/ttl-parse.ts
@@ -52,7 +52,11 @@ export function parseTtlShorthand(raw: unknown): TtlParseResult {
}
const ms = parseDurationShorthandMs(s);
- if (ms !== null) return { ok: true, validUntil: new Date(Date.now() + ms) };
+ if (ms !== null) {
+ const validUntil = new Date(Date.now() + ms);
+ // #8913: a duration past the Date range would be an Invalid Date.
+ return Number.isFinite(validUntil.getTime()) ? { ok: true, validUntil } : { ok: false, code: 'unparseable', input: s };
+ }
if (/^\d{4}-\d{2}-\d{2}$/.test(s) &&
(!Number.isFinite(Date.parse(s)) || new Date(s).toISOString().slice(0, 10) !== s)) {
diff --git a/test/writeback-config.test.ts b/test/writeback-config.test.ts
index 45e2ad20da..57c2118257 100644
--- a/test/writeback-config.test.ts
+++ b/test/writeback-config.test.ts
@@ -66,6 +66,14 @@ describe('parseTtlShorthand (pure leaf)', () => {
expect(parseTtlShorthand('2026-02-28T10:00:00Z').ok).toBe(true);
});
+ test('#8913: a duration past the Date range is unparseable, never an Invalid Date', () => {
+ for (const raw of ['100000001d', `${'9'.repeat(400)}s`]) {
+ expect(parseTtlShorthand(raw)).toEqual({ ok: false, code: 'unparseable', input: raw });
+ expect(() => parseTtlParam(raw)).toThrow(`Cannot parse ttl "${raw}".`);
+ }
+ expect(parseTtlShorthand('36500d').ok).toBe(true);
+ });
+
test('typed failures: not_string / iso_duration / unparseable', () => {
expect(parseTtlShorthand(30)).toMatchObject({ ok: false, code: 'not_string' });
expect(parseTtlShorthand('P30D')).toMatchObject({ ok: false, code: 'iso_duration' });