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): restore builtin arity that HogQL accepts (#96261)

Meikel Ratz81dd0351be10
diff --git a/common/hogvm/CHANGELOG.md b/common/hogvm/CHANGELOG.md
index 5101daf7f7b0..f2e61b24d859 100644
--- a/common/hogvm/CHANGELOG.md
+++ b/common/hogvm/CHANGELOG.md
@@ -1,5 +1,32 @@
# HogQL bytecode changelog
+## 2026-09-07 - 1.0.70
+
+Eleven standard library functions accept the trailing arguments that HogQL accepts. No bytecode
+operations changed.
+
+Version 1.0.69 started to enforce a `maxArgs` limit that no dispatch path had ever checked. Several
+limits were below the HogQL signature for the same name, so a call that runs in an insight failed in
+Hog:
+
+```bash
+round(19.99, 2) # and floor
+now('UTC') # and toString, toStartOfDay, toStartOfWeek, dateTrunc
+position('abc', 'b', 1) # and positionCaseInsensitive
+arraySort(arr, x) # and arrayReverseSort
+```
+
+Each of these runs again. The trailing argument is accepted and ignored, which is what the VM did
+before 1.0.69.
+
+`range` keeps its limit of two arguments. HogQL takes a step argument, and neither VM implements one.
+
+`JSONHas` also accepts a single argument with no path components, matching HogQL and the existing
+implementation.
+
+See [Hog function argument counts](../../../docs/internal/hog-function-arities.md) for the remaining
+differences from HogQL.
+
## 2026-08-27 - 1.0.69
The VM checks the argument count of a standard library function before it calls it. No bytecode
diff --git a/common/hogvm/python/stl/__init__.py b/common/hogvm/python/stl/__init__.py
index 63f5c4a7edbf..1857d58401b8 100644
--- a/common/hogvm/python/stl/__init__.py
+++ b/common/hogvm/python/stl/__init__.py
@@ -996,7 +996,7 @@ STL: dict[str, STLFunction] = {
"notILike": STLFunction(
fn=lambda args, team, stdout, timeout: not like(args[0], args[1], True), minArgs=2, maxArgs=2
),
- "toString": STLFunction(fn=toString, minArgs=1, maxArgs=1),
+ "toString": STLFunction(fn=toString, minArgs=1, maxArgs=2),
"toUUID": STLFunction(fn=toString, minArgs=1, maxArgs=1),
"toInt": STLFunction(fn=toInt, minArgs=1, maxArgs=1),
"toFloat": STLFunction(fn=toFloat, minArgs=1, maxArgs=1),
@@ -1017,7 +1017,7 @@ STL: dict[str, STLFunction] = {
"print": STLFunction(fn=print, minArgs=0, maxArgs=None),
"jsonParse": STLFunction(fn=jsonParse, minArgs=1, maxArgs=1),
"jsonStringify": STLFunction(fn=jsonStringify, minArgs=1, maxArgs=2),
- "JSONHas": STLFunction(fn=JSONHas, minArgs=2, maxArgs=None),
+ "JSONHas": STLFunction(fn=JSONHas, minArgs=1, maxArgs=None),
"isValidJSON": STLFunction(fn=isValidJSON, minArgs=1, maxArgs=1),
"JSONLength": STLFunction(fn=JSONLength, minArgs=1, maxArgs=None),
"JSONExtractBool": STLFunction(fn=JSONExtractBool, minArgs=1, maxArgs=None),
@@ -1037,7 +1037,7 @@ STL: dict[str, STLFunction] = {
(args[0].index(str(args[1])) + 1) if isinstance(args[0], str) and str(args[1]) in args[0] else 0
),
minArgs=2,
- maxArgs=2,
+ maxArgs=3,
),
"positionCaseInsensitive": STLFunction(
fn=lambda args, team, stdout, timeout: (
@@ -1046,7 +1046,7 @@ STL: dict[str, STLFunction] = {
else 0
),
minArgs=2,
- maxArgs=2,
+ maxArgs=3,
),
"trim": STLFunction(fn=trim, minArgs=1, maxArgs=2),
"trimLeft": STLFunction(fn=trimLeft, minArgs=1, maxArgs=2),
@@ -1106,12 +1106,12 @@ STL: dict[str, STLFunction] = {
"arrayPushFront": STLFunction(fn=arrayPushFront, minArgs=2, maxArgs=2),
"arrayPopBack": STLFunction(fn=arrayPopBack, minArgs=1, maxArgs=1),
"arrayPopFront": STLFunction(fn=arrayPopFront, minArgs=1, maxArgs=1),
- "arraySort": STLFunction(fn=arraySort, minArgs=1, maxArgs=1),
+ "arraySort": STLFunction(fn=arraySort, minArgs=1, maxArgs=None),
"arrayReverse": STLFunction(fn=arrayReverse, minArgs=1, maxArgs=1),
- "arrayReverseSort": STLFunction(fn=arrayReverseSort, minArgs=1, maxArgs=1),
+ "arrayReverseSort": STLFunction(fn=arrayReverseSort, minArgs=1, maxArgs=None),
"arrayStringConcat": STLFunction(fn=arrayStringConcat, minArgs=1, maxArgs=2),
"has": STLFunction(fn=has, minArgs=2, maxArgs=2),
- "now": STLFunction(fn=lambda args, team, stdout, timeout: now(), minArgs=0, maxArgs=0),
+ "now": STLFunction(fn=lambda args, team, stdout, timeout: now(), minArgs=0, maxArgs=1),
"toUnixTimestamp": STLFunction(
fn=lambda args, team, stdout, timeout: toUnixTimestamp(args[0], args[1] if len(args) > 1 else None),
minArgs=1,
@@ -1172,10 +1172,10 @@ STL: dict[str, STLFunction] = {
"coalesce": STLFunction(fn=coalesce, minArgs=1, maxArgs=None),
"dateAdd": STLFunction(fn=date_add, minArgs=3, maxArgs=3),
"dateDiff": STLFunction(fn=date_diff, minArgs=3, maxArgs=3),
- "dateTrunc": STLFunction(fn=date_trunc, minArgs=2, maxArgs=2),
+ "dateTrunc": STLFunction(fn=date_trunc, minArgs=2, maxArgs=3),
"equals": STLFunction(fn=equals, minArgs=2, maxArgs=2),
"extract": STLFunction(fn=extract, minArgs=2, maxArgs=2),
- "floor": STLFunction(fn=floor_fn, minArgs=1, maxArgs=1),
+ "floor": STLFunction(fn=floor_fn, minArgs=1, maxArgs=2),
"greater": STLFunction(fn=greater, minArgs=2, maxArgs=2),
"greaterOrEquals": STLFunction(fn=greaterOrEquals, minArgs=2, maxArgs=2),
"if": STLFunction(fn=if_fn, minArgs=3, maxArgs=3),
@@ -1191,7 +1191,7 @@ STL: dict[str, STLFunction] = {
"or": STLFunction(fn=or_fn, minArgs=1, maxArgs=None),
"plus": STLFunction(fn=plus, minArgs=2, maxArgs=2),
"range": STLFunction(fn=range_fn, minArgs=1, maxArgs=2),
- "round": STLFunction(fn=round_fn, minArgs=1, maxArgs=1),
+ "round": STLFunction(fn=round_fn, minArgs=1, maxArgs=2),
"startsWith": STLFunction(fn=startsWith, minArgs=2, maxArgs=2),
"substring": STLFunction(fn=substring, minArgs=2, maxArgs=3),
"toIntervalDay": STLFunction(fn=toIntervalDay, minArgs=1, maxArgs=1),
@@ -1199,10 +1199,10 @@ STL: dict[str, STLFunction] = {
"toIntervalMinute": STLFunction(fn=toIntervalMinute, minArgs=1, maxArgs=1),
"toIntervalMonth": STLFunction(fn=toIntervalMonth, minArgs=1, maxArgs=1),
"toMonth": STLFunction(fn=toMonth_fn, minArgs=1, maxArgs=1),
- "toStartOfDay": STLFunction(fn=toStartOfDay, minArgs=1, maxArgs=1),
+ "toStartOfDay": STLFunction(fn=toStartOfDay, minArgs=1, maxArgs=2),
"toStartOfHour": STLFunction(fn=toStartOfHour, minArgs=1, maxArgs=1),
"toStartOfMonth": STLFunction(fn=toStartOfMonth, minArgs=1, maxArgs=1),
- "toStartOfWeek": STLFunction(fn=toStartOfWeek, minArgs=1, maxArgs=1),
+ "toStartOfWeek": STLFunction(fn=toStartOfWeek, minArgs=1, maxArgs=2),
"toYYYYMM": STLFunction(fn=toYYYYMM, minArgs=1, maxArgs=1),
"toYear": STLFunction(fn=toYear, minArgs=1, maxArgs=1),
"today": STLFunction(fn=today, minArgs=0, maxArgs=0),
diff --git a/common/hogvm/python/test/test_execute.py b/common/hogvm/python/test/test_execute.py
index 5883361cd677..98b0c96bec6b 100644
--- a/common/hogvm/python/test/test_execute.py
+++ b/common/hogvm/python/test/test_execute.py
@@ -189,6 +189,11 @@ class TestBytecodeExecute:
else:
raise AssertionError("Expected Exception not raised")
+ @pytest.mark.parametrize("indirect", [False, True])
+ def test_json_has_without_path(self, indirect: bool) -> None:
+ program = "let hasPath := JSONHas; return hasPath('{}');" if indirect else "return JSONHas('{}');"
+ assert self._run_program(program) is True
+
def test_every_builtin_tolerates_its_own_min_args(self):
# A builtin whose fn indexes past its declared minArgs raises a bare IndexError instead of a
# HogVMException, which callers cannot tell apart from a bug in their own code. Blocking
diff --git a/common/hogvm/typescript/package.json b/common/hogvm/typescript/package.json
index 4e6f399ee607..8dc427b197d0 100644
--- a/common/hogvm/typescript/package.json
+++ b/common/hogvm/typescript/package.json
@@ -1,6 +1,6 @@
{
"name": "@posthog/hogvm",
- "version": "1.0.69",
+ "version": "1.0.70",
"description": "PostHog Hog Virtual Machine",
"license": "MIT",
"author": "PostHog <[email protected]>",
diff --git a/common/hogvm/typescript/src/__tests__/execute.test.ts b/common/hogvm/typescript/src/__tests__/execute.test.ts
index 7d0911c88ba5..9d7ad19c8db9 100644
--- a/common/hogvm/typescript/src/__tests__/execute.test.ts
+++ b/common/hogvm/typescript/src/__tests__/execute.test.ts
@@ -120,6 +120,7 @@ describe('hogvm execute', () => {
const match = new RegExp(regex).exec(value)
return match?.[1] ?? match?.[0] ?? ''
},
+ match: (regex: string, value: string): boolean => new RE2(regex).test(value),
},
},
}
@@ -178,6 +179,58 @@ describe('hogvm execute', () => {
).toThrow('Function lower requires at most 1 arguments')
})
+ test.each<[string, unknown[], unknown]>([
+ ['round', [1.2345, 2], 1],
+ ['floor', [1.9, 1], 1],
+ ['toString', [123, 'UTC'], '123'],
+ ['now', ['UTC'], expect.objectContaining({ __hogDateTime__: true, zone: 'UTC' })],
+ ['position', ['abc', 'b', 1], 2],
+ ['positionCaseInsensitive', ['abc', 'B', 1], 2],
+ [
+ 'dateTrunc',
+ ['day', { __hogDateTime__: true, dt: 3600, zone: 'UTC' }, 'UTC'],
+ { __hogDateTime__: true, dt: 0, zone: 'UTC' },
+ ],
+ [
+ 'toStartOfDay',
+ [{ __hogDateTime__: true, dt: 3600, zone: 'UTC' }, 'UTC'],
+ { __hogDateTime__: true, dt: 0, zone: 'UTC' },
+ ],
+ [
+ 'toStartOfWeek',
+ [{ __hogDateTime__: true, dt: 345600, zone: 'UTC' }, 1],
+ { __hogDateTime__: true, dt: 345600, zone: 'UTC' },
+ ],
+ [
+ 'arraySort',
+ [
+ [2, 1],
+ [20, 10],
+ ],
+ [1, 2],
+ ],
+ [
+ 'arrayReverseSort',
+ [
+ [2, 1],
+ [20, 10],
+ ],
+ [2, 1],
+ ],
+ ['JSONHas', ['{}'], true],
+ ])('%s accepts HogQL arguments through direct and indirect calls', (name, args, expected) => {
+ const bytecode: (string | number)[] = ['_H', 1]
+ const globals: Record<string, unknown> = {}
+ for (const [index, arg] of args.entries()) {
+ globals[`arg${index}`] = arg
+ bytecode.push(op.STRING, `arg${index}`, op.GET_GLOBAL, 1)
+ }
+ expect(execSync([...bytecode, op.CALL_GLOBAL, name, args.length], { globals })).toEqual(expected)
+ expect(
+ execSync([...bytecode, op.STRING, name, op.GET_GLOBAL, 1, op.CALL_LOCAL, args.length], { globals })
+ ).toEqual(expected)
+ })
+
test('null coercion in ordering comparisons - preserved behavior', () => {
// This test documents the current typescript hogvm behavior where null is coerced to 0 in ordering comparisons.
// HogVM in python/rust does not share this behavior.
diff --git a/common/hogvm/typescript/src/stl/stl.ts b/common/hogvm/typescript/src/stl/stl.ts
index 9c61a79f65a1..27933fba5efd 100644
--- a/common/hogvm/typescript/src/stl/stl.ts
+++ b/common/hogvm/typescript/src/stl/stl.ts
@@ -558,7 +558,7 @@ export const STL: Record<string, STLFunction> = {
description: 'Converts a value to its string representation',
example: 'toString($1)',
minArgs: 1,
- maxArgs: 1,
+ maxArgs: 2,
},
toUUID: {
fn: STLToString,
@@ -848,7 +848,7 @@ export const STL: Record<string, STLFunction> = {
},
description: 'Checks if a JSON path exists in an object',
example: 'JSONHas($1, $2)',
- minArgs: 2,
+ minArgs: 1,
},
isValidJSON: {
fn: ([str]) => {
@@ -996,7 +996,7 @@ export const STL: Record<string, STLFunction> = {
description: 'Returns position of substring in string (1-based)',
example: 'position($1, $2)',
minArgs: 2,
- maxArgs: 2,
+ maxArgs: 3,
},
positionCaseInsensitive: {
fn: ([str, elem]) => {
@@ -1008,7 +1008,7 @@ export const STL: Record<string, STLFunction> = {
description: 'Case-insensitive substring position (1-based)',
example: 'positionCaseInsensitive($1, $2)',
minArgs: 2,
- maxArgs: 2,
+ maxArgs: 3,
},
trim: {
fn: ([str, char]) => {
@@ -1287,7 +1287,6 @@ export const STL: Record<string, STLFunction> = {
description: 'Sorts array in ascending order',
example: 'arraySort($1)',
minArgs: 1,
- maxArgs: 1,
},
arrayReverse: {
fn: ([arr]) => {
@@ -1311,7 +1310,6 @@ export const STL: Record<string, STLFunction> = {
description: 'Sorts array in descending order',
example: 'arrayReverseSort($1)',
minArgs: 1,
- maxArgs: 1,
},
arrayStringConcat: {
fn: ([arr, separator = '']) => {
@@ -1344,7 +1342,7 @@ export const STL: Record<string, STLFunction> = {
description: 'Returns current datetime',
example: 'now()',
minArgs: 0,
- maxArgs: 0,
+ maxArgs: 1,
},
toUnixTimestamp: {
fn: (args) => {
@@ -1550,7 +1548,7 @@ export const STL: Record<string, STLFunction> = {
description: 'Truncates datetime to unit',
example: 'dateTrunc($1, $2)',
minArgs: 2,
- maxArgs: 2,
+ maxArgs: 3,
},
equals: {
fn: equalsFn,
@@ -1571,7 +1569,7 @@ export const STL: Record<string, STLFunction> = {
description: 'Rounds number down to integer',
example: 'floor($1)',
minArgs: 1,
- maxArgs: 1,
+ maxArgs: 2,
},
greater: {
fn: greaterFn,
@@ -1680,7 +1678,7 @@ export const STL: Record<string, STLFunction> = {
description: 'Rounds number to nearest integer',
example: 'round($1)',
minArgs: 1,
- maxArgs: 1,
+ maxArgs: 2,
},
startsWith: {
fn: startsWithFn,
@@ -1736,7 +1734,7 @@ export const STL: Record<string, STLFunction> = {
description: 'Truncates datetime to start of day',
example: 'toStartOfDay($1)',
minArgs: 1,
- maxArgs: 1,
+ maxArgs: 2,
},
toStartOfHour: {
fn: toStartOfHourFn,
@@ -1757,7 +1755,7 @@ export const STL: Record<string, STLFunction> = {
description: 'Truncates datetime to start of week',
example: 'toStartOfWeek($1)',
minArgs: 1,
- maxArgs: 1,
+ maxArgs: 2,
},
toYYYYMM: {
fn: toYYYYMMFn,
diff --git a/docs/internal/hog-function-arities.md b/docs/internal/hog-function-arities.md
new file mode 100644
index 000000000000..651ff822009c
--- /dev/null
+++ b/docs/internal/hog-function-arities.md
@@ -0,0 +1,20 @@
+# Hog function argument counts
+
+Hog checks standard library argument counts for direct calls and functions stored in variables.
+The Python and TypeScript native function registries define the minimum and maximum accepted counts.
+The HogQL parity test checks both bounds against shared HogQL function names in these registries.
+
+`JSONHas(json)` accepts no path components and returns `true`, preserving Hog's existing empty-path behavior.
+
+Some Hog signatures are deliberately narrower than HogQL:
+
+| Function | Hog arguments | Reason |
+| ------------ | ------------- | --------------------------------------------------------------------------------------------- |
+| `range` | 1–2 | The VM does not implement HogQL's step argument. |
+| `dateAdd` | 3 | The VM requires unit, amount, and datetime; it does not implement the date/interval overload. |
+| `toTimeZone` | 2 | Hog requires an explicit timezone; HogQL can supply the project's timezone. |
+
+Accepting an argument does not imply that Hog implements every HogQL option. For compatibility,
+`round`, `floor`, `toString`, `now`, `position`, `positionCaseInsensitive`, `dateTrunc`,
+`toStartOfDay`, `toStartOfWeek`, `arraySort`, and `arrayReverseSort` accept and ignore trailing options.
+For example, `round(19.99, 2)` returns `20`; Hog does not apply the precision argument.
diff --git a/posthog/hogql/functions/test/test_hog_stl_arity.py b/posthog/hogql/functions/test/test_hog_stl_arity.py
new file mode 100644
index 000000000000..3a56a3a7c154
--- /dev/null
+++ b/posthog/hogql/functions/test/test_hog_stl_arity.py
@@ -0,0 +1,36 @@
+from django.test import SimpleTestCase
+
+from posthog.hogql.functions.mapping import HOGQL_CLICKHOUSE_FUNCTIONS, HOGQL_POSTHOG_FUNCTIONS
+
+from common.hogvm.python.stl import STL
+
+HOGQL_FUNCTIONS = {**HOGQL_CLICKHOUSE_FUNCTIONS, **HOGQL_POSTHOG_FUNCTIONS}
+
+HIGHER_MIN_ARGS_THAN_HOGQL = {
+ "dateAdd": "Hog requires unit, amount, and datetime; it does not implement HogQL's date/interval overload",
+ "toTimeZone": "Hog has no implicit project timezone, so the timezone argument is required",
+}
+
+LOWER_MAX_ARGS_THAN_HOGQL = {
+ "range": "HogQL takes a step argument, Hog's implementation has no step and would ignore it",
+}
+
+
+class TestHogStlArity(SimpleTestCase):
+ def test_no_builtin_accepts_fewer_arguments_than_hogql(self) -> None:
+ too_strict = []
+ for name, stl_fn in STL.items():
+ hogql_fn = HOGQL_FUNCTIONS.get(name)
+ if hogql_fn is None:
+ continue
+ if (stl_fn.minArgs or 0) > hogql_fn.min_args and name not in HIGHER_MIN_ARGS_THAN_HOGQL:
+ too_strict.append(f"{name}: Hog minArgs={stl_fn.minArgs}, HogQL accepts {hogql_fn.min_args}")
+ if (
+ stl_fn.maxArgs is not None
+ and name not in LOWER_MAX_ARGS_THAN_HOGQL
+ and (hogql_fn.max_args is None or hogql_fn.max_args > stl_fn.maxArgs)
+ ):
+ limit = "unbounded" if hogql_fn.max_args is None else hogql_fn.max_args
+ too_strict.append(f"{name}: Hog maxArgs={stl_fn.maxArgs}, HogQL accepts {limit}")
+
+ assert too_strict == []