Skip to content

feat(auth): cut over current guide policy reads - #221

Merged
abiorh-claw merged 14 commits into
mainfrom
codex/ws-auth-001-11c2-effective-policy-active-guide-reads
Jul 29, 2026
Merged

feat(auth): cut over current guide policy reads#221
abiorh-claw merged 14 commits into
mainfrom
codex/ws-auth-001-11c2-effective-policy-active-guide-reads

Conversation

@Abiorh001

@Abiorh001 Abiorh001 commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Chunk

WS-AUTH-001-11C2 — effective policy and active-guide read cutover

Outcome

Hard-cuts exactly three administrative GET actions:

  • project.effective_submission_artifact_policy.read
  • project.pre_submit_checker_policy.read
  • project.active_guide.read

Only a covered Project Manager, covered Audit Authority, or system Operator can read them. Finance, Access Administrator, contributors, services, wrong-scope callers, and token-role-only callers receive centralized concealed denial.

Security and design

  • Human read admission plus centralized AuthorizationService.require.
  • Transaction-local locks for actor, identity link, matched grant, project, guide, latest snapshot, source items, and policy rows.
  • Exact lineage, lifecycle, canonical hash, and shared activation-readiness validation.
  • Strict response projections; GET /active-guide omits payment_policy.
  • Allowed and denied evidence includes exact resource digest and post-grant provenance.
  • No migration, mutation, compatibility fallback, or token-role authority.

External review repairs

All five CodeRabbit comments were addressed:

  • one shared active-guide role allowlist;
  • active guide status required by the typed policy context;
  • shared effective-policy chain consistency predicate;
  • unused snapshot lock removed;
  • shared activation/read response shaping.

Detailed disposition: .agent-loop/initiatives/WS-AUTH-001-workstream-authorization-service/reviews/WS-AUTH-001-11C2-external-review-response.md.

Verification

Exact head: 120bc553aeabfb6cc42d7fa0360552068204d66f

  • Agent Gates passed: run 30444471663.
  • Backend passed: run 30444471409.
    • four semantic lanes and independent custody validation;
    • real API E2E;
    • repository-wide, authorization >=90%, and project-composer >=90% coverage gates;
    • exact-tree reassertion.
  • Focused Ruff/tests, Markdown links, stale wording/docs, lightweight gates, and diff check passed.
  • Full suite ran only in GitHub as required.
  • CodeRabbit original review completed; its five comments are fixed. Its automated follow-up was service-rate-limited, so exact-head closure is additionally covered by post-fix architecture, security, reuse/dedup, senior, test-delta, and hosted checks.

Internal review

Architecture, security, product/ops, QA, senior engineering, CI integrity, docs, reuse/dedup, and test-delta passed after repair.

Human review focus

  • exactly three actions activated;
  • local-grant-only authority and concealed denial;
  • locked lineage and canonical readiness reuse;
  • non-compensation active-guide projection;
  • denied audit provenance.

Human merge approval remains required.

@coderabbitai

coderabbitai Bot commented Jul 29, 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: 14 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: cd297066-a28b-4a26-9251-63157f2c142c

📥 Commits

Reviewing files that changed from the base of the PR and between 298e827 and 71e6bf6.

📒 Files selected for processing (13)
  • .agent-loop/initiatives/WS-AUTH-001-workstream-authorization-service/chunks/WS-AUTH-001-11C2-effective-policy-active-guide-reads.md
  • .agent-loop/initiatives/WS-AUTH-001-workstream-authorization-service/reviews/WS-AUTH-001-11C2-external-review-response.md
  • backend/app/modules/authorization/kernel.py
  • backend/app/modules/authorization/policy.py
  • backend/app/modules/authorization/read_service.py
  • backend/app/modules/authorization/runtime.py
  • backend/app/modules/projects/authorization_reads.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/test_authorization.py
  • backend/tests/test_projects.py
📝 Walkthrough

Walkthrough

AUTH-11C2 activates project policy and active-guide read actions, adds strict authorization contexts and locked policy-chain reads, routes endpoints through authorization-driven composition, tightens response schemas, and updates tests, E2E checks, workflow coverage, documentation, and status tracking.

Changes

Project policy and active-guide authorization

Layer / File(s) Summary
Authorization contracts and enforcement
backend/app/modules/authorization/*, backend/tests/test_authorization.py, backend/tests/test_audit.py, docs/*authorization*, docs/operations_roles_permissions.md
New project policy and active-guide actions, resource contexts, target matching, role allowlists, denial provenance, effective-action filtering, and audit staging are implemented and documented.
Locked policy and active-guide read composition
backend/app/modules/projects/authorization_reads.py, backend/app/modules/projects/repository.py
Transactional locks, canonical binding checks, policy-chain validation, authorization calls, and active-guide read bundling are added.
Response projection and authorization-driven routes
backend/app/modules/projects/router.py, backend/app/modules/projects/schemas.py, backend/app/modules/projects/service.py, backend/app/api/deps/authorization.py
Policy and active-guide endpoints use authorization services, strict response projections, concealed denials, and public validation helpers.
Contract validation and rollout updates
backend/tests/*, backend/scripts/api_contract_e2e.py, .github/workflows/backend.yml, docs/*, .agent-loop/...
OpenAPI, integration, authorization, E2E, coverage, specification, operating documentation, and initiative status are updated for the new reads.

Estimated code review effort: 5 (Critical) | ~120 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant ProjectsRouter
  participant ProjectAuthorizationReads
  participant ProjectRepository
  participant AuthorizationKernel
  Client->>ProjectsRouter: GET active-guide or policy endpoint
  ProjectsRouter->>ProjectAuthorizationReads: authorize requested project read
  ProjectAuthorizationReads->>ProjectRepository: lock project, guide, and policy-chain rows
  ProjectAuthorizationReads->>AuthorizationKernel: require strict resource context
  AuthorizationKernel-->>ProjectsRouter: allow or concealed denial
  ProjectsRouter-->>Client: validated response or 404
Loading

Possibly related PRs

  • Flow-Research/workstream#7: Introduced the project domain routes, schemas, services, and repositories extended by these authorization-driven reads.
  • Flow-Research/workstream#126: Added the authorization catalogue and action-evidence foundations used by the activated actions.
  • Flow-Research/workstream#216: Extended the authorization read infrastructure that this change parallels for project policy and active-guide contexts.

Suggested reviewers: abiorh-claw

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 58.59% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description covers the core change, but it omits many required template sections, tables, and checklists. Fill in the missing template sections: Goal, planning context, what/why/design/alternatives, scope control, evidence, test delta, review tables, and merge ownership.
✅ Passed checks (3 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 is concise and accurately summarizes the main auth read cutover in this PR.
✨ 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-auth-001-11c2-effective-policy-active-guide-reads

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
Abiorh001 marked this pull request as ready for review July 29, 2026 10:10

@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.

🧹 Nitpick comments (5)
backend/app/modules/projects/authorization_reads.py (1)

107-163: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider extracting the policy-chain consistency predicate.

These row-vs-row equality checks largely repeat what authorize_project_active_guide_read (Lines 297-347) and ProjectService.validate_activation_ready already assert. A shared helper (e.g. effective_chain_is_consistent(guide, snapshot, effective, submission, checker)) would keep the three sites from drifting as the chain grows.

🤖 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/app/modules/projects/authorization_reads.py` around lines 107 - 163,
The policy-chain consistency checks in the shown target validation repeat logic
from authorize_project_active_guide_read and
ProjectService.validate_activation_ready. Extract a shared helper such as
effective_chain_is_consistent accepting guide, snapshot, effective, submission,
and checker, move the row-to-row and integrity predicates into it, and update
all three call sites to reuse the helper while preserving the current failure
behavior.
backend/app/modules/authorization/kernel.py (1)

83-85: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Active-guide admin role allowlist is defined twice. Enforcement (kernel) and projection (read service) each own a private copy of the same frozenset; if they drift, effective_action_ids will advertise project.active_guide.read to an actor the kernel denies (or hide it from one it allows).

  • backend/app/modules/authorization/kernel.py#L83-L85: import the shared allowlist instead of declaring it locally.
  • backend/app/modules/authorization/read_service.py#L65-L67: remove this duplicate and import the same shared constant (e.g. exported from catalogue.py).
🤖 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/app/modules/authorization/kernel.py` around lines 83 - 85, Centralize
the active-guide admin role allowlist in a shared authorization module such as
catalogue.py. In backend/app/modules/authorization/kernel.py lines 83-85, remove
the local _ACTIVE_GUIDE_ADMIN_ROLES declaration and import the shared constant;
do the same in backend/app/modules/authorization/read_service.py lines 65-67,
preserving both consumers’ existing behavior.
backend/app/modules/authorization/runtime.py (1)

320-331: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick win

Pin guide_status == "active" in the policy-read bound predicate.

ProjectActiveGuideReadResourceContext requires the active guide status, but this model derives bound without it, so a caller could assert target_exists=True for a draft/superseded guide. The current composer nulls non-active guides, so this is defensive rather than exploitable, but the strict context should carry the invariant itself. The stray and on its own line (Line 322) can also be folded.

🛡️ Proposed tightening
         bound = (
             self.project_status == "active"
-            and
-            self.source_snapshot_id is not None
+            and self.guide_status == "active"
+            and self.source_snapshot_id is not None
             and self.source_snapshot_hash is not None
🤖 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/app/modules/authorization/runtime.py` around lines 320 - 331, Update
the policy-read bound predicate around the bound computation to require
guide_status == "active" alongside the existing project and policy checks,
ensuring target_exists=True is rejected for draft or superseded guides. Fold the
standalone and into the adjacent condition without changing the existing
consistency validation.
backend/app/modules/projects/repository.py (1)

219-227: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Remove the unused lock_guide_source_snapshot stub.

This by-ID row-lock method is only defined in backend/app/modules/projects/repository.py; the active-guide path uses lock_latest_guide_source_snapshot plus the already-called lock_guide_source_snapshot_items(snapshot.id).

🤖 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/app/modules/projects/repository.py` around lines 219 - 227, Remove
the unused lock_guide_source_snapshot method from the repository. Leave
lock_latest_guide_source_snapshot and lock_guide_source_snapshot_items
unchanged, as they provide the active-guide locking flow.
backend/app/modules/projects/service.py (1)

1880-1918: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Extract shared bundle-shaping logic to avoid drift with _active_response.

This new method duplicates 8 of the 9 model_validate calls in _active_response (guide, sufficiency, submission, effective, pre-submit checker, post-submit checker, review, revision) verbatim — only the snapshot construction and payment_policy differ. A future field addition to the shared bundle risks being applied to only one of the two projections.

♻️ Suggested extraction of shared shaping logic
+    def _shared_active_bundle_fields(
+        self,
+        guide: ProjectGuide,
+        sufficiency_report: GuideSufficiencyReport,
+        submission_artifact_policy: SubmissionArtifactPolicy,
+        effective_policy: EffectiveProjectSubmissionArtifactPolicy,
+        pre_submit_checker_policy: PreSubmitCheckerPolicy,
+        post_submit_checker_policy: PostSubmitCheckerPolicy,
+        review_policy: ReviewPolicy,
+        revision_policy: RevisionPolicy,
+    ) -> dict[str, Any]:
+        """Shape the fields shared by active-guide activation and read projections."""
+        return {
+            "guide": ProjectGuideResponse.model_validate(guide),
+            "guide_sufficiency_report": GuideSufficiencyReportResponse.model_validate(
+                sufficiency_report
+            ),
+            "submission_artifact_policy": SubmissionArtifactPolicyResponse.model_validate(
+                submission_artifact_policy
+            ),
+            "effective_submission_artifact_policy": (
+                EffectiveProjectSubmissionArtifactPolicyResponse.model_validate(effective_policy)
+            ),
+            "pre_submit_checker_policy": ActiveGuidePreSubmitCheckerPolicyResponse.model_validate(
+                pre_submit_checker_policy
+            ),
+            "post_submit_checker_policy": PostSubmitCheckerPolicyResponse.model_validate(
+                post_submit_checker_policy
+            ),
+            "review_policy": ReviewPolicyResponse.model_validate(review_policy),
+            "revision_policy": RevisionPolicyResponse.model_validate(revision_policy),
+        }

Then both active_guide_read_response and _active_response call this helper and only add their own guide_source_snapshot (+ payment_policy for _active_response).

🤖 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/app/modules/projects/service.py` around lines 1880 - 1918, Extract
the shared policy and guide response shaping from active_guide_read_response and
_active_response into a common helper, preserving the existing model_validate
mappings. Update both callers to use the helper, with active_guide_read_response
adding only its source snapshot and _active_response adding its source snapshot
and payment policy.
🤖 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.

Nitpick comments:
In `@backend/app/modules/authorization/kernel.py`:
- Around line 83-85: Centralize the active-guide admin role allowlist in a
shared authorization module such as catalogue.py. In
backend/app/modules/authorization/kernel.py lines 83-85, remove the local
_ACTIVE_GUIDE_ADMIN_ROLES declaration and import the shared constant; do the
same in backend/app/modules/authorization/read_service.py lines 65-67,
preserving both consumers’ existing behavior.

In `@backend/app/modules/authorization/runtime.py`:
- Around line 320-331: Update the policy-read bound predicate around the bound
computation to require guide_status == "active" alongside the existing project
and policy checks, ensuring target_exists=True is rejected for draft or
superseded guides. Fold the standalone and into the adjacent condition without
changing the existing consistency validation.

In `@backend/app/modules/projects/authorization_reads.py`:
- Around line 107-163: The policy-chain consistency checks in the shown target
validation repeat logic from authorize_project_active_guide_read and
ProjectService.validate_activation_ready. Extract a shared helper such as
effective_chain_is_consistent accepting guide, snapshot, effective, submission,
and checker, move the row-to-row and integrity predicates into it, and update
all three call sites to reuse the helper while preserving the current failure
behavior.

In `@backend/app/modules/projects/repository.py`:
- Around line 219-227: Remove the unused lock_guide_source_snapshot method from
the repository. Leave lock_latest_guide_source_snapshot and
lock_guide_source_snapshot_items unchanged, as they provide the active-guide
locking flow.

In `@backend/app/modules/projects/service.py`:
- Around line 1880-1918: Extract the shared policy and guide response shaping
from active_guide_read_response and _active_response into a common helper,
preserving the existing model_validate mappings. Update both callers to use the
helper, with active_guide_read_response adding only its source snapshot and
_active_response adding its source snapshot and payment policy.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8e35564f-6649-4881-9192-ef04c11dc3ce

📥 Commits

Reviewing files that changed from the base of the PR and between e6573aa and 298e827.

📒 Files selected for processing (24)
  • .agent-loop/initiatives/WS-AUTH-001-workstream-authorization-service/STATUS.md
  • .agent-loop/initiatives/WS-AUTH-001-workstream-authorization-service/chunks/WS-AUTH-001-11C2-effective-policy-active-guide-reads.md
  • .github/workflows/backend.yml
  • backend/app/api/deps/authorization.py
  • backend/app/modules/authorization/catalogue.py
  • backend/app/modules/authorization/kernel.py
  • backend/app/modules/authorization/read_service.py
  • backend/app/modules/authorization/repository.py
  • backend/app/modules/authorization/runtime.py
  • backend/app/modules/projects/authorization_reads.py
  • backend/app/modules/projects/repository.py
  • backend/app/modules/projects/router.py
  • backend/app/modules/projects/schemas.py
  • backend/app/modules/projects/service.py
  • backend/scripts/api_contract_e2e.py
  • backend/tests/test_api_controls.py
  • backend/tests/test_audit.py
  • backend/tests/test_authorization.py
  • backend/tests/test_projects.py
  • docs/operations_authorization_service.md
  • docs/operations_project_operating_manual.md
  • docs/operations_roles_permissions.md
  • docs/spec_authorization_service.md
  • docs/spec_chunk_3_project_guide_foundation.md

@abiorh-claw
abiorh-claw self-requested a review July 29, 2026 11:03
@abiorh-claw
abiorh-claw merged commit 3fc323d into main Jul 29, 2026
3 checks passed
@abiorh-claw
abiorh-claw deleted the codex/ws-auth-001-11c2-effective-policy-active-guide-reads branch July 29, 2026 14:56
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