Skip to content

HTTP policy control (concurrency, etc) - #429

Open
Thom Chiovoloni (thomcc-work) wants to merge 11 commits into
mainfrom
thomcc/policies
Open

Thom Chiovoloni (thomcc-work) wants to merge 11 commits into
mainfrom
thomcc/policies

Conversation

@thomcc-work

@thomcc-work Thom Chiovoloni (thomcc-work) commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Give administrators a ceiling on outbound HTTP concurrency and let a workflow set a lower ceiling for itself or a subtree. When a request cannot run yet, it stays in the durable queue rather than waiting inside an activity slot.

Server setting What it limits Default
pg_durable.max_activity_concurrency All activities in the shared runtime, including SQL and metadata work 2
pg_durable.max_http_concurrency df.http() and df.http_multipart() combined, across all users and origin databases 2

Both settings require a PostgreSQL restart. The defaults preserve the existing two-activity capacity. Set the HTTP ceiling below total activity capacity to leave slots available for other work.

Workflow policies

SELECT df.start(
    df.with_policy(
        df.join(
            df.http('https://api.github.com/repos/microsoft/pg_durable', 'GET'),
            df.http('https://api.github.com/repos/microsoft/duroxide', 'GET')
        ),
        '{"http": {"max_concurrency": 1}}'::jsonb
    ),
    'repository-metadata'
);

In this example, only one of the two HTTP requests can run at a time. Each request reserves capacity against the server ceiling and every enclosing scope, or takes no capacity at all. An inner policy cannot raise an outer limit. Parallel branches and loop iterations share their enclosing scopes, including after restart; separate workflow starts have independent local budgets. df.explain() shows which scopes apply.

Admission and authorization

  • df.start() checks the submitter's HTTP privileges in the origin database before enqueueing, including for raw graphs and untaken branches. A missing grant raises 42501 in either transaction mode. Activities still recheck privileges before sending, so a later revocation takes effect.
  • An admitted HTTP activity holds its reservation through request preparation, response-body processing, and optional sink storage. Between admission attempts, waiting requests hold neither an activity slot nor an origin connection. Waiting does not consume the request timeout.
  • Committed deferrals restore their fetch attempt and move behind already-ready work. Unrelated SQL can progress while HTTP remains saturated, but polling a large backlog still generates queue writes and WAL. Concurrency limits do not guarantee low latency, per-tenant fairness, or a request rate.

Dependencies and upgrade

The PR uses the released duroxide 0.2.0 and duroxide-pg 0.2.0 crates. There are no Git overrides or pending upstream dependencies.

  • Drain all provider callers before upgrading through 0027/0028, including clients, workers, maintenance jobs, and direct SQL callers. Start the new control worker first and wait for readiness 5 before resuming traffic. Allow time and WAL space for the continue-as-new timestamp backfill and plan for the 0029 queue-index lock. 0030 installs disabled notification triggers; long polling remains off.
  • The new binary enforces the global limit on supported older extension schemas. Run ALTER EXTENSION pg_durable UPDATE TO '0.2.10' for df.with_policy(). Unconfigured HTTP payloads keep their existing bytes; policies add no orchestration operations to replay.
  • The former PR-only provider pin recorded 0029 without 0027/0028. Development stores with that gap cannot upgrade in place; do not edit the migration ledger. This caveat does not apply to fresh installations or upgrades from released pg_durable versions. See the rollout and prerelease-store guidance.

Validation

Local PostgreSQL 17 checks used the shared test lock and a disposable cluster:

  • 469 unit tests passed (16 ignored); 177 upgrade checks passed, including replay of workflows started by the released v0.2.9 binary.
  • Readiness and HTTP E2E tests passed for global and nested limits, multipart and satellite requests, sink writes, cancellation, restart recovery, and authorization. In the 500-request backlog regression, an independent SQL workflow completed before the held HTTP request was released.
  • Epoch-race and shutdown checks passed. A fresh store recorded migrations 0027, 0028, 0029, and 0030 in order, published readiness 5, and had all six notification triggers disabled.

@thomcc-work
Thom Chiovoloni (thomcc-work) force-pushed the thomcc/policies branch 2 times, most recently from d363447 to ff6c0f8 Compare October 29, 2026 14:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The runtime pin relies on an unmerged dependency and changes admission, shutdown, and replay behavior, requiring PostgreSQL shutdown, epoch-replacement, HTTP restart, and N-1 replay integration results beyond source inspection.

No open issues 🎉

What changed in this PR

