Repository navigation
feat(review): clause-level 061 adapter with per-clause subject profile - #292
Conversation
Each captured human clause becomes one reviewable subject bound to its exact original raw identity, borrowing from the genuine sealed CurrentAuthoringPlanClosure. - hash_v3 profile8 clause_subject: domain-separated per-clause fingerprint over the clause key, exact original digest and extent (independent byte oracle). - adapters::authoring_clause: prepare() re-verifies each selected clause's exact original against its sealed member; a tampered clause original refuses. bind_queue() binds every clause subject to its own sealed ordinal source pin. - CurrentAuthoringPlanClosure::clause_members() borrows each sealed clause's native key and complete original digest. - Consumed in authoring_binding::prepare (retained) and authoring_finalize (bind_queue), mirroring the /1 mapping/applicability adapter pattern. The /3 whole-plan queue shape and all existing zero-edit/quorum/dissent/M-10 contracts are unchanged. 4 new clause tests; 598 review tests green.
… charge CodeRabbit findings on PR #289 (clause-061 adapter): - bind_queue precomputes a BTreeMap of clause key -> declaration ordinal once, replacing the per-fact O(n) position() scan (O(n^2) at 10k clauses) with O(log n) lookups; first-wins ordinal, unknown-key refusal and derived storage charge preserved. - Replace the misleading chain::compare() call with an explicit ledger.bytes() charge of both complete digest extents (same accounting, no discarded lexical comparison). - Correct clause_subjects comment: keys iterate in lexicographic BTreeMap key order, not native declaration order.
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 40 minutes. View limit details
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. |
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
4 open issues
clause_subjectvalidatesclause_keyviakey(...), which (per context) enforces… · Newbind_queuecurrently requiresfacts().len()to equal the totalHumanClausepin count, which… · New This performs a linear search overpinsfor every selected fact (iter().find(...)), which… · New The1_048_576(1 MiB) extent ceiling is a hard-coded magic number and is duplicated in tests.… · New
What changed in this PR
Adds a clause-level (profile8) “061 adapter” so each captured human clause becomes its own reviewable subject bound to the exact sealed original identity, with ordering/membership enforcement and tamper refusal.
Changes:
- Introduces
hash_v3::clause_subject(profile8) plus an independent oracle-style unit test. - Adds
adapters::authoring_clauseto derive per-clause review facts fromCurrentAuthoringPlanClosureand bind them to queueHumanClausepins. - Wires clause binding into authoring finalize flow and adds dedicated adapter tests.
| File | Description |
|---|---|
| src/review/hash_v3.rs | Adds profile8 per-clause subject digest function. |
| src/review/hash_v3_tests.rs | Adds oracle-based test coverage for clause subject hashing and validation. |
| src/review/authoring_finalize.rs | Ensures clause subjects are bound to queue pins before issuance. |
| src/review/authoring_capture.rs | Exposes clause member (key, raw_sha256) projection from sealed closure. |
| src/review/authoring_binding.rs | Prepares/stashes per-clause review facts as part of pending binding. |
| src/review/adapters/mod.rs | Registers the new authoring_clause adapter module. |
| src/review/adapters/authoring_clause.rs | Implements per-clause re-review fact preparation and queue pin binding. |
| src/review/adapters/authoring_clause_tests.rs | Adds tests for correct binding, tamper refusal, and selection enforcement. |
| src/review/authoring_capture_tests.rs | Wires the new adapter tests into the test suite. |
Review effort: Lite
| pub(crate) fn clause_subject( | ||
| clause_key: &str, | ||
| raw_sha256: &str, | ||
| byte_length: u64, | ||
| ledger: &mut ContractLedger, | ||
| control: &mut dyn WorkControl, | ||
| ) -> Result<String, ContractError> { | ||
| phase(ledger, control, |ledger, control| { | ||
| key(clause_key, ledger)?; | ||
| hash_operand(raw_sha256, ledger)?; | ||
| if byte_length == 0 || byte_length > 1_048_576 { | ||
| return Err(ContractError::Invalid); | ||
| } |
| let pins: Vec<_> = | ||
| queue.source_pins.iter().filter(|pin| pin.kind == SourceKindV3::HumanClause).collect(); | ||
| ledger.visits(pins.len())?; | ||
| if pins.len() != self.complete_clauses() || pins.len() != self.facts().len() { |
| for fact in self.facts() { | ||
| ledger.visits(1)?; | ||
| let ordinal = declared.get(fact.subject_id()).ok_or(ContractError::Binding)?; | ||
| let expected = format!("authoring:clause:{ordinal}"); | ||
| ledger.derived(expected.len())?; | ||
| let pin = pins | ||
| .iter() | ||
| .find(|pin| pin.artifact_key == expected) | ||
| .ok_or(ContractError::Binding)?; |
| if byte_length == 0 || byte_length > 1_048_576 { | ||
| return Err(ContractError::Invalid); | ||
| } |



Re-opened from #289 (auto-closed when its stacked base feat/f12-f13-m10-adapters was deleted on #288 merge). Rebased onto current main; M-10 is already merged.
Clause-level 061 adapter: each captured human clause becomes one reviewable subject bound to its exact original raw identity, borrowing from the genuine sealed CurrentAuthoringPlanClosure (hash_v3 profile8 clause_subject). Tampered-original refusal, selection-order/membership enforcement.
CodeRabbit findings remediated: O(n²)->BTreeMap key->ordinal lookup, explicit ledger digest charge, accurate BTreeMap-order comment.
Verification: 598 review tests + 4 clause tests green; full suite green; fmt/clippy clean.