Skip to content

Conversation

@jumski
Copy link
Contributor

@jumski jumski commented Nov 3, 2025

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 after upgrading packages.

@changeset-bot
Copy link

changeset-bot bot commented Nov 3, 2025

⚠️ No Changeset found

Latest commit: bdd4a3c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor Author

jumski commented Nov 3, 2025

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.
Learn more


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • merge:queue - adds this PR to the back of the merge queue
  • hotfix:queue - for urgent hot fixes, skip the queue and merge this PR next

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.

@nx-cloud
Copy link

nx-cloud bot commented Nov 3, 2025

View your CI Pipeline Execution ↗ for commit bdd4a3c

Command Status Duration Result
nx affected -t build --configuration=production... ✅ Succeeded 25s View ↗
nx affected -t lint typecheck test --parallel -... ✅ Succeeded 6m 30s View ↗
nx affected -t test:e2e --parallel --base=962cd... ✅ Succeeded 6m 8s View ↗

☁️ Nx Cloud last updated this comment at 2025-11-03 23:24:18 UTC

@jumski jumski changed the title feat: add AbortSignal support for canceling wait operations Fix missing realtime broadcasts for step:started and step:completed events Nov 3, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Nov 3, 2025

🔍 Preview Deployment: Website

Deployment successful!

🔗 Preview URL: https://pr-306.pgflow.pages.dev

📝 Details:

  • Branch: docs-update-missing-ts-client-things-in-docs
  • Commit: 0e455eed435698f68ab51a4574e7d548b1db32f0
  • View Logs

_Last updated: _

@graphite-app
Copy link
Contributor

graphite-app bot commented Nov 3, 2025

Merge activity

  • Nov 3, 11:28 PM UTC: jumski added this pull request to the Graphite merge queue.
  • Nov 3, 11:28 PM UTC: CI is running for this pull request on a draft pull request (#307) due to your merge queue CI optimization settings.
  • Nov 3, 11:29 PM UTC: Merged by the Graphite merge queue via draft PR: #307.

graphite-app bot pushed a commit that referenced this pull request Nov 3, 2025
…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.
@graphite-app graphite-app bot closed this Nov 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants