-
Notifications
You must be signed in to change notification settings - Fork 14
Fix missing realtime broadcasts for step:started and step:completed events #306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix missing realtime broadcasts for step:started and step:completed events #306
Conversation
|
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
|
View your CI Pipeline Execution ↗ for commit bdd4a3c
☁️ Nx Cloud last updated this comment at |
🔍 Preview Deployment: Website✅ Deployment successful! 🔗 Preview URL: https://pr-306.pgflow.pages.dev 📝 Details:
_Last updated: _ |
Merge activity
|
…vents (#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.

Summary
Fixes critical bug where clients were not receiving
step:startedandstep:completedrealtime events. PostgreSQL's query optimizer was eliminating CTEs containingrealtime.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:startedevents now broadcast when steps begin executingstep:completedevents now broadcast for empty map stepsstep:completedevents now broadcast for cascade completionsChanges
Core Package (@pgflow/core)
start_ready_steps(): Broadcastsstep:startedandstep:completedevents in RETURNING clausescascade_complete_taskless_steps(): Broadcastsstep:completedevents atomically with cascade completioncomplete_task(): Added PERFORM statements forrun:failedandstep:failedbroadcastsClient Package (@pgflow/client)
applySnapshot()methods to FlowRun and FlowStep for proper initial state hydration without event emissionwaitForStatus()with empty map steps and abort signalsTesting
Documentation
waitForStatus()step:started, go directly tostep:completed)waitForStatus()timingBreaking Changes
None
Migration
This release includes database migrations. Users should follow the update guide after upgrading packages.