feat: add single-use research mandate guard - #299
Conversation
Co-Authored-By: Codex <noreply@openai.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b3d4ca32b8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| descriptor = os.open( | ||
| self._database, | ||
| os.O_CREAT | os.O_EXCL | os.O_WRONLY, | ||
| 0o600, | ||
| ) |
There was a problem hiding this comment.
When multiple valid issuers hit a fresh authority DB concurrently, the loser of the O_EXCL create gets FileExistsError here and the following except OSError denies it instead of reopening/validating the newly-created store. A second process can also connect while the first has only created the empty file and fail validation, so valid first-start issuance nondeterministically fails; retry/open the existing DB after an exclusive-create race or initialize under a lock.
Useful? React with 👍 / 👎.
| columns = tuple( | ||
| row[1] for row in connection.execute("PRAGMA table_info(mandates)") | ||
| ) | ||
| if columns != _ROW_FIELDS: |
There was a problem hiding this comment.
Reject stores with missing constraints
If the authority opens an existing SQLite file that has the same column order and metadata but omits the UNIQUE/CHECK/PRIMARY KEY constraints from _CREATE_SCHEMA, this validation still passes. In that context issue() can insert multiple rows with the same mandate_id because the code relies on the database constraint rather than rechecking it, so a damaged or spoofed store does not fail closed; validate the actual schema/indexes before accepting an existing store.
Useful? React with 👍 / 👎.
Summary
Boundaries
Tests
20 passed920 passed, 1 skipped, 80 subtests passedgit diff --check, exact-two-path scope and dependency-file gates passed