duroxide-pg
Copilot instructions44 starsChanged 3 months agoMITView on GitHub
Prefer cargo-nextest if installed (faster, better output). Fall back to cargo test otherwise. Each test runtime creates a connection pool (default 10 max connections). At high parallelism (e.g., 14 cores), peak PostgreSQL connections can reach ~104. If PostgreSQL max_connections is set to the default 100, tests will fail with timeouts due to connection exhaustion. Fix: Increase PostgreSQL max_connections to at least 300:
- Reads credentials
In this repositoryOne other file it gives its agents.
- release-preparationSkill
The file
Show its rules and text
We split this copilot-instructions.md into the rules it gives an agent
15 rules. About 0 are common, 5 are distinctive, and 10 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
10
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 15
Stored Procedures over inline SQL: - All database operations use schema-qualified stored procedures in 0002_create_stored_procedures.sql …
- Very specific: line 16
Rust-provided timestamps: - All procedures receive p_now_ms from Rust (not database NOW()) to avoid clock skew (see migration 0006)
- Very specific: line 40
Prefer
cargo-nextest: if installed (faster, better output). - Very specific: line 107
Create NNNN_description.sql in migrations/
- Distinctive: line 108
Use unqualified table names (search_path is set by runner)
- Distinctive: line 110
Update stored procedures with new parameters if needed
- Very specific: line 114
Every migration that modifies schema or stored procedures must have a companion NNNN_diff.md file.
- Distinctive: line 126
When a live database isn't available, generate diffs by extracting stored procedure bodies from the SQL migration files:
- Very specific: line 135
Diff: Run diff -u <baseline_normalized> <new_normalized> to get unified diff output.
- Distinctive: line 147
Follow the detailed guide in prompts/update-duroxide-dependency.md.
- Distinctive: line 148
Review changes: Read duroxide CHANGELOG, README, and provider guides at the duroxide repo
- Very specific: line 150
Implement API changes: Update src/provider.rs, add migrations if needed
- Very specific: line 153
Document as unreleased: Add dependency and compatibility notes under CHANGELOG.md's existing [Unreleased] section
- Very specific: line 159
Use .agents/skills/release-preparation/SKILL.md to prepare release metadata and create the release PR.
- Very specific: line 171
Check schema cleanup: Run scripts/cleanup_test_schemas.sh after failed tests
≈ “Common” is an estimate: at least 1 in 5 of the 1,644 Copilot instructions files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Duroxide-PG Copilot Instructions
Project Overview
This is a PostgreSQL provider for Duroxide, a durable task orchestration framework for Rust. It implements the Provider and ProviderAdmin traits, storing orchestration state, history, and work queues in PostgreSQL using stored procedures.
Architecture
Core Components
- src/provider.rs - Main
PostgresProviderimplementing duroxide traits (Provider,ProviderAdmin) - src/migrations.rs - Embedded SQL migration runner using
include_dir! - migrations/ - Sequential SQL migrations (schema + stored procedures)
- pg-stress/ - Stress testing binary for performance validation
Key Design Decisions
- Stored Procedures over inline SQL - All database operations use schema-qualified stored procedures in
0002_create_stored_procedures.sqlfor atomic transactions and deadlock prevention - Rust-provided timestamps - All procedures receive
p_now_msfrom Rust (not databaseNOW()) to avoid clock skew (see migration0006) - Schema isolation - Multi-tenant support via custom PostgreSQL schemas (
new_with_schema()) - Two-phase locking in fetch operations - Prevents B-tree index deadlocks (peek query → advisory lock → FOR UPDATE verification)
Data Flow
Duroxide Runtime → PostgresProvider → Stored Procedures → PostgreSQL Tables
(instances, executions, history,
orchestrator_queue, worker_queue)Development Workflow
Prerequisites
# PostgreSQL running locally (or use Docker)
docker run -d --name duroxide-pg -p 5432:5432 -e POSTGRES_PASSWORD=postgres postgres:15
# Create .env file
echo "DATABASE_URL=postgres://postgres:postgres@localhost:5432/duroxide_test" > .envRunning Tests
Prefer cargo-nextest if installed (faster, better output). Fall back to cargo test otherwise.
# Check if nextest is available
command -v cargo-nextest >/dev/null 2>&1 && echo "nextest available" || echo "use cargo test"
# All tests with nextest (preferred)
cargo nextest run
# All tests with cargo test (fallback)
cargo test
# Specific test with output
cargo nextest run test_provider_creation --nocapture
# or: cargo test test_provider_creation -- --nocapture
# Provider validation tests only (99 tests from duroxide)
cargo nextest run --test postgres_provider_test
# or: cargo test --test postgres_provider_test
# Stress tests (long-running, marked #[ignore])
cargo nextest run --test stress_tests --run-ignored only
# or: cargo test --test stress_tests -- --ignoredConnection Exhaustion Under High Parallelism
Each test runtime creates a connection pool (default 10 max connections). At high parallelism (e.g., 14 cores), peak PostgreSQL connections can reach ~104. If PostgreSQL max_connections is set to the default 100, tests will fail with timeouts due to connection exhaustion.
Fix: Increase PostgreSQL max_connections to at least 300:
docker exec <container> psql -U postgres -c "ALTER SYSTEM SET max_connections = 500;"
docker restart <container>Stress Testing
# Quick stress test (10 seconds)
cargo run --release --package duroxide-pg-stress --bin pg-stress -- --duration 10
# Custom configuration
cargo run --release --package duroxide-pg-stress --bin pg-stress -- \
--duration 30 --orch-concurrency 4 --worker-concurrency 4Conventions
Error Handling
Provider errors are classified as retryable or permanent via ProviderError:
// Retryable: deadlocks (40P01), pool timeouts, I/O errors
ProviderError::retryable(operation, message)
// Permanent: constraint violations (23505, 23503), invalid tokens
ProviderError::permanent(operation, message)Schema Naming for Tests
Tests create unique schemas with GUID suffix to allow parallel execution:
fn next_schema_name() -> String {
let guid = uuid::Uuid::new_v4().to_string();
format!("test_{}", &guid[guid.len()-8..])
}Adding Migrations
- Create
NNNN_description.sqlinmigrations/ - Use unqualified table names (search_path is set by runner)
- Make idempotent with
IF NOT EXISTS/IF EXISTS - Update stored procedures with new parameters if needed
- REQUIRED: Generate a diff markdown file (see below)
Migration Diff Files (Required)
Every migration that modifies schema or stored procedures must have a companion NNNN_diff.md file. This is required because git diffs for SQL migrations only show the new code, not the delta from the previous version.
Option A: Auto-generate with PostgreSQL (preferred)
./scripts/generate_migration_diff.sh <migration_number>
# Example: ./scripts/generate_migration_diff.sh 9
# Creates: migrations/0009_diff.mdThe script creates temp schemas, applies migrations before/after, extracts DDL, and diffs them.
Option B: Manual extraction (when no PostgreSQL available)
When a live database isn't available, generate diffs by extracting stored procedure bodies from the SQL migration files:
- Identify baselines: For each SP modified in migration N, find the most recent migration before N that contains
CREATE OR REPLACE FUNCTION ... <sp_name>. Usegrep -n "CREATE OR REPLACE FUNCTION.*<sp_name>" migrations/*.sqlto find them. - Extract SP bodies: Extract the
CREATE OR REPLACE FUNCTION ... LANGUAGE plpgsql;block from both the baseline and new migration files. - Normalize before diffing: Migration files use different SQL quoting mechanisms across versions:
- Replace schema placeholders (
%I.or@SCHEMA@.) withSCHEMA. - Replace escaped single quotes (
'') with'(old migrations insideformat('...')need''; newer ones insideformat($fmt$...$fmt$)don't) - Replace escaped percent signs (
%%) with%(same reason:format()uses%for placeholders) - Expand tabs to spaces and strip trailing whitespace
- Replace schema placeholders (
- Diff: Run
diff -u <baseline_normalized> <new_normalized>to get unified diff output. - Assemble: Strip the
---/+++header lines and include the hunks in```diffcode blocks.
Diff format requirements
Each changed function must be shown with +/- diff markers on changed lines inside a ```diff code block. The diff file should contain:
- Table Changes — New tables (full DDL in
```sqlblock), modified tables (mark new columns with+) - New Indexes — Any indexes added by the migration (full DDL in
```sqlblock) - Function Changes — For each changed function: unified diff in a
```diffblock with the baseline migration number noted in the heading (e.g.,### \func_name` — body modified (baseline: 0016)`)
Example output: See migrations/0017_diff.md
Updating duroxide Dependency
Follow the detailed guide in prompts/update-duroxide-dependency.md. Key steps:
- Review changes: Read duroxide CHANGELOG, README, and provider guides at the duroxide repo
- Update Cargo.toml: Change version, run
cargo check, fix compilation errors - Implement API changes: Update
src/provider.rs, add migrations if needed - Add validation tests: New tests go in
tests/postgres_provider_test.rsusing theprovider_validation_test!macro - Test thoroughly:
cargo test, run flaky tests 10x - Document as unreleased: Add dependency and compatibility notes under
CHANGELOG.md's existing[Unreleased]section
Dependency update and feature PRs must keep the current duroxide-pg package version and published README release sections unchanged. Release preparation and publishing are governed by RELEASE_POLICY.md.
⚠️ Never publish directly to crates.io.
Use .agents/skills/release-preparation/SKILL.md to prepare release metadata and create the release PR. After the PR is merged into main, the skill may create and push the version tag only with fresh explicit user approval.
Key Files Reference
| File | Purpose |
| provider.rs | Provider trait implementations |
| 0002_create_stored_procedures.sql | All stored procedures |
| tests/common/mod.rs | Test utilities (create_postgres_store, test_create_execution) |
| postgres_provider_test.rs | Provider validation test harness |
Debugging Tips
- Enable tracing:
RUST_LOG=duroxide::providers::postgres=debug cargo test - Check schema cleanup: Run
scripts/cleanup_test_schemas.shafter failed tests - Deadlock issues: Review two-phase locking in
fetch_orchestration_itemstored procedure
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

