: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(notebooks): name the kernel lifetime setting for what it does (#100107)
Sinan Kucukkoselerb7b8c3396be6
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 1943ab9d4bcd..7508510deee7 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -9041,21 +9041,21 @@ snapshots:scenes-app-notebooks-dataframe-hint--on-a-cell-with-no-dataframe-name--light:hash: v1.k794b7964.9cb4583e02d3192ab41346398046f32619977f6a4d7d56644245f4018b1c1451.rqbs7lbVXIaK4wH1m1_NFxMizFc2esosnCWk6XB-_VQscenes-app-notebooks-kernel-info--free-compute--dark:- hash: v1.k794b7964.9f16845ad724b67d68cd068ab5a2f8ca6fc8ab83e710d6e2f28b113fe09b9171._s-RfNP8c5cc0e10ja9PrgPhUh70q_D7letZIoo0vf8+ hash: v1.k794b7964.e8e81cc18d66dcca3d1cd23cc5017833b040abcaa4a3be85c6161787fed0efcd.OiaNuBz69zbpOxiLQsFYOQuJn_226577RmjJ_GbOdyQscenes-app-notebooks-kernel-info--free-compute--light:- hash: v1.k794b7964.eeefc7496054ed3acf0758c2728eb92448a079e8e100bd5f83d95009d87c5553.DqEbRSwEidVqUbSHir-u4pSMfQ7Uh9bfQs-IE1DerWQ+ hash: v1.k794b7964.c27e113d2390551267feb2cea74f0bb689bdbf25626a6dd9cb128fec74b9b26e._kxDv_e1H_Uy9H4TTJR0rJs02KBWEg8GUNlecqDlJTcscenes-app-notebooks-kernel-info--running-on-a-preset--dark:- hash: v1.k794b7964.677cbd7a30829cd3e0e808d46a387ab581b8096c8c67e9e6bd6395e4653558d9.JDYjW_JJS7soXBbosLLG7g_xssiymwwkNcQNmF00T4s+ hash: v1.k794b7964.82a5e5a0c66642bc7a5f0f6d457660c23ef39d412943ae01790625b013b31825.vg2fP6tJhvbvq3gyulundpXwsduP_lap2nXheD97g7Yscenes-app-notebooks-kernel-info--running-on-a-preset--light:- hash: v1.k794b7964.673dc5cd5a03d75346cef3c8e1293a8e66dbd90edbceddf6a040bec1b5078147.NtxH0gn0hrkTq2tyEi7fD5PiuVOpXNPVmyv91QcrtRs+ hash: v1.k794b7964.6ddacc62c1f423097c98f9db5e5a9d2e346214efbf192542e2ddf38d5ec51178.tgE6qhQpKuLYmeXZp7VBlOlm32A8H0bQVucN9RPlFDYscenes-app-notebooks-kernel-info--stopped-on-docker--dark:hash: v1.k794b7964.d4d47762ad9e9b7dee1962999a8a10eb7bc5e1b799a32718047763fa477bc0f2.BMgw1xsCY97eGl6rVy_9vI6mhgT34U5ISlcpNT-etNgscenes-app-notebooks-kernel-info--stopped-on-docker--light:hash: v1.k794b7964.8966d7960865a6c20149572d8a27c3bc66304fd2cd7109d7e9b4d4010603bb42.pahxDY_fRgb8hrmB0SQt4Glpi6x_Yb--W934Xvktx60scenes-app-notebooks-kernel-info--tuned-by-hand--dark:- hash: v1.k794b7964.315164254176c2572be6094fffd5fee014b405ad7ec1517166408d485a3c2fb5.8LpJDGyNL_xPSE7u9XoFpHkQMH1-BfL8JImtv2w5qW4+ hash: v1.k794b7964.347db9ec9f0feaf884411972f781190c25afaeba7cb33c74af5003f160726424.M-4MDzr-7ZAygSlW59c1-dGsAK8IN1mwQXk8Ksah8Csscenes-app-notebooks-kernel-info--tuned-by-hand--light:- hash: v1.k794b7964.de7fd0786989fbb2a529f1828c004adb9a23866be08f8e36830cf716d49938f9.4TjG4Kh-L6jHhWakS4GiSz8BHUnV6B9xahTdNfKjd5k+ hash: v1.k794b7964.ac626c9bdea16d7836559e40c21813ab15b5c6c4e0e237725d66f8f0c9f1c9a2.p-4SGszZwtdI7-ApAaMAzEVmUQJUMxmx13C7GtkG88Iscenes-app-notebooks-nodes-customer-journey--all-steps-completed--dark:hash: v1.k794b7964.21a8db46b074c796548d4e0fc63caf6443807d16fc5bf18de4d8702336870cd8.F16rPJkkmnadbRylNt9D1y4vd-_qggONDZaX0ErA27gscenes-app-notebooks-nodes-customer-journey--all-steps-completed--light:diff --git a/frontend/src/scenes/notebooks/Notebook/NotebookKernelInfo.tsx b/frontend/src/scenes/notebooks/Notebook/NotebookKernelInfo.tsxindex c732b443479e..ed905038c3e6 100644--- a/frontend/src/scenes/notebooks/Notebook/NotebookKernelInfo.tsx+++ b/frontend/src/scenes/notebooks/Notebook/NotebookKernelInfo.tsx@@ -267,10 +267,11 @@ export const NotebookKernelInfo = (): JSX.Element => {<div className="space-y-1 flex w-full justify-between items-center"><div><div className="text-xs font-semibold text-muted uppercase tracking-wide">- Idle timeout+ Shut down after</div><div className="text-xs text-muted">- Automatically stop after this period of inactivity.+ The kernel stops this long after it starts, even if you're still using it. A+ change applies the next time the kernel starts.</div></div><LemonSelectdiff --git a/products/notebooks/backend/presentation/views/notebook.py b/products/notebooks/backend/presentation/views/notebook.pyindex d7e82166fd37..5398d2923ab3 100644--- a/products/notebooks/backend/presentation/views/notebook.py+++ b/products/notebooks/backend/presentation/views/notebook.py@@ -1,7 +1,6 @@import mathimport hashlibfrom collections import Counter-from datetime import timedeltafrom typing import Any, castfrom django.conf import settings@@ -535,7 +534,11 @@ class NotebookKernelConfigSerializer(serializers.Serializer):required=False, help_text="Memory in GB for the notebook's sandbox kernel; must be a supported option.")idle_timeout_seconds = serializers.IntegerField(- required=False, help_text="Seconds of inactivity before the sandbox kernel shuts down."+ required=False,+ help_text=(+ "Maximum lifetime of the sandbox kernel in seconds. It shuts down this long after it starts, even while "+ "in use. A running kernel keeps its current lifetime until it restarts."+ ),)def validate_cpu_cores(self, value: float) -> float:@@ -550,7 +553,7 @@ class NotebookKernelConfigSerializer(serializers.Serializer):def validate_idle_timeout_seconds(self, value: int) -> int:if value not in ALLOWED_KERNEL_IDLE_TIMEOUT_SECONDS:- raise serializers.ValidationError("Idle timeout must be a supported option.")+ raise serializers.ValidationError("Lifetime must be a supported option.")return valuedef validate(self, attrs):@@ -1509,9 +1512,8 @@ class NotebookViewSet(TeamAndOrgViewSetMixin, AccessControlViewSetMixin, ForbidDif (runtime.backend == KernelRuntime.Backend.MODALand runtime.status in (KernelRuntime.Status.RUNNING, KernelRuntime.Status.STARTING)- and runtime.last_used_at- and sandbox_config.ttl_seconds- and now() >= runtime.last_used_at + timedelta(seconds=sandbox_config.ttl_seconds)+ and runtime.ttl_expires_at is not None+ and now() >= runtime.ttl_expires_at):status = KernelRuntime.Status.TIMED_OUTdiff --git a/products/notebooks/backend/sql_v2_serializers.py b/products/notebooks/backend/sql_v2_serializers.pyindex 2f741ad96bb1..ef5be869988d 100644--- a/products/notebooks/backend/sql_v2_serializers.py+++ b/products/notebooks/backend/sql_v2_serializers.py@@ -478,7 +478,9 @@ class NotebookKernelStateSerializer(serializers.Serializer):required=False, allow_null=True, help_text="Memory in GB the notebook's sandbox is configured with.")idle_timeout_seconds = serializers.IntegerField(- required=False, allow_null=True, help_text="Seconds of inactivity before the sandbox shuts down."+ required=False,+ allow_null=True,+ help_text="Maximum lifetime of the sandbox in seconds. It shuts down this long after it starts, even while in use.",)@@ -550,7 +552,9 @@ class NotebookKernelStatusResponseSerializer(serializers.Serializer):required=False, allow_null=True, help_text="Disk size in GB the sandbox is configured with.")idle_timeout_seconds = serializers.IntegerField(- required=False, allow_null=True, help_text="Seconds of inactivity before the sandbox shuts down."+ required=False,+ allow_null=True,+ help_text="Maximum lifetime of the sandbox in seconds. It shuts down this long after it starts, even while in use.",)hourly_price = serializers.FloatField(help_text=(@@ -593,7 +597,8 @@ class NotebookComputeOptionsResponseSerializer(serializers.Serializer):child=serializers.FloatField(), help_text="Memory sizes in GB the kernel config endpoint accepts.")allowed_idle_timeout_seconds = serializers.ListField(- child=serializers.IntegerField(), help_text="Idle timeouts in seconds the kernel config endpoint accepts."+ child=serializers.IntegerField(),+ help_text="Maximum sandbox lifetimes in seconds that the kernel config endpoint accepts.",)@@ -605,7 +610,9 @@ class NotebookKernelConfigResponseSerializer(serializers.Serializer):required=False, allow_null=True, help_text="Configured memory in GB; null means the default applies.")idle_timeout_seconds = serializers.IntegerField(- required=False, allow_null=True, help_text="Configured idle timeout in seconds; null means the default."+ required=False,+ allow_null=True,+ help_text="Configured maximum sandbox lifetime in seconds; null means the default.",)restarted = serializers.BooleanField(help_text=(diff --git a/products/notebooks/backend/test/test_compute_pricing.py b/products/notebooks/backend/test/test_compute_pricing.pyindex c44c0bde6fd3..044d83b4945f 100644--- a/products/notebooks/backend/test/test_compute_pricing.py+++ b/products/notebooks/backend/test/test_compute_pricing.py@@ -1,7 +1,10 @@+from datetime import timedelta+from posthog.test.base import APIBaseTestfrom unittest.mock import MagicMock, patchfrom django.test import SimpleTestCase+from django.utils import timezonefrom parameterized import parameterized@@ -16,6 +19,7 @@ from products.notebooks.backend.compute_pricing import ()from products.notebooks.backend.kernel_runtime import build_notebook_sandbox_configfrom products.notebooks.backend.models import KernelRuntime, Notebook+from products.tasks.backend.facade.sandbox import SandboxStatusclass TestComputePricing(SimpleTestCase):@@ -314,6 +318,30 @@ class TestComputeOptionsEndpoint(APIBaseTest):assert payload["hourly_price"] == get_compute_rates().hourly_price(cpu_cores=8, memory_gb=16)+ @parameterized.expand(+ [+ ("past_its_lifetime_right_after_use", -60, "timed_out"),+ ("stopped_before_its_lifetime", 1800, "stopped"),+ ]+ )+ @patch("products.notebooks.backend.presentation.views.notebook.get_kernel_runtime")+ def test_status_times_out_a_kernel_at_its_lifetime_not_after_its_last_use(+ self, _name: str, seconds_until_lifetime_ends: int, expected_status: str, mock_runtime: MagicMock+ ) -> None:+ notebook = Notebook.objects.create(team=self.team, created_by=self.user, kernel_cpu_cores=1, kernel_memory_gb=2)+ runtime = self._live_kernel(notebook)+ KernelRuntime.objects.filter(pk=runtime.pk).update(+ sandbox_id="sb-notebook-kernel",+ last_used_at=timezone.now(),+ ttl_expires_at=timezone.now() + timedelta(seconds=seconds_until_lifetime_ends),+ )+ sandbox_class = mock_runtime.return_value.service._get_sandbox_class.return_value+ sandbox_class.get_by_id.return_value.get_status.return_value = SandboxStatus.SHUTDOWN++ payload = self.client.get(f"/api/projects/{self.team.id}/notebooks/{notebook.short_id}/kernel/status/").json()++ assert payload["status"] == expected_status+@patch("products.notebooks.backend.presentation.views.notebook.start_sql_v2_run_workflow")@patch("products.notebooks.backend.presentation.views.notebook.is_sql_v2_enabled", return_value=True)@patch(diff --git a/products/notebooks/frontend/generated/api.schemas.ts b/products/notebooks/frontend/generated/api.schemas.tsindex 11629aea354b..ab48a7573327 100644--- a/products/notebooks/frontend/generated/api.schemas.ts+++ b/products/notebooks/frontend/generated/api.schemas.ts@@ -845,7 +845,7 @@ export interface NotebookKernelConfigApi {cpu_cores?: number/** Memory in GB for the notebook's sandbox kernel; must be a supported option. */memory_gb?: number- /** Seconds of inactivity before the sandbox kernel shuts down. */+ /** Maximum lifetime of the sandbox kernel in seconds. It shuts down this long after it starts, even while in use. A running kernel keeps its current lifetime until it restarts. */idle_timeout_seconds?: number}@@ -861,7 +861,7 @@ export interface NotebookKernelConfigResponseApi {*/memory_gb?: number | null/**- * Configured idle timeout in seconds; null means the default.+ * Configured maximum sandbox lifetime in seconds; null means the default.* @nullable*/idle_timeout_seconds?: number | null@@ -944,7 +944,7 @@ export interface NotebookKernelStatusResponseApi {*/disk_size_gb?: number | null/**- * Seconds of inactivity before the sandbox shuts down.+ * Maximum lifetime of the sandbox in seconds. It shuts down this long after it starts, even while in use.* @nullable*/idle_timeout_seconds?: number | null@@ -1114,7 +1114,7 @@ export interface NotebookKernelStateApi {*/memory_gb?: number | null/**- * Seconds of inactivity before the sandbox shuts down.+ * Maximum lifetime of the sandbox in seconds. It shuts down this long after it starts, even while in use.* @nullable*/idle_timeout_seconds?: number | null@@ -1368,7 +1368,7 @@ export interface NotebookComputeOptionsResponseApi {allowed_cpu_cores: number[]/** Memory sizes in GB the kernel config endpoint accepts. */allowed_memory_gb: number[]- /** Idle timeouts in seconds the kernel config endpoint accepts. */+ /** Maximum sandbox lifetimes in seconds that the kernel config endpoint accepts. */allowed_idle_timeout_seconds: number[]}diff --git a/products/notebooks/frontend/generated/api.zod.ts b/products/notebooks/frontend/generated/api.zod.tsindex 562394ef786c..d986024b0f25 100644--- a/products/notebooks/frontend/generated/api.zod.ts+++ b/products/notebooks/frontend/generated/api.zod.ts@@ -391,7 +391,9 @@ export const NotebooksKernelConfigCreateBody = /* @__PURE__ */ zod.object({idle_timeout_seconds: zod.number().optional()- .describe('Seconds of inactivity before the sandbox kernel shuts down.'),+ .describe(+ 'Maximum lifetime of the sandbox kernel in seconds. It shuts down this long after it starts, even while in use. A running kernel keeps its current lifetime until it restarts.'+ ),})/**diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex 2839163f53a1..57286f5e1174 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -54944,7 +54944,7 @@ export namespace Schemas {allowed_cpu_cores: number[];/** Memory sizes in GB the kernel config endpoint accepts. */allowed_memory_gb: number[];- /** Idle timeouts in seconds the kernel config endpoint accepts. */+ /** Maximum sandbox lifetimes in seconds that the kernel config endpoint accepts. */allowed_idle_timeout_seconds: number[];}@@ -54953,7 +54953,7 @@ export namespace Schemas {cpu_cores?: number;/** Memory in GB for the notebook's sandbox kernel; must be a supported option. */memory_gb?: number;- /** Seconds of inactivity before the sandbox kernel shuts down. */+ /** Maximum lifetime of the sandbox kernel in seconds. It shuts down this long after it starts, even while in use. A running kernel keeps its current lifetime until it restarts. */idle_timeout_seconds?: number;}@@ -54969,7 +54969,7 @@ export namespace Schemas {*/memory_gb?: number | null;/**- * Configured idle timeout in seconds; null means the default.+ * Configured maximum sandbox lifetime in seconds; null means the default.* @nullable*/idle_timeout_seconds?: number | null;@@ -55000,7 +55000,7 @@ export namespace Schemas {*/memory_gb?: number | null;/**- * Seconds of inactivity before the sandbox shuts down.+ * Maximum lifetime of the sandbox in seconds. It shuts down this long after it starts, even while in use.* @nullable*/idle_timeout_seconds?: number | null;@@ -55072,7 +55072,7 @@ export namespace Schemas {*/disk_size_gb?: number | null;/**- * Seconds of inactivity before the sandbox shuts down.+ * Maximum lifetime of the sandbox in seconds. It shuts down this long after it starts, even while in use.* @nullable*/idle_timeout_seconds?: number | null;diff --git a/services/mcp/src/generated/notebooks/api.ts b/services/mcp/src/generated/notebooks/api.tsindex fdb6f2cb3403..90662e83c0a7 100644--- a/services/mcp/src/generated/notebooks/api.ts+++ b/services/mcp/src/generated/notebooks/api.ts@@ -247,7 +247,9 @@ export const NotebooksKernelConfigCreateBody = () => zod.object({idle_timeout_seconds: zod.number().optional()- .describe('Seconds of inactivity before the sandbox kernel shuts down.'),+ .describe(+ 'Maximum lifetime of the sandbox kernel in seconds. It shuts down this long after it starts, even while in use. A running kernel keeps its current lifetime until it restarts.'+ ),})/**