Repository navigation
fix(projects): require second-review policy false #502
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2c2acd5
fix(projects): require second review policy false
bc959b6
test(migrations): assert canonical current head
dcbae84
Merge remote-tracking branch 'origin/main' into codex/pilot11-second-…
cbdf3d2
Merge remote-tracking branch 'origin/main' into codex/pilot11-second-…
08bb029
docs: reconcile second-review guard with merged base
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
.commitrail/changes/enforce-requires-second-review-false.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| # Enforce requires_second_review=false | ||
|
|
||
| - Initiative: None | ||
| - Durable disposition: Complete | ||
| - Intended merge outcome: ReviewPolicy accepts and persists only `requires_second_review=false`, while existing false-policy hashes and immutable lineage remain unchanged. | ||
|
|
||
| ## Intent | ||
|
|
||
| Adjudication and second-review lifecycle behavior are deferred. The current | ||
| ReviewPolicy surface nevertheless accepts `requires_second_review=true`, and | ||
| the database permits the unsupported value through raw writes. This change | ||
| closes both paths without inventing review behavior or rewriting retained | ||
| policy facts. | ||
|
|
||
| ## Current behavior | ||
|
|
||
| `ReviewPolicyInput`, `ReviewPolicySemantics`, and `ReviewPolicyResponse` type the | ||
| field as an unrestricted boolean. `ReviewPolicy` stores it as a non-null boolean | ||
| without a false-only constraint. The authorized policy writer hashes the field, | ||
| shared locked-policy projection validates it, and the external API drill | ||
| currently submits true on replacement. Migration 0023 is the merged predecessor | ||
| and owns the separate obsolete TASK payment cleanup. | ||
|
|
||
| ## Bounded change | ||
|
|
||
| ### Allowed | ||
|
|
||
| - PROJECTS review-policy input, immutable semantics/lineage response and ORM | ||
| constraint metadata. | ||
| - One additive migration 0024 after 0023: lock `review_policies`, refuse any | ||
| retained true row, then install the false-only check constraint. | ||
| - Alembic accepted-revision registration, graph proof, PostgreSQL 16 schema | ||
| fingerprint, semantic test-lane registration and the external API drill. | ||
| - Focused input/hash, shared projection, public API, raw-write and real | ||
| predecessor-upgrade tests, plus the existing payment-cleanup full-head | ||
| migration proof's current-revision assertion. | ||
| - Current README, architecture, review lifecycle, guide template and roadmap | ||
| statements affected by the supported ReviewPolicy contract. | ||
|
|
||
| ### Not allowed | ||
|
|
||
| - Second-review, adjudication, reviewer assignment or decision behavior. | ||
| - ContributionPolicy, award, payment, routing, activation or acceptance | ||
| semantics. | ||
| - Retained-data rewrite/deletion, policy rehashing, migration 0023 changes, | ||
| compatibility variants or duplicate payment cleanup. | ||
|
|
||
| ## Design and decisions | ||
|
|
||
| Use `Literal[False] = False` at untrusted input and immutable typed lineage | ||
| boundaries. Keep the stored column because it remains part of canonical v1/v2 | ||
| policy bodies and removing it would change existing false-policy hashes. Add a | ||
| named PostgreSQL check for raw-write enforcement. Migration 0024 takes an | ||
| `ACCESS EXCLUSIVE` table lock across preflight and constraint installation so a | ||
| writer cannot introduce true between them. A retained true row raises SQLSTATE | ||
| 23514 before DDL; the migration does not repair, rewrite, delete or rehash it. | ||
|
|
||
| ## Acceptance criteria | ||
|
|
||
| - [x] Public true input returns 422 without advancing the selected policy. | ||
| - [x] Omitted/false v1 and v2 canonical hashes retain their exact bytes. | ||
| - [x] Typed immutable lineage and shared locked-policy projection reject true. | ||
| - [x] PostgreSQL rejects raw true writes through the named model/migration | ||
| constraint. | ||
| - [x] Real 0023-to-0024 upgrade refuses a custody-committed retained true policy | ||
| with its row, hash, guide selector and schema version unchanged. | ||
| - [x] Ordinary false-only upgrade preserves policy rows/hashes/selectors and | ||
| installs one recognized 0024 head. | ||
|
|
||
| ## Risk and review routing | ||
|
|
||
| - Risk class: L1 | ||
| - Required reviewers: architecture, reuse/dedup, security, QA, test delta, documentation | ||
| - Human review focus: retained-fact refusal, unchanged hashes, schema/model/type parity, and no accidental second-review or payment semantics | ||
|
|
||
| ## Evidence | ||
|
|
||
| | Claim | Command or proof | Result | Remaining uncertainty | | ||
| |---|---|---|---| | ||
| | Typed and shared caller behavior | Focused review-policy, locked-policy and identity-lineage pytest modules | False contracts and fixed hash bytes pass; true lineage fails closed | Full hosted suite remains external evidence | | ||
| | PostgreSQL schema identity | Fresh PostgreSQL 16 migration through 0024, canonical fingerprint generation and focused graph/raw-write proof | Head installs the named constraint; fingerprint updated from the real schema; focused boundary nodes pass | Hosted PostgreSQL lane remains external evidence | | ||
| | Retained-data safety | Actual 0023 predecessor migration tests | Custody-committed true facts refuse unchanged; false facts upgrade unchanged | Operational handling of any discovered true row requires a separate preservation decision | | ||
|
|
||
| ## Review findings | ||
|
|
||
| No material finding is recorded in this durable change record. | ||
|
|
||
| ## Reconciliation | ||
|
|
||
| - Current-source reconciliation: current `main` at `235f9e1b` includes the | ||
| merged obsolete-payment cleanup, local runtime, evaluation-capacity and guide | ||
| CLI work. Migration 0024 extends the merged 0023 head without changing that | ||
| migration or cleanup behavior. | ||
| - The existing payment-cleanup proof still upgrades through full Alembic head | ||
| and now checks that result against the canonical current revision lookup. | ||
| - Next usable boundary: second-review/adjudication behavior remains deferred; other pilot work proceeds only after this pull request is merged. | ||
| - Remaining risks: a database containing retained true policies cannot upgrade until an explicit preservation/disposition design is approved. | ||
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
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
36 changes: 36 additions & 0 deletions
36
backend/alembic/versions/0024_require_second_review_false.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| """Refuse unsupported retained second-review policy before fixing it false.""" | ||
|
|
||
| from alembic import op | ||
|
|
||
| revision = "0024_require_second_review_false" | ||
| down_revision = "0023_remove_task_payment_policy" | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| """Preserve retained policy facts and install the current false-only invariant.""" | ||
| op.execute("LOCK TABLE public.review_policies IN ACCESS EXCLUSIVE MODE") | ||
| op.execute(""" | ||
| DO $$ | ||
| BEGIN | ||
| IF EXISTS ( | ||
| SELECT 1 FROM public.review_policies WHERE requires_second_review | ||
| ) THEN | ||
| RAISE EXCEPTION | ||
| 'retained requires_second_review=true policy requires an explicit preservation design' | ||
| USING ERRCODE='23514'; | ||
| END IF; | ||
| END; | ||
| $$; | ||
| """) | ||
| op.create_check_constraint( | ||
| "review_policy_second_review_disabled", | ||
| "review_policies", | ||
| "not requires_second_review", | ||
| schema="public", | ||
| ) | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| raise RuntimeError("Workstream v0.1 migrations cannot be downgraded; recreate the database") |
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.