feat: implement worker deprecation with graceful shutdown#188
Conversation
🦋 Changeset detectedLatest commit: 09ea1f9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 7 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThis change introduces a comprehensive worker deprecation mechanism for zero-downtime deployments. Workers now check their deprecation status via heartbeat signals and stop accepting new tasks when deprecated, completing in-flight work before shutdown. The database schema and related type definitions are updated to track deprecation, and extensive tests are added for deprecation scenarios. Changes
Sequence Diagram(s)sequenceDiagram
participant Worker
participant DB
participant Heartbeat (internal)
participant TaskQueue
loop Every heartbeatInterval
Worker->>Heartbeat (internal): sendHeartbeat()
Heartbeat (internal)->>DB: Update last_heartbeat_at, get deprecated_at
DB-->>Heartbeat (internal): { is_deprecated }
alt is_deprecated == true
Heartbeat (internal)->>Worker: transitionToDeprecated()
Worker->>TaskQueue: Stop polling for new tasks
Worker->>TaskQueue: Complete in-flight tasks
Worker->>DB: Mark worker as deprecated
Worker->>Worker: Shutdown after in-flight tasks complete
else is_deprecated == false
Heartbeat (internal)->>Worker: Continue normal operation
end
end
Possibly related PRs
Poem
✨ Finishing Touches🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
View your CI Pipeline Execution ↗ for commit 09ea1f9
☁️ Nx Cloud last updated this comment at |
|
@CodeRabbit full review |
✅ Actions performedFull review triggered. |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (11)
examples/playground/supabase/functions/pgflow-cron-worker/index.ts (1)
112-127: Consider the deprecation strategy for cron workers.The current approach logs deprecation but continues processing. For cron workers with scheduled invocations, you might want to:
- Complete the current batch and exit gracefully
- Skip new batch processing if deprecated
Consider implementing a more definitive deprecation response based on your deployment strategy.
pkgs/edge-worker/src/core/WorkerLifecycle.ts (1)
53-58: Track this technical debt for future resolution.The commented-out
onWorkerStoppedquery indicates a timing issue with worker termination. While the heartbeat-based approach works, consider:
- Creating an issue to track this technical debt
- Investigating graceful shutdown mechanisms that allow cleanup queries to complete
Would you like me to create an issue to track this technical debt?
pkgs/edge-worker/src/flow/FlowWorkerLifecycle.ts (1)
7-10: Add JSDoc documentation for the configuration interface.Document the purpose and units (milliseconds) for better developer experience.
+/** + * Configuration options for FlowWorkerLifecycle + */ export interface FlowLifecycleConfig { + /** + * Interval in milliseconds between heartbeat signals. Default: 5000ms + */ heartbeatInterval?: number; }pkgs/edge-worker/tests/integration/flow_deprecation.test.ts (2)
95-97: Remove console.log or use proper test logging.Console output in tests can clutter test results.
// Wait for heartbeat to detect deprecation - console.log('Waiting for deprecation detection...'); + // Waiting for deprecation detection (heartbeat interval + buffer) await delay(6000);
198-199: Remove debug console.log statements.Debug output should be removed from committed test code.
- console.log('Worker 1 executed:', worker1Executions); - console.log('Worker 2 executed:', worker2Executions); // Deprecate all workers for this flow (simulating deployment) await sql` UPDATE pgflow.workers SET deprecated_at = NOW() WHERE queue_name = ${queueName} AND deprecated_at IS NULL `; // Wait for heartbeat detection - console.log('Waiting for all workers to detect deprecation...'); + // Wait for all workers to detect deprecation (heartbeat interval + buffer) await delay(6000);Also applies to: 210-211
pkgs/edge-worker/tests/integration/deprecation_simple.test.ts (3)
77-79: Remove console.log and document the delay reason.// Wait for heartbeat to detect deprecation (heartbeat interval is 5 seconds) - console.log('Waiting for heartbeat to detect deprecation...'); + // Adding 1s buffer to 5s heartbeat interval await delay(6000);
102-102: Remove debug console.log statement.- console.log(`Queue count: ${queueMessages[0].count}, Archive count: ${archiveMessages[0].count}`);
201-202: Remove all debug console.log statements.- console.log('Worker1 processed:', worker1Messages); - console.log('Worker2 processed:', worker2Messages); // Check initial archive count const archiveCountBefore = await sql` SELECT COUNT(*) as count FROM ${sql(`pgmq.a_${queueName}`)} `; assertEquals(Number(archiveCountBefore[0].count), firstBatch.length, 'First batch should be archived'); // Deprecate all workers for this function (simulating deployment) await sql` UPDATE pgflow.workers SET deprecated_at = NOW() WHERE function_name = ${functionName} AND deprecated_at IS NULL `; // Wait for heartbeat detection (5s interval + buffer) - console.log('Waiting for all workers to detect deprecation...'); await delay(6000); // Add more messages after deprecation const secondBatch = ['multi5', 'multi6', 'multi7', 'multi8']; for (const msgId of secondBatch) { await sql`SELECT pgmq.send(${queueName}::text, ${JSON.stringify({ id: msgId })}::jsonb)`; } // Wait longer to ensure workers would have polled if they were still active await delay(3000); // Verify no new messages were processed by either worker const totalProcessedAfter = worker1Messages.length + worker2Messages.length; assertEquals( totalProcessedAfter, totalProcessedBefore, 'No new messages should be processed after deprecation' ); // Check queue and archive counts const queueCount = await sql` SELECT COUNT(*) as count FROM ${sql(`pgmq.q_${queueName}`)} `; const archiveCountAfter = await sql` SELECT COUNT(*) as count FROM ${sql(`pgmq.a_${queueName}`)} `; - console.log(`Queue count: ${queueCount[0].count}, Archive count: ${archiveCountAfter[0].count}`);Also applies to: 219-219, 248-248
pkgs/edge-worker/tests/integration/deprecation.test.ts (3)
26-26: Remove all debug console.log statements for cleaner test output.Remove the following console.log statements:
- Line 26: Processing message log
- Line 31: Processed message log
- Line 64: Processed messages log
- Lines 76-77: Deprecation detection log
- Line 83: Worker deprecated_at log
- Line 90: Added second batch log
- Line 96: Final processed messages log
- Lines 112-113: Queue and archive messages logs
These debug statements clutter test output and should be removed from committed code.
Also applies to: 31-31, 64-64, 76-77, 83-83, 90-90, 96-96, 112-113
142-280: Excellent test for in-flight message handling!This test effectively validates that messages already being processed complete even after deprecation. Consider removing the console.log statements on lines 217-218, 249-250, and 268-269 for cleaner output.
365-366: Remove debug console.log statements from multi-worker test.Remove console.log statements on:
- Lines 365-366: Worker processed messages
- Lines 389-392: Final message counts
- Lines 413-414: Queue and archive messages
- Lines 431-432: Second batch location logs
Also applies to: 389-392, 413-414, 431-432
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
pkgs/core/supabase/migrations/atlas.sumis excluded by!**/*.sum
📒 Files selected for processing (26)
.changeset/calm-ties-give.md(1 hunks).claude/settings.json(1 hunks)examples/playground/supabase/functions/pgflow-cron-worker/index.ts(3 hunks)pkgs/core/schemas/0055_tables_workers.sql(1 hunks)pkgs/core/src/database-types.ts(1 hunks)pkgs/core/supabase/migrations/20250719205006_pgflow_worker_deprecation.sql(1 hunks)pkgs/edge-worker/src/core/Heartbeat.ts(0 hunks)pkgs/edge-worker/src/core/Queries.ts(1 hunks)pkgs/edge-worker/src/core/Worker.ts(1 hunks)pkgs/edge-worker/src/core/WorkerLifecycle.ts(3 hunks)pkgs/edge-worker/src/core/WorkerState.ts(3 hunks)pkgs/edge-worker/src/core/types.ts(1 hunks)pkgs/edge-worker/src/flow/FlowWorkerLifecycle.ts(3 hunks)pkgs/edge-worker/tests/db.ts(2 hunks)pkgs/edge-worker/tests/e2e/_helpers.ts(4 hunks)pkgs/edge-worker/tests/e2e/performance.test.ts(3 hunks)pkgs/edge-worker/tests/e2e/restarts.test.ts(3 hunks)pkgs/edge-worker/tests/integration/_helpers.ts(1 hunks)pkgs/edge-worker/tests/integration/creating_queue.test.ts(1 hunks)pkgs/edge-worker/tests/integration/deprecation.test.ts(1 hunks)pkgs/edge-worker/tests/integration/deprecation_simple.test.ts(1 hunks)pkgs/edge-worker/tests/integration/flow_deprecation.test.ts(1 hunks)pkgs/edge-worker/tests/sql.ts(2 hunks)pkgs/edge-worker/tests/unit/FlowWorkerLifecycle.deprecation.test.ts(1 hunks)pkgs/edge-worker/tests/unit/WorkerLifecycle.deprecation.test.ts(1 hunks)pkgs/edge-worker/tests/unit/WorkerState.test.ts(2 hunks)
💤 Files with no reviewable changes (1)
- pkgs/edge-worker/src/core/Heartbeat.ts
🧰 Additional context used
🧠 Learnings (24)
pkgs/edge-worker/tests/integration/_helpers.ts (7)
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/**/*.{ts,tsx} : When adding configuration options, provide sensible defaults.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/src/**/*.{ts,tsx} : Make changes to TypeScript files in the 'src/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/tests/integration/**/*.{ts,tsx} : Integration tests should be placed in 'tests/integration/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/tests/e2e/**/*.{ts,tsx} : E2E tests should be placed in 'tests/e2e/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/tests/unit/**/*.{ts,tsx} : Unit tests should be placed in 'tests/unit/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/**/*.{ts,tsx} : Follow TypeScript strict mode with proper type annotations.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: examples/playground/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:53:04.790Z
Learning: Use Supabase for backend with Edge Functions.
pkgs/core/supabase/migrations/20250719205006_pgflow_worker_deprecation.sql (3)
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/client/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:53:40.127Z
Learning: Applies to pkgs/client/pkgs/core/schemas/**/*.sql : Use SECURITY DEFINER for pgflow functions that need to access internal tables
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/client/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:53:40.127Z
Learning: Applies to pkgs/client/pkgs/core/schemas/**/*.sql : Grant only minimal required permissions to the API user (anon role) for pgflow schema, functions, and tables
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/client/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:53:40.127Z
Learning: Applies to pkgs/client/supabase/config.toml : The supabase/config.toml file must include '[api] schemas = ["public", "graphql_public", "pgflow"]' to allow integration tests to access the pgflow schema
pkgs/core/schemas/0055_tables_workers.sql (2)
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/client/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:53:40.127Z
Learning: Applies to pkgs/client/pkgs/core/schemas/**/*.sql : Use SECURITY DEFINER for pgflow functions that need to access internal tables
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/client/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:53:40.127Z
Learning: Applies to pkgs/client/pkgs/core/schemas/**/*.sql : Grant only minimal required permissions to the API user (anon role) for pgflow schema, functions, and tables
pkgs/edge-worker/src/core/types.ts (6)
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/src/**/*.{ts,tsx} : Make changes to TypeScript files in the 'src/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/**/*.{ts,tsx} : Follow TypeScript strict mode with proper type annotations.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/**/*.{ts,tsx} : When adding configuration options, provide sensible defaults.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/tests/e2e/**/*.{ts,tsx} : E2E tests should be placed in 'tests/e2e/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/tests/integration/**/*.{ts,tsx} : Integration tests should be placed in 'tests/integration/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/tests/unit/**/*.{ts,tsx} : Unit tests should be placed in 'tests/unit/' directory.
pkgs/edge-worker/src/core/Worker.ts (5)
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/**/*.{ts,tsx} : When adding configuration options, provide sensible defaults.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/src/**/*.{ts,tsx} : Make changes to TypeScript files in the 'src/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/**/*.{ts,tsx} : Follow TypeScript strict mode with proper type annotations.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Keep Edge Worker lightweight - heavy logic should go in the SQL Core (Layer 2).
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Remember that Edge Worker is stateless and can restart at any time.
pkgs/edge-worker/tests/db.ts (6)
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/src/**/*.{ts,tsx} : Make changes to TypeScript files in the 'src/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/tests/integration/**/*.{ts,tsx} : Integration tests should be placed in 'tests/integration/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/tests/e2e/**/*.{ts,tsx} : E2E tests should be placed in 'tests/e2e/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/**/*.{ts,tsx} : When adding configuration options, provide sensible defaults.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/tests/unit/**/*.{ts,tsx} : Unit tests should be placed in 'tests/unit/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/**/*.{ts,tsx} : Follow TypeScript strict mode with proper type annotations.
pkgs/edge-worker/tests/e2e/restarts.test.ts (7)
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/tests/e2e/**/*.{ts,tsx} : E2E tests should be placed in 'tests/e2e/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/src/**/*.{ts,tsx} : Make changes to TypeScript files in the 'src/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/tests/integration/**/*.{ts,tsx} : Integration tests should be placed in 'tests/integration/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/tests/unit/**/*.{ts,tsx} : Unit tests should be placed in 'tests/unit/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/**/*.{ts,tsx} : Follow TypeScript strict mode with proper type annotations.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/**/*.{ts,tsx} : When adding configuration options, provide sensible defaults.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/client/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:53:40.127Z
Learning: Applies to pkgs/client/packages/client/**/*.{test,spec}.{ts,tsx} : Write comprehensive tests for all client functionality
pkgs/edge-worker/tests/integration/creating_queue.test.ts (6)
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/tests/integration/**/*.{ts,tsx} : Integration tests should be placed in 'tests/integration/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/tests/e2e/**/*.{ts,tsx} : E2E tests should be placed in 'tests/e2e/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/src/**/*.{ts,tsx} : Make changes to TypeScript files in the 'src/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/tests/unit/**/*.{ts,tsx} : Unit tests should be placed in 'tests/unit/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/**/*.{ts,tsx} : When adding configuration options, provide sensible defaults.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/**/*.{ts,tsx} : Follow TypeScript strict mode with proper type annotations.
pkgs/edge-worker/tests/unit/WorkerState.test.ts (6)
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/tests/unit/**/*.{ts,tsx} : Unit tests should be placed in 'tests/unit/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/tests/e2e/**/*.{ts,tsx} : E2E tests should be placed in 'tests/e2e/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/tests/integration/**/*.{ts,tsx} : Integration tests should be placed in 'tests/integration/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/src/**/*.{ts,tsx} : Make changes to TypeScript files in the 'src/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/**/*.{ts,tsx} : Follow TypeScript strict mode with proper type annotations.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/**/*.{ts,tsx} : When adding configuration options, provide sensible defaults.
pkgs/edge-worker/tests/sql.ts (6)
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/src/**/*.{ts,tsx} : Make changes to TypeScript files in the 'src/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/**/*.{ts,tsx} : Follow TypeScript strict mode with proper type annotations.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/tests/e2e/**/*.{ts,tsx} : E2E tests should be placed in 'tests/e2e/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/**/*.{ts,tsx} : When adding configuration options, provide sensible defaults.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/tests/unit/**/*.{ts,tsx} : Unit tests should be placed in 'tests/unit/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/tests/integration/**/*.{ts,tsx} : Integration tests should be placed in 'tests/integration/' directory.
.changeset/calm-ties-give.md (2)
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/**/*.{ts,tsx} : When adding configuration options, provide sensible defaults.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Keep Edge Worker lightweight - heavy logic should go in the SQL Core (Layer 2).
pkgs/edge-worker/tests/e2e/performance.test.ts (8)
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/tests/e2e/**/*.{ts,tsx} : E2E tests should be placed in 'tests/e2e/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/src/**/*.{ts,tsx} : Make changes to TypeScript files in the 'src/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Keep Edge Worker lightweight - heavy logic should go in the SQL Core (Layer 2).
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/**/*.{ts,tsx} : Follow TypeScript strict mode with proper type annotations.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/tests/unit/**/*.{ts,tsx} : Unit tests should be placed in 'tests/unit/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/tests/integration/**/*.{ts,tsx} : Integration tests should be placed in 'tests/integration/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/**/*.{ts,tsx} : When adding configuration options, provide sensible defaults.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/client/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:53:40.127Z
Learning: Applies to pkgs/client/packages/client/**/*.{test,spec}.{ts,tsx} : Write comprehensive tests for all client functionality
pkgs/core/src/database-types.ts (4)
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/**/*.{ts,tsx} : Follow TypeScript strict mode with proper type annotations.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/src/**/*.{ts,tsx} : Make changes to TypeScript files in the 'src/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/client/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:53:40.127Z
Learning: Applies to pkgs/client/pkgs/core/schemas/**/*.sql : Use SECURITY DEFINER for pgflow functions that need to access internal tables
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/client/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:53:40.127Z
Learning: Applies to pkgs/client/pkgs/core/schemas/**/*.sql : Grant only minimal required permissions to the API user (anon role) for pgflow schema, functions, and tables
pkgs/edge-worker/tests/e2e/_helpers.ts (10)
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/src/**/*.{ts,tsx} : Make changes to TypeScript files in the 'src/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/tests/e2e/**/*.{ts,tsx} : E2E tests should be placed in 'tests/e2e/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/**/*.{ts,tsx} : Follow TypeScript strict mode with proper type annotations.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/**/*.{ts,tsx} : When adding configuration options, provide sensible defaults.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Keep Edge Worker lightweight - heavy logic should go in the SQL Core (Layer 2).
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/tests/unit/**/*.{ts,tsx} : Unit tests should be placed in 'tests/unit/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/tests/integration/**/*.{ts,tsx} : Integration tests should be placed in 'tests/integration/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/client/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:53:40.127Z
Learning: Applies to pkgs/client/packages/client/**/*.{test,spec}.{ts,tsx} : Write comprehensive tests for all client functionality
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/client/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:53:40.127Z
Learning: Applies to pkgs/client/pkgs/core/schemas/**/*.sql : Use SECURITY DEFINER for pgflow functions that need to access internal tables
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/**/*.{ts,tsx} : The name of the project should only ever be used as lowercase: pgflow. Never use: pgFlow, PgFlow, Pgflow, PGFlow. The only exception is in class names, where 'Pgflow' can be used (PascalCase).
pkgs/edge-worker/src/core/WorkerState.ts (4)
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/**/*.{ts,tsx} : Follow TypeScript strict mode with proper type annotations.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/src/**/*.{ts,tsx} : Make changes to TypeScript files in the 'src/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/**/*.{ts,tsx} : When adding configuration options, provide sensible defaults.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Remember that Edge Worker is stateless and can restart at any time.
pkgs/edge-worker/tests/unit/WorkerLifecycle.deprecation.test.ts (7)
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/tests/integration/**/*.{ts,tsx} : Integration tests should be placed in 'tests/integration/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/tests/unit/**/*.{ts,tsx} : Unit tests should be placed in 'tests/unit/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/tests/e2e/**/*.{ts,tsx} : E2E tests should be placed in 'tests/e2e/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/src/**/*.{ts,tsx} : Make changes to TypeScript files in the 'src/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/**/*.{ts,tsx} : Follow TypeScript strict mode with proper type annotations.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/**/*.{ts,tsx} : When adding configuration options, provide sensible defaults.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/client/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:53:40.127Z
Learning: Applies to pkgs/client/packages/client/**/*.{test,spec}.{ts,tsx} : Write comprehensive tests for all client functionality
examples/playground/supabase/functions/pgflow-cron-worker/index.ts (1)
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/**/*.{ts,tsx} : The name of the project should only ever be used as lowercase: pgflow. Never use: pgFlow, PgFlow, Pgflow, PGFlow. The only exception is in class names, where 'Pgflow' can be used (PascalCase).
pkgs/edge-worker/src/core/Queries.ts (4)
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/src/**/*.{ts,tsx} : Make changes to TypeScript files in the 'src/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/**/*.{ts,tsx} : When adding configuration options, provide sensible defaults.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/**/*.{ts,tsx} : Follow TypeScript strict mode with proper type annotations.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Keep Edge Worker lightweight - heavy logic should go in the SQL Core (Layer 2).
pkgs/edge-worker/src/core/WorkerLifecycle.ts (3)
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/**/*.{ts,tsx} : When adding configuration options, provide sensible defaults.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/src/**/*.{ts,tsx} : Make changes to TypeScript files in the 'src/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Keep Edge Worker lightweight - heavy logic should go in the SQL Core (Layer 2).
pkgs/edge-worker/tests/unit/FlowWorkerLifecycle.deprecation.test.ts (8)
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/tests/integration/**/*.{ts,tsx} : Integration tests should be placed in 'tests/integration/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/tests/unit/**/*.{ts,tsx} : Unit tests should be placed in 'tests/unit/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/tests/e2e/**/*.{ts,tsx} : E2E tests should be placed in 'tests/e2e/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/src/**/*.{ts,tsx} : Make changes to TypeScript files in the 'src/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/**/*.{ts,tsx} : Follow TypeScript strict mode with proper type annotations.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/**/*.{ts,tsx} : When adding configuration options, provide sensible defaults.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/client/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:53:40.127Z
Learning: Applies to pkgs/client/packages/client/**/*.{test,spec}.{ts,tsx} : Write comprehensive tests for all client functionality
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/**/*.{ts,tsx} : The name of the project should only ever be used as lowercase: pgflow. Never use: pgFlow, PgFlow, Pgflow, PGFlow. The only exception is in class names, where 'Pgflow' can be used (PascalCase).
pkgs/edge-worker/src/flow/FlowWorkerLifecycle.ts (3)
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/**/*.{ts,tsx} : When adding configuration options, provide sensible defaults.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/**/*.{ts,tsx} : The name of the project should only ever be used as lowercase: pgflow. Never use: pgFlow, PgFlow, Pgflow, PGFlow. The only exception is in class names, where 'Pgflow' can be used (PascalCase).
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/src/**/*.{ts,tsx} : Make changes to TypeScript files in the 'src/' directory.
pkgs/edge-worker/tests/integration/flow_deprecation.test.ts (7)
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/tests/integration/**/*.{ts,tsx} : Integration tests should be placed in 'tests/integration/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/tests/e2e/**/*.{ts,tsx} : E2E tests should be placed in 'tests/e2e/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/tests/unit/**/*.{ts,tsx} : Unit tests should be placed in 'tests/unit/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/src/**/*.{ts,tsx} : Make changes to TypeScript files in the 'src/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/**/*.{ts,tsx} : Follow TypeScript strict mode with proper type annotations.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/**/*.{ts,tsx} : When adding configuration options, provide sensible defaults.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/client/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:53:40.127Z
Learning: Applies to pkgs/client/packages/client/**/*.{test,spec}.{ts,tsx} : Write comprehensive tests for all client functionality
pkgs/edge-worker/tests/integration/deprecation_simple.test.ts (8)
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/tests/integration/**/*.{ts,tsx} : Integration tests should be placed in 'tests/integration/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/tests/e2e/**/*.{ts,tsx} : E2E tests should be placed in 'tests/e2e/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/tests/unit/**/*.{ts,tsx} : Unit tests should be placed in 'tests/unit/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/src/**/*.{ts,tsx} : Make changes to TypeScript files in the 'src/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/**/*.{ts,tsx} : Follow TypeScript strict mode with proper type annotations.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/**/*.{ts,tsx} : When adding configuration options, provide sensible defaults.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/client/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:53:40.127Z
Learning: Applies to pkgs/client/packages/client/**/*.{test,spec}.{ts,tsx} : Write comprehensive tests for all client functionality
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Keep Edge Worker lightweight - heavy logic should go in the SQL Core (Layer 2).
pkgs/edge-worker/tests/integration/deprecation.test.ts (7)
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/tests/integration/**/*.{ts,tsx} : Integration tests should be placed in 'tests/integration/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/tests/e2e/**/*.{ts,tsx} : E2E tests should be placed in 'tests/e2e/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/tests/unit/**/*.{ts,tsx} : Unit tests should be placed in 'tests/unit/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/src/**/*.{ts,tsx} : Make changes to TypeScript files in the 'src/' directory.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/**/*.{ts,tsx} : Follow TypeScript strict mode with proper type annotations.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/edge-worker/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:54:04.123Z
Learning: Applies to pkgs/edge-worker/**/*.{ts,tsx} : When adding configuration options, provide sensible defaults.
Learnt from: CR
PR: pgflow-dev/pgflow#0
File: pkgs/client/CLAUDE.md:0-0
Timestamp: 2025-07-02T15:53:40.127Z
Learning: Applies to pkgs/client/packages/client/**/*.{test,spec}.{ts,tsx} : Write comprehensive tests for all client functionality
🧬 Code Graph Analysis (6)
pkgs/edge-worker/tests/e2e/restarts.test.ts (2)
pkgs/edge-worker/tests/sql.ts (1)
withSql(33-42)pkgs/edge-worker/tests/e2e/_helpers.ts (1)
startWorker(149-158)
pkgs/edge-worker/tests/unit/WorkerState.test.ts (1)
pkgs/edge-worker/src/core/WorkerState.ts (1)
WorkerState(42-97)
pkgs/edge-worker/tests/e2e/performance.test.ts (2)
pkgs/edge-worker/tests/sql.ts (2)
withSql(33-42)createSql(5-12)pkgs/edge-worker/tests/e2e/_helpers.ts (3)
startWorker(149-158)waitFor(16-41)log(12-14)
examples/playground/supabase/functions/pgflow-cron-worker/index.ts (3)
pkgs/edge-worker/tests/unit/FlowWorkerLifecycle.deprecation.test.ts (1)
sendHeartbeat(38-41)pkgs/edge-worker/src/core/WorkerLifecycle.ts (1)
sendHeartbeat(76-92)pkgs/edge-worker/src/flow/FlowWorkerLifecycle.ts (1)
sendHeartbeat(80-96)
pkgs/edge-worker/src/core/Queries.ts (1)
pkgs/edge-worker/src/core/types.ts (1)
WorkerRow(41-48)
pkgs/edge-worker/tests/integration/deprecation.test.ts (4)
pkgs/edge-worker/tests/db.ts (1)
withTransaction(13-57)pkgs/edge-worker/tests/fakes.ts (1)
createFakeLogger(12-12)pkgs/edge-worker/tests/integration/_helpers.ts (1)
createTestPlatformAdapter(30-47)pkgs/edge-worker/src/core/types.ts (1)
WorkerRow(41-48)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build-and-test
🔇 Additional comments (51)
.claude/settings.json (1)
5-5: LGTM! Proper permission addition for Deno test support.The addition of the "Bash(deno test:*)" permission correctly enables the new Deno test suites introduced for worker deprecation functionality. This follows the existing permission pattern and supports the comprehensive test coverage mentioned in the PR objectives.
pkgs/edge-worker/tests/integration/_helpers.ts (1)
13-13: LGTM! Database connection standardization improves test reliability.Replacing
localhostwith127.0.0.1in the database URL avoids potential DNS resolution issues in test environments and aligns with the broader standardization effort mentioned in the PR.pkgs/core/supabase/migrations/20250719205006_pgflow_worker_deprecation.sql (1)
1-2: LGTM! Clean column rename migration for deprecation semantics.The migration correctly renames
stopped_attodeprecated_atto better reflect the new worker deprecation functionality. The simple ALTER TABLE approach is appropriate for this semantic change.Note: Since this is a column rename without data transformation, existing timestamps will be preserved, which is the expected behavior for this feature.
pkgs/core/schemas/0055_tables_workers.sql (1)
8-8: LGTM! Schema definition aligns with migration.The column rename from
stopped_attodeprecated_atcorrectly maintains the same type (timestamptz) and nullability while supporting the new deprecation semantics. This change is consistent with the corresponding migration file.pkgs/edge-worker/src/core/types.ts (1)
45-45: LGTM! Type definition consistently updated for deprecation semantics.The property rename from
stopped_attodeprecated_atin theWorkerRowtype correctly maintains the same type signature (string | null) while aligning with the database schema changes. This ensures type safety and consistency across the entire stack for the new worker deprecation feature.pkgs/edge-worker/tests/db.ts (1)
16-16: LGTM: Database connection standardizationThe change from
localhostto127.0.0.1improves test reliability by avoiding potential DNS resolution issues and aligns with the standardization effort across the test suite.Also applies to: 62-62
pkgs/edge-worker/src/core/Worker.ts (1)
49-54: Well-designed deprecation detection flowThe deprecation check is strategically placed after the heartbeat (which likely updates the deprecation status) but before batch processing. This ensures workers can detect their deprecation promptly and stop accepting new work while completing the current iteration cleanly.
pkgs/edge-worker/tests/e2e/restarts.test.ts (1)
1-1: Improved SQL connection lifecycle managementThe refactoring to use
withSqlwrapper ensures proper connection cleanup and eliminates the risk of connection leaks. This aligns with the broader test infrastructure improvements across the codebase.Also applies to: 18-18, 53-53
pkgs/edge-worker/tests/integration/creating_queue.test.ts (1)
65-65: Correct schema alignment with worker deprecationThe update from
stopped_at IS NULLtodeprecated_at IS NULLproperly reflects the database schema change where the worker status column was renamed to support the new deprecation functionality.pkgs/edge-worker/tests/sql.ts (2)
3-3: Database connection standardizationUsing the standard PostgreSQL port
5432and IP address127.0.0.1improves test reliability and consistency across the test suite.
44-44: Improved resource management by removing global SQL instanceRemoving the global
sqlexport encourages proper connection lifecycle management through thewithSqlandwithRollbackpatterns, reducing the risk of connection leaks in tests.pkgs/edge-worker/src/core/Queries.ts (2)
25-34: LGTM: Correctly updates deprecated_at instead of stopped_at.The change from
stopped_attodeprecated_ataligns with the database schema migration and the new worker deprecation functionality. The method continues to update both the deprecation timestamp and last heartbeat timestamp as expected.
36-45: LGTM: Properly implements heartbeat-based deprecation detection.The method now correctly returns deprecation status by checking if
deprecated_atis non-null. The fallback to{ is_deprecated: false }handles cases where no worker row is returned. This enables workers to detect their deprecation status and transition to the appropriate state.pkgs/core/src/database-types.ts (1)
314-340: LGTM: Type definitions correctly updated for deprecated_at column.The workers table type definitions have been properly updated to replace
stopped_atwithdeprecated_atacross Row, Insert, and Update interfaces. The nullable string typestring | nullis appropriate for timestamp fields, and the optional markers in Insert/Update interfaces are consistent with typical database operation patterns..changeset/calm-ties-give.md (1)
1-14: LGTM: Comprehensive and accurate changeset documentation.The changeset clearly describes the worker deprecation feature and its key benefits for zero-downtime deployments. It accurately captures the main changes including the database schema migration, heartbeat refactoring, and improved type safety.
pkgs/edge-worker/tests/unit/WorkerState.test.ts (2)
42-62: LGTM: Comprehensive test coverage for deprecation state transitions.The new test case properly validates the deprecation workflow:
- Correctly tests the Running → Deprecated → Stopping → Stopped transition sequence
- Verifies state getters (
isDeprecated,isRunning) work correctly in the Deprecated state- Ensures the worker can transition through all deprecation-related states as expected
This provides good coverage for the new deprecation functionality.
98-107: LGTM: Proper validation of new state getters.The additions correctly test that
isDeprecatedandisStoppedreturnfalsein the initial Created state, maintaining consistency with the other state getter assertions. This ensures the new state getters work correctly across all states.pkgs/edge-worker/tests/e2e/performance.test.ts (1)
1-61: LGTM: Improved SQL client lifecycle management.The refactoring properly implements the new SQL client management pattern:
- Uses
withSqlwrapper to ensure proper cleanup of the main SQL connection- Creates temporary SQL clients in the polling function with proper
finallyblock cleanup- Eliminates manual connection management and potential resource leaks
- Maintains the same test logic while improving reliability
This follows the established pattern from other test files and enhances resource management.
pkgs/edge-worker/tests/e2e/_helpers.ts (5)
43-57: Good resource management pattern!The refactoring to use local SQL client with try-finally ensures proper connection cleanup.
59-76: Consistent resource management pattern applied.The function correctly manages SQL client lifecycle.
120-138: Well-structured async resource management.The SQL client is properly managed even within the waitFor predicate function.
140-147: Clean implementation with proper cleanup.
149-158: Proper separation of SQL client instances.Each function correctly manages its own SQL client lifecycle.
pkgs/edge-worker/src/core/WorkerState.ts (3)
13-15: Well-documented state addition.The
Deprecatedstate is clearly defined and positioned appropriately in the worker lifecycle.
27-28: Correct state transition logic for deprecation flow.The transitions properly support both direct stopping and graceful deprecation paths.
70-73: Consistent getter implementation.examples/playground/supabase/functions/pgflow-cron-worker/index.ts (2)
41-43: Appropriate heartbeat configuration for cron worker.The 4-second interval is reasonable for periodic execution patterns.
131-131: Correct heartbeat placement in processing flow.Heartbeats are sent at appropriate points to maintain worker liveness.
Also applies to: 199-199
pkgs/edge-worker/tests/unit/WorkerLifecycle.deprecation.test.ts (7)
16-53: Well-designed mock for testing heartbeat behavior.The mock provides good control over test scenarios with call counting and configurable responses.
69-106: Thorough test of deprecation state transition.Correctly verifies the lifecycle transitions from Running to Deprecated state.
108-138: Good edge case coverage for idempotent deprecation.
140-159: Important defensive test for uninitialized worker.
161-186: Complete lifecycle transition test.
188-208: Proper validation of state machine constraints.
250-281: Excellent test for heartbeat interval enforcement.Ensures heartbeats are rate-limited according to configuration.
pkgs/edge-worker/src/core/WorkerLifecycle.ts (3)
7-27: Well-designed configuration with sensible defaults.The 5-second heartbeat interval is a reasonable default that balances liveness detection with resource usage.
76-92: Robust heartbeat implementation with proper deprecation handling.The method correctly:
- Guards against uninitialized state
- Enforces heartbeat intervals
- Detects and handles deprecation with appropriate state transitions
110-116: Clean deprecation API following existing patterns.pkgs/edge-worker/tests/unit/FlowWorkerLifecycle.deprecation.test.ts (9)
16-47: Well-designed mock implementation!The MockQueries class provides excellent control for testing different deprecation scenarios with proper type safety and call tracking.
58-92: Comprehensive test for deprecation state transition!The test effectively validates the heartbeat-triggered deprecation flow with proper state assertions.
94-121: Good edge case coverage!Testing idempotency of deprecation transitions ensures robust state management.
123-135: Excellent defensive programming test!Ensures graceful handling when heartbeat is called before worker initialization.
137-158: Thorough state transition testing!Validates the complete lifecycle from deprecated through to stopped state.
160-173: Important state machine validation!Ensures invalid state transitions are properly rejected with clear error messages.
175-208: Good logging verification!Ensures proper user notification when workers are deprecated.
210-260: Excellent test coverage for lifecycle properties and heartbeat throttling!The tests thoroughly validate getters and the heartbeat interval enforcement logic.
9-9: Import path validated forpostgrestype.
- Verified that
pkgs/edge-worker/tests/sql.tsexists.- Confirmed it exports
export type { postgres };No changes needed—the relative import
'../sql.ts'is correct.pkgs/edge-worker/src/flow/FlowWorkerLifecycle.ts (3)
25-31: Good implementation with sensible defaults!The 5-second default heartbeat interval is reasonable and the nullish coalescing operator is used appropriately. This aligns with the retrieved learning about providing sensible defaults for configuration options.
80-96: Excellent heartbeat implementation with deprecation handling!The method properly handles:
- Graceful early return when worker not initialized
- Heartbeat throttling to prevent excessive database calls
- Deprecation detection with appropriate state transition
- Clear logging of heartbeat status
114-121: Clean deprecation API!The methods provide a clear interface for deprecation state management.
pkgs/edge-worker/tests/integration/flow_deprecation.test.ts (1)
8-24: Well-designed test flow helper!The execution tracking and async simulation make it easy to verify worker behavior.
…ate related code - Renamed column stopped_at to deprecated_at in the workers table and migration - Updated database schema types to include deprecated_at field - Modified heartbeat logic to return deprecation status - Adjusted worker heartbeat handling to mark workers as deprecated - Enhanced worker lifecycle to transition to deprecated state upon deprecation - Updated worker state checks for deprecated status across modules - Refined queries to handle deprecated_at field and deprecation detection - Ensured deprecation status triggers worker to transition to deprecated state in main loop
…havior Includes integration tests for worker deprecation handling, in-flight message completion, multiple worker deprecation, and heartbeat deprecation detection. Also adds unit tests for Heartbeat class and WorkerLifecycle deprecation state transitions to improve coverage.
…ing message processing, in-flight message completion, multiple worker coordination, and post-deprecation message routing
…and message handling - Changed database URLs from localhost to 127.0.0.1 for consistency in tests - Updated message parsing to handle double-encoded JSON in multiple test files - Improved deprecation flow tests to verify message processing and worker deprecation - Adjusted delay timings to ensure proper detection of worker deprecation - Refined test logic for queue and archive counts after deprecation events - Enhanced test coverage for worker lifecycle and flow deprecation scenarios - Overall, these changes improve test reliability and consistency across environments
- Introduced heartbeatInterval option in WorkerLifecycle and FlowWorkerLifecycle - Replaced Heartbeat class with inline sendHeartbeat function for simplicity - Updated tests to mock sendHeartbeat behavior and verify deprecation handling - Ensured heartbeat respects interval, avoiding unnecessary calls - Removed deprecated Heartbeat.ts file to streamline codebase
… exports - Changed localhost IP from 127.0.0.1:5432 to ensure consistency across test files - Corrected database URL port in sql.ts to 5432 for proper connection - Removed unnecessary export of sql and postgres types in sql.ts for cleaner module - Overall, aligned test setup configurations for reliable database connections
…across tests - Replace direct sql import with createSql() calls for better resource management - Wrap database interactions in try-finally blocks to guarantee sql.end() is called - Update tests to use withSql helper for consistent SQL client handling - Minor adjustments to test setup and assertions for clarity and reliability
…rtions in test mocks - Renamed variables with leading underscores to improve readability - Corrected type assertions for SQL and logger mocks to align with expected types - Simplified Promise handling in mock methods for consistency - Minor formatting adjustments for better code clarity
Implement deprecation mechanism allowing workers to gracefully shut down by checking deprecation status via heartbeat, repurposing existing columns for tracking, and completing in-flight work before shutdown. Also, refactor heartbeat logic into lifecycle classes and add configurable heartbeat interval.
… tests - Updated transitionToDeprecated calls to be properly awaited in tests - Corrected mock return values to use Promise.resolve for consistency - Enhanced mockQueue.safeCreate to return a proper RowList structure - Ensured all test assertions handle asynchronous code correctly
Update test assertions to correctly expect exceptions when transitioning to deprecated state, ensuring compatibility with the testing framework.
Refactor message processing to avoid double JSON parsing, replace JSON.stringify with sql.json, and streamline message assertions across multiple test files.
09be1b2 to
09ea1f9
Compare
🔍 Preview Deployment: Website✅ Deployment successful! 🔗 Preview URL: https://pr-188.pgflow.pages.dev 📝 Details:
_Last updated: _ |
🔍 Preview Deployment: Playground✅ Deployment successful! 🔗 Preview URL: https://pr-188--pgflow-demo.netlify.app 📝 Details:
_Last updated: _ |
🚀 Production Deployment: Website✅ Successfully deployed to production! 🔗 Production URL: https://pgflow.dev 📝 Details:
Deployed at: 2025-08-04T19:26:43+02:00 |
🚀 Production Deployment: Playground✅ Successfully deployed to production! 🔗 Production URL: https://playground.pgflow.dev 📝 Details:
Deployed at: 2025-08-04T19:26:43+02:00 |
Summary
Key Changes
Database Schema
stopped_atcolumn todeprecated_atin theworkerstable to better reflect the worker stateCore Implementation
WorkerLifecycleandFlowWorkerLifecycleclasses to improve type safety and eliminate need for type castingTesting
WorkerLifecycleandFlowWorkerLifecycleanycastsOther Improvements
Test Plan
Breaking Changes
None - the deprecation feature is backward compatible. Existing workers will continue to function normally.
Summary by CodeRabbit
New Features
Bug Fixes
Tests
Refactor
deprecated_atinstead ofstopped_atfor worker records.