Skip to content

WS-ARCH-001-02B: expose PROJECT locked-policy API - #315

Merged
abiorh-claw merged 13 commits into
mainfrom
codex/ws-arch-001-02b-project-policy-api
Aug 11, 2026
Merged

WS-ARCH-001-02B: expose PROJECT locked-policy API#315
abiorh-claw merged 13 commits into
mainfrom
codex/ws-arch-001-02b-project-policy-api

Conversation

@Abiorh001

@Abiorh001 Abiorh001 commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

Chunk

WS-ARCH-001-02B — PROJECT Locked Policy Public API

Goal

Expose dependency-free immutable PROJECT locked-policy facts without leaking PROJECT persistence into TASK, ART, or CHECKER.

Human-approved intent

Preserve exact historical guide, snapshot, effective-policy, and pre-submit-policy lineage, including valid superseded rows, without substituting successors.

What changed

  • Added dependency-safe app.modules.projects.api contracts.
  • Added focused ProjectLockedPolicyRepository historical-lineage resolution.
  • Removed lock_locked_policy_context from the general ProjectRepository with no alias, forwarding method, fallback, or duplicate.
  • Added fail-closed lineage, canonical-hash, PostgreSQL state, successor, and lock-contention tests.
  • Updated ownership evidence, the capability manifest, and external-review evidence.

Why it changed

TASK needs exact PROJECT facts without importing PROJECT ORM models, repositories, or sessions. The focused repository also provides a truthful bounded coverage gate.

Design chosen

A PROJECT-owned concrete repository structurally implements ProjectLockedPolicyContextPort. Only dependency-safe requests, immutable facts, and the bounded failure cross the public API.

Alternatives rejected

  • Keeping the resolver in the 1,364-line general repository.
  • Adding a compatibility alias or forwarding method.
  • Performing live TASK, ART, or CHECKER composition in this chunk.

Scope control

No routes, authorization availability, policy compilation, task preparation, artifact behavior, checker behavior, ORM schema, or migrations changed. No cross-module private import was added.

Product behavior

Exact current and valid historical superseded lineage resolves under row locks. Missing, drifted, cross-project, pending, malformed, successor-substituted, or non-canonical context fails closed with the existing bounded error.

Acceptance criteria proof

  • No ProjectRepository.lock_locked_policy_context reference remains.
  • All five selected PROJECT rows use FOR UPDATE with preserved lock order.
  • Exact superseded rows remain valid; successors are never substituted.
  • Public outputs remain deeply immutable canonical values.
  • Behavior ownership includes the focused repository and validates against the protected baseline.

Tests and checks run

  • Ruff: pass.
  • Focused non-PostgreSQL suite: 38 passed, 3 deselected.
  • Focused API and repository coverage: 100 percent; threshold 90 percent.
  • Module-boundary, behavior-ownership, and test-structure validation: pass.
  • Markdown links, stale wording, and diff checks: pass.
  • Hosted Agent Gates, Backend preflight, all seven Backend lanes, and aggregate test: pass on a58118fc.

Test delta

No skips or xfails were added. Exact facts, failure, successor, and contention assertions remain. Both bounded repository exception paths are covered.

CI integrity

No threshold reduction, exclusion, continue-on-error, lane removal, or assertion weakening. The focused repository is registered in the existing project lifecycle lane and ownership partition.

Reviewer results

Architecture, security, product/ops, QA, senior engineering, CI integrity, docs, reuse/dedup, and test-delta reviews pass. Valid findings were addressed.

External review

All valid CodeRabbit findings were fixed: focused resolver coverage, exact module public-API foundation wording, bounded lock polling, and historical-lineage terminology. All review threads are resolved.

Remaining risks

None identified for this bounded chunk. Live consumer composition remains intentionally deferred.

Follow-up work

WS-ARCH-001-02C owns later composition and caller cutover under its own contract.

Human review focus

Exact historical lineage, clean removal from the general repository, immutable output, lock ordering, successor non-substitution, and absence of cross-module leakage.

Human merge ownership

The PR is ready for human review. Only the user may approve and merge it.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR adds a public PROJECT locked-policy API, an exact historical-lineage repository, PostgreSQL validation and concurrency tests, architecture checks, ownership registration, test-lane updates, and supporting project records.

Changes

PROJECT locked-policy context

Layer / File(s) Summary
Public locked-policy contracts
backend/app/modules/projects/api/*
Adds immutable request and facts dataclasses, canonical JSON values, status and failure contracts, a context-unavailable exception, and a transaction-bound protocol.
Exact historical lineage resolution
backend/app/modules/projects/locked_policy_repository.py
Locks the selected project, guide, snapshot, effective policy, and pre-submit policy rows. It validates lifecycle state, lineage links, identifiers, hashes, compiler data, and canonical policy content before returning facts.
Lineage validation and concurrency coverage
backend/tests/projects/test_locked_policy_context.py
Tests current and superseded rows, invalid contexts, canonical immutability, successor non-substitution, PostgreSQL state transitions, and row-lock serialization.
Boundary, ownership, and verification registration
backend/tests/architecture/test_module_boundaries.py, .ci/behavior-ownership/partition.v1.json, backend/scripts/behavior_ownership.py, backend/scripts/run_test_lanes.py, backend/tests/test_ci_test_lanes.py, docs/architecture_lockdown.md, .agent-loop/initiatives/WS-ARCH-001-modular-monolith-boundaries/...
Registers the PROJECTS public boundary, ownership assignments, test lane, architecture rules, manifest, review response, and implementation status. The records defer caller cutover and successor substitution.

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

Possibly related issues

Possibly related PRs

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant ProjectLockedPolicyRepository
  participant PostgreSQL
  participant CanonicalJsonObject
  Caller->>ProjectLockedPolicyRepository: Submit ProjectLockedPolicyContextRequest
  ProjectLockedPolicyRepository->>PostgreSQL: Lock exact project and policy lineage rows
  PostgreSQL-->>ProjectLockedPolicyRepository: Return current or superseded historical rows
  ProjectLockedPolicyRepository->>CanonicalJsonObject: Validate and hash policy mappings
  CanonicalJsonObject-->>ProjectLockedPolicyRepository: Return immutable canonical values
  ProjectLockedPolicyRepository-->>Caller: Return ProjectLockedPolicyContextFacts or failure
Loading

Suggested reviewers: abiorh-claw

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 78.26% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly identifies the primary change: exposing the PROJECT locked-policy API.
Description check ✅ Passed The description explains the goal, design, scope, behavior, tests, risks, follow-up work, and review focus with sufficient detail.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/ws-arch-001-02b-project-policy-api

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.

@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: 2

🧹 Nitpick comments (1)
backend/tests/projects/test_locked_policy_context.py (1)

300-322: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Bound the lock wait by time, not by iteration count.

The loop runs up to 5000 iterations with asyncio.sleep(0). Each iteration issues one pg_stat_activity query. The effective timeout therefore depends on database round-trip latency, so the test is non-deterministic across environments. A slow CI database can also receive thousands of queries in a short window.

Use a wall-clock deadline and a small sleep interval.

♻️ Proposed deadline-based wait
     engine = create_async_engine(database_url)
     try:
         async with engine.connect() as connection:
-            for _ in range(5000):
+            deadline = asyncio.get_running_loop().time() + 30.0
+            while asyncio.get_running_loop().time() < deadline:
                 waiting = await connection.scalar(
                     text(
                         "select exists(select 1 from pg_stat_activity where "
                         "application_name = :application_name "
                         "and wait_event_type = 'Lock')"
                     ),
                     {"application_name": application_name},
                 )
                 if waiting:
                     return
-                await asyncio.sleep(0)
+                await asyncio.sleep(0.01)
     finally:
         await engine.dispose()
🤖 Prompt for 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.

In `@backend/tests/projects/test_locked_policy_context.py` around lines 300 - 322,
Update _wait_for_project_database_lock to use a wall-clock deadline instead of
the fixed 5000-iteration loop: compute an end time, poll pg_stat_activity until
that deadline, and await a small positive sleep interval between checks.
Preserve the immediate return when the lock is observed and raise the existing
AssertionError after the deadline expires.
🤖 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-ARCH-001-modular-monolith-boundaries/chunks/WS-ARCH-001-02B-project-locked-policy-api.md:
- Around line 90-94: Update the verification pytest command’s coverage options
to include app.modules.projects.repository alongside app.modules.projects.api,
so ProjectRepository.lock_locked_policy_context is measured by the existing 90%
coverage gate.

In `@backend/scripts/behavior_ownership.py`:
- Around line 77-81: Update the _validate_additive_partition_transition
docstring to describe MODULE_PUBLIC_API_FOUNDATION_TARGETS as the module
public-API foundation allowlist, replacing the stale “AUTH boundary-foundation
additions” terminology while preserving the validator’s behavior.

---

Nitpick comments:
In `@backend/tests/projects/test_locked_policy_context.py`:
- Around line 300-322: Update _wait_for_project_database_lock to use a
wall-clock deadline instead of the fixed 5000-iteration loop: compute an end
time, poll pg_stat_activity until that deadline, and await a small positive
sleep interval between checks. Preserve the immediate return when the lock is
observed and raise the existing AssertionError after the deadline expires.
🪄 Autofix

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: 7c97416c-339f-4c76-9b56-08148cbbd9de

📥 Commits

Reviewing files that changed from the base of the PR and between 3e9785e and ae4e160.

📒 Files selected for processing (11)
  • .agent-loop/initiatives/WS-ARCH-001-modular-monolith-boundaries/chunks/WS-ARCH-001-02B-project-locked-policy-api.md
  • .agent-loop/initiatives/WS-ARCH-001-modular-monolith-boundaries/evidence/WS-ARCH-001-02B-project-manifest.md
  • .ci/behavior-ownership/partition.v1.json
  • backend/app/modules/projects/api/__init__.py
  • backend/app/modules/projects/api/locked_policy.py
  • backend/app/modules/projects/repository.py
  • backend/scripts/behavior_ownership.py
  • backend/scripts/run_test_lanes.py
  • backend/tests/architecture/test_module_boundaries.py
  • backend/tests/projects/test_locked_policy_context.py
  • docs/architecture_lockdown.md

Comment thread backend/scripts/behavior_ownership.py
@abiorh-claw
abiorh-claw self-requested a review August 11, 2026 14:22

@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: 1

🧹 Nitpick comments (1)
.agent-loop/initiatives/WS-ARCH-001-modular-monolith-boundaries/reviews/WS-ARCH-001-02B-external-review-response.md (1)

21-28: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Record exact verification commands and outcomes.

This section lists validation categories but not executable commands, exit status, coverage results, or the hosted project_lifecycle run result. Add those details, or reference the exact CI run. Keep the local checks separate from the delegated PostgreSQL checks.

🤖 Prompt for 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.

In
@.agent-loop/initiatives/WS-ARCH-001-modular-monolith-boundaries/reviews/WS-ARCH-001-02B-external-review-response.md
around lines 21 - 28, Update the “Commands rerun” section to record the exact
executable local verification commands, each outcome or exit status, and
coverage results, while keeping local checks separate from delegated PostgreSQL
validation. Also include the hosted project_lifecycle run result or an exact CI
run reference.
🤖 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-ARCH-001-modular-monolith-boundaries/reviews/WS-ARCH-001-02B-external-review-response.md:
- Around line 7-9: Update the summary sentence referencing
ProjectLockedPolicyRepository to replace “exact locked-policy persistence” with
lineage-resolution terminology such as “exact historical-lineage resolution” or
“exact locked-policy context resolution,” consistent with the project glossary
and architecture documentation.

---

Nitpick comments:
In
@.agent-loop/initiatives/WS-ARCH-001-modular-monolith-boundaries/reviews/WS-ARCH-001-02B-external-review-response.md:
- Around line 21-28: Update the “Commands rerun” section to record the exact
executable local verification commands, each outcome or exit status, and
coverage results, while keeping local checks separate from delegated PostgreSQL
validation. Also include the hosted project_lifecycle run result or an exact CI
run reference.
🪄 Autofix

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: 56df527d-d927-4200-a643-341a9076c472

📥 Commits

Reviewing files that changed from the base of the PR and between 8b1a17a and 09ce66e.

📒 Files selected for processing (7)
  • .agent-loop/initiatives/WS-ARCH-001-modular-monolith-boundaries/chunks/WS-ARCH-001-02B-project-locked-policy-api.md
  • .agent-loop/initiatives/WS-ARCH-001-modular-monolith-boundaries/evidence/WS-ARCH-001-02B-project-manifest.md
  • .agent-loop/initiatives/WS-ARCH-001-modular-monolith-boundaries/reviews/WS-ARCH-001-02B-external-review-response.md
  • .ci/behavior-ownership/partition.v1.json
  • backend/app/modules/projects/locked_policy_repository.py
  • backend/scripts/behavior_ownership.py
  • backend/tests/projects/test_locked_policy_context.py
🚧 Files skipped from review as they are similar to previous changes (5)
  • .ci/behavior-ownership/partition.v1.json
  • .agent-loop/initiatives/WS-ARCH-001-modular-monolith-boundaries/evidence/WS-ARCH-001-02B-project-manifest.md
  • backend/tests/projects/test_locked_policy_context.py
  • .agent-loop/initiatives/WS-ARCH-001-modular-monolith-boundaries/chunks/WS-ARCH-001-02B-project-locked-policy-api.md
  • backend/scripts/behavior_ownership.py

@abiorh-claw
abiorh-claw merged commit fc84c41 into main Aug 11, 2026
11 checks passed
@abiorh-claw
abiorh-claw deleted the codex/ws-arch-001-02b-project-policy-api branch August 11, 2026 16:07
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.

2 participants