Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

fix(plugins): keep invalid dates from dropping hook events (#837)

Rudy Mizrahi Celekliff29b03bb72b
diff --git a/cli/beacon/internal/endpoint/hooks/assets/cline/beacon.ts b/cli/beacon/internal/endpoint/hooks/assets/cline/beacon.ts
index 1c5dea0d..b0d2bac8 100644
--- a/cli/beacon/internal/endpoint/hooks/assets/cline/beacon.ts
+++ b/cli/beacon/internal/endpoint/hooks/assets/cline/beacon.ts
@@ -51,7 +51,8 @@ function safeClone(value: unknown, depth = 0, seen = new WeakSet<object>()): unk
const object = value as object
if (seen.has(object)) return undefined
if (value instanceof Error) return { name: value.name, message: value.message }
- if (value instanceof Date) return value.toISOString()
+ // Match native JSON: an invalid Date is null, not a lost event.
+ if (value instanceof Date) return Number.isFinite(value.getTime()) ? value.toISOString() : null
seen.add(object)
try {
diff --git a/cli/beacon/internal/endpoint/hooks/assets/omo/beacon.ts b/cli/beacon/internal/endpoint/hooks/assets/omo/beacon.ts
index ec37df67..be5f7d63 100644
--- a/cli/beacon/internal/endpoint/hooks/assets/omo/beacon.ts
+++ b/cli/beacon/internal/endpoint/hooks/assets/omo/beacon.ts
@@ -112,7 +112,8 @@ function safeClone(value: unknown, depth = 0, seen = new WeakSet<object>()): unk
const object = value as object
if (seen.has(object)) return undefined
if (value instanceof Error) return { name: value.name, message: value.message }
- if (value instanceof Date) return value.toISOString()
+ // Match native JSON: an invalid Date is null, not a lost event.
+ if (value instanceof Date) return Number.isFinite(value.getTime()) ? value.toISOString() : null
seen.add(object)
try {
diff --git a/cli/beacon/internal/endpoint/hooks/assets/omp/beacon.ts b/cli/beacon/internal/endpoint/hooks/assets/omp/beacon.ts
index c5d8d4ee..5cd1d44a 100644
--- a/cli/beacon/internal/endpoint/hooks/assets/omp/beacon.ts
+++ b/cli/beacon/internal/endpoint/hooks/assets/omp/beacon.ts
@@ -290,7 +290,8 @@ function safeClone(value: unknown, depth = 0, seen = new WeakSet<object>()): unk
if (seen.has(value)) return undefined
if (value instanceof Error) return { name: value.name, message: value.message }
- if (value instanceof Date) return value.toISOString()
+ // Match native JSON: an invalid Date is null, not a lost event.
+ if (value instanceof Date) return Number.isFinite(value.getTime()) ? value.toISOString() : null
seen.add(value)
try {
diff --git a/cli/beacon/internal/endpoint/hooks/assets/openclaw/beacon.js b/cli/beacon/internal/endpoint/hooks/assets/openclaw/beacon.js
index c34be79d..b99ffd4f 100644
--- a/cli/beacon/internal/endpoint/hooks/assets/openclaw/beacon.js
+++ b/cli/beacon/internal/endpoint/hooks/assets/openclaw/beacon.js
@@ -141,7 +141,8 @@ function safeClone(value, depth = 0, seen = new WeakSet()) {
if (seen.has(value)) return undefined
if (value instanceof Error) return { name: value.name, message: value.message }
- if (value instanceof Date) return value.toISOString()
+ // Match native JSON: an invalid Date is null, not a lost event.
+ if (value instanceof Date) return Number.isFinite(value.getTime()) ? value.toISOString() : null
seen.add(value)
try {
diff --git a/cli/beacon/internal/endpoint/hooks/assets/pi/beacon.ts b/cli/beacon/internal/endpoint/hooks/assets/pi/beacon.ts
index 2a1d7cfc..971c3d7b 100644
--- a/cli/beacon/internal/endpoint/hooks/assets/pi/beacon.ts
+++ b/cli/beacon/internal/endpoint/hooks/assets/pi/beacon.ts
@@ -97,7 +97,8 @@ function safeClone(value: unknown, depth = 0, seen = new WeakSet<object>()): unk
const object = value as object
if (seen.has(object)) return undefined
if (value instanceof Error) return { name: value.name, message: value.message }
- if (value instanceof Date) return value.toISOString()
+ // Match native JSON: an invalid Date is null, not a lost event.
+ if (value instanceof Date) return Number.isFinite(value.getTime()) ? value.toISOString() : null
seen.add(object)
try {
diff --git a/cli/beacon/internal/endpoint/hooks/assets/prime/beacon.ts b/cli/beacon/internal/endpoint/hooks/assets/prime/beacon.ts
index 7d95d7d7..30513cd4 100644
--- a/cli/beacon/internal/endpoint/hooks/assets/prime/beacon.ts
+++ b/cli/beacon/internal/endpoint/hooks/assets/prime/beacon.ts
@@ -108,7 +108,8 @@ function safeClone(value: unknown, depth = 0, seen = new WeakSet<object>()): unk
const object = value as object
if (seen.has(object)) return undefined
if (value instanceof Error) return { name: value.name, message: value.message }
- if (value instanceof Date) return value.toISOString()
+ // Match native JSON: an invalid Date is null, not a lost event.
+ if (value instanceof Date) return Number.isFinite(value.getTime()) ? value.toISOString() : null
seen.add(object)
try {
diff --git a/plugins/cline-beacon/src/beacon.test.ts b/plugins/cline-beacon/src/beacon.test.ts
index 24ae8e37..7267a861 100644
--- a/plugins/cline-beacon/src/beacon.test.ts
+++ b/plugins/cline-beacon/src/beacon.test.ts
@@ -19,6 +19,16 @@ afterEach(() => {
})
describe("beacon cline plugin", () => {
+ test("retains an event containing an invalid Date with native JSON date semantics", async () => {
+ const sent = captureSends()
+ const metadata = { invalid: new Date(NaN), valid: new Date("2026-01-02T03:04:05Z") }
+ const expected = JSON.parse(JSON.stringify(metadata))
+ const plugin = createBeaconPlugin()
+ await plugin.hooks.beforeRun({ taskId: "task-date", metadata })
+ expect(sent).toHaveLength(1)
+ expect(sent[0]).toMatchObject({ type: "beforeRun", taskId: "task-date", metadata: expected })
+ })
+
test("declares itself as a hooks plugin", () => {
const plugin = createBeaconPlugin()
expect(plugin.manifest.capabilities).toEqual(["hooks"])
diff --git a/plugins/cline-beacon/src/beacon.ts b/plugins/cline-beacon/src/beacon.ts
index 1c5dea0d..b0d2bac8 100644
--- a/plugins/cline-beacon/src/beacon.ts
+++ b/plugins/cline-beacon/src/beacon.ts
@@ -51,7 +51,8 @@ function safeClone(value: unknown, depth = 0, seen = new WeakSet<object>()): unk
const object = value as object
if (seen.has(object)) return undefined
if (value instanceof Error) return { name: value.name, message: value.message }
- if (value instanceof Date) return value.toISOString()
+ // Match native JSON: an invalid Date is null, not a lost event.
+ if (value instanceof Date) return Number.isFinite(value.getTime()) ? value.toISOString() : null
seen.add(object)
try {
diff --git a/plugins/omo-beacon/src/beacon.test.ts b/plugins/omo-beacon/src/beacon.test.ts
index b7420ba9..fcba7ad8 100644
--- a/plugins/omo-beacon/src/beacon.test.ts
+++ b/plugins/omo-beacon/src/beacon.test.ts
@@ -45,6 +45,17 @@ afterEach(() => {
})
describe("beacon omo (senpi) extension", () => {
+ test("retains an event containing an invalid Date with native JSON date semantics", async () => {
+ const sent = captureSends()
+ const metadata = { invalid: new Date(NaN), valid: new Date("2026-01-02T03:04:05Z") }
+ const expected = JSON.parse(JSON.stringify(metadata))
+ const host = fakePi()
+ createBeaconExtension().register(host.api)
+ await host.fire({ type: "session_start", metadata }, context())
+ expect(sent).toHaveLength(1)
+ expect(sent[0]).toMatchObject({ type: "session_start", sessionId: "sess-1", metadata: expected })
+ })
+
// These strings are the contract between this extension and the omo-event mapper in the hook
// adapter. A typo on either side produces no telemetry rather than an error, so the list is
// pinned here and asserted against the mapper's own list on the Go side.
diff --git a/plugins/omo-beacon/src/beacon.ts b/plugins/omo-beacon/src/beacon.ts
index ec37df67..be5f7d63 100644
--- a/plugins/omo-beacon/src/beacon.ts
+++ b/plugins/omo-beacon/src/beacon.ts
@@ -112,7 +112,8 @@ function safeClone(value: unknown, depth = 0, seen = new WeakSet<object>()): unk
const object = value as object
if (seen.has(object)) return undefined
if (value instanceof Error) return { name: value.name, message: value.message }
- if (value instanceof Date) return value.toISOString()
+ // Match native JSON: an invalid Date is null, not a lost event.
+ if (value instanceof Date) return Number.isFinite(value.getTime()) ? value.toISOString() : null
seen.add(object)
try {
diff --git a/plugins/omp-beacon/src/beacon.test.ts b/plugins/omp-beacon/src/beacon.test.ts
index d8db8b3e..3f8f658a 100644
--- a/plugins/omp-beacon/src/beacon.test.ts
+++ b/plugins/omp-beacon/src/beacon.test.ts
@@ -48,6 +48,17 @@ afterEach(() => {
})
describe("beacon oh my pi extension", () => {
+ test("retains an event containing an invalid Date with native JSON date semantics", async () => {
+ const sent = captureSends()
+ const metadata = { invalid: new Date(NaN), valid: new Date("2026-01-02T03:04:05Z") }
+ const expected = JSON.parse(JSON.stringify(metadata))
+ const host = fakeOmp()
+ createBeaconExtension().register(host.api)
+ await host.fire({ type: "session_start", metadata }, context())
+ expect(sent).toHaveLength(1)
+ expect(sent[0]).toMatchObject({ type: "session_start", sessionId: "sess-1", metadata: expected })
+ })
+
// These strings are the contract between this extension and the omp-event mapper in the hook
// adapter. A typo on either side produces no telemetry rather than an error, so the list is
// pinned here and asserted against the mapper's own list on the Go side.
diff --git a/plugins/omp-beacon/src/beacon.ts b/plugins/omp-beacon/src/beacon.ts
index c5d8d4ee..5cd1d44a 100644
--- a/plugins/omp-beacon/src/beacon.ts
+++ b/plugins/omp-beacon/src/beacon.ts
@@ -290,7 +290,8 @@ function safeClone(value: unknown, depth = 0, seen = new WeakSet<object>()): unk
if (seen.has(value)) return undefined
if (value instanceof Error) return { name: value.name, message: value.message }
- if (value instanceof Date) return value.toISOString()
+ // Match native JSON: an invalid Date is null, not a lost event.
+ if (value instanceof Date) return Number.isFinite(value.getTime()) ? value.toISOString() : null
seen.add(value)
try {
diff --git a/plugins/openclaw-beacon/src/beacon.js b/plugins/openclaw-beacon/src/beacon.js
index c34be79d..b99ffd4f 100644
--- a/plugins/openclaw-beacon/src/beacon.js
+++ b/plugins/openclaw-beacon/src/beacon.js
@@ -141,7 +141,8 @@ function safeClone(value, depth = 0, seen = new WeakSet()) {
if (seen.has(value)) return undefined
if (value instanceof Error) return { name: value.name, message: value.message }
- if (value instanceof Date) return value.toISOString()
+ // Match native JSON: an invalid Date is null, not a lost event.
+ if (value instanceof Date) return Number.isFinite(value.getTime()) ? value.toISOString() : null
seen.add(value)
try {
diff --git a/plugins/openclaw-beacon/src/beacon.test.ts b/plugins/openclaw-beacon/src/beacon.test.ts
index c68c7472..cef7910e 100644
--- a/plugins/openclaw-beacon/src/beacon.test.ts
+++ b/plugins/openclaw-beacon/src/beacon.test.ts
@@ -62,6 +62,17 @@ afterEach(() => {
})
describe("beacon openclaw plugin", () => {
+ test("retains an event containing an invalid Date with native JSON date semantics", async () => {
+ const sent = captureSends()
+ const metadata = { invalid: new Date(NaN), valid: new Date("2026-01-02T03:04:05Z") }
+ const expected = JSON.parse(JSON.stringify(metadata))
+ const gateway = fakeGateway()
+ createBeaconPlugin().register(gateway.api)
+ await gateway.fire("session_start", { sessionId: "session-date", metadata }, context())
+ expect(sent).toHaveLength(1)
+ expect(sent[0]).toMatchObject({ hook: "session_start", sessionId: "session-date", event: { metadata: expected } })
+ })
+
// These strings are the contract between this plugin and the openclaw-event mapper in the hook
// adapter. A typo on either side produces no telemetry rather than an error, so the list is
// pinned here and asserted against the mapper's own list on the Go side.
diff --git a/plugins/pi-beacon/src/beacon.test.ts b/plugins/pi-beacon/src/beacon.test.ts
index ab96ad35..1b6aa7ff 100644
--- a/plugins/pi-beacon/src/beacon.test.ts
+++ b/plugins/pi-beacon/src/beacon.test.ts
@@ -45,6 +45,17 @@ afterEach(() => {
})
describe("beacon pi extension", () => {
+ test("retains an event containing an invalid Date with native JSON date semantics", async () => {
+ const sent = captureSends()
+ const metadata = { invalid: new Date(NaN), valid: new Date("2026-01-02T03:04:05Z") }
+ const expected = JSON.parse(JSON.stringify(metadata))
+ const host = fakePi()
+ createBeaconExtension().register(host.api)
+ await host.fire({ type: "session_start", metadata }, context())
+ expect(sent).toHaveLength(1)
+ expect(sent[0]).toMatchObject({ type: "session_start", sessionId: "sess-1", metadata: expected })
+ })
+
// These strings are the contract between this extension and the pi-event mapper in the hook
// adapter. A typo on either side produces no telemetry rather than an error, so the list is
// pinned here and asserted against the mapper's own list on the Go side.
diff --git a/plugins/pi-beacon/src/beacon.ts b/plugins/pi-beacon/src/beacon.ts
index 2a1d7cfc..971c3d7b 100644
--- a/plugins/pi-beacon/src/beacon.ts
+++ b/plugins/pi-beacon/src/beacon.ts
@@ -97,7 +97,8 @@ function safeClone(value: unknown, depth = 0, seen = new WeakSet<object>()): unk
const object = value as object
if (seen.has(object)) return undefined
if (value instanceof Error) return { name: value.name, message: value.message }
- if (value instanceof Date) return value.toISOString()
+ // Match native JSON: an invalid Date is null, not a lost event.
+ if (value instanceof Date) return Number.isFinite(value.getTime()) ? value.toISOString() : null
seen.add(object)
try {
diff --git a/plugins/prime-beacon/src/beacon.test.ts b/plugins/prime-beacon/src/beacon.test.ts
index 7e98faf4..bfd574bb 100644
--- a/plugins/prime-beacon/src/beacon.test.ts
+++ b/plugins/prime-beacon/src/beacon.test.ts
@@ -45,6 +45,17 @@ afterEach(() => {
})
describe("beacon prime agent extension", () => {
+ test("retains an event containing an invalid Date with native JSON date semantics", async () => {
+ const sent = captureSends()
+ const metadata = { invalid: new Date(NaN), valid: new Date("2026-01-02T03:04:05Z") }
+ const expected = JSON.parse(JSON.stringify(metadata))
+ const host = fakePi()
+ createBeaconExtension().register(host.api)
+ await host.fire({ type: "session_start", metadata }, context())
+ expect(sent).toHaveLength(1)
+ expect(sent[0]).toMatchObject({ type: "session_start", sessionId: "sess-1", metadata: expected })
+ })
+
// These strings are the contract between this extension and the prime-event mapper in the hook
// adapter. A typo on either side produces no telemetry rather than an error, so the list is
// pinned here and asserted against the mapper's own list on the Go side.
diff --git a/plugins/prime-beacon/src/beacon.ts b/plugins/prime-beacon/src/beacon.ts
index 7d95d7d7..30513cd4 100644
--- a/plugins/prime-beacon/src/beacon.ts
+++ b/plugins/prime-beacon/src/beacon.ts
@@ -108,7 +108,8 @@ function safeClone(value: unknown, depth = 0, seen = new WeakSet<object>()): unk
const object = value as object
if (seen.has(object)) return undefined
if (value instanceof Error) return { name: value.name, message: value.message }
- if (value instanceof Date) return value.toISOString()
+ // Match native JSON: an invalid Date is null, not a lost event.
+ if (value instanceof Date) return Number.isFinite(value.getTime()) ? value.toISOString() : null
seen.add(object)
try {