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(workflows): remove polling and park waits for their whole duration (#101604)

Daniel Marchuk2bd852db6f4a
diff --git a/nodejs/src/cdp/services/hogflows/actions/conditional_branch.test.ts b/nodejs/src/cdp/services/hogflows/actions/conditional_branch.test.ts
index bfabeeda7baa..cd248eab6ffa 100644
--- a/nodejs/src/cdp/services/hogflows/actions/conditional_branch.test.ts
+++ b/nodejs/src/cdp/services/hogflows/actions/conditional_branch.test.ts
@@ -13,14 +13,18 @@ import {
ConditionalBranchHandler,
checkConditions,
counterHogflowRekeyWake,
- counterHogflowWaitPollOnlyAdvance,
+ counterHogflowWaitAdvancedAtMaxWait,
+ counterHogflowWaitPersonRefreshFailed,
} from './conditional_branch'
-const pollOnlyAdvanceCount = async (): Promise<number> =>
- (await counterHogflowWaitPollOnlyAdvance.get()).values[0]?.value ?? 0
+const lateAdvanceCount = async (): Promise<number> =>
+ (await counterHogflowWaitAdvancedAtMaxWait.get()).values[0]?.value ?? 0
-const pollOnlyAdvanceLabels = async (): Promise<Record<string, string | number> | undefined> =>
- (await counterHogflowWaitPollOnlyAdvance.get()).values[0]?.labels
+const lateAdvanceLabels = async (): Promise<Record<string, string | number> | undefined> =>
+ (await counterHogflowWaitAdvancedAtMaxWait.get()).values[0]?.labels
+
+const personRefreshFailedCount = async (): Promise<number> =>
+ (await counterHogflowWaitPersonRefreshFailed.get()).values[0]?.value ?? 0
const rekeyWakeCount = async (outcome: 'advanced' | 'reparked'): Promise<number> =>
(await counterHogflowRekeyWake.get()).values.find((v) => v.labels.outcome === outcome)?.value ?? 0
@@ -96,14 +100,14 @@ describe('action.conditional_branch', () => {
// A wait arrives here already normalised into a conditional_branch, so its ceiling comes in
// as `repark` rather than off the action. A branch without one never parks.
describe('wait logic', () => {
- const repark = (maxWaitDuration: string) => ({ maxWaitDuration, recheckSeconds: 60 * 60 })
+ const repark = (maxWaitDuration: string) => ({ maxWaitDuration })
- it('should cap the next check at the backstop', async () => {
+ it('should park for the whole ceiling', async () => {
const result = await checkConditions(invocation, action, undefined, repark('2h'))
- expect(result).toEqual({ scheduledAt: DateTime.utc().plus({ hours: 1 }) })
+ expect(result).toEqual({ scheduledAt: DateTime.utc().plus({ hours: 2 }) })
})
- it('should not schedule for later than the max wait duration', async () => {
+ it('should park a short ceiling for its own duration', async () => {
const result = await checkConditions(invocation, action, undefined, repark('5m'))
expect(result).toEqual({ scheduledAt: DateTime.utc().plus({ minutes: 5 }) })
})
@@ -328,6 +332,12 @@ describe('action.conditional_branch', () => {
type: 'branch',
index: 0,
},
+ // The timeout edge, so a wait that reaches its ceiling unmatched has somewhere to go.
+ {
+ from: 'wait_until_condition',
+ to: 'matched_target',
+ type: 'continue',
+ },
],
})
.build()
@@ -342,8 +352,9 @@ describe('action.conditional_branch', () => {
getMemberCohortIds: () => Promise.resolve([]),
}
handler = new ConditionalBranchHandler(stubCohortMembershipRepository)
- counterHogflowWaitPollOnlyAdvance.reset()
+ counterHogflowWaitAdvancedAtMaxWait.reset()
counterHogflowRekeyWake.reset()
+ counterHogflowWaitPersonRefreshFailed.reset()
})
it('evaluates a first wait against the refreshed person, on the invocation and the result alike', async () => {
@@ -378,19 +389,23 @@ describe('action.conditional_branch', () => {
expect(waitInvocation.filterGlobals.person).not.toBeNull()
})
- it('keeps the cached person on a re-check of a wait that already parked', async () => {
- const refreshPerson = jest.fn().mockResolvedValue(undefined)
- waitInvocation.refreshPerson = refreshPerson
- // Set once the wait parks; its re-checks run an hour apart, by when the cache expired.
- waitInvocation.state.currentAction!.pollReparked = true
+ it('keeps the person it already had when the refresh fails, and stays parked', async () => {
+ // A failed read must not reach the executor's error handling: that follows the continue
+ // edge, which for a wait is the timeout edge, so the run would leave the wait early.
+ const before = waitInvocation.person
+ waitInvocation.refreshPerson = jest.fn().mockRejectedValue(new Error('person read failed'))
+ const result = createInvocationResult<CyclotronJobInvocationHogFlow>(waitInvocation)
- await handler.execute({
+ const handlerResult = await handler.execute({
invocation: waitInvocation,
action: waitAction,
- result: createInvocationResult(waitInvocation),
+ result,
})
- expect(refreshPerson).not.toHaveBeenCalled()
+ expect(handlerResult.scheduledAt).toEqual(DateTime.utc().plus({ minutes: 10 }))
+ expect(handlerResult.nextAction).toBeUndefined()
+ expect(waitInvocation.person).toEqual(before)
+ expect(await personRefreshFailedCount()).toBe(1)
})
it('advances to the matched branch and clears eventMatched', async () => {
@@ -439,9 +454,8 @@ describe('action.conditional_branch', () => {
expect(result.nextAction).toBeUndefined()
})
- it('re-parks a wait_until_condition on the hourly cap (backstop retained)', async () => {
- // The re-check is kept as a reconciliation backstop, so a wait longer than an hour parks
- // for an hour at a time rather than for its full duration.
+ it('parks a wait for its whole max_wait_duration, with no periodic re-check', async () => {
+ // The matcher is the only thing that wakes a wait, so it parks once rather than on a timer.
waitAction.config.max_wait_duration = '4h'
const result = await handler.execute({
@@ -450,12 +464,10 @@ describe('action.conditional_branch', () => {
result: createInvocationResult(waitInvocation),
})
- expect(result.scheduledAt).toEqual(DateTime.utc().plus({ hours: 1 }))
+ expect(result.scheduledAt).toEqual(DateTime.utc().plus({ hours: 4 }))
})
- it('parks a wait shorter than the backstop for its own duration', async () => {
- // The cap only shortens a park; a 30-minute wait must still resolve at 30 minutes rather
- // than being stretched to the hourly re-check.
+ it('parks a short wait for its own duration too', async () => {
waitAction.config.max_wait_duration = '30m'
const result = await handler.execute({
@@ -467,31 +479,18 @@ describe('action.conditional_branch', () => {
expect(result.scheduledAt).toEqual(DateTime.utc().plus({ minutes: 30 }))
})
- it('marks the wait as re-parked when its condition does not match', async () => {
- // The default condition does not match, so the wait re-parks and records that it has
- // polled at least once — without counting a poll-only advance.
- const result = await handler.execute({
- invocation: waitInvocation,
- action: waitAction,
- result: createInvocationResult(waitInvocation),
- })
-
- expect(result.scheduledAt).toBeDefined()
- expect(waitInvocation.state.currentAction!.pollReparked).toBe(true)
- expect(await pollOnlyAdvanceCount()).toBe(0)
- })
-
- it('counts a poll-only advance when a re-parked wait matches on a later re-check', async () => {
- // Evaluable event-name filter that matches the example invocation's `test` event.
+ it('counts a wait whose condition only matched once max_wait_duration elapsed', async () => {
+ // Nothing re-checks a wait any more, so a match at the ceiling means the condition became
+ // true earlier and no stream woke the run. That is the signal that replaces the poll.
waitAction.config.condition = {
filters: {
bytecode: ['_H', 1, 32, 'test', 32, 'event', 1, 1, 11],
events: [{ id: 'test', name: 'test', type: 'events', order: 0 }],
},
}
- // The wait already re-parked at least once and the matcher did not wake it: the periodic
- // re-check is what found the condition true.
- waitInvocation.state.currentAction!.pollReparked = true
+ waitInvocation.state.currentAction!.startedAtTimestamp = DateTime.utc().minus({ hours: 5 }).toMillis()
+ waitInvocation.state.currentAction!.parkedMaxWaitDuration = '4h'
+ waitAction.config.max_wait_duration = '4h'
const result = await handler.execute({
invocation: waitInvocation,
@@ -500,23 +499,24 @@ describe('action.conditional_branch', () => {
})
expect(result.nextAction).toEqual(findActionById(waitInvocation.hogFlow, 'matched_target'))
- expect(await pollOnlyAdvanceCount()).toBe(1)
+ expect(await lateAdvanceCount()).toBe(1)
// Must name the flow, not the run: attributing the residual is the counter's whole job.
- expect(await pollOnlyAdvanceLabels()).toEqual({
+ expect(await lateAdvanceLabels()).toEqual({
team_id: waitInvocation.hogFlow.team_id,
hog_flow_id: waitInvocation.hogFlow.id,
})
})
- it('does not count an evaluate-on-entry match (the wait never re-parked)', async () => {
- // Evaluable event-name filter that matches the example invocation's `test` event.
+ it('does not count a wait that matched before its ceiling', async () => {
+ // The ordinary case: a stream woke the run, or it matched on entry, well inside max_wait.
waitAction.config.condition = {
filters: {
bytecode: ['_H', 1, 32, 'test', 32, 'event', 1, 1, 11],
events: [{ id: 'test', name: 'test', type: 'events', order: 0 }],
},
}
- // pollReparked is unset: the condition was already true on entry, which polling did not catch.
+ waitInvocation.state.currentAction!.startedAtTimestamp = DateTime.utc().minus({ minutes: 5 }).toMillis()
+ waitAction.config.max_wait_duration = '4h'
const result = await handler.execute({
invocation: waitInvocation,
@@ -525,32 +525,22 @@ describe('action.conditional_branch', () => {
})
expect(result.nextAction).toEqual(findActionById(waitInvocation.hogFlow, 'matched_target'))
- expect(await pollOnlyAdvanceCount()).toBe(0)
+ expect(await lateAdvanceCount()).toBe(0)
})
- it('does not count a matcher (eventMatched) wake as poll-only', async () => {
- waitInvocation.state.currentAction!.pollReparked = true
- waitInvocation.state.currentAction!.eventMatched = true
-
- await handler.execute({
- invocation: waitInvocation,
- action: waitAction,
- result: createInvocationResult(waitInvocation),
- })
-
- expect(await pollOnlyAdvanceCount()).toBe(0)
- })
-
- // A matcher wake reaches here without eventMatched, so before this both read as poll advances.
- it.each(['rekeyWake', 'anchorWake'] as const)('does not count a %s matcher wake as poll-only', async (flag) => {
+ it('does not count a match woken by a sweep after the ceiling was shortened', async () => {
+ // The timing sweep moves `scheduled` with a bulk UPDATE and stamps no marker, so a run
+ // parked against a ceiling the author later cut wakes past the new one. That is an edit
+ // landing, not a wake the streams missed.
waitAction.config.condition = {
filters: {
bytecode: ['_H', 1, 32, 'test', 32, 'event', 1, 1, 11],
events: [{ id: 'test', name: 'test', type: 'events', order: 0 }],
},
}
- waitInvocation.state.currentAction!.pollReparked = true
- waitInvocation.state.currentAction![flag] = true
+ waitInvocation.state.currentAction!.startedAtTimestamp = DateTime.utc().minus({ hours: 5 }).toMillis()
+ waitInvocation.state.currentAction!.parkedMaxWaitDuration = '7d'
+ waitAction.config.max_wait_duration = '4h'
const result = await handler.execute({
invocation: waitInvocation,
@@ -559,8 +549,21 @@ describe('action.conditional_branch', () => {
})
expect(result.nextAction).toEqual(findActionById(waitInvocation.hogFlow, 'matched_target'))
- expect(await pollOnlyAdvanceCount()).toBe(0)
- expect(waitInvocation.state.currentAction![flag]).toBe(false)
+ expect(await lateAdvanceCount()).toBe(0)
+ })
+
+ it('does not count a timeout, which takes the continue edge rather than matching', async () => {
+ // The default condition never matches, so reaching the ceiling is an ordinary timeout.
+ waitInvocation.state.currentAction!.startedAtTimestamp = DateTime.utc().minus({ hours: 5 }).toMillis()
+ waitAction.config.max_wait_duration = '4h'
+
+ await handler.execute({
+ invocation: waitInvocation,
+ action: waitAction,
+ result: createInvocationResult(waitInvocation),
+ })
+
+ expect(await lateAdvanceCount()).toBe(0)
})
it('records a rekey wake as advanced and consumes the one-shot flag when the merge makes the condition match', async () => {
diff --git a/nodejs/src/cdp/services/hogflows/actions/conditional_branch.ts b/nodejs/src/cdp/services/hogflows/actions/conditional_branch.ts
index 77dc805af7e6..6691bd658b02 100644
--- a/nodejs/src/cdp/services/hogflows/actions/conditional_branch.ts
+++ b/nodejs/src/cdp/services/hogflows/actions/conditional_branch.ts
@@ -10,21 +10,27 @@ import { findContinueAction, findNextAction, isEvaluableCondition } from '../hog
import { ActionHandler, ActionHandlerOptions, ActionHandlerResult } from './action.interface'
import { calculatedScheduledAt } from './delay'
-// A wait is woken by the matcher on a matching signal, so its re-check only has to reconcile a wake
-// lost between the condition being evaluated and the job being persisted.
-const WAIT_RECHECK_SECONDS = 60 * 60
-
-// Increments only when the periodic re-check advances a wait_until_condition that the subscription
-// matcher did NOT wake (and not an evaluate-on-entry match). It measures how often the backstop is
-// the only thing that moved a run, which is the rate of wakes the streams lost.
-// Labelled by team and flow so a non-zero reading names the workflow still leaning on the poll; a
-// series only exists for flows that actually poll-advance, so cardinality tracks incidence.
-export const counterHogflowWaitPollOnlyAdvance = new Counter({
- name: 'cdp_hogflow_wait_poll_only_advance',
- help: 'wait_until_condition advanced via the polling re-check, not the subscription matcher — a wake the streams missed.',
+// A wait parks for its whole max_wait_duration: the subscription matcher wakes it when a matching
+// event, person update or internal event arrives, so nothing has to re-check it on a timer.
+//
+// Increments when a wait's condition only matched once that ceiling arrived. The condition was
+// therefore true earlier and no stream woke the run, so this counts wakes the matcher lost. A
+// condition turning true in the same second as the ceiling is a coincidence, so a sustained
+// non-zero reading names a workflow whose wakes are going missing.
+export const counterHogflowWaitAdvancedAtMaxWait = new Counter({
+ name: 'cdp_hogflow_wait_advanced_at_max_wait',
+ help: 'wait_until_condition that only matched once max_wait_duration elapsed — a wake the streams missed.',
labelNames: ['team_id', 'hog_flow_id'],
})
+// A person re-read that failed, so the wait evaluated against the person the dequeue read. Kept as
+// a counter because swallowing the failure is what stops it from ending the wait early, and a
+// sustained non-zero reading means waits are routing on person data that is older than they expect.
+export const counterHogflowWaitPersonRefreshFailed = new Counter({
+ name: 'cdp_hogflow_wait_person_refresh_failed',
+ help: 'wait_until_condition evaluations whose person re-read failed, falling back to the dequeue read.',
+})
+
// Outcome of a wait_until_condition re-check that ran because a person merge re-keyed the parked job
// onto the survivor and woke it (scheduled=now). 'advanced' = the merge made the condition match;
// 'reparked' = it didn't, so waking was wasted churn. A high reparked:advanced ratio means the wake
@@ -75,11 +81,16 @@ export class ConditionalBranchHandler implements ActionHandler {
// The person the worker read at dequeue can predate a write this wait is waiting for, and a
// wait that parks on that read is stuck: the write already happened, so no person message
- // follows to wake it. Re-read before the first evaluation of each wait — including a wait
- // reached later in the same dequeue. Re-checks of a wait that already parked run an hour
- // apart, by when the cache has expired, so they keep the cheaper read.
- if (action.type === 'wait_until_condition' && !invocation.state?.currentAction?.pollReparked) {
- const refreshed = await invocation.refreshPerson?.()
+ // follows to wake it. Re-read before every evaluation of a wait: on entry, and on each
+ // matcher wake, where the person the wake refers to is the point of the re-check.
+ if (action.type === 'wait_until_condition') {
+ const refreshed = await invocation.refreshPerson?.().catch(() => {
+ // A read that throws keeps the dequeue's person as well. Letting it reach the
+ // executor's error handling would follow the continue edge, which for a wait is the
+ // timeout edge, so one failed read would end a multi-day wait early.
+ counterHogflowWaitPersonRefreshFailed.inc()
+ return undefined
+ })
// A refresh that finds no person keeps the dequeue's read. The refresh exists to make a
// just-written property visible, not to drop a person: a lookup that comes back empty
// (replica lag, a transient miss) would otherwise evaluate the condition against nothing.
@@ -112,27 +123,20 @@ export class ConditionalBranchHandler implements ActionHandler {
conditionalAction,
this.createMemberCohortIdsLoader(invocation),
action.type === 'wait_until_condition' && action.config.max_wait_duration
- ? { maxWaitDuration: action.config.max_wait_duration, recheckSeconds: WAIT_RECHECK_SECONDS }
+ ? { maxWaitDuration: action.config.max_wait_duration }
: undefined
)
const isWait = action.type === 'wait_until_condition'
if (conditionResult.scheduledAt) {
- // Record that this wait has re-parked at least once, so a later condition match is
- // attributable to the polling re-check rather than an evaluate-on-entry match.
- if (isWait && invocation.state.currentAction) {
- invocation.state.currentAction.pollReparked = true
- }
if (rekeyWoken) {
counterHogflowRekeyWake.labels('reparked').inc()
}
return { scheduledAt: conditionResult.scheduledAt, result: { conditionResult } }
} else if (conditionResult.nextAction) {
- // Poll-only advance: a wait matched on a re-check that no matcher wake caused, and not on
- // entry. Re-key and anchor wakes arrive without eventMatched, so both must be excluded.
- if (isWait && !rekeyWoken && !anchorWoken && invocation.state.currentAction?.pollReparked === true) {
- counterHogflowWaitPollOnlyAdvance
+ if (isWait && !rekeyWoken && !anchorWoken && matchedAtMaxWait(invocation, action)) {
+ counterHogflowWaitAdvancedAtMaxWait
.labels({ team_id: invocation.hogFlow.team_id, hog_flow_id: invocation.hogFlow.id })
.inc()
}
@@ -184,13 +188,38 @@ function conditionReferencesCohorts(condition: { filters?: unknown }): boolean {
)
}
+// True when this wait is being evaluated at or past the max_wait_duration it parked against.
+// calculatedScheduledAt returns null once that instant has passed, which is the same test the
+// timeout path uses. A wait that never parked, or that parked against a ceiling the flow has since
+// changed, reads false: neither is a wake the streams missed.
+function matchedAtMaxWait(
+ invocation: CyclotronJobInvocationHogFlow,
+ action: Extract<HogFlowAction, { type: 'conditional_branch' | 'wait_until_condition' }>
+): boolean {
+ const startedAtTimestamp = invocation.state.currentAction?.startedAtTimestamp
+ const maxWait = action.type === 'wait_until_condition' ? action.config.max_wait_duration : undefined
+ if (!startedAtTimestamp || !maxWait) {
+ return false
+ }
+ if (invocation.state.currentAction?.parkedMaxWaitDuration !== maxWait) {
+ return false
+ }
+ try {
+ return calculatedScheduledAt(maxWait, startedAtTimestamp) === null
+ } catch {
+ // An unreadable duration is the timeout path's problem, not this counter's.
+ return false
+ }
+}
+
export async function checkConditions(
invocation: CyclotronJobInvocationHogFlow,
action: Extract<HogFlowAction, { type: 'conditional_branch' }>,
loadMemberCohortIds?: () => Promise<number[]>,
- // Only a wait re-parks; a conditional_branch routes on the spot. A wait is normalised into a
- // branch before it gets here, so the caller passes its ceiling rather than the type carrying it.
- repark?: { maxWaitDuration: string; recheckSeconds: number }
+ // Only a wait re-parks, for its whole ceiling; a conditional_branch routes on the spot. A wait is
+ // normalised into a branch before it gets here, so the caller passes its ceiling rather than the
+ // type carrying it.
+ repark?: { maxWaitDuration: string }
): Promise<{
scheduledAt?: DateTime
nextAction?: HogFlowAction
@@ -200,7 +229,8 @@ export async function checkConditions(
// Loaded only when evaluation actually reaches a cohort condition, so a run whose earlier
// condition matches never touches the behavioral cohorts DB. A lookup failure throws here
// on purpose (following the action's on_error) instead of guessing non-membership; the
- // inCohort/notInCohort STL functions read the resulting cohort_ids global.
+ // inCohort/notInCohort STL functions read the resulting cohort_ids global. The matcher does
+ // not watch cohort membership, so a wait gated on a cohort advances at its deadline.
const cohortGlobals =
loadMemberCohortIds && conditionReferencesCohorts(condition)
? { cohort_ids: await loadMemberCohortIds() }
@@ -226,15 +256,17 @@ export async function checkConditions(
}
if (repark) {
- // A wake arriving between this evaluation and the job being persisted finds no available row
- // and is never replayed, so a wait cannot rely on the matcher alone.
+ // Park to the ceiling rather than a re-check interval: the matcher wakes the job when
+ // something relevant changes, so the deadline is the only timer left.
const scheduledAt = calculatedScheduledAt(
repark.maxWaitDuration,
- invocation.state.currentAction?.startedAtTimestamp,
- repark.recheckSeconds
+ invocation.state.currentAction?.startedAtTimestamp
)
if (scheduledAt) {
+ if (invocation.state.currentAction) {
+ invocation.state.currentAction.parkedMaxWaitDuration = repark.maxWaitDuration
+ }
return {
scheduledAt,
}
diff --git a/nodejs/src/cdp/types.ts b/nodejs/src/cdp/types.ts
index 322d580f05cc..6f6426113c9c 100644
--- a/nodejs/src/cdp/types.ts
+++ b/nodejs/src/cdp/types.ts
@@ -478,6 +478,11 @@ export type HogFlowInvocationContext = {
// Set when a distinct_id's first mapping fills a parked wait's missing person anchor and wakes
// it. A matcher wake carrying no eventMatched, so the handler consumes it like rekeyWake.
anchorWake?: boolean
+ // The max_wait_duration this wait parked against. The timing sweep moves `scheduled` with a
+ // bulk UPDATE and cannot stamp a marker the way the matcher does, so a wake that follows a
+ // shortened ceiling is otherwise indistinguishable from the deadline arriving. Comparing the
+ // parked ceiling with the action's current one tells the two apart.
+ parkedMaxWaitDuration?: string
// Set by hog-function action handler when it returns `finished: false` without an
// explicit `queueScheduledAt` — i.e. the reschedule is purely to move the job onto a
// dedicated queue (e.g. 'email' for SES rate-limit gating) and the next dequeue will
@@ -493,11 +498,6 @@ export type HogFlowInvocationContext = {
// debug line *and clears the flag* so any subsequent actions on the same dequeue
// (the email handler's `nextAction: exit`, etc.) log normally.
routingOnlyReschedule?: boolean
- // Set when a wait_until_condition re-parks on its polling interval. Lets the handler
- // attribute a later condition match to the periodic poll (vs evaluate-on-entry) and emit
- // the cdp_hogflow_wait_poll_only_advance metric — the signal that proves whether the poll
- // ever catches a wake the subscription streams missed, gating its eventual removal.
- pollReparked?: boolean
// A step parked on an external run: cleared when the matcher writes a matching `resumeResult`.
awaitingResume?: {
key: string
diff --git a/products/workflows/backend/services/timing_reschedule.py b/products/workflows/backend/services/timing_reschedule.py
index a71f5e4cbf69..356909829bff 100644
--- a/products/workflows/backend/services/timing_reschedule.py
+++ b/products/workflows/backend/services/timing_reschedule.py
@@ -11,9 +11,8 @@ from products.workflows.backend.utils.durations import (
logger = structlog.get_logger(__name__)
# Steps whose parked runs a timing edit can strand: delays park up to 30 days out and time
-# windows up to a week. wait_until_condition re-parks on an hourly reconciliation cap, so a
-# sweep is a cheap no-op re-park for waits shorter than that; past an hour the sweep is what
-# stops a shortened max-wait stranding runs.
+# windows up to a week. A wait_until_condition parks for its whole max_wait_duration, so the
+# sweep is what stops a shortened one stranding runs.
TIMING_ACTION_TYPES = {"delay", "wait_until_time_window", "wait_until_condition"}
# Only jobs parked on this many steps or fewer get swept; a diff touching more than this is
@@ -66,7 +65,7 @@ def get_timing_reschedule_action_ids(
- wait_until_condition: trigger on a shortened max_wait_duration (same comparison as
delay) and on any condition edit - a swept run re-evaluates the live condition at
wake (advance if it now matches, re-park if not), which keeps fixes to broken
- conditions taking effect promptly once the poll re-check is gone.
+ conditions taking effect promptly, with no periodic re-check to fall back on.
- wait_until_time_window: trigger on any timing-config change - whether a window edit
moves a given run's wake earlier depends on each person's timezone and position in
the week, so it isn't statically decidable.
diff --git a/products/workflows/backend/services/wait_clock_conditions.py b/products/workflows/backend/services/wait_clock_conditions.py
index 9dd39f973ba0..7eb14c9cb576 100644
--- a/products/workflows/backend/services/wait_clock_conditions.py
+++ b/products/workflows/backend/services/wait_clock_conditions.py
@@ -1,14 +1,14 @@
"""
-Detects `wait_until_condition` conditions that only the polling re-check could ever satisfy.
+Detects `wait_until_condition` conditions that nothing can ever wake.
A wait is woken by the subscription matcher when a message arrives on one of its streams: an event,
a person change, an internal event, a distinct_id repoint. A condition that compares against the
-clock produces no message at all, so nothing wakes it. The periodic re-check is what has been
-covering that gap, and it re-parks every wait in the fleet to do it.
+clock produces no message at all, so such a wait sits until its max_wait_duration and then takes the
+timeout edge, whatever the condition says by then.
-Rejecting these at save time keeps that re-check a backstop rather than the mechanism: express the
-same intent with a delay step and a condition that guards it, and the wait is woken by something
-that actually happens.
+Rejecting these at save time is what makes the matcher sufficient: express the same intent with a
+delay step and a condition that guards it, and the wait is woken by something that actually
+happens.
"""
from typing import Optional