Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(hogvm): order temporal values in comparison operators (#66639)

Harley Alexander6c914a75b014
diff --git a/common/hogvm/typescript/src/__tests__/utils.test.ts b/common/hogvm/typescript/src/__tests__/utils.test.ts
index 5c16aa5a2202..0c9db4581274 100644
--- a/common/hogvm/typescript/src/__tests__/utils.test.ts
+++ b/common/hogvm/typescript/src/__tests__/utils.test.ts
@@ -1,8 +1,38 @@
-import { calculateCost, convertHogToJS, convertJSToHog, getNestedValue } from '../utils'
+import { toHogDate, toHogDateTime } from '../stl/date'
+import { calculateCost, convertHogToJS, convertJSToHog, getNestedValue, unifyComparisonTypes } from '../utils'
const PTR_COST = 8
describe('hogvm utils', () => {
+ describe('unifyComparisonTypes temporal ordering', () => {
+ // Regression: `is date after`/`is date before` filters compile to `toDateTime(x) > toDateTime(y)`,
+ // and the VM's GT opcode does `unifyComparisonTypes(a, b)` then `a > b`. Two HogDateTime objects
+ // fell through unchanged, so `object > object` coerced to "[object Object]" and was always false —
+ // realtime workflow date filters never matched. They must order by epoch seconds.
+ const laterDateTime = toHogDateTime(1782988689) // 2026-06-28
+ const earlierDateTime = toHogDateTime(1782518400) // 2026-06-23 00:00:00 UTC
+ const laterDate = toHogDate(2026, 6, 28) // UTC midnight, exercises the isHogDate branch
+ const earlierDate = toHogDate(2026, 6, 23)
+
+ // Cover both temporalSeconds branches (HogDateTime → .dt, HogDate → toHogDateTime().dt) and the
+ // cross-type pairings — the GT opcode does `unifyComparisonTypes(a, b)` then `a > b`.
+ test.each([
+ ['HogDateTime vs HogDateTime', laterDateTime, earlierDateTime],
+ ['HogDate vs HogDate', laterDate, earlierDate],
+ ['HogDate vs HogDateTime', laterDate, earlierDateTime],
+ ['HogDateTime vs HogDate', laterDateTime, earlierDate],
+ ])('orders %s chronologically', (_label, later, earlier) => {
+ const [a, b] = unifyComparisonTypes(later, earlier)
+ expect(a > b).toBe(true)
+ expect(a < b).toBe(false)
+ })
+
+ test('equal instants compare equal', () => {
+ const [a, b] = unifyComparisonTypes(laterDateTime, toHogDateTime(1782988689))
+ expect(a === b).toBe(true)
+ })
+ })
+
test('calculateCost', async () => {
expect(calculateCost(1)).toBe(PTR_COST)
expect(calculateCost('hello')).toBe(PTR_COST + 5)
diff --git a/common/hogvm/typescript/src/utils.ts b/common/hogvm/typescript/src/utils.ts
index 9c29dc680b92..514906d94309 100644
--- a/common/hogvm/typescript/src/utils.ts
+++ b/common/hogvm/typescript/src/utils.ts
@@ -1,5 +1,17 @@
+import { isHogDate, isHogDateTime } from './objects'
import { toHogDate, toHogDateTime } from './stl/date'
+/** Epoch seconds for a Hog datetime/date value, else null. A bare HogDate is UTC midnight. */
+function temporalSeconds(value: any): number | null {
+ if (isHogDateTime(value)) {
+ return value.dt
+ }
+ if (isHogDate(value)) {
+ return toHogDateTime(value).dt
+ }
+ return null
+}
+
export class HogVMException extends Error {
constructor(message: string) {
super(message)
@@ -204,6 +216,14 @@ export function calculateCost(object: any, marked: Set<any> | undefined = undefi
}
export function unifyComparisonTypes(left: any, right: any): [any, any] {
+ // Two temporal values order by epoch seconds (matching ClickHouse and the Rust VM). Without this they
+ // stay as objects and `object > object` coerces to "[object Object]", which is always false — silently
+ // breaking realtime `is date after`/`is date before` filters.
+ const leftSeconds = temporalSeconds(left)
+ const rightSeconds = temporalSeconds(right)
+ if (leftSeconds !== null && rightSeconds !== null) {
+ return [leftSeconds, rightSeconds]
+ }
if (typeof left === 'number' && typeof right === 'string') {
return [left, Number(right)]
}