Skip to content

fix(edge-worker): await worker startup in integration tests - #680

Merged
jumski merged 1 commit into
mainfrom
650-await-worker-startup
Sep 13, 2026
Merged

fix(edge-worker): await worker startup in integration tests#680
jumski merged 1 commit into
mainfrom
650-await-worker-startup

Conversation

@jumski

@jumski jumski commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Summary

Make the integration-test harness await worker startup. startWorker() in pkgs/edge-worker/tests/integration/_helpers.ts fired worker.startOnlyOnce() fire-and-forget, so the startup transaction (ensure_flow_compiled: create_flow/add_step, or destructive local recompile via delete_flow_and_data) could race the test body and commit across test boundaries, interleaving with the next test's reset_db. A stray commit then left a listed PGMQ queue with no owning flow row, and a later create_flow rejected it (queue "X" is already in use by another owner). Startup errors now fail at the call site instead of surfacing via a later worker.stop().

Test-only change: _helpers.ts, 31 call sites across 9 integration test files, and performanceMapFlow's startWorkers. No product code, SQL, or migrations.

Base of the #679 stack (queue identity feature); that PR's CI originally failed on this race.

Checks

  • mapFlow.test.ts focused runs pass twice consecutively (no orphan-queue leak across runs); queueIdentity.test.ts likewise
  • Full pnpm nx test:integration edge-worker: 63 passed, 0 failed
  • nx affected --target=prepush: 32/32 successful

Part of #650

startWorker() fired worker.startOnlyOnce() fire-and-forget, so the startup transaction (ensure_flow_compiled: create_flow/add_step, or destructive local recompile via delete_flow_and_data) raced the test body and could commit across test boundaries, interleaving with the next test's reset_db. A stray commit then left a listed PGMQ queue with no owning flow row, and the next create_flow correctly rejected it: cannot create flow "X": queue "X" is already in use by another owner.

Fix: make startWorker() async and await startup; await all 31 call sites and performanceMapFlow's startWorkers. Startup errors now fail at the call site instead of surfacing via a later worker.stop(). Product code, SQL, and migrations are untouched; the ownership guard stays as approved in #650.

mapFlow.test.ts focused runs pass twice consecutively; full integration suite 63 passed, 0 failed.

Refs #650. CI: edge-worker-integration on PR #679.
@changeset-bot

changeset-bot Bot commented Sep 13, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: cae4772

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

jumski commented Sep 13, 2026

Copy link
Copy Markdown
Contributor Author

@nx-cloud

nx-cloud Bot commented Sep 13, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit cae4772

Command Status Duration Result
nx run edge-worker:smoke:bun ✅ Succeeded 4s View ↗

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-09-13 06:53:23 UTC

@nx-cloud

nx-cloud Bot commented Sep 13, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit cae4772

Command Status Duration Result
nx run-many -t build --projects=dsl,core,cli ✅ Succeeded 4s View ↗

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-09-13 06:53:41 UTC

jumski commented Sep 13, 2026

Copy link
Copy Markdown
Contributor Author

Merge activity

  • Sep 13, 5:59 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Sep 13, 5:59 PM UTC: @jumski merged this pull request with Graphite.

@jumski
jumski merged commit e66a3d7 into main Sep 13, 2026
17 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Production Deployment: Website

Successfully deployed to production!

🔗 Production URL: https://pgflow.dev

📝 Details:

  • Commit: e66a3d768da21a33e926b15973322fa9f2841d57
  • View Logs

Deployed at: 2026-09-13T19:59:50+02:00

jumski added a commit that referenced this pull request Sep 13, 2026
## Summary

Persist physical queue identity independently of flow identity while keeping today's one-flow/one-queue behavior (#650). Replacement for rejected #677. Stacked on the test-harness startup fix #680; each PR contains one commit.

- Store canonical `queue_name` on steps and task snapshots; enforce partial `(queue_name, message_id)` uniqueness while retaining nullable message IDs and the task primary key. Lifecycle operations use stored routes, grouped by queue, with existing concurrency, terminal-state and visibility safeguards.
- **Breaking claim API:** SQL `pgflow.start_tasks(flow_slug, msg_ids, worker_id, queue_name)` and TypeScript `startTasks()` require the canonical queue argument (`lower(flow_slug)` today). The released three-argument SQL overload is removed; no default, fallback or compatibility shim remains. JavaScript message IDs are exact decimal strings.
- **No hot-path queue listing:** PGMQ already normalizes message-operation names. Remove `_effective_queue_name`, its session cache, and worker spelling-resolution plumbing. Pruning also uses canonical routes directly. Public listing remains for provisioning collisions and fresh original-spelling resolution before destructive queue deletion. Existing mixed-case queues remain usable without moving messages or recreating queues.
- Preserve exact-flow ownership checks, ambiguous-match rejection before destructive work, transactional deletion, single-read claiming, and unmatched/wrong-flow message preservation. Keep accepted `set_vt_batch()` and direct archive pruning.
- Regenerate the unreleased `20260913093141_pgflow_persist_queue_identity` migration: nullable adds, populated backfill, constraints, then new functions and removal of the old claim overload. Bounded lock waits and atomic rollback safeguards remain. Update the maintenance guide, pruning instructions, lifecycle diagram and 0.17.0 news article.

## Maintenance upgrade

No mixed-version rolling upgrade. Pause producers; record worker enablement and running process states before changing them; drain active handlers under the old schema; stop workers and re-invocation; quiesce maintenance/recovery/definition writers; apply migrations to the explicit target through Supabase's runner; replace any installed pruning helper; deploy matching packages and callers; restore the saved states and resume producers.

Draining active work does not mean emptying queues. Queued tasks and messages survive the upgrade. A failed migration rolls back; after success, old three-argument workers cannot simply restart.

## Checks

Three GLM implementation / independent Sol review rounds completed. Final code and documentation review: **APPROVED**.

- Full core pgTAP: **300 files / 1,464 tests pass**, including populated 0.16.0 upgrade and conflict rollback fixtures.
- Edge-worker unit: **254 pass**; edge-worker E2E and portable-runtime E2E: **12 each pass**; client E2E: **47 pass**.
- Migration/generated-type checks, website lint/build/link checks, changeset validation and post-commit affected prepush: **pass** (32/32 prepush tasks).
- Current-head GitHub CI **passes edge-worker integration**, core pgTAP, build/test, edge-worker E2E, client/CLI E2E, smoke, type infrastructure and changesets. The local integration timeout did not recur in CI.
- **Remaining CI blocker:** portable-runtime E2E is **11/12**. `portable runtimes - max_concurrency works in supabase` fails with `Timeout after 60000ms waiting for test_seq to increment by 200`. One targeted failed-job rerun reproduced the same failure. Local portable-runtime suites passed twice; that does not establish the cause of the CI failure. No timeout or assertion was weakened. Three authorized correction/review rounds are exhausted.

Closes #650
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.

1 participant