Adds server-wide and workflow-scoped HTTP concurrency controls to pg_durable’s shared runtime, with durable queue deferral when capacity is unavailable. The PR depends on the admission support in microsoft/duroxide#74.

Changes:

  • Adds configurable activity and HTTP limits, plus composable subtree policies through df.with_policy().
  • Integrates admission checks and shutdown-interruptible runtime initialization.
  • Adds concurrency, cancellation, and restart tests, alongside API and operational documentation.
File Description
USER_GUIDE.md Explains concurrency settings, workflow policies, and limitations.
tests/​e2e/​sql/​92_http_restart.sql Tests interrupted HTTP recovery and persisted policy enforcement.
tests/​e2e/​sql/​91_http_policies.sql Tests nested scopes, independent budgets, loops, and races.
tests/​e2e/​sql/​90_http_concurrency.sql Tests global limits, cancellation, SQL headroom, and permit lifetimes.
tests/​e2e/​http_origin_server.py Adds gated responses and concurrency counters.
src/​worker.rs Configures runtime capacity and interruptible startup.
src/​types.rs Carries policies and materializes HTTP scope metadata.
src/​registry.rs Registers admission hooks for both HTTP activities.
src/​policies.rs Implements policy validation, scope accounting, and admission guards.
src/​lib.rs Registers concurrency settings and adds integration tests.
src/​explain.rs Displays HTTP scope limits in graph explanations.
src/​dsl.rs Adds the df.with_policy() graph helper.
sql/​pg_durable--0.2.9--0.2.10.sql Exposes the policy helper during extension upgrades.
scripts/​test-e2e-local.sh Runs HTTP concurrency scenarios and restart orchestration.
scripts/​test-e2e-docker.sh Skips tests requiring the local TLS fixture.
docs/​upgrade-testing.md Documents schema compatibility, replay behavior, and validation.
docs/​multi-database-installation.md Updates runtime shutdown guarantees and remaining limitations.
docs/​http-security.md Explains capacity enforcement and its security boundaries.
docs/​grammar.md Documents policy annotations in the DSL grammar.
docs/​E2E_TESTING.md Lists the new HTTP test scenarios.
docs/​api-reference.md Documents the policy API and concurrency settings.
CHANGELOG.md Records HTTP limits, policies, and startup shutdown handling.
Cargo.toml Updates Duroxide and pins the temporary admission revision.
Cargo.lock Locks the updated runtime dependency graph.
.agents/​skills/​pg-durable-sql/​SKILL.md Adds workflow policy syntax and usage guidance.

Review effort: Balanced

@thomcc-work
Thom Chiovoloni (thomcc-work) marked this pull request as ready for review November 3, 2026 15:37
Still pinned via git.
Pinned to 9ae067b, alongside the merged duroxide revision.

Changes:

- Updated the provider dependency and lockfile.
- Advanced WORKER_SCHEMA_VERSION to 4 for the bundled migrations.
- Added a 500-request backlog regression.
- Updated migration, rollout, and behavior documentation.
Address review 429-1 using the documented disposable-database alternative. The current provider pin records migration 0029 without the pending 0027/0028 prefix; do not disguise this by changing readiness or migration ledger rows.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Address review 429-3 with the supplied full-stack measurement, its workload and limits. Keep retry-delay policy unchanged as requested; tuning latency versus database load remains follow-up work.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Address review 429-2: recover poisoned admission locks without resetting reservations, make counter cleanup non-panicking with saturating decrements, and log invariant faults. Add tests for poisoned admission/release and inconsistent counters.

Validation: build and Clippy passed; 469 unit tests passed (16 ignored); all 91 E2E tests passed through the shared PostgreSQL lock-aware runners.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Address review 429-4 by checking the submitting role against every required HTTP overload in the origin database. Share signature selection with activity-time checks, cache repeated checks per graph, and preserve SQLSTATE 42501 for independent starts. Retain execution-time authorization for revocation and historical work.

Cover raw and nested graphs, all four overloads, both transaction modes, hostile search paths, inherited grants, definer identity, no persisted submission on denial, satellite isolation and post-submission revocation. Build, Clippy, unit and authorization regressions pass; the corrected satellite test and all 177 upgrade checks pass.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace both Git overrides with exact crates.io dependencies. The former
provider could publish readiness 4 without applying migrations 0027 and
0028. Require readiness 5 before accepting new work; installing the full
migration sequence does not enable long polling.

Document the drained upgrade from released versions separately from PR-only
stores that recorded 0029 out of order and cannot upgrade in place.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

This branch has not been deployed

No deployments
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