Skip to content

feat(review): persist immutable review and revision policies#195

Open
Abiorh001 wants to merge 27 commits into
mainfrom
codex/ws-rev-001-03p-review-revision-policy-v2
Open

feat(review): persist immutable review and revision policies#195
Abiorh001 wants to merge 27 commits into
mainfrom
codex/ws-rev-001-03p-review-revision-policy-v2

Conversation

@Abiorh001

@Abiorh001 Abiorh001 commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

PR Trust Bundle: WS-REV-001-03P

Chunk

WS-REV-001-03P - Review And Revision Policy Persistence.

Goal

Persist the immutable REV-owned policy facts required by later review routing,
leases, decisions, and human revision work, without implementing those later
lifecycle stages.

Human-approved intent

REV starts only after allow_review, consumes the existing Submission and
artifact set, records complete traceable review/revision history in later
chunks, and never absorbs Project Guide, Task, AUTH, ART, or CON ownership.

What changed and why

Migration 0034 replaces ambiguous legacy policy columns with explicit review
preference/lease, finding-evidence, revision-limit/deadline, and provenance
facts. Legacy values remain private and losslessly downgradeable until one
atomic conversion. Models, schemas, repository/service mapping, active docs,
and focused tests now agree with that database contract.

Design chosen

Separate table-specific triggers make policy rows immutable, serialize every
insert/update with the exact guide row, reject runtime legacy claims, and permit
only atomic legacy-to-canonical conversion. Downgrade locks all three involved
tables and refuses canonical facts or unreconstructible archives before DDL.

Alternatives rejected

  • No mutable published policy or delete path.
  • No runtime fallback defaults for migrated incomplete rows.
  • No combined queue, lease, Review, decision, revision, or contribution work.
  • No AUTH-owned actor schema or ART/Submission behavior.
  • No lossy downgrade.

Scope control and product behavior

The change is limited to the contract's policy persistence, mapping, docs, and
proof-only compatibility exceptions. Canonical decisions remain exactly
accept, needs_revision, and reject. No review lifecycle transition is
activated by this PR.

Acceptance criteria proof

Direct SQL proves canonical shape, provenance, private archives, immutable
identity/context, update/delete refusal, runtime-insert denial, atomic
conversion, downgrade refusal, and lossless legacy round-trip. Eight real
PostgreSQL races prove both policy tables and both write operations serialize
with guide publication in both lock orders.

Tests/checks run

Focused migration, Project, Task, and artifact tests passed. Alembic has one
head, Ruff passed all changed backend paths, stale wording and Markdown links
passed, 100 agent-gate tests passed, and diff integrity passed. Full backend
tests and coverage are delegated to GitHub Actions as instructed by the user.

Test delta and CI integrity

Tests add constraints, downgrade, deterministic waiter, legacy compatibility,
archive privacy, and immutable snapshot proof. Existing compensation and ART
assertions remain intact. No workflow, package script, skip, xfail, coverage
floor, or assertion was weakened; CI must preserve 78 percent repository-wide
coverage and prove at least 90 percent for the materially changed subsystem.

Reviewer results

Senior engineering, QA/test, security/auth, product/ops, architecture, docs,
reuse/dedup, test delta, CI integrity, and circuit breaker all PASS on code
candidate 35531df254c6b25726d666a5e89eda997b97d792 after three repair rounds.

External review

Pending publication. GitHub Actions and CodeRabbit must pass on the final pushed
head, and every actionable external comment must be resolved before merge.

Remaining risks and follow-up work

Later queue, lease, Review chain, decision, revision, FinalAcceptance, and CON
composition remain deliberately unimplemented. After merge, loop memory may
name same-initiative successor 03A, but 03A requires a separate explicit signed
start and a fresh current-main dependency check.

Human review focus

Review the trigger invariants, downgrade refusal/reconstruction, eight race
cases, legacy API privacy, strict REV boundary, and preservation of Task and
ART compatibility assertions.

Human merge ownership

Only the user may approve and merge this specific PR. Do not merge with a
pending/failed current-head GitHub or CodeRabbit check or an unresolved
actionable comment. Merge does not start 03A.

Summary by CodeRabbit

  • New Features

    • Added explicit review and revision policy persistence with canonical configuration fields and provenance.
    • Preserved migrated legacy policy data privately while preventing unsupported edits, deletions, or lossy conversions.
    • Added validation for policy values, immutable published policies, and safe policy activation behavior.
  • Documentation

    • Updated project guide and data model documentation to reflect active and archival policy fields.
  • Bug Fixes

    • Repaired API and migration compatibility checks for updated policy formats.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@Abiorh001, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 17 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: b95a0d4a-eae3-44ee-99bb-06eb4f6a0a4e

📥 Commits

Reviewing files that changed from the base of the PR and between 6cf3ad4 and f2becbd.

📒 Files selected for processing (7)
  • .agent-loop/initiatives/WS-REV-001-review-revision-lifecycle/STATUS.md
  • .agent-loop/initiatives/WS-REV-001-review-revision-lifecycle/chunks/WS-REV-001-03P-review-revision-policy-persistence.md
  • .agent-loop/initiatives/WS-REV-001-review-revision-lifecycle/reviews/WS-REV-001-03P-external-review-response.md
  • .agent-loop/initiatives/WS-REV-001-review-revision-lifecycle/reviews/WS-REV-001-03P-internal-review-evidence.md
  • backend/alembic/versions/0034_review_revision_policy_persistence.py
  • backend/tests/conftest.py
  • backend/tests/test_alembic.py
📝 Walkthrough

Walkthrough

Adds canonical immutable ReviewPolicy and RevisionPolicy persistence, migration guards, legacy archival handling, actor provenance, activation validation, updated fixtures/tests, documentation, and implementation review evidence for WS-REV-001-03P.

Changes

Policy persistence lifecycle

Layer / File(s) Summary
Canonical policy contract and lifecycle boundaries
.agent-loop/..., .agent-loop/merge-intents/*, backend/app/modules/projects/{models.py,schemas.py}, docs/*
Defines canonical review/revision fields, legacy archival storage, public response shapes, lifecycle boundaries, and explicit implementation authorization.
0034 migration and write guards
backend/alembic/versions/0034_review_revision_policy_persistence.py
Adds canonical columns and constraints, preserves legacy values, installs PostgreSQL immutability and conversion guards, and blocks unsafe downgrades.
Runtime policy construction and persistence
backend/app/modules/projects/{repository.py,service.py}
Persists canonical policy values with actor provenance, clears legacy state for new configurations, and validates legacy revision state during activation.
Migration, API, and lifecycle validation
backend/scripts/*, backend/tests/{conftest.py,test_alembic.py,test_artifact_admission.py,test_projects.py,test_tasks.py}
Updates schema and API fixtures and verifies migration losslessness, locking, retired-field rejection, archival non-exposure, fixture lifecycle ordering, and published-policy immutability.
Review, repair, and release evidence
.agent-loop/initiatives/WS-REV-001-review-revision-lifecycle/{REVIEW_LOG.md,reviews/*}
Records implementation authorization, repair outcomes, internal review results, verification evidence, and remaining external proof requirements.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant APIClient
  participant GuideService
  participant ProjectRepository
  participant PostgreSQL
  APIClient->>GuideService: create or update draft guide
  GuideService->>ProjectRepository: upsert policies with actor context
  ProjectRepository->>PostgreSQL: write canonical policy fields and provenance
  PostgreSQL->>PostgreSQL: enforce constraints and publication guards
  PostgreSQL-->>ProjectRepository: accept or reject policy write
  ProjectRepository-->>GuideService: return persisted policy state
  GuideService-->>APIClient: return guide and non-archival policy response
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the gist, but it omits required template sections like Signed Start Provenance, Allowed Files Changed, and Evidence/Test Delta details. Add the missing template sections with signed-start provenance, allowed-file list, evidence command/results blocks, and explicit test delta entries.
Docstring Coverage ⚠️ Warning Docstring coverage is 47.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: immutable review and revision policy persistence.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/ws-rev-001-03p-review-revision-policy-v2

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Abiorh001

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
@.agent-loop/initiatives/WS-REV-001-review-revision-lifecycle/reviews/WS-REV-001-03P-internal-review-evidence.md:
- Around line 5-22: Update the review evidence so the “Final reviewed code
candidate” field consistently uses the actually reviewed commit SHA
ba9c6249c053696dc9f32bfd750a2b9bb787e4f6, matching “Reviewed code SHA” and the
reviewer run IDs; do not alter unrelated evidence fields.

In @.agent-loop/initiatives/WS-REV-001-review-revision-lifecycle/STATUS.md:
- Around line 5-11: Align the active implementation candidate with the trust
bundle by identifying b9501b... as the current reviewed post-repair candidate in
STATUS.md and the corresponding WS-REV-001-03P review-policy persistence chunk;
clearly label 35531df... as historical authorization context if it remains, so
both artifacts bind merge evidence to the same exact SHA.

In `@backend/alembic/versions/0034_review_revision_policy_persistence.py`:
- Around line 165-279: Update _create_write_guards to add statement-level BEFORE
TRUNCATE triggers for both review_policies and revision_policies, alongside the
existing row-level guards. Extend each guard function’s TG_OP handling to
explicitly reject TRUNCATE with the immutability error path. Update downgrade()
to drop both truncate triggers.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 9747dead-4c6c-4474-a989-4035a1292ec3

📥 Commits

Reviewing files that changed from the base of the PR and between bcf1292 and 6cf3ad4.

📒 Files selected for processing (20)
  • .agent-loop/initiatives/WS-REV-001-review-revision-lifecycle/REVIEW_LOG.md
  • .agent-loop/initiatives/WS-REV-001-review-revision-lifecycle/STATUS.md
  • .agent-loop/initiatives/WS-REV-001-review-revision-lifecycle/chunks/WS-REV-001-03P-review-revision-policy-persistence.md
  • .agent-loop/initiatives/WS-REV-001-review-revision-lifecycle/reviews/WS-REV-001-03P-external-review-response.md
  • .agent-loop/initiatives/WS-REV-001-review-revision-lifecycle/reviews/WS-REV-001-03P-internal-review-evidence.md
  • .agent-loop/initiatives/WS-REV-001-review-revision-lifecycle/reviews/WS-REV-001-03P-pr-trust-bundle.md
  • .agent-loop/merge-intents/WS-REV-001-03P.json
  • backend/alembic/versions/0034_review_revision_policy_persistence.py
  • backend/app/modules/projects/models.py
  • backend/app/modules/projects/repository.py
  • backend/app/modules/projects/schemas.py
  • backend/app/modules/projects/service.py
  • backend/scripts/api_contract_e2e.py
  • backend/tests/conftest.py
  • backend/tests/test_alembic.py
  • backend/tests/test_artifact_admission.py
  • backend/tests/test_projects.py
  • backend/tests/test_tasks.py
  • docs/architecture_data_model.md
  • docs/template_project_guide.md

Comment thread .agent-loop/initiatives/WS-REV-001-review-revision-lifecycle/STATUS.md Outdated
Comment thread backend/alembic/versions/0034_review_revision_policy_persistence.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant