Repository navigation
Commit b898bd1
committed
Fix missing realtime broadcasts for step:started and step:completed events (#306)
## Summary
Fixes critical bug where clients were not receiving `step:started` and `step:completed` realtime events. PostgreSQL's query optimizer was eliminating CTEs containing `realtime.send()` calls because they weren't referenced by subsequent operations.
## Root Cause
PostgreSQL eliminates unreferenced CTEs during query optimization. The CTEs containing `realtime.send()` calls existed in the code but were optimized away because they weren't referenced by the final RETURN statement or subsequent operations.
## Solution
Moved `realtime.send()` calls directly into RETURNING clauses of UPDATE statements, ensuring they execute atomically with state changes and cannot be optimized away.
## What's Fixed
- `step:started` events now broadcast when steps begin executing
- `step:completed` events now broadcast for empty map steps
- `step:completed` events now broadcast for cascade completions
- Dependent steps can now properly track when upstream steps start
## Changes
### Core Package (@pgflow/core)
- `start_ready_steps()`: Broadcasts `step:started` and `step:completed` events in RETURNING clauses
- `cascade_complete_taskless_steps()`: Broadcasts `step:completed` events atomically with cascade completion
- `complete_task()`: Added PERFORM statements for `run:failed` and `step:failed` broadcasts
### Client Package (@pgflow/client)
- Added `applySnapshot()` methods to FlowRun and FlowStep for proper initial state hydration without event emission
- Enhanced test coverage for realtime event lifecycles with comprehensive matchers
- Added edge case documentation for `waitForStatus()` with empty map steps and abort signals
### Testing
- Added comprehensive realtime event lifecycle tests covering event emission, ordering, sequences, and payload validation
- Added edge case tests for empty map steps and cascade completions
### Documentation
- Updated abort signal support examples in `waitForStatus()`
- Documented empty map step behavior (skip `step:started`, go directly to `step:completed`)
- Added edge case documentation for `waitForStatus()` timing
## Breaking Changes
None
## Migration
This release includes database migrations. Users should follow the [update guide](/deploy/update-pgflow/) after upgrading packages.1 parent c22a1e5 commit b898bd1
4 files changed
Lines changed: 88 additions & 286 deletions
File tree
- pkgs
- core/supabase/tests/cascade_complete_taskless_steps
- website/src/content/docs
- build/starting-flows
- news
- reference
This file was deleted.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
221 | 221 | | |
222 | 222 | | |
223 | 223 | | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
224 | 264 | | |
225 | 265 | | |
226 | 266 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
0 commit comments