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(workflows): accept issued invocation ids when cancelling runs (#96235)

posthog[bot]f18e93bf43e0
diff --git a/nodejs/src/cdp/cdp-api.serial.test.ts b/nodejs/src/cdp/cdp-api.serial.test.ts
index dbfde2796c0d..106beb34a79a 100644
--- a/nodejs/src/cdp/cdp-api.serial.test.ts
+++ b/nodejs/src/cdp/cdp-api.serial.test.ts
@@ -2083,6 +2083,26 @@ describe('CDP API', () => {
)
})
+ // A version-aware id check rejects every id the runs list hands the Cancel action,
+ // because the invocation store issues UUIDTs. Only the shape must hold, to keep a
+ // malformed id away from cancelJobs' ::uuid[] bind.
+ it.each([
+ ['ids the invocation store issues', [new UUIDT().toString(), new UUIDT().toString()], 200],
+ ['an id that is not UUID-shaped', ['not-a-uuid'], 400],
+ ])('cancelling by %s', async (_desc, invocationIds, expectedStatus) => {
+ const res = await supertest(app)
+ .post(`/api/projects/${team.id}/hog_flows/${cancelFlowId}/invocations/cancel`)
+ .set(cancelAuth(team.id, cancelFlowId))
+ .send({ invocation_ids: invocationIds })
+
+ expect(res.status).toEqual(expectedStatus)
+ if (expectedStatus === 200) {
+ expect(mockCancelJobs).toHaveBeenCalledWith(expect.objectContaining({ jobIds: invocationIds }))
+ } else {
+ expect(mockCancelJobs).not.toHaveBeenCalled()
+ }
+ })
+
it.each([
['no token', () => ({})],
[
diff --git a/nodejs/src/cdp/cdp-api.ts b/nodejs/src/cdp/cdp-api.ts
index 533d87a12d44..771fba5000f4 100644
--- a/nodejs/src/cdp/cdp-api.ts
+++ b/nodejs/src/cdp/cdp-api.ts
@@ -1263,7 +1263,9 @@ export class CdpApi {
// request to this flow id, and cancelJobs filters on (team_id, function_id).
// UUID-shaped ids only: cancelJobs binds them as ::uuid[], so a malformed id must be a
- // 400 here rather than a Postgres cast error surfaced as a 500. The cap is the same
+ // 400 here rather than a Postgres cast error surfaced as a 500. Match the shape only:
+ // invocation ids are UUIDTs, whose version and variant nibbles carry a series counter
+ // and random bytes, so a version-aware check rejects every real id. The cap is the same
// env-driven one the Django cancel serializer validates against, so raising the env
// var lifts both sides together instead of leaving Django accepting ids this route
// then rejects with a 400 (which Django surfaces as a 500).
@@ -1272,7 +1274,7 @@ export class CdpApi {
const parsed = z
.object({
invocation_ids: z
- .array(z.string().uuid(idsMessage))
+ .array(z.string().refine((id) => UUID.validateString(id, false), idsMessage))
.min(1, idsMessage)
.max(maxInvocationIds, idsMessage)
.optional(),
diff --git a/products/workflows/backend/api/test/test_hog_flow_cancel.py b/products/workflows/backend/api/test/test_hog_flow_cancel.py
index 735b639c8b96..7abab51e6da6 100644
--- a/products/workflows/backend/api/test/test_hog_flow_cancel.py
+++ b/products/workflows/backend/api/test/test_hog_flow_cancel.py
@@ -6,6 +6,8 @@ from unittest.mock import MagicMock, patch
from parameterized import parameterized
from rest_framework import status
+from posthog.uuidt import UUIDT
+
from products.workflows.backend.models.hog_flow.hog_flow import HogFlow
from products.workflows.backend.models.hog_flow_batch_job import HogFlowBatchJob
@@ -32,8 +34,15 @@ class TestHogFlowCancelInvocations(APIBaseTest):
format="json",
)
- def test_cancel_by_ids_proxies_with_team_and_flow_pinned(self):
- invocation_id = str(uuid.uuid4())
+ @parameterized.expand(
+ [
+ # The invocation store issues UUIDTs, which carry no RFC version. Cancel must forward
+ # such an id untouched, so a version-aware check here would reject every real run.
+ ("issued_invocation_id", str(UUIDT())),
+ ("rfc_uuid", str(uuid.uuid4())),
+ ]
+ )
+ def test_cancel_by_ids_proxies_with_team_and_flow_pinned(self, _name, invocation_id):
with patch(CANCEL_PROXY, return_value=_cdp_response()) as mock_cancel:
response = self._cancel({"invocation_ids": [invocation_id]})