Dispatch routine maintenance gate: isolated experiment
Status: test-only proof of a narrow two-transaction sequence. The script
tests/dispatch_maintenance_gate_poc.sh uses disposable PostgreSQL and a
temporary Rails copy. It does not modify development provisioning, grant any
real dispatch capability or send messages.
Tested sequence
Section titled “Tested sequence”- A fixed fixture routine is first granted EXECUTE to the app through the existing test-only manifest. A separate close transaction revokes app and PUBLIC routine rights and checks effective EXECUTE for roles the app can assume. It commits before any later validation or reopen.
- A new app session cannot call the function after close. Leaving that state alone models a process stopping between the two transactions.
- Changing the fixture’s function body makes the separate reconciliation transaction fail. The already-committed close stays in effect.
- After the approved body is restored, the test deliberately terminates the reopening PostgreSQL backend after it granted EXECUTE but before COMMIT. PostgreSQL rolls back that transaction and the app remains denied. An explicit later reconciliation can validate and reopen the fixture.
The test also covers a failed close: if a role the app can assume retains EXECUTE, the close check aborts and rolls back the direct revoke, leaving the previous app grant in place. A failed close is therefore not maintenance mode. The test removes the deliberately added role grant before demonstrating successful closure. This is a material obstacle, not a production remediation.
Limits and required design
Section titled “Limits and required design”- This is a fixture and test-only SQL, not a shared production provisioning, restore or deployment mechanism. Existing fail-closed production behavior is unchanged. PostgreSQL routine permissions do not prove product authorization.
- Revoke prevents subsequent permission-checked calls; this test does not prove an already executing routine stops or that open transactions and cached sessions cannot cause relevant in-flight effects. A real maintenance procedure needs an explicit drain/coordination strategy, timeout and truthful status.
- If close fails, old grants may remain. Recovery needs an independent trusted way to remove or neutralize all effective paths, verify closure and report an unsafe state without proceeding. It must handle assumable roles, PUBLIC, ownership and concurrent grants without assuming rollback did the cleanup.
- The test-only advisory lock is voluntary. Concurrent privileged DDL or grant changes can race with validation and reopening. Real role ownership and DDL authority, administrative serialization, transaction boundaries, startup, restart, timeout and drift detection require design and adversarial tests.
- The fixture hard-codes an exact body and a single function; it is not a versioned protected manifest, and does not cover overloads, all dependencies, role changes, restore/provision failure or arbitrary PostgreSQL versions.
- Failed or unknown COMMIT outcomes require explicit recovery: verify effective privileges from a fresh trusted connection before claiming closed or open. This narrow test intentionally simulates confirmed backend termination, not a lost commit response or network partition.
Before enabling an app-executable production routine, integrate one reviewed policy with real provisioning and restoration, test the actual deployment and failure paths, and define how to handle already running work. No dispatch migration or transport is authorized by this experiment.