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.

feat(aio): share ai event limits across python, rust and node (#129973)

Carlos Marchaldd03acf13b99
diff --git a/.github/workflows/ci-rust.yml b/.github/workflows/ci-rust.yml
index 10cd7fde3294..09e9a18f7734 100644
--- a/.github/workflows/ci-rust.yml
+++ b/.github/workflows/ci-rust.yml
@@ -92,6 +92,8 @@ jobs:
# The rust mirror of the out-of-band domain list has a parity test
# against the shared json.
- 'posthog/security/crosslang/**'
+ # The rust mirror of the AI event limits has a parity test against the shared json.
+ - 'products/ai_observability/shared/crosslang/**'
# Hypercache contract: Python serializer changes may break Rust deserialization
- 'posthog/api/feature_flag.py'
- 'posthog/models/feature_flag/flags_cache.py'
diff --git a/bin/verify-ai-ingestion-stack b/bin/verify-ai-ingestion-stack
index 9f1d8cf43b4a..77a2b0cf1d6b 100755
--- a/bin/verify-ai-ingestion-stack
+++ b/bin/verify-ai-ingestion-stack
@@ -6,7 +6,7 @@ set -euo pipefail
PROXY="${PROXY:-http://localhost:8010}"
API_KEY="${API_KEY:?set API_KEY to a project api_token}"
-# Must stay over AI_BLOB_OFFLOAD_MIN_BASE64_LENGTH (20480) or ingestion leaves the image inline.
+# Must stay over AI_BLOB_OFFLOAD_MIN_BASE64_LENGTH (20000) or ingestion leaves the image inline.
BLOB="$(head -c 18750 /dev/urandom | base64 | tr -d '\n' | head -c 25000)"
CID="$(docker ps -q -f name=clickhouse | head -1)"
diff --git a/common/fixtures/ai-multimodal/README.md b/common/fixtures/ai-multimodal/README.md
index 7cf10b336472..ec9c558cc25e 100644
--- a/common/fixtures/ai-multimodal/README.md
+++ b/common/fixtures/ai-multimodal/README.md
@@ -41,6 +41,6 @@ Both overrides are load-bearing:
yields an *empty* key and OpenAI then answers `401 ... You didn't provide an API key`, so check the
key resolved before blaming the credential.
-The screenshot must stay above `AI_BLOB_OFFLOAD_MIN_BASE64_LENGTH` (20480 base64 chars,
-`nodejs/src/ingestion/config.ts:386`). Below that, ingestion leaves the image inline and
+The screenshot must stay above `AI_BLOB_OFFLOAD_MIN_BASE64_LENGTH` (20000 base64 chars by default,
+the base64 length of `media_offload_min_bytes` in `products/ai_observability/shared/crosslang/ai_event_limits.json`). Below that, ingestion leaves the image inline and
both tests pass while covering nothing. The recorder enforces this.
diff --git a/common/fixtures/ai-multimodal/record_fixture.py b/common/fixtures/ai-multimodal/record_fixture.py
index d20804ab6a65..ed4d893a8e25 100644
--- a/common/fixtures/ai-multimodal/record_fixture.py
+++ b/common/fixtures/ai-multimodal/record_fixture.py
@@ -57,10 +57,10 @@ def main() -> None:
encoded = json.dumps(properties["$ai_input"])
if "[base64 image redacted]" in encoded:
raise SystemExit("image was redacted — _enable_multimodal_capture did not take effect")
- if len(image_b64) <= 20480:
+ if len(image_b64) <= 20000:
raise SystemExit(
f"screenshot is too small ({len(image_b64)} base64 chars); "
- "it must exceed AI_BLOB_OFFLOAD_MIN_BASE64_LENGTH (20480) or ingestion will not offload it"
+ "it must exceed AI_BLOB_OFFLOAD_MIN_BASE64_LENGTH (20000) or ingestion will not offload it"
)
FIXTURE.write_text(
diff --git a/common/ingestion/acceptance_tests/test_ai_multimodal_blessed_path.py b/common/ingestion/acceptance_tests/test_ai_multimodal_blessed_path.py
index 6916b0895cc7..a9a4680aa9c7 100644
--- a/common/ingestion/acceptance_tests/test_ai_multimodal_blessed_path.py
+++ b/common/ingestion/acceptance_tests/test_ai_multimodal_blessed_path.py
@@ -77,8 +77,8 @@ class TestMultimodalBlessedPath:
encoded = json.dumps(recorded_event["properties"]["$ai_input"])
data_url = re.search(r"data:image/png;base64,([A-Za-z0-9+/=]+)", encoded)
assert data_url, "fixture has no inline base64 image"
- assert len(data_url.group(1)) > 20480, (
+ assert len(data_url.group(1)) > 20000, (
f"fixture image is {len(data_url.group(1))} base64 chars, at or under "
- "AI_BLOB_OFFLOAD_MIN_BASE64_LENGTH (20480), so ingestion would not offload it"
+ "AI_BLOB_OFFLOAD_MIN_BASE64_LENGTH (20000), so ingestion would not offload it"
)
assert base64.b64decode(data_url.group(1)), "inline image is not valid base64"
diff --git a/nodejs/src/ingestion/common/ai-event-limits.test.ts b/nodejs/src/ingestion/common/ai-event-limits.test.ts
new file mode 100644
index 000000000000..8dd6d97d15af
--- /dev/null
+++ b/nodejs/src/ingestion/common/ai-event-limits.test.ts
@@ -0,0 +1,27 @@
+import { readFileSync } from 'fs'
+import path from 'path'
+
+import { parseJSON } from '~/common/utils/json-parse'
+
+import { AI_INCLUDED_BYTES_PER_EVENT, AI_MAX_EVENT_BYTES_CEILING, AI_MEDIA_OFFLOAD_MIN_BYTES } from './ai-event-limits'
+
+const LIMITS_JSON = path.resolve(
+ __dirname,
+ '../../../../products/ai_observability/shared/crosslang/ai_event_limits.json'
+)
+
+describe('ai-event-limits', () => {
+ it('mirrors products/ai_observability/shared/crosslang/ai_event_limits.json', () => {
+ const limits = parseJSON(readFileSync(LIMITS_JSON, 'utf8'))
+
+ expect({
+ max_event_bytes_ceiling: AI_MAX_EVENT_BYTES_CEILING,
+ included_bytes_per_event: AI_INCLUDED_BYTES_PER_EVENT,
+ media_offload_min_bytes: AI_MEDIA_OFFLOAD_MIN_BYTES,
+ }).toEqual({
+ max_event_bytes_ceiling: limits.max_event_bytes_ceiling,
+ included_bytes_per_event: limits.included_bytes_per_event,
+ media_offload_min_bytes: limits.media_offload_min_bytes,
+ })
+ })
+})
diff --git a/nodejs/src/ingestion/common/ai-event-limits.ts b/nodejs/src/ingestion/common/ai-event-limits.ts
new file mode 100644
index 000000000000..8459bdc78ec5
--- /dev/null
+++ b/nodejs/src/ingestion/common/ai-event-limits.ts
@@ -0,0 +1,7 @@
+/**
+ * Mirror of products/ai_observability/shared/crosslang/ai_event_limits.json, in decimal bytes. Edit that file first,
+ * then these constants. The parity test in ai-event-limits.test.ts fails when they differ.
+ */
+export const AI_MAX_EVENT_BYTES_CEILING = 48_000_000
+export const AI_INCLUDED_BYTES_PER_EVENT = 100_000
+export const AI_MEDIA_OFFLOAD_MIN_BYTES = 15_000
diff --git a/nodejs/src/ingestion/config.ts b/nodejs/src/ingestion/config.ts
index 9d88278a0748..d0793c02b52f 100644
--- a/nodejs/src/ingestion/config.ts
+++ b/nodejs/src/ingestion/config.ts
@@ -17,6 +17,7 @@ import {
} from '~/common/config/kafka-topics'
import type { PostgresRouterConfig } from '~/common/utils/db/postgres'
import { isDevEnv, isProdEnv } from '~/common/utils/env-utils'
+import { AI_MEDIA_OFFLOAD_MIN_BYTES } from '~/ingestion/common/ai-event-limits'
import {
INGESTION_DOWNSTREAM_PRODUCER,
INGESTION_UPSTREAM_PRODUCER,
@@ -461,7 +462,8 @@ export function getDefaultIngestionConsumerConfig(): IngestionConsumerConfig {
AI_BLOB_S3_TIMEOUT_MS: 30000,
AI_BLOB_OFFLOAD_TEAMS: '',
// Keep the floor above base64-packed embedding vectors so logged embeddings stay inline as text.
- AI_BLOB_OFFLOAD_MIN_BASE64_LENGTH: 20480,
+ // The shortest base64 that decodes to AI_MEDIA_OFFLOAD_MIN_BYTES, so no media of that size stays inline.
+ AI_BLOB_OFFLOAD_MIN_BASE64_LENGTH: Math.ceil(AI_MEDIA_OFFLOAD_MIN_BYTES / 3) * 4,
AI_BLOB_OFFLOAD_MAX_BLOBS_PER_EVENT: 50,
// Chunk-wide cap on concurrent blob uploads, so blob-heavy traffic
// can't monopolize the S3 socket pool.
diff --git a/products/ai_observability/README.md b/products/ai_observability/README.md
index 7eccf9cf4927..b8bc0dbbf63b 100644
--- a/products/ai_observability/README.md
+++ b/products/ai_observability/README.md
@@ -36,7 +36,7 @@ products/ai_observability/
dags/ # Dagster jobs + metrics
skills/ # Agent skills scoped to the product
docs/ # Product-level docs (architecture decision records)
- shared/ # Cross-frontend/backend constants, schemas
+ shared/ # Constants and schemas shared across frontend, backend, capture and ingestion (crosslang/)
manifest.tsx # Scene + navigation registration
package.json # Turborepo package (@posthog/products-ai-observability)
```
diff --git a/products/ai_observability/backend/ai_event_limits.py b/products/ai_observability/backend/ai_event_limits.py
new file mode 100644
index 000000000000..0dba03da8a64
--- /dev/null
+++ b/products/ai_observability/backend/ai_event_limits.py
@@ -0,0 +1,57 @@
+import json
+from functools import lru_cache
+from pathlib import Path
+
+from posthog.dataclasses import frozen
+
+_LIMITS_PATH = Path(__file__).parents[1] / "shared" / "crosslang" / "ai_event_limits.json"
+
+
+@frozen
+class AIEventLimits:
+ """The size limits for AI events, in bytes. `shared/crosslang/README.md` describes each field."""
+
+ max_event_bytes_default: int
+ max_event_bytes_overrides: tuple[int, ...]
+ max_event_bytes_ceiling: int
+ included_bytes_per_event: int
+ media_offload_min_bytes: int
+ text_offload_enabled: bool
+ text_offload_min_event_bytes: int
+
+ def __post_init__(self) -> None:
+ sizes = {
+ "max_event_bytes_default": self.max_event_bytes_default,
+ "max_event_bytes_ceiling": self.max_event_bytes_ceiling,
+ "included_bytes_per_event": self.included_bytes_per_event,
+ "media_offload_min_bytes": self.media_offload_min_bytes,
+ "text_offload_min_event_bytes": self.text_offload_min_event_bytes,
+ **{f"max_event_bytes_overrides[{i}]": size for i, size in enumerate(self.max_event_bytes_overrides)},
+ }
+ for name, size in sizes.items():
+ # bool is an int subclass, and a float such as 12e6 parses from JSON, so check the exact type.
+ if type(size) is not int or size <= 0:
+ raise ValueError(f"{name} must be a positive integer of bytes, got {size!r}")
+ if type(self.text_offload_enabled) is not bool:
+ raise ValueError(f"text_offload_enabled must be a boolean, got {self.text_offload_enabled!r}")
+ caps = (self.max_event_bytes_default, *self.max_event_bytes_overrides)
+ if any(larger <= smaller for smaller, larger in zip(caps, caps[1:])):
+ raise ValueError(f"each override must be larger than the default and the override before it, got {caps}")
+ if caps[-1] > self.max_event_bytes_ceiling:
+ raise ValueError(f"no cap may exceed max_event_bytes_ceiling ({self.max_event_bytes_ceiling}), got {caps}")
+ if self.included_bytes_per_event >= self.max_event_bytes_default:
+ raise ValueError("included_bytes_per_event must be smaller than max_event_bytes_default")
+
+
+@lru_cache(maxsize=1)
+def get_ai_event_limits() -> AIEventLimits:
+ """Read the limits once.
+
+ A missing or invalid file raises instead of falling back to a guess, because these values decide what a
+ customer is billed and what capture accepts.
+ """
+ raw = json.loads(_LIMITS_PATH.read_text())
+ try:
+ return AIEventLimits(**{**raw, "max_event_bytes_overrides": tuple(raw["max_event_bytes_overrides"])})
+ except (KeyError, TypeError) as error:
+ raise ValueError(f"{_LIMITS_PATH.name} does not match AIEventLimits: {error!r}") from error
diff --git a/products/ai_observability/backend/facade/limits.py b/products/ai_observability/backend/facade/limits.py
new file mode 100644
index 000000000000..39a5c64af33d
--- /dev/null
+++ b/products/ai_observability/backend/facade/limits.py
@@ -0,0 +1,7 @@
+"""Kept apart from ``facade/api.py``, which imports the clustering workflows, so core Django can read the limits without
+loading them.
+"""
+
+from products.ai_observability.backend.ai_event_limits import AIEventLimits, get_ai_event_limits
+
+__all__ = ["AIEventLimits", "get_ai_event_limits"]
diff --git a/products/ai_observability/backend/test/test_ai_event_limits.py b/products/ai_observability/backend/test/test_ai_event_limits.py
new file mode 100644
index 000000000000..dbb88677fdcd
--- /dev/null
+++ b/products/ai_observability/backend/test/test_ai_event_limits.py
@@ -0,0 +1,48 @@
+import json
+import dataclasses
+from pathlib import Path
+from typing import Any
+
+import pytest
+
+from products.ai_observability.backend.facade.limits import AIEventLimits, get_ai_event_limits
+
+VALID = AIEventLimits(
+ max_event_bytes_default=12_000_000,
+ max_event_bytes_overrides=(24_000_000, 48_000_000),
+ max_event_bytes_ceiling=48_000_000,
+ included_bytes_per_event=100_000,
+ media_offload_min_bytes=15_000,
+ text_offload_enabled=False,
+ text_offload_min_event_bytes=100_000,
+)
+
+
+def test_file_and_loader_agree() -> None:
+ raw = json.loads((Path(__file__).parents[2] / "shared" / "crosslang" / "ai_event_limits.json").read_text())
+ get_ai_event_limits.cache_clear()
+ try:
+ assert dataclasses.asdict(get_ai_event_limits()) == {
+ **raw,
+ "max_event_bytes_overrides": tuple(raw["max_event_bytes_overrides"]),
+ }
+ finally:
+ get_ai_event_limits.cache_clear()
+
+
+ "changes,error",
+ [
+ ({"max_event_bytes_default": 12e6}, "max_event_bytes_default must be a positive integer"),
+ ({"max_event_bytes_default": True}, "max_event_bytes_default must be a positive integer"),
+ ({"media_offload_min_bytes": 0}, "media_offload_min_bytes must be a positive integer"),
+ ({"max_event_bytes_overrides": (48_000_000, 24_000_000)}, "each override must be larger"),
+ ({"max_event_bytes_overrides": (12_000_000, 48_000_000)}, "each override must be larger"),
+ ({"max_event_bytes_ceiling": 24_000_000}, "no cap may exceed max_event_bytes_ceiling"),
+ ({"included_bytes_per_event": 12_000_000}, "included_bytes_per_event must be smaller"),
+ ({"text_offload_enabled": "false"}, "text_offload_enabled must be a boolean"),
+ ],
+)
+def test_rejects_limits_that_contradict_each_other(changes: dict[str, Any], error: str) -> None:
+ with pytest.raises(ValueError, match=error):
+ dataclasses.replace(VALID, **changes)
diff --git a/products/ai_observability/shared/crosslang/README.md b/products/ai_observability/shared/crosslang/README.md
new file mode 100644
index 000000000000..5566ef82b307
--- /dev/null
+++ b/products/ai_observability/shared/crosslang/README.md
@@ -0,0 +1,42 @@
+# AI event limits
+
+`ai_event_limits.json` holds the size limits and thresholds for AI events (`$ai_*`).
+It is the source of truth for these values: the Rust and Node copies follow it, and their parity tests fail when a copy differs.
+Every value is in decimal bytes: 100 KB is `100000` and 48 MB is `48000000`.
+`max_event_bytes_default` is the exception. It stays at the binary 8 MiB (`8388608`) that deployments run today, until the infrastructure around capture accepts larger events.
+
+| Key | Meaning |
+| ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------- |
+| `max_event_bytes_default` | The largest AI event a project can send unless it has an override. |
+| `max_event_bytes_overrides` | The larger caps a project can get on request, in ascending order. |
+| `max_event_bytes_ceiling` | The largest AI event any project can send. SDKs check against this value only, because the per-project cap is the server's job. |
+| `included_bytes_per_event` | The bytes of each event that the event price covers. Size pricing bills the bytes above it. |
+| `media_offload_min_bytes` | The decoded size from which ingestion moves inline media to object storage. |
+| `text_offload_enabled` | Whether ingestion moves the text content of large events to object storage. Off. |
+| `text_offload_min_event_bytes` | The event size from which text offload applies, once it is on. |
+
+Values that follow from these are computed by the code that needs them, never stored here.
+
+## Who reads it
+
+- Python reads this file at runtime. Core Django gets the values through `products.ai_observability.backend.facade.limits`.
+- Rust capture mirrors the keys it needs in `rust/capture/src/ai_event_limits.rs`.
+- The Node AI pipeline mirrors the keys it needs in `nodejs/src/ingestion/common/ai-event-limits.ts`.
+
+The Rust image build context is `rust/` and the Node build compiles from `nodejs/`, so neither can read this file at runtime.
+A key `k` is the constant `AI_<K>` in each mirror, for example `max_event_bytes_ceiling` is `AI_MAX_EVENT_BYTES_CEILING`.
+
+## Overrides
+
+- `included_bytes_per_event` takes no environment override, because the Node usage records and the Django usage report must agree on it.
+- Capture reads `AI_MAX_EVENT_BYTES` to set a smaller cap for a deployment that needs one. Its default is `max_event_bytes_default`.
+- Capture's `AI_MAX_SUM_OF_PARTS_BYTES` bounds a whole multipart request, not an event, and is not one of these values.
+- The Node pipeline reads `AI_BLOB_OFFLOAD_MIN_BASE64_LENGTH` as a tuning knob. Its default is the base64 length of `media_offload_min_bytes`.
+
+## How to change a value
+
+1. Edit this file first.
+2. Update each mirror that carries the key. Its parity test fails until you do:
+ `cargo test -p capture --test ai_event_limits_parity` and `hogli test nodejs/src/ingestion/common/ai-event-limits.test.ts`.
+ For `max_event_bytes_default`, also update the `envconfig` default of `ai_max_event_bytes` in `rust/capture/src/config.rs`, which cannot name a constant.
+3. A cap change also needs the deployment limits around it, such as the Kafka producer limit and the edge proxy body limit.
diff --git a/products/ai_observability/shared/crosslang/ai_event_limits.json b/products/ai_observability/shared/crosslang/ai_event_limits.json
new file mode 100644
index 000000000000..fe8ef088e277
--- /dev/null
+++ b/products/ai_observability/shared/crosslang/ai_event_limits.json
@@ -0,0 +1,9 @@
+{
+ "max_event_bytes_default": 8388608,
+ "max_event_bytes_overrides": [24000000, 48000000],
+ "max_event_bytes_ceiling": 48000000,
+ "included_bytes_per_event": 100000,
+ "media_offload_min_bytes": 15000,
+ "text_offload_enabled": false,
+ "text_offload_min_event_bytes": 100000
+}
diff --git a/rust/affected-services/determinator-rules.toml b/rust/affected-services/determinator-rules.toml
index f52a84c93751..921e1c2bb3e2 100644
--- a/rust/affected-services/determinator-rules.toml
+++ b/rust/affected-services/determinator-rules.toml
@@ -99,6 +99,12 @@ mark-changed = "all"
globs = ["../posthog/security/crosslang/**"]
mark-changed = ["common-dns"]
+# The AI event limits: capture mirrors them, and a parity test in that crate fails when
+# the two differ. Must come BEFORE the catch-all rule below.
+[[path-rule]]
+globs = ["../products/ai_observability/shared/crosslang/**"]
+mark-changed = ["capture"]
+
# Catch-all for files outside the rust workspace (Python, frontend, CI, docs,
# etc.) — these are not crate source and should not trigger rust rebuilds.
# Must come AFTER all specific rules for files outside the workspace.
diff --git a/rust/capture/src/ai_event_limits.rs b/rust/capture/src/ai_event_limits.rs
new file mode 100644
index 000000000000..f26c09d8f091
--- /dev/null
+++ b/rust/capture/src/ai_event_limits.rs
@@ -0,0 +1,7 @@
+//! Mirror of `products/ai_observability/shared/crosslang/ai_event_limits.json`, in bytes.
+//! Edit that file first, then these constants. The parity test in
+//! `tests/ai_event_limits_parity.rs` fails when they differ.
+
+pub const AI_MAX_EVENT_BYTES_DEFAULT: u64 = 8_388_608;
+pub const AI_MAX_EVENT_BYTES_OVERRIDES: [u64; 2] = [24_000_000, 48_000_000];
+pub const AI_MAX_EVENT_BYTES_CEILING: u64 = 48_000_000;
diff --git a/rust/capture/src/config.rs b/rust/capture/src/config.rs
index fd2bca6e35a0..eda42b2b0061 100644
--- a/rust/capture/src/config.rs
+++ b/rust/capture/src/config.rs
@@ -385,6 +385,8 @@ pub struct Config {
/// the event, and the producer refuses it anyway. A deployment that has not
/// raised its producer cap wants a lower value than this default; the boot
/// warning says so when the two are out of order.
+ ///
+ /// Must equal `AI_MAX_EVENT_BYTES_DEFAULT`, or `tests/ai_event_limits_parity.rs` fails.
#[envconfig(default = "8388608")] // 8MiB
pub ai_max_event_bytes: u64,
diff --git a/rust/capture/src/lib.rs b/rust/capture/src/lib.rs
index 8f692129a64d..8b3c68766852 100644
--- a/rust/capture/src/lib.rs
+++ b/rust/capture/src/lib.rs
@@ -1,4 +1,5 @@
pub mod ai_endpoint;
+pub mod ai_event_limits;
pub mod ai_rejection;
pub mod api;
pub mod config;
diff --git a/rust/capture/tests/ai_event_limits_parity.rs b/rust/capture/tests/ai_event_limits_parity.rs
new file mode 100644
index 000000000000..21ee7ad48f96
--- /dev/null
+++ b/rust/capture/tests/ai_event_limits_parity.rs
@@ -0,0 +1,71 @@
+//! The limits file lives outside this workspace, so point the test at it with `AI_EVENT_LIMITS_JSON`.
+
+use std::collections::HashMap;
+use std::path::PathBuf;
+
+use capture::ai_event_limits::{
+ AI_MAX_EVENT_BYTES_CEILING, AI_MAX_EVENT_BYTES_DEFAULT, AI_MAX_EVENT_BYTES_OVERRIDES,
+};
+use capture::config::Config;
+use envconfig::Envconfig;
+
+const RELATIVE_PATH: &str = "products/ai_observability/shared/crosslang/ai_event_limits.json";
+
+fn limits_json() -> PathBuf {
+ if let Ok(path) = std::env::var("AI_EVENT_LIMITS_JSON") {
+ let path = PathBuf::from(path);
+ if path.is_file() {
+ return path;
+ }
+ panic!(
+ "AI_EVENT_LIMITS_JSON is set to {}, which is not a file",
+ path.display()
+ );
+ }
+ let mut current = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
+ loop {
+ let candidate = current.join(RELATIVE_PATH);
+ if candidate.is_file() {
+ return candidate;
+ }
+ if !current.pop() {
+ panic!("Could not locate {RELATIVE_PATH} - set AI_EVENT_LIMITS_JSON");
+ }
+ }
+}
+
+#[test]
+fn mirror_matches_the_shared_json() {
+ let raw = std::fs::read_to_string(limits_json()).expect("the limits file is readable");
+ let limits: serde_json::Value = serde_json::from_str(&raw).expect("the limits file is json");
+
+ let from_file = serde_json::json!({
+ "max_event_bytes_default": limits["max_event_bytes_default"],
+ "max_event_bytes_overrides": limits["max_event_bytes_overrides"],
+ "max_event_bytes_ceiling": limits["max_event_bytes_ceiling"],
+ });
+ let from_mirror = serde_json::json!({
+ "max_event_bytes_default": AI_MAX_EVENT_BYTES_DEFAULT,
+ "max_event_bytes_overrides": AI_MAX_EVENT_BYTES_OVERRIDES,
+ "max_event_bytes_ceiling": AI_MAX_EVENT_BYTES_CEILING,
+ });
+
+ assert_eq!(
+ from_file, from_mirror,
+ "src/ai_event_limits.rs has drifted from {RELATIVE_PATH}. Edit the json first, then the mirror."
+ );
+}
+
+#[test]
+fn config_defaults_to_the_shared_cap() {
+ let env = HashMap::from([(
+ "REDIS_URL".to_string(),
+ "redis://localhost:6379/".to_string(),
+ )]);
+ let config = Config::init_from_hashmap(&env).expect("the config loads with only REDIS_URL set");
+
+ assert_eq!(
+ config.ai_max_event_bytes, AI_MAX_EVENT_BYTES_DEFAULT,
+ "the envconfig default of Config::ai_max_event_bytes has drifted from {RELATIVE_PATH}. Edit the json first, then the mirror and that default."
+ );
+}
diff --git a/tools/snob_backend_test_selection_shadow.py b/tools/snob_backend_test_selection_shadow.py
index 1d8fce25ead4..3016e95a3cc1 100755
--- a/tools/snob_backend_test_selection_shadow.py
+++ b/tools/snob_backend_test_selection_shadow.py
@@ -93,6 +93,8 @@ FULL_RUN_PATTERNS = (
# Non-Python files that affect generated Python code or test behavior
# A data file the host guards read at runtime, so a change to it is a behavior change
"posthog/security/crosslang/",
+ # The AI event limits, which get_ai_event_limits reads at runtime, so a change to them is a behavior change
+ "products/ai_observability/shared/crosslang/",
"frontend/src/queries/schema.json",
"frontend/src/products.json",
"frontend/public/email/",