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.

fix(tasks): keep the refresh claim on a failed custom image build (#114366)

Alessandro Pogliaghi15290b5d4dff
diff --git a/docs/internal/sandboxes-setup-guide.md b/docs/internal/sandboxes-setup-guide.md
index eed4b0b30db7..d74d64e0748d 100644
--- a/docs/internal/sandboxes-setup-guide.md
+++ b/docs/internal/sandboxes-setup-guide.md
@@ -407,6 +407,7 @@ Release reads use the configured GitHub App installation for `PostHog/posthog`,
The read-only page compares the published package, master version pin, registry platforms, custom-image bases, and the last recorded dev-stack bake.
Release evidence separates workflow status from image build and base promotion results, including skipped builds.
Select a custom image to inspect its latest Temporal execution. A failed refresh can leave a ready image on an older base.
+The refresh sweep retries that image only when the VM base digest changes again.
Missing or stale sources remain unverified. This view does not measure versions inside running sandboxes or reconstruct historical rollout completion.
The Data sources tab lists each source's status and last successful read in UTC. Registry coverage remains unverified when the release source is unavailable or stale.
Graph release badges compare observed versions with npm latest; cached observations say "Last seen". Select an image for its separate version-pin and base-lineage assessment.
diff --git a/products/tasks/backend/temporal/build_image/activities.py b/products/tasks/backend/temporal/build_image/activities.py
index b60ac033e84c..6952334b3803 100644
--- a/products/tasks/backend/temporal/build_image/activities.py
+++ b/products/tasks/backend/temporal/build_image/activities.py
@@ -410,7 +410,5 @@ def mark_image_build_failed(input: MarkImageBuildFailedInput) -> None:
else SandboxCustomImage.Status.BUILD_FAILED
)
image.error = input.error[:2000]
- if input.refresh:
- image.base_image_refresh_reference = None
- image.save(update_fields=["status", "error", "base_image_refresh_reference", "updated_at"])
+ image.save(update_fields=["status", "error", "updated_at"])
observe_custom_image_build("failed")
diff --git a/products/tasks/backend/tests/test_custom_image_refresh.py b/products/tasks/backend/tests/test_custom_image_refresh.py
index fc15d2301086..e519d2de33ed 100644
--- a/products/tasks/backend/tests/test_custom_image_refresh.py
+++ b/products/tasks/backend/tests/test_custom_image_refresh.py
@@ -75,23 +75,31 @@ class TestCustomImageRefresh(APIBaseTest):
assert stale.status == SandboxCustomImage.Status.READY
assert stale.base_image_refresh_reference is None
- def test_refresh_build_failure_remains_ready_and_can_retry(self) -> None:
+ @patch("products.tasks.backend.logic.services.custom_image_refresh.execute_build_sandbox_image_workflow")
+ @patch("products.tasks.backend.logic.services.custom_image_refresh.resolve_template_base_image_reference")
+ def test_refresh_build_failure_remains_ready_and_waits_for_next_base(self, mock_reference, mock_execute) -> None:
+ mock_reference.return_value = "ghcr.io/posthog/posthog-sandbox-vm@sha256:current"
stale = self._create_image(base_image_reference="ghcr.io/posthog/posthog-sandbox-vm@sha256:old")
- stale.status = SandboxCustomImage.Status.BUILDING
- stale.base_image_refresh_reference = "ghcr.io/posthog/posthog-sandbox-vm@sha256:current"
- stale.save(update_fields=["status", "base_image_refresh_reference"])
+ assert refresh_stale_sandbox_custom_images() == 1
activity_body = cast(Callable[[MarkImageBuildFailedInput], None], vars(mark_image_build_failed)["__wrapped__"])
activity_body(
MarkImageBuildFailedInput(
image_id=str(stale.id),
team_id=self.team.id,
- error="transient build failure",
+ error="repo setup failed",
refresh=True,
)
)
stale.refresh_from_db()
assert stale.status == SandboxCustomImage.Status.READY
- assert stale.error == "transient build failure"
- assert stale.base_image_refresh_reference is None
+ assert stale.error == "repo setup failed"
+ assert stale.base_image_refresh_reference == "ghcr.io/posthog/posthog-sandbox-vm@sha256:current"
+
+ assert refresh_stale_sandbox_custom_images() == 0
+ assert mock_execute.call_count == 1
+
+ mock_reference.return_value = "ghcr.io/posthog/posthog-sandbox-vm@sha256:next"
+ assert refresh_stale_sandbox_custom_images() == 1
+ assert mock_execute.call_count == 2