Skip to content

WS-POL-003-01: add unified guide compilation contracts - #299

Merged
abiorh-claw merged 4 commits into
mainfrom
codex/ws-pol-003-01-contract-catalogue
Aug 8, 2026
Merged

WS-POL-003-01: add unified guide compilation contracts#299
abiorh-claw merged 4 commits into
mainfrom
codex/ws-pol-003-01-contract-catalogue

Conversation

@Abiorh001

@Abiorh001 Abiorh001 commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator

Chunk

WS-POL-003-01 — Unified project-guide compilation contracts and canonical catalogue projections.

Goal

Define one strict, bounded contract for compiling immutable verified project-guide material into guide sufficiency, pre-submission policy, and post-submission policy outputs without activating runtime orchestration.

Intent And Planning Context

  • Intent: make the three outputs one atomic compilation result over the same immutable ART evidence and canonical checker catalogues.
  • Chunk contract: .agent-loop/initiatives/WS-POL-003-unified-project-guide-compilation/chunks/WS-POL-003-01-contract-and-catalogue.md

What Changed

  • Added immutable compilation input, output, evidence, finding, requirement, and capability-binding models.
  • Added fail-closed result validation for lineage, bounded safe text, status consistency, platform coverage, and catalogue ownership.
  • Added read-only projections of the canonical ART pre-submit catalogue and CHECKER post-submit registry/default truth.
  • Added comprehensive contract tests and assigned them exactly once to the existing task_lifecycle CI lane.
  • Updated the initiative contract, internal review evidence, and PR trust bundle.

Why It Changed

The guide-sufficiency result and both checker-policy drafts must be derived together from one verified guide snapshot. Separate or mutable inputs could allow policy drift, stale lineage, duplicated catalogues, or unsupported model-authored capability definitions.

Design Chosen

The contract snapshots ART material into deeply immutable canonical values, projects existing phase-owned catalogues without duplicating them, and validates the complete result before any later persistence or activation chunk can consume it.

Alternatives Rejected

  • A second POL-owned checker registry: rejected because ART and CHECKER retain catalogue ownership.
  • Mutable ORM/domain objects as model input: rejected because later mutation could alter the evidence being compiled.
  • Partial result acceptance: rejected because sufficiency and both policy outputs share one atomic evidence boundary.

Scope Control

Allowed Files Changed

  • Project-agent interfaces and validation.
  • Read-only catalogue projection helpers.
  • Contract and CI-lane tests.
  • WS-POL-003 planning and review evidence.
  • Existing CI lane inventory only to assign the new test module.

Files Outside Stated Scope

  • None.

Product Behavior

  • No live Workstream product behavior changed. This chunk defines contracts and validation only.

It does not add a model call, persistence, migration, route, Celery task, authorization action, checker execution, registry mutation, or lifecycle activation.

Evidence

Commands Run

ruff check <changed Python files>
pytest <focused compilation and CI-lane tests>
docstr-coverage --config .docstr.yaml
python backend/scripts/run_test_lanes.py --list
<repository stale wording, auth-doc, Markdown-link, static-boundary, and diff checks>

Result Summary

Focused Ruff: passed
Focused local non-database tests: 66 passed
Docstring coverage: 80.5% (80% gate)
Stale wording, stale authorization docs, Markdown links, static boundary, and diff checks: passed
Hosted Backend lanes: running on exact head; lane jobs passed before aggregate coverage began

Acceptance Criteria Proof

  • One immutable verified guide snapshot supplies exact canonical bytes, hash, and source lineage.
  • Pre-submit projection matches the exact canonical ART catalogue and manifest hash.
  • Post-submit projection matches registered capabilities, canonical defaults, and selectable-minus-default truth.
  • Supported requirements require exact capability bindings.
  • Platform coverage accepts only enabled mandatory pre-submit platform capabilities or canonical post-submit defaults.
  • Unsafe, stale, misplaced, copied, incomplete, or inconsistent results fail closed.
  • No second registry or runtime activation was introduced.

Test Delta

Tests Added

  • backend/tests/test_project_guide_compilation_contracts.py covers immutable snapshots, projections, evidence lineage, bindings, safe/bounded fields, phase ownership, platform coverage, and fail-closed status rules.

Tests Modified

  • backend/tests/test_ci_test_lanes.py proves the new test module is assigned exactly once.

Tests Removed Or Skipped

  • None.

Internal Reviewer Results

Reviewed code SHA: e1a7f41e3d138b5954d4fd55f60110506bda0e9f

Reviewer Result Blocking Findings Notes
Senior engineering PASS AFTER FIXES None Final review passed.
QA/test PASS AFTER FIXES None Final review passed.
Security/auth PASS AFTER FIXES None Fail-closed and safe-text boundaries passed.
Product/ops PASS None Atomic compilation intent preserved.
Architecture PASS None No ownership or runtime-boundary drift.
CI integrity PASS AFTER FIXES None Exact-once lane assignment; no gate weakening.
Docs PASS None Planning and trust evidence aligned.
Reuse/dedup PASS AFTER FIXES None Canonical catalogues reused.
Test delta PASS AFTER FIXES None No weakened or removed coverage.

Detailed evidence is recorded under .agent-loop/initiatives/WS-POL-003-unified-project-guide-compilation/reviews/.

External Review

Source Status Notes
CodeRabbit Findings resolved; incremental re-review quota-limited All three review threads are resolved; fresh internal re-review passed.
GitHub checks PASS Agent Gates, five Backend lanes, and aggregate full coverage passed on the exact head.

CI And Gate Integrity

  • No workflow weakening.
  • No lint/test/docstring gate weakening.
  • No coverage threshold weakening.
  • No package script weakening.
  • No unpinned new GitHub Action.
  • Checkout credential behavior unchanged.

Remaining Risks

  • Later chunks must retain this strict validator at the persistence boundary and must not treat model output as trusted before validation.
  • Runtime orchestration, atomic persistence, and activation are intentionally deferred to their bounded successor chunks.

Follow-Up Work

  • Implement the bounded unified compilation invocation and validated persistence boundary in the next approved WS-POL-003 chunk.
  • Keep ART and CHECKER as the sole owners of their respective catalogues.

Human Review Focus

Please inspect deep snapshot immutability, exact phase-owner catalogue reuse, fail-closed platform/default coverage, and the absence of runtime activation.

Human Merge Ownership

  • The implementation and risks are documented for human review.
  • The user explicitly approved this specific PR for merge.

@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR defines bounded project-guide compilation models, immutable ART evidence handling, pre- and post-submission capability projections, fail-closed validation, contract tests, and test-lane integration.

Changes

Project-guide compilation

Layer / File(s) Summary
Contract definition
.agent-loop/initiatives/WS-POL-003-unified-project-guide-compilation/*
The initiative now specifies the active compilation contract, immutable ART inputs, capability projections, validation boundaries, acceptance criteria, and review evidence.
Compilation models and validation
backend/app/interfaces/project_agents.py
Adds bounded immutable models for compilation inputs and results. Validation covers evidence lineage, capability bindings, platform coverage, status consistency, safe text, and output limits.
Capability projections
backend/app/modules/checkers/catalogue.py, backend/app/modules/projects/post_submit_policy.py
Adds canonical pre-submission and post-submission capability projections with registry checks and SHA-256 manifest hashes.
Contract verification
backend/tests/test_project_guide_compilation_contracts.py, backend/scripts/run_test_lanes.py, backend/tests/test_ci_test_lanes.py
Adds contract tests for projections and validation rules. Registers the tests in the task_lifecycle lane.

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

Possibly related PRs

Suggested reviewers: abiorh-claw

Sequence Diagram(s)

sequenceDiagram
  participant PreSubmissionCheckerCatalogue
  participant PostSubmitPolicy
  participant ProjectGuideCompilationContext
  participant CompilationValidator
  PreSubmissionCheckerCatalogue->>ProjectGuideCompilationContext: provide pre-submission capability projection
  PostSubmitPolicy->>ProjectGuideCompilationContext: provide post-submission capability projection
  ProjectGuideCompilationContext->>CompilationValidator: validate compilation result
  CompilationValidator-->>ProjectGuideCompilationContext: accept or reject result
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% 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 main change: adding unified project-guide compilation contracts.
Description check ✅ Passed The description follows the required template and documents scope, design, evidence, tests, reviews, risks, and follow-up work.
✨ 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-pol-003-01-contract-catalogue

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 Aug 8, 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

🧹 Nitpick comments (3)
backend/tests/test_project_guide_compilation_contracts.py (2)

99-103: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Replace the hardcoded catalogue size with a source-derived length.

Line 99 pins 26 definitions. Lines 100-102 and the strict=True zip on line 103 already prove one projected definition per catalogue entry. Any valid catalogue addition then fails line 99 for no contract reason.

♻️ Proposed change
-    assert len(projection.definitions) == 26
+    assert len(projection.definitions) == len(catalogue.entries)
🤖 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/test_project_guide_compilation_contracts.py` around lines 99 -
103, Replace the hardcoded 26 in the definition-count assertion with the length
derived from catalogue.entries, keeping the existing stable-ID comparison and
strict zip validation unchanged.

290-291: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Rejection tests do not pin the rule that must reject each case. Both parametrizations assert only that some ValueError is raised. A case can then fail through an unrelated validation rule and still pass, which weakens the fail-closed evidence this PR claims.

  • backend/tests/test_project_guide_compilation_contracts.py#L290-L291: replace match="capability binding|version" with a per-case expected message fragment passed through pytest.mark.parametrize.
  • backend/tests/test_project_guide_compilation_contracts.py#L487-L488: add the same per-case expected message fragment to pytest.raises(ValueError) for each status, severity, and disposition combination.
🤖 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/test_project_guide_compilation_contracts.py` around lines 290 -
291, Update backend/tests/test_project_guide_compilation_contracts.py lines
290-291 and 487-488: pass a per-case expected message fragment through each
pytest.mark.parametrize entry, and use that fragment in
pytest.raises(ValueError, match=...) so every capability/version case and every
status, severity, and disposition combination asserts the specific validation
rule that rejects it.
backend/app/modules/projects/post_submit_policy.py (1)

88-96: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick win

selectable opens by default for every registered checker.

selectable=name not in default_set grants model-facing selectability to any name present in default_checker_registry(). A new registration, including an internal or experimental checker, becomes selectable with no explicit allow decision. The contract elsewhere in this PR is fail-closed, so this default is inconsistent.

Consider an explicit frozen selectable snapshot keyed by compiler version, in the same shape as POST_SUBMIT_DEFAULT_CHECKERS_BY_COMPILER_VERSION. Then selectable becomes membership in that snapshot, and an unlisted registration is neither default nor selectable.

♻️ Sketch of an explicit selectable snapshot
+POST_SUBMIT_V01_SELECTABLE_CHECKERS = ("check_acceptance_criteria_present",)
+POST_SUBMIT_SELECTABLE_CHECKERS_BY_COMPILER_VERSION = MappingProxyType(
+    {POST_SUBMIT_COMPILER_VERSION: POST_SUBMIT_V01_SELECTABLE_CHECKERS}
+)
@@
     definitions = tuple(
         PostSubmissionCapabilityDefinition(
             capability_id=name,
             capability_version=compiler_version,
             platform_default=name in default_set,
-            selectable=name not in default_set,
+            selectable=name in selectable_set,
         )
         for name in registered
     )
🤖 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/post_submit_policy.py` around lines 88 - 96,
Update the capability-definition construction around
PostSubmissionCapabilityDefinition to use an explicit frozen selectable snapshot
keyed by compiler version, alongside
POST_SUBMIT_DEFAULT_CHECKERS_BY_COMPILER_VERSION. Set selectable only when the
checker name is present in the snapshot for compiler_version; keep default
membership based on default_set so unlisted registrations are neither default
nor selectable.
🤖 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 `@backend/app/interfaces/project_agents.py`:
- Around line 246-264: Update from_material so every material.source_items entry
must have non-empty source_item_id, extraction_usage_id, and
canonical_output_sha256; reject invalid entries instead of filtering them out.
Also reject material when source_items produces no lineage references, and
preserve constructing GuideSourceLineageRef only from complete valid entries.
- Around line 482-509: The validate_project_guide_compilation_result function
must reject results when context.pre_submission_capabilities.available is false.
Add this guard before validating requirements or platform coverage, raising the
established validation error for unavailable mandatory pre-submit coverage;
preserve the existing validation flow when the projection is available.
- Around line 34-40: Update _UNSAFE_MODEL_TEXT to detect credential keywords
followed by whitespace-separated values, not only colon or equals delimiters;
cover Bearer tokens and password/secret/credential/api-key/token forms while
preserving existing matches. Add regression cases for these bare credential
formats in the relevant tests.

---

Nitpick comments:
In `@backend/app/modules/projects/post_submit_policy.py`:
- Around line 88-96: Update the capability-definition construction around
PostSubmissionCapabilityDefinition to use an explicit frozen selectable snapshot
keyed by compiler version, alongside
POST_SUBMIT_DEFAULT_CHECKERS_BY_COMPILER_VERSION. Set selectable only when the
checker name is present in the snapshot for compiler_version; keep default
membership based on default_set so unlisted registrations are neither default
nor selectable.

In `@backend/tests/test_project_guide_compilation_contracts.py`:
- Around line 99-103: Replace the hardcoded 26 in the definition-count assertion
with the length derived from catalogue.entries, keeping the existing stable-ID
comparison and strict zip validation unchanged.
- Around line 290-291: Update
backend/tests/test_project_guide_compilation_contracts.py lines 290-291 and
487-488: pass a per-case expected message fragment through each
pytest.mark.parametrize entry, and use that fragment in
pytest.raises(ValueError, match=...) so every capability/version case and every
status, severity, and disposition combination asserts the specific validation
rule that rejects it.
🪄 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: 0674cc40-fb2c-46fc-be0b-9d536a093ffe

📥 Commits

Reviewing files that changed from the base of the PR and between 7676ce4 and 9dd1a82.

📒 Files selected for processing (11)
  • .agent-loop/initiatives/WS-POL-003-unified-project-guide-compilation/DISCOVERY.md
  • .agent-loop/initiatives/WS-POL-003-unified-project-guide-compilation/PLAN.md
  • .agent-loop/initiatives/WS-POL-003-unified-project-guide-compilation/chunks/WS-POL-003-01-contract-catalogue-projection.md
  • .agent-loop/initiatives/WS-POL-003-unified-project-guide-compilation/reviews/WS-POL-003-01-internal-review-evidence.md
  • .agent-loop/initiatives/WS-POL-003-unified-project-guide-compilation/reviews/WS-POL-003-01-pr-trust-bundle.md
  • backend/app/interfaces/project_agents.py
  • backend/app/modules/checkers/catalogue.py
  • backend/app/modules/projects/post_submit_policy.py
  • backend/scripts/run_test_lanes.py
  • backend/tests/test_ci_test_lanes.py
  • backend/tests/test_project_guide_compilation_contracts.py

Comment thread backend/app/interfaces/project_agents.py
Comment thread backend/app/interfaces/project_agents.py
Comment thread backend/app/interfaces/project_agents.py
@abiorh-claw
abiorh-claw self-requested a review August 8, 2026 15:57
@abiorh-claw
abiorh-claw merged commit fb90237 into main Aug 8, 2026
11 checks passed
@abiorh-claw
abiorh-claw deleted the codex/ws-pol-003-01-contract-catalogue branch August 8, 2026 15:59
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