π keep the admission advisory-lock key valid PostgreSQL text - #688
Open
jrosseel wants to merge 1 commit into
Open
π keep the admission advisory-lock key valid PostgreSQL text#688jrosseel wants to merge 1 commit into
jrosseel wants to merge 1 commit into
Conversation
Run admission and child-run reservation each serialise one idempotency key by taking an advisory lock on hashtextextended of the silo and key joined by a NUL byte. PostgreSQL text cannot hold a NUL: the parameter fails the statement with SQLSTATE 22021, so the transaction rolled back and every message submit returned 503. On testv4 that made agent sessions unusable β "OpenCrane could not complete that action" for every send. Both sites now compose the key through __AdmissionLockKey, which prefixes the pair with the silo length. That keeps distinct pairs distinct without reserving a character either part may contain, and reserves no byte PostgreSQL rejects. The unit tests could not catch this because they stub $queryRaw, so the repository suites now assert that no text parameter reaching Postgres carries a NUL. Both new assertions fail against the previous separator.
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What broke
On testv4, every message sent to an Agent session failed with "OpenCrane could not complete that action. Try again." The API returned 503 on every
POST /api/v1/me/conversations/{id}/messages.Server log from the live silo:
Cause
Both admission paths serialise one idempotency key with an advisory lock, joining the silo and the key with a NUL byte before hashing:
PostgreSQL text cannot hold a NUL byte β the parameter fails the statement with SQLSTATE 22021, the transaction rolls back, and admission reports
transaction_failed. This affectedprisma-run-admission-repository.tsandprisma-child-run-reservation-repository.ts, so both agent-session sends and child@agentruns were dead against a real database.What changed
__AdmissionLockKeyhelper composes the key, prefixing the pair with the silo's length. Distinct pairs stay distinct without reserving a character either part may legitimately contain, and no byte PostgreSQL rejects is used.Verification
The existing suites stub
$queryRaw, which is exactly why a NUL reached production. So both repository suites now assert that no text parameter handed to Postgres carries a NUL, plus a unit suite for the helper covering NUL-freedom, injectivity, and stability.Proof the tests catch the regression β restoring the old separator:
With the fix: 23 files, 144 tests pass.
nx lintclean,agent-style-check.sh0 errors.Not covered
No test exercises these repositories against a real PostgreSQL, so a statement-level SQL error of a different kind would still reach a cluster before CI catches it. Worth a follow-up: a Prisma integration harness against the
databasejob's Postgres service.Review order
Single PR, no stack. Independent of #687.