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.

chore(notebooks): give kernel sandboxes their own 2 hour modal ttl (#80400)

Sinan Kucukkoseler919a40f9d562
diff --git a/products/notebooks/backend/kernel_runtime.py b/products/notebooks/backend/kernel_runtime.py
index 87f8cc60d358..802ed658d902 100644
--- a/products/notebooks/backend/kernel_runtime.py
+++ b/products/notebooks/backend/kernel_runtime.py
@@ -34,6 +34,12 @@ from products.tasks.backend.facade.sandbox import (
logger = structlog.get_logger(__name__)
+# Hard lifetime of a notebook kernel sandbox, used when the notebook sets no
+# `kernel_idle_timeout_seconds`. A kernel serves one interactive session, so nobody waits on it
+# once the tab closes and this TTL is what reclaims it. The task-agent default
+# (`SANDBOX_TTL_SECONDS`) is longer because it has to outlast an unattended agent run.
+NOTEBOOK_KERNEL_TTL_SECONDS = 2 * 60 * 60
+
@dataclass
class KernelExecutionResult:
@@ -234,6 +240,7 @@ def build_notebook_sandbox_config(notebook: Notebook) -> SandboxConfig:
template=SandboxTemplate.NOTEBOOK_BASE,
cpu_cores=1,
memory_gb=2,
+ ttl_seconds=NOTEBOOK_KERNEL_TTL_SECONDS,
)
if notebook.kernel_cpu_cores:
sandbox_config.cpu_cores = notebook.kernel_cpu_cores
diff --git a/products/notebooks/backend/test/test_kernel_runtime.py b/products/notebooks/backend/test/test_kernel_runtime.py
index 18190b332504..1439958f5c64 100644
--- a/products/notebooks/backend/test/test_kernel_runtime.py
+++ b/products/notebooks/backend/test/test_kernel_runtime.py
@@ -13,6 +13,7 @@ from django.utils import timezone
from parameterized import parameterized
from products.notebooks.backend.kernel_runtime import (
+ NOTEBOOK_KERNEL_TTL_SECONDS,
KernelRuntimeService,
_KernelHandle,
_NotebookBridgeParser,
@@ -105,7 +106,7 @@ class TestKernelRuntimeService(BaseTest):
(
"memory_only",
{"kernel_memory_gb": 12.0},
- {"memory_gb": 12.0},
+ {"memory_gb": 12.0, "ttl_seconds": NOTEBOOK_KERNEL_TTL_SECONDS},
),
]
)