Skip to content

fix(previews): fence stale hogbox teardown - #71052

Merged
webjunkie merged 5 commits into
masterfrom
posthog-code/fix-hogbox-preview-teardown
Jul 15, 2026
Merged

fix(previews): fence stale hogbox teardown#71052
webjunkie merged 5 commits into
masterfrom
posthog-code/fix-hogbox-preview-teardown

Conversation

@webjunkie

Copy link
Copy Markdown
Contributor

Problem

A cancelled preview workflow can complete after a newer workflow for the same PR has repointed its preview pen. Name-based cleanup then risks deleting the replacement preview.

Changes

  • Stop sweeping boxes by shared preview name during provision and teardown.
  • Read the pen and delete it only when it still points to the observed box.
  • Use the Hogland conditional-delete API from Hogland #379, which returns a conflict when a newer workflow has taken ownership.

Warning

Deploy the Hogland API change before this workflow change. The safety fence is enforced server-side.

How did you test this code?

I used Codex to run ruff format and ruff check on tools/hogbox-preview/hogbox_preview/hogland_backend.py.

The commit hook also ran Python linting, formatting, and ty check successfully. I did not add tests in this repository; the behavior is exercised by the accompanying Hogland API and SDK regression tests.

👉 Stay up-to-date with PostHog coding conventions for a smoother review.

Automatic notifications

  • Publish to changelog?
  • Alert Sales and Marketing teams?

Docs update

No PostHog documentation update is needed. The Hogland API and SDK documentation is updated in the linked server PR.

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

I used Codex CLI. No repository skills were invoked. I removed client-side cross-run deletion rather than trying to make name matching more selective, because the stable pen pointer is the authoritative ownership boundary. The workflow remains compatible with its currently pinned SDK by issuing the fenced request directly.


Created with PostHog Code

Generated-By: PostHog Code
Task-Id: 8603304a-c1cf-4544-b309-b1dc1a767ce7
@webjunkie webjunkie self-assigned this Jul 15, 2026
@webjunkie
webjunkie marked this pull request as ready for review July 15, 2026 12:42
Copilot AI review requested due to automatic review settings July 15, 2026 12:42
chatgpt-codex-connector[bot]

This comment was marked as outdated.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens the hogbox preview teardown path against race conditions where an older/cancelled workflow run can “win” cleanup after a newer run has already repointed the same preview pen, risking deletion of the replacement preview.

Changes:

  • Removes name-based sweeping of boxes during provisioning/teardown to avoid cross-run deletion.
  • Switches teardown to a fenced (conditional) pen delete via Hogland’s expected_current_box_id mechanism.
  • Adds a direct HTTP call path (URL-quoted pen name + raise_for_status) to support the fence before the workflow’s pinned SDK is updated.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tools/hogbox-preview/hogbox_preview/hogland_backend.py
Comment thread tools/hogbox-preview/hogbox_preview/hogland_backend.py
@trunk-io

trunk-io Bot commented Jul 15, 2026

Copy link
Copy Markdown

Static BadgeStatic BadgeStatic BadgeStatic Badge

View Full Report ↗︎Docs

Treat an explicit box id as invocation-owned when a pen is already gone, and
skip unsafe conditional cleanup when a name-only pen has no current box.

Generated-By: PostHog Code
Task-Id: 8603304a-c1cf-4544-b309-b1dc1a767ce7

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cb2e8260b4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tools/hogbox-preview/hogbox_preview/hogland_backend.py
Comment thread tools/hogbox-preview/hogbox_preview/hogland_backend.py
Delete invocation-owned explicit boxes after a pen conflict and remove empty
pens during authoritative name-only teardown.

Generated-By: PostHog Code
Task-Id: 8603304a-c1cf-4544-b309-b1dc1a767ce7

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cbb0c115c3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tools/hogbox-preview/hogbox_preview/hogland_backend.py
@webjunkie webjunkie added the stamphog Request AI approval (no full review) label Jul 15, 2026

@stamphog stamphog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preview-environment teardown tooling with a real race-condition fix; every substantive concern raised by Codex/Copilot across several rounds was addressed with a matching code change (verified in the diff), and the author has STRONG familiarity with this exact file, giving independent assurance for this CI-adjacent tooling change.

  • Author wrote 100% of the modified lines and has 6 merged PRs in these paths (familiarity STRONG).
  • chatgpt-codex-connector[bot] reviewed the current head.
  • Fenced delete for the name-only teardown path reads the pen and immediately reuses its current_box_id as the expected value, which only protects the GET→DELETE window rather than a wider race — acceptable per the author's design rationale since production callers only invoke name-only teardown from PR-closed/label-removed/stale-sweep flows serialized by a per-PR concurrency group, but worth a human's eyes given no test exercises this happy-path branch.
  • Uses private hogland SDK internals (_http.delete, hogland._http.raise_for_status) as a stopgap until the pinned SDK version is bumped; disclosed in the PR description along with an explicit warning that the companion Hogland API change must be deployed first — an operational sequencing risk outside this diff's control.
Gate mechanics and policy version
Gate Result
prerequisites all clear
deny-list no deny categories matched
size 109L, 1F substantive, 289L/2F incl. docs/generated/snapshots — within ceiling
tier T1-agent / T1c-medium (289L, 2F, single-area, fix)
stamphog 2.0.0b3 .stamphog/policy.yml @ 8823c9e · reviewed head cbb0c11

@webjunkie
webjunkie merged commit 90ad2ce into master Jul 15, 2026
256 checks passed
@webjunkie
webjunkie deleted the posthog-code/fix-hogbox-preview-teardown branch July 15, 2026 14:01
@deployment-status-posthog

deployment-status-posthog Bot commented Jul 15, 2026

Copy link
Copy Markdown

Deploy status

Environment Status Deployed At Workflow
dev ✅ Deployed 2026-07-15 14:33 UTC Run
prod-us ✅ Deployed 2026-07-15 15:01 UTC Run
prod-eu ✅ Deployed 2026-07-15 15:01 UTC Run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stamphog Request AI approval (no full review)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants