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(tasks): pluggable-memory golden for task boxes (bake + flag) (#105407)

Tom Owers0cfc503b8cff
diff --git a/.github/workflows/cd-tasks-golden-snapshot.yml b/.github/workflows/cd-tasks-golden-snapshot.yml
index a954985550d6..edfb91ad312b 100644
--- a/.github/workflows/cd-tasks-golden-snapshot.yml
+++ b/.github/workflows/cd-tasks-golden-snapshot.yml
@@ -51,6 +51,14 @@ on:
description: "PostHog ref/SHA to render the skills from (blank = this workflow's checkout ref, i.e. master on schedule)"
required: false
default: ''
+ box_mem_mib:
+ description: 'Total/cap memory (MiB) for the golden. Blank = 20480 (fixed-size default).'
+ required: false
+ default: ''
+ box_mem_boot_mib:
+ description: 'Boot memory (MiB) for a pluggable-memory golden — boots this small and hot-adds up to the cap. Blank = fixed-size golden (today).'
+ required: false
+ default: ''
schedule:
# Daily, minute offset off :00 — GitHub's scheduler is contended at the
# top of the hour and may drop those runs. No-op until armed (job `if`).
@@ -613,7 +621,11 @@ jobs:
SKILLS_TARBALL: ${{ env.SKILLS_TARBALL }}
AGENT_VERSION: ${{ steps.agent-version.outputs.version }}
BOX_CPUS: '4'
- BOX_MEM_MIB: '20480'
+ # Both blank on the schedule -> fixed-size 20 GiB golden, unchanged.
+ # A manual dispatch can bake a pluggable-memory golden (e.g. cap 32768
+ # + boot 4096) without touching the scheduled path.
+ BOX_MEM_MIB: ${{ inputs.box_mem_mib || '20480' }}
+ BOX_MEM_BOOT_MIB: ${{ inputs.box_mem_boot_mib || '' }}
BOX_DISK_GIB: '64'
run: |
set -euo pipefail
diff --git a/products/tasks/backend/constants.py b/products/tasks/backend/constants.py
index bec78bf4f1ff..1352d021ab9b 100644
--- a/products/tasks/backend/constants.py
+++ b/products/tasks/backend/constants.py
@@ -35,6 +35,7 @@ DEV_STACK_IMAGE_BAKE_FEATURE_FLAG = "tasks-dev-stack-image-bake"
MODAL_NETWORK_ALLOWLIST_FEATURE_FLAG = "tasks-modal-network-allowlist"
# Routes a plain default-template run onto the hogland (Firecracker) sandbox backend.
HOGLAND_SANDBOX_FEATURE_FLAG = "tasks-hogland-sandbox"
+HOGLAND_HOTPLUG_GOLDEN_FEATURE_FLAG = "tasks-hogland-hotplug-golden"
AGENT_RUN_OTEL_TELEMETRY_FEATURE_FLAG = "tasks-agent-run-otel-telemetry"
PI_CLOUD_RUNTIME_FEATURE_FLAG = "pi-harness"
REASONING_EFFORTS = model_catalog.REASONING_EFFORTS
diff --git a/products/tasks/backend/logic/services/hogland_sandbox.py b/products/tasks/backend/logic/services/hogland_sandbox.py
index 97985172f2be..a8cf5cffd98e 100644
--- a/products/tasks/backend/logic/services/hogland_sandbox.py
+++ b/products/tasks/backend/logic/services/hogland_sandbox.py
@@ -69,6 +69,13 @@ TEMPLATE_TO_SNAPSHOT_ALIAS: dict[SandboxTemplate, str] = {
SandboxTemplate.DEFAULT_BASE: "alias:posthog-tasks-default",
}
+# The pluggable-memory golden (baked by the tasks golden-snapshot workflow with a
+# BOX_MEM_BOOT_MIB below the cap). A box restored from it boots small and hot-adds guest
+# RAM up to the cap on demand. Selected per run by the tasks-hogland-hotplug-golden flag
+# (config.use_hotplug_golden); only the default template has a pluggable variant. The
+# alias must exist before the flag is enabled for a team.
+HOGLAND_HOTPLUG_SNAPSHOT_ALIAS = "alias:posthog-tasks-hotplug"
+
# The golden snapshot (baked in CI) pins this machine shape. A hogland
# restore must inherit-or-match it, so per-task overrides are ignored and the provisioned
# box is always this size. Keep in sync with the shape the CI golden bake boots at.
@@ -234,6 +241,12 @@ class HoglandSandbox(AgentServerLaunchMixin):
{"config_name": config.name, "template": config.template.value},
cause=RuntimeError(f"no hogland golden snapshot for template {config.template.value}"),
)
+ if config.use_hotplug_golden and config.template == SandboxTemplate.DEFAULT_BASE:
+ snapshot_alias = HOGLAND_HOTPLUG_SNAPSHOT_ALIAS
+ logger.info(
+ "Hogland run provisioning from the pluggable-memory golden",
+ extra={"config_name": config.name, "snapshot_alias": snapshot_alias},
+ )
if config.snapshot_id or config.snapshot_external_id:
# Backend resolution forces resume snapshots off for hogland runs; if an id
# slips through anyway, cold-boot loudly rather than restoring the wrong thing.
diff --git a/products/tasks/backend/logic/services/sandbox.py b/products/tasks/backend/logic/services/sandbox.py
index 4cd2c584b685..749ade2062f6 100644
--- a/products/tasks/backend/logic/services/sandbox.py
+++ b/products/tasks/backend/logic/services/sandbox.py
@@ -223,6 +223,10 @@ class SandboxConfig(BaseModel):
# surfaced in the run log so image downgrades are never silent.
image_fallback: str | None = None
dev_stack_present: bool | None = None
+ # Hogland only: provision from the pluggable-memory golden (boots small, hot-adds
+ # guest RAM up to the cap) instead of the fixed-size default golden. Set from the
+ # tasks-hogland-hotplug-golden flag at context time; ignored by other providers.
+ use_hotplug_golden: bool = False
@model_validator(mode="before")
@classmethod
diff --git a/products/tasks/backend/logic/services/tests/test_hogland_sandbox.py b/products/tasks/backend/logic/services/tests/test_hogland_sandbox.py
index ff50af35ab85..63e4394308e3 100644
--- a/products/tasks/backend/logic/services/tests/test_hogland_sandbox.py
+++ b/products/tasks/backend/logic/services/tests/test_hogland_sandbox.py
@@ -93,6 +93,17 @@ class TestHoglandSandboxCreate:
assert sandbox.id == "box-abc123def456"
assert config.snapshot_restored is False
+ @parameterized.expand(
+ [
+ ("fixed golden by default", False, "alias:posthog-tasks-default"),
+ ("pluggable golden when the flag is on", True, "alias:posthog-tasks-hotplug"),
+ ]
+ )
+ def test_create_selects_the_golden_by_hotplug_flag(self, _name, use_hotplug, expected_alias):
+ config = SandboxConfig(name="sandbox-task-1", use_hotplug_golden=use_hotplug)
+ _, client = self._create(config)
+ assert client.create.call_args.kwargs["snapshot_id"] == expected_alias
+
def test_create_bounds_tags_to_the_hogland_length_limit(self):
# Hogland rejects the whole create when any tag exceeds 64 characters, and a task
# workflow id is longer than that on its own.
diff --git a/products/tasks/backend/sandbox/images/hogland/bake-golden.sh b/products/tasks/backend/sandbox/images/hogland/bake-golden.sh
index 5f29ecdb571b..64d19032ef37 100755
--- a/products/tasks/backend/sandbox/images/hogland/bake-golden.sh
+++ b/products/tasks/backend/sandbox/images/hogland/bake-golden.sh
@@ -28,6 +28,9 @@
# Optional env:
# AGENT_VERSION — @posthog/agent version to install in-box (default: latest)
# BOX_CPUS / BOX_MEM_MIB / BOX_DISK_GIB — seed box shape (default 4 / 20480 / 64)
+# BOX_MEM_BOOT_MIB — boot memory (MiB) for a pluggable-memory golden: the box
+# boots this small and hot-adds guest RAM up to BOX_MEM_MIB on demand. Blank
+# (default) bakes a fixed-size golden at BOX_MEM_MIB.
#
# On success prints a single parseable line to stdout:
# BAKED_SNAPSHOT_ID=<id>
@@ -41,6 +44,7 @@ set -euo pipefail
AGENT_VERSION="${AGENT_VERSION:-latest}"
BOX_CPUS="${BOX_CPUS:-4}"
BOX_MEM_MIB="${BOX_MEM_MIB:-20480}"
+BOX_MEM_BOOT_MIB="${BOX_MEM_BOOT_MIB:-}"
BOX_DISK_GIB="${BOX_DISK_GIB:-64}"
log() { printf '[tasks-bake] %s\n' "$*" >&2; }
@@ -104,7 +108,16 @@ fi
# fix the snapshot's machine shape to the task sandbox shape. --no-connect keeps
# create non-interactive. --name gives teardown a handle that survives never
# learning the id.
-log "creating seed box (cold boot, $BOX_CPUS cpu / $BOX_MEM_MIB MiB / $BOX_DISK_GIB GiB)"
+# When BOX_MEM_BOOT_MIB is set (and below the cap), the box boots small and
+# hot-adds guest RAM up to BOX_MEM_MIB via virtio-mem; the golden snapshot pins
+# that geometry, so every restored task box inherits it. Blank => fixed-size.
+mem_boot_args=()
+if [[ -n "$BOX_MEM_BOOT_MIB" ]]; then
+ mem_boot_args+=(--memory-boot-mib "$BOX_MEM_BOOT_MIB")
+ log "creating seed box (cold boot, $BOX_CPUS cpu / boot ${BOX_MEM_BOOT_MIB}->cap $BOX_MEM_MIB MiB / $BOX_DISK_GIB GiB)"
+else
+ log "creating seed box (cold boot, $BOX_CPUS cpu / $BOX_MEM_MIB MiB / $BOX_DISK_GIB GiB)"
+fi
create_rc=0
# --kind posthog-tasks-golden: an UNREGISTERED kind carries no server-side idle
# TTL, so the box is never reaped mid-bake. A registered kind like `ci` expires
@@ -125,6 +138,7 @@ box_json=$(
--access-type ssh-private \
--cpus "$BOX_CPUS" \
--memory-mib "$BOX_MEM_MIB" \
+ ${mem_boot_args[@]+"${mem_boot_args[@]}"} \
--disk-gib "$BOX_DISK_GIB" \
--disk-mbps 0 \
--disk-iops 0 \
diff --git a/products/tasks/backend/temporal/process_task/activities/get_task_processing_context.py b/products/tasks/backend/temporal/process_task/activities/get_task_processing_context.py
index f3d7d642eb3b..8635e2b81e92 100644
--- a/products/tasks/backend/temporal/process_task/activities/get_task_processing_context.py
+++ b/products/tasks/backend/temporal/process_task/activities/get_task_processing_context.py
@@ -24,6 +24,7 @@ from products.tasks.backend.constants import (
DESKTOP_WORKSPACE_WARM_FEATURE_FLAG,
DEV_STACK_IMAGE_NAME,
DEV_STACK_PREVIEW_FEATURE_FLAG,
+ HOGLAND_HOTPLUG_GOLDEN_FEATURE_FLAG,
HOGLAND_SANDBOX_FEATURE_FLAG,
MODAL_NETWORK_ALLOWLIST_FEATURE_FLAG,
OVERLAP_CLONE_BOOT_FEATURE_FLAG,
@@ -162,6 +163,10 @@ class TaskProcessingContext:
# workflow start and persisted into TaskRun.state at provision time, so activities
# and out-of-band consumers route deterministically for the run's whole life.
sandbox_backend: str = "modal"
+ # When True (and sandbox_backend == "hogland"), provision from the pluggable-memory
+ # golden instead of the fixed-size default: the box boots small and hot-adds guest RAM
+ # up to the cap. Off by default; the pluggable golden must be baked before enabling.
+ use_hogland_hotplug_golden: bool = False
dev_stack_preview_enabled: bool = False
claude_model_access: Literal["posthog-gateway", "own-subscription"] = "posthog-gateway"
@@ -1517,6 +1522,29 @@ def get_task_processing_context(input: GetTaskProcessingContextInput) -> TaskPro
"debug",
f"sandbox_backend: {sandbox_backend} for this task run",
)
+ # Pluggable-memory golden: only meaningful on hogland, and org-scoped like the
+ # backend flag itself. Fails closed to the fixed-size golden on any error.
+ use_hogland_hotplug_golden = False
+ if sandbox_backend == "hogland":
+ try:
+ use_hogland_hotplug_golden = bool(
+ posthoganalytics.feature_enabled(
+ HOGLAND_HOTPLUG_GOLDEN_FEATURE_FLAG,
+ distinct_id=distinct_id,
+ groups={"organization": organization_id},
+ group_properties={"organization": {"id": organization_id}},
+ only_evaluate_locally=False,
+ send_feature_flag_events=False,
+ )
+ )
+ except Exception as e:
+ log_with_activity_context("hogland_hotplug_golden_flag_check_failed", run_id=run_id, error=str(e))
+ use_hogland_hotplug_golden = False
+ emit_agent_log(
+ run_id,
+ "debug",
+ f"use_hogland_hotplug_golden: {use_hogland_hotplug_golden} for this task run",
+ )
dev_stack_preview_enabled = _is_dev_stack_preview_enabled(
distinct_id=distinct_id,
@@ -1591,6 +1619,7 @@ def get_task_processing_context(input: GetTaskProcessingContextInput) -> TaskPro
use_modal_vm_sandbox=use_modal_vm_sandbox,
use_modal_network_allowlist=use_modal_network_allowlist,
burstable_sandbox_resources_enabled=burstable_sandbox_resources_enabled,
+ use_hogland_hotplug_golden=use_hogland_hotplug_golden,
overlap_clone_boot_enabled=overlap_clone_boot_enabled,
desktop_workspace_warm_enabled=desktop_workspace_warm_enabled,
agent_proxy_keep_stream_open=agent_proxy_keep_stream_open,
diff --git a/products/tasks/backend/temporal/process_task/activities/provision_sandbox.py b/products/tasks/backend/temporal/process_task/activities/provision_sandbox.py
index 62b227e69007..52e93070652b 100644
--- a/products/tasks/backend/temporal/process_task/activities/provision_sandbox.py
+++ b/products/tasks/backend/temporal/process_task/activities/provision_sandbox.py
@@ -843,6 +843,7 @@ def _create_sandbox_for_repository(input: CreateSandboxForRepositoryInput) -> Cr
snapshot_source=prepared.snapshot_source,
metadata=_build_sandbox_tags(ctx, prepared, use_vm_sandbox),
vm_runtime=use_vm_sandbox,
+ use_hotplug_golden=ctx.use_hogland_hotplug_golden,
**resource_overrides,
)