: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(tasks): lower task-run-stream MAXLEN from 20k to 5k to cap redis memory (#71302)
Alessandro Pogliaghia3a0b272da22
diff --git a/products/tasks/backend/logic/stream/redis_stream.py b/products/tasks/backend/logic/stream/redis_stream.pyindex 7a6fdc1aac7e..ba916b6ca208 100644--- a/products/tasks/backend/logic/stream/redis_stream.py+++ b/products/tasks/backend/logic/stream/redis_stream.py@@ -16,7 +16,7 @@ logger = structlog.get_logger(__name__)# Keep enough live history for users who open an in-progress run late while# still bounding Redis growth to the sandbox lifetime.-TASK_RUN_STREAM_MAX_LENGTH = 20_000+TASK_RUN_STREAM_MAX_LENGTH = 5_000TASK_RUN_STREAM_TIMEOUT = SANDBOX_TTL_SECONDSTASK_RUN_STREAM_SEQUENCE_TIMEOUT = int(SANDBOX_EVENT_INGEST_TOKEN_TTL.total_seconds())TASK_RUN_STREAM_PREFIX = "task-run-stream:"diff --git a/products/tasks/backend/metrics.py b/products/tasks/backend/metrics.pyindex a7bfdde6559e..e2ce16954232 100644--- a/products/tasks/backend/metrics.py+++ b/products/tasks/backend/metrics.py@@ -105,7 +105,7 @@ STREAM_CONNECTION_DURATION_BUCKETS = [7_200.0,21_600.0,]-# Stream length is capped at TASK_RUN_STREAM_MAX_LENGTH (~20k); the top buckets+# Stream length is capped at TASK_RUN_STREAM_MAX_LENGTH (~5k); the top buckets# show how close real runs get to the trim threshold.STREAM_LENGTH_BUCKETS = [10.0, 50.0, 100.0, 500.0, 1_000.0, 2_500.0, 5_000.0, 10_000.0, 15_000.0, 20_000.0]diff --git a/services/agent-proxy/src/hono/metrics.ts b/services/agent-proxy/src/hono/metrics.tsindex 4127afa5d8bc..d744d93a8fe3 100644--- a/services/agent-proxy/src/hono/metrics.ts+++ b/services/agent-proxy/src/hono/metrics.ts@@ -47,7 +47,7 @@ export const taskRunStreamConnectionDurationSeconds = new Histogram({registers: [register],})-// Stream length is capped at TASK_RUN_STREAM_MAX_LENGTH (~20k); the top+// Stream length is capped at TASK_RUN_STREAM_MAX_LENGTH (~5k); the top// buckets show how close real runs get to the trim threshold.export const taskRunStreamLengthOnConnect = new Histogram({name: 'posthog_tasks_task_run_stream_length_on_connect',diff --git a/services/agent-proxy/src/lib/constants.ts b/services/agent-proxy/src/lib/constants.tsindex ba8ce339915b..177e343993d3 100644--- a/services/agent-proxy/src/lib/constants.ts+++ b/services/agent-proxy/src/lib/constants.ts@@ -14,7 +14,7 @@ export const STREAM_TTL_SECONDS = 6 * 60 * 60 // 21600export const SEQUENCE_TTL_SECONDS = STREAM_TTL_SECONDS + 3600 // 25200// Redis XADD MAXLEN ~ (approximate trim, not exact).-export const STREAM_MAX_LENGTH = 20_000+export const STREAM_MAX_LENGTH = 5_000// XREAD tuningexport const READ_COUNT = 16