Repository navigation
fix(database): compose jobstore SQL safely - #25116
Merged
Merged
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Git-on-my-level
added a commit
that referenced
this pull request
Nov 12, 2026
…3761) (#23806) Fixes #23761 Restores the recovery-cancellation prerequisite tracked by SCA-1689. Account deletion during recovery now durably cancels the prepared or running recovery through the shared Store interface before paid work or result upload on Firestore, Postgres, and the simulator. The coordinator delegates to `cancel_fenced_recovery`; each adapter rechecks the privacy fence and changes only the cancellation marker when blocked. Firestore refreshes the shadow after commit. Main is merged into the existing branch without rewriting its history, retaining the SQL identifier hardening from #25116 and the newer privacy-defer methods. The overlapping #23763 is already closed. ## Verification Run from `backend/` under a loopback Firestore emulator, with a throwaway local Postgres cluster and synthetic customer authority: - `OMI_REQUIRE_STORE_BACKENDS=all .venv/bin/python -m pytest -v -rxX -p no:cacheprovider tests/integration/test_recovery_admission_conformance.py`: exit 0, 27 passed; all three adapters, no skips or xfails. PL-057/072/086 cover cancellation before recovery and after download, restart/redelivery, no paid calls or result uploads, and unrelated-owner progress. Only the PL-072 strict xfails whose contract now passes were removed. - `OMI_REQUIRE_STORE_BACKENDS=all .venv/bin/python -m pytest -q -rxX -p no:cacheprovider tests/integration/test_store_conformance.py tests/integration/test_recovery_custody_conformance.py`: exit 0, 267 passed, 6 adapter-specific not-applicable skips; every adapter available. - `backend/.venv/bin/python -m pytest -q -p no:cacheprovider backend/tests/unit/test_batch_pipeline_scheduler.py`: exit 0, 62 passed. This source repair books **$0/day**. Production serving parity, cross-database privacy safety, physical erasure, reverse migration/rollback, pooler readiness, deployment/readback, production-fence decisions, and a full settled before/after day of normalized net cost remain separate gates owned by the pipeline driver and SCA-1683. Existing dark/staging selectors and production fences remain in force. ## Product invariants affected none ## Failure-Class Failure-Class: none ## UI-Evidence UI-Evidence: none -- internal recovery Store integration and conformance evidence.
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.
Summary
Canonical re-cut of #24042 on current
main(72d5dfdc671a2ccb0ffbb983785e995d8bdaa507). Head:6a634c9706cd4f84d20cc492be8662f8ef5dc1b4.This replaces f-string interpolation at all 13 assigned composition sites with
psycopg.sqlidentifiers, literals, and typed literal SQL fragments. Runtime values remain query parameters. A single publicdatabase.jobstore.connection.sql()accessor preserves the lazy-postgres-driver invariant, and_fenced_updatenow types its SQL fragments asLiteralString.This is defense in depth, not a claim of a live exploit: the existing call paths already gate table/column choices through fixed allowlists, validated priorities/pools, or internal constants, as the reviewers of the overlapping PRs noted.
Failure-Class: none
Sites fixed
backend/database/jobstore/postgres_store.py:261—due(): quote the selected due column in both predicate and ordering.backend/database/jobstore/postgres_store.py:404—control_candidates(): quote every priority/pool-derived column reference.backend/database/jobstore/postgres_store.py:508— typedread_doc(): compose the table identifier and lock suffix.backend/database/jobstore/postgres_store.py:541—write_doc(): quote the typed table identifier.backend/database/jobstore/postgres_store.py:556—delete_doc(): quote the typed table identifier.backend/database/jobstore/postgres_store.py:569—service_frontier_in(): quote the priority-derived column.backend/database/jobstore/postgres_store.py:593—purge_namespace(): quote every cleanup table identifier.backend/database/jobstore/backfill.py:60—postgres_keys(): quote the typed table identifier.backend/database/jobstore/outbox_pg.py:169—claim(): compose the fixedRETURNINGcolumn list.backend/database/jobstore/outbox_pg.py:202—claim_key(): compose the fixedRETURNINGcolumn list.backend/database/jobstore/outbox_pg.py:255—_fenced_update(): compose onlyLiteralStringset/guard fragments; keep claim data bound.backend/testing/pipeline_sim/postgres_store.py:35—PgRows._all(): compose each typed table asIdentifierand its projected name asLiteralacross theUNION ALL.backend/testing/pipeline_sim/postgres_store.py:210— simulatordelete(): quote the typed table identifier.backend/database/jobstore/connection.py:28adds the single lazypsycopg.sqlaccessor. The two simulator hunks are folded in from #24015. None of #24042's unrelatedcommit_message.txt,test_sql.py, or.agent-brief/firestore-index-guard/tests.txtfiles are carried over.Tests
New hermetic behavioral coverage exercises every site above with hostile identifiers/values, verifies parameter tuples never enter rendered statement text, checks the outbox produces real
psycopg.sql.Composablestatements, and imports every changed module in clean subprocesses wherepsycopgis explicitly unavailable.Focused pytest runs (one process per file):
test_jobstore_sql_composition.pytest_jobstore_backfill.pytest_jobstore_dual_store.pytest_jobstore_migrations.pytest_jobstore_postgres_locking.pytest_jobstore_projection_mirror.pytest_jobstore_protocol_parity.pytest_jobstore_shadow_seams.pytest_jobstore_codec.pytest_batch_pipeline_lock_jobstore.pyTotal: 218 passed. No full-suite or live-service run was used.
bash backend/scripts/typecheck.sh: 0 errors.scripts/backend-python-format --check ...: 7 files unchanged.Supersedes and follow-up
_psycopg()access are both avoided by the public lazy accessor.