Skip to content

fix(perl): mapping-integrity hotfix for packet_to_findings (PR H1, Campaign 31 #1409) - #1447

Merged
EffortlessSteven merged 2 commits into
mainfrom
perl-mapper-integrity-h1
Jun 26, 2026
Merged

EffortlessSteven merged 2 commits into
mainfrom
perl-mapper-integrity-h1

Conversation

@EffortlessSteven

Copy link
Copy Markdown
Member

Summary

Campaign 31 Perl repair routing — PR H1: mapping-integrity hotfix. First of a two-PR honesty split (H1 mapping integrity lands now; H2 classification semantics lands after the cross-repo contract freeze adds sink-alignment fields).

The production mapper packet_to_findings bypassed the packet-owned relation/oracle/command/identity helpers and reimplemented classification inline, incorrectly. This PR rewrites it to route through the existing (tested) packet helpers. Classification is conservative-or-stricter only.

Defects fixed (all routed through existing packet helpers — no third classifier)

Defect Before After
related_test.file production source path (lib/*.pm) — cardinal-sin risk test path via test.file_id (related_test_evidence_for_change)
related_test.line hardcoded 1 TestFact range
relation_reason / relation_confidence always None typed map via perl_relation_to_domain (mirrors ts_relation_to_domain)
verify command global CommandScope::Test scan per-test verify_command_for_test(test_id)
dynamic boundary whole file_id conservative has_blocking_dynamic_boundary (owner OR file OR test file); ownerless file-level boundary still blocks
canonical gap generic enum labels attached only when a concrete discriminator:-prefixed digest exists; else None

Classification policy (H1)

  • Advisory relation kinds (FileProximity, PackageReference, TestNameMatch, FixtureSetup, Unknown) never promote past ReachableUnrevealed. This is the relation-kind gate classify_related_relation omits.
  • "Already observed" is intentionally NOT claimed. Owner-target identity (oracle.target_owner_id) is not changed-sink observation; the Finding leaves observed_sink/oracle_alignment None. The three-way matrix lands in H2 once the producer can prove sink alignment (cf. docs/LEARNINGS.md).
  • No gap_state: emission; public readiness stays off (projection gated-closed at preview_actionability.rs:46).

Tests

8 adversarial tests added — the first direct coverage of packet_to_findings (it previously had zero, which is why the production-path bug survived 3 merged PRs). Pins: test-path-not-production-path, line-from-range, file_proximity-not-eligible, verify-by-test_id, boundary-on-other-owner-doesn't-block, ownerless-file-boundary-blocks, generic-discriminator-no-gap, concrete-discriminator-attaches-gap. All 51 Perl tests pass.

Validation (feature-gated — lang-perl is NOT a default feature)

cargo test -p ripr --features lang-perl --lib analysis::language::perl → 51/0
cargo fmt --check → clean
cargo xtask goldens check → clean
cargo xtask check-output-contracts → clean
cargo xtask check-spec-{format,numbering} / check-traceability / check-static-language / check-doc-index / check-generated-clean → all clean

Caveats

  • cargo clippy --workspace --all-targets --features lang-perl -- -D warnings fails on pre-existing dead scaffolding (main fails it too: 51 errors; this branch: 49). CI runs clippy on default features (no lang-perl), so it never sees the Perl module. The new H1 code is clippy-clean within the feature. Clearing the pre-existing scaffolding is out of H1 scope (flagged for PRs 4–7).

Spec / docs

  • docs/LEARNINGS.md: two durable lessons (owner-target ≠ sink observation; the feature-gate false-green oracle).
  • RIPR-SPEC-0121 (proposed): the perl-lsp-swarm CI scratch-GC orphan-reaper path mismatch — spec-only, fix lands in the other repo.

Non-goals

  • No H2 classification matrix (blocked on cross-repo contract freeze).
  • No public readiness change.
  • No perl-lsp-swarm CI change (spec-only).

Campaign 31 (#1379). Followups: H2 (after PR 2A adds ChangeFact.changed_observable/OracleFact.observed_sink), perl-lsp-swarm scratch-GC fix.

)

The production mapper `packet_to_findings` bypassed the packet-owned
relation/oracle/command/identity helpers and reimplemented classification
inline, incorrectly. This is the first PR of the Perl honesty split (H1:
mapping integrity; H2: classification semantics lands after the producer
contract adds sink-alignment fields).

Verified defects fixed (all routed through existing packet helpers, no
third classifier):

- `related_test.file` was built from the PRODUCTION source path
  (`PathBuf::from(&file.path)`, mod.rs:178), not the test file. The
  cardinal-sin risk: an edit surface pointing at `lib/*.pm`. Now resolved
  through `test.file_id` via `related_test_evidence_for_change`.
- `related_test.line` was hardcoded to `1`. Now from the TestFact range.
- `relation_reason`/`relation_confidence` were always `None`. Now mapped
  via `perl_relation_to_domain` (mirrors `ts_relation_to_domain`).
- Verify command was selected globally by `CommandScope::Test`. Now
  per-test via `verify_command_for_test(test_id)`.
- Dynamic boundary was scoped to the whole `file_id`. Now uses the
  conservative `has_blocking_dynamic_boundary` (owner OR file OR test
  file); an ownerless file-level boundary still blocks.
- Canonical gap was built from generic enum labels. Now attached ONLY
  when a concrete `discriminator:`-prefixed `changed_text_digest` exists;
  otherwise the Finding is informational with `canonical_gap: None`.

Classification is conservative-or-stricter only. Advisory relation kinds
(`FileProximity`, `PackageReference`, `TestNameMatch`, `FixtureSetup`,
`Unknown`) never promote past `ReachableUnrevealed` — this is the
relation-kind gate `classify_related_relation` omits. "Already observed"
is intentionally NOT claimed: owner-target identity
(`oracle.target_owner_id`) is not changed-sink observation, and the
Finding leaves `observed_sink`/`oracle_alignment` `None`. That matrix
lands in H2 once the producer can prove sink alignment.

No `gap_state:` emission; public readiness stays off (the projection
remains gated-closed at `preview_actionability.rs:46`).

Tests: 8 adversarial tests added — the FIRST direct coverage of
`packet_to_findings` (it previously had zero). All 51 Perl tests pass.

Validation (feature-gated; `lang-perl` is opt-in, NOT a default feature):
  cargo test    -p ripr --features lang-perl --lib analysis::language::perl
  cargo fmt --check
  cargo xtask goldens check
  cargo xtask check-output-contracts
all exit 0.

Note: `cargo clippy --workspace --all-targets --features lang-perl` fails
on pre-existing dead-code scaffolding that `main` also fails (51 errors
on main, 49 on this branch). CI runs clippy on default features (no
`lang-perl`), so it does not see the Perl module; the new H1 code is
clippy-clean within the feature. Clearing the pre-existing scaffolding is
out of H1 scope (it is the "dead scaffolding" flagged for PRs 4-7).

Campaign 31 (#1379). Followups: H2 classification semantics (after PR 2A
adds `ChangeFact.changed_observable`/`OracleFact.observed_sink`), and the
perl-lsp-swarm CI scratch-GC fix (documented separately).
…scratch-GC spec

Companion to the H1 mapper hotfix (97be8b9). Two durable artifacts:

docs/LEARNINGS.md — new entry "Perl mapper honesty" capturing two lessons:
  1. Owner-target identity (oracle.target_owner_id == changed_owner) is not
     changed-sink observation. The packet leaves observed_sink/oracle_alignment
     None, so crediting reach-plus-strong-oracle as "already discriminated" is
     the false-exposed family. Fail closed until the producer contract adds
     ChangeFact.changed_observable / OracleFact.observed_sink; split mapping
     integrity (H1) from classification semantics (H2).
  2. lang-perl is not a default feature, so CI's default-feature clippy gate
     never compiles the Perl module — a false-green oracle. Validation for a
     feature-gated module must pass --features <feature> explicitly.

RIPR-SPEC-0121 (proposed) — the perl-lsp-swarm CI scratch-GC orphan-reaper
  path mismatch: per-run dirs nest under /mnt/ci-scratch/{perl-lsp-swarm,tmp}
  /ripr-* but the reaper scans the parent at depth 1, so killed/OOM/cancelled
  runs leak multi-GB Cargo target trees. Spec-only (the fix lands in
  perl-lsp-swarm, unreachable from this session); ripr-swarm's own
  scratch-gc.yml is the reference pattern (it sweeps inside each subdir at
  -maxdepth 1). Status proposed until applied there.

Registered in docs/specs/README.md, policy/doc-artifacts.toml, and
.ripr/traceability.toml.

Gates: check-spec-format, check-spec-numbering, check-traceability,
check-static-language, check-doc-index, check-generated-clean all exit 0.

Campaign 31 (#1379).
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@EffortlessSteven, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 19 minutes and 22 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

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

🚦 How do rate 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 see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 9c22d5fa-4480-4719-918a-246d2700f62e

📥 Commits

Reviewing files that changed from the base of the PR and between 826a128 and bfe5fa7.

📒 Files selected for processing (7)
  • .ripr/traceability.toml
  • crates/ripr/src/analysis/language/perl/mod.rs
  • crates/ripr/src/analysis/language/perl/tests.rs
  • docs/LEARNINGS.md
  • docs/specs/README.md
  • docs/specs/RIPR-SPEC-0121-perl-lsp-swarm-scratch-gc-orphan-reaper-paths.md
  • policy/doc-artifacts.toml
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch perl-mapper-integrity-h1

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.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request implements the H1 mapping-integrity contract for the Perl adapter, ensuring that related-test evidence correctly resolves to test file paths rather than production source paths, gating canonical repair gaps behind concrete discriminators, and adding comprehensive adversarial tests. Feedback on these changes highlights a potential logic issue where dynamic boundaries are only evaluated for the first related evidence, the use of the unstable let_chains feature which should be refactored for stable Rust compatibility, and an opportunity to simplify perl_relation_to_domain into a single match statement.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +191 to +194
let has_boundary = related_evidence
.first()
.map(|ev| packet.has_blocking_dynamic_boundary(change, Some(ev)))
.unwrap_or_else(|| packet.has_blocking_dynamic_boundary(change, None));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

Using .first() on related_evidence to determine has_boundary introduces an ordering dependency. If there are multiple related tests, a dynamic boundary on the second or subsequent test will be completely ignored if the first one is unblocked. Conversely, if the first test is blocked, the entire change is classified as StaticUnknown even if other unblocked tests exist.

Evaluating the boundaries for all related evidences ensures consistent and robust classification.

Suggested change
let has_boundary = related_evidence
.first()
.map(|ev| packet.has_blocking_dynamic_boundary(change, Some(ev)))
.unwrap_or_else(|| packet.has_blocking_dynamic_boundary(change, None));
let has_boundary = if related_evidence.is_empty() {
packet.has_blocking_dynamic_boundary(change, None)
} else {
related_evidence
.iter()
.any(|ev| packet.has_blocking_dynamic_boundary(change, Some(ev)))
};

Comment on lines +322 to 332
if has_concrete_discriminator && let Some(first) = related.first() {
evidence.push(format!(
"perl_suggested_test_location: {}::{}",
first.file.display(),
first.name
));
evidence.push(format!(
"perl_verify_command: {}",
verify_cmd.argv.join(" ")
"perl_suggested_assertion: {}",
change.behavior_hint.default_missing_discriminator()
));
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

This code uses the let_chains feature (if ... && let ...), which is currently unstable in Rust. To ensure compatibility with stable Rust compilers and avoid relying on unstable nightly features, rewrite this using nested if let statements.

Suggested change
if has_concrete_discriminator && let Some(first) = related.first() {
evidence.push(format!(
"perl_suggested_test_location: {}::{}",
first.file.display(),
first.name
));
evidence.push(format!(
"perl_verify_command: {}",
verify_cmd.argv.join(" ")
"perl_suggested_assertion: {}",
change.behavior_hint.default_missing_discriminator()
));
}
if has_concrete_discriminator {
if let Some(first) = related.first() {
evidence.push(format!(
"perl_suggested_test_location: {}::{}",
first.file.display(),
first.name
));
evidence.push(format!(
"perl_suggested_assertion: {}",
change.behavior_hint.default_missing_discriminator()
));
}
}

Comment on lines +335 to +340
if let Some(first_ev) = related_evidence.first()
&& let Some(argv) = first_ev.verify_command.as_ref()
&& !argv.is_empty()
{
evidence.push(format!("perl_verify_command: {}", argv.join(" ")));
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

This is another instance of the unstable let_chains feature. It can be cleanly rewritten using standard Option::and_then and a nested if statement to remain compatible with stable Rust.

        if let Some(argv) = related_evidence.first().and_then(|ev| ev.verify_command.as_ref()) {
            if !argv.is_empty() {
                evidence.push(format!("perl_verify_command: {}", argv.join(" ")));
            }
        }

Comment on lines +2164 to +2194
fn perl_relation_to_domain(
kind: RelationKind,
) -> (
Option<crate::domain::RelationReason>,
Option<crate::domain::RelationConfidence>,
) {
use crate::domain::{RelationConfidence, RelationReason};
let reason = match kind {
RelationKind::DirectOwnerCall => RelationReason::DirectOwnerCall,
RelationKind::HelperCall => RelationReason::HelperOwnerCall,
RelationKind::PackageReference => RelationReason::ImportPathAffinity,
RelationKind::MethodReceiver => RelationReason::DirectOwnerCall,
RelationKind::TestNameMatch => RelationReason::OwnerNamedTest,
// Advisory-only signals with no clean owner-call mapping: emit None so
// they disclose as `relation_reason: null` (legacy advisory style),
// matching how the TS adapter treats SameFileProximity/DescribeName.
RelationKind::FileProximity | RelationKind::FixtureSetup | RelationKind::Unknown => {
return (None, None);
}
};
let confidence = match kind {
RelationKind::DirectOwnerCall | RelationKind::MethodReceiver => RelationConfidence::High,
RelationKind::HelperCall => RelationConfidence::High,
RelationKind::PackageReference | RelationKind::TestNameMatch => RelationConfidence::Medium,
// Unreachable: the match above returns early for these.
RelationKind::FileProximity | RelationKind::FixtureSetup | RelationKind::Unknown => {
RelationConfidence::Low
}
};
(Some(reason), Some(confidence))
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The current implementation of perl_relation_to_domain uses two separate match statements, an early return, and duplicate unreachable match arms.

We can refactor this into a single, elegant, and exhaustive match statement. This improves readability, idiomaticity, and maintainability.

fn perl_relation_to_domain(
    kind: RelationKind,
) -> (
    Option<crate::domain::RelationReason>,
    Option<crate::domain::RelationConfidence>,
) {
    use crate::domain::{RelationConfidence, RelationReason};
    match kind {
        RelationKind::DirectOwnerCall => (
            Some(RelationReason::DirectOwnerCall),
            Some(RelationConfidence::High),
        ),
        RelationKind::MethodReceiver => (
            Some(RelationReason::DirectOwnerCall),
            Some(RelationConfidence::High),
        ),
        RelationKind::HelperCall => (
            Some(RelationReason::HelperOwnerCall),
            Some(RelationConfidence::High),
        ),
        RelationKind::PackageReference => (
            Some(RelationReason::ImportPathAffinity),
            Some(RelationConfidence::Medium),
        ),
        RelationKind::TestNameMatch => (
            Some(RelationReason::OwnerNamedTest),
            Some(RelationConfidence::Medium),
        ),
        RelationKind::FileProximity | RelationKind::FixtureSetup | RelationKind::Unknown => {
            (None, None)
        }
    }
}

@codecov

codecov Bot commented Jun 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.06780% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/ripr/src/analysis/language/perl/mod.rs 94.06% 7 Missing ⚠️

📢 Thoughts on this report? Let us know!

@EffortlessSteven
EffortlessSteven merged commit 4d99e86 into main Jun 26, 2026
26 of 27 checks passed
@EffortlessSteven
EffortlessSteven deleted the perl-mapper-integrity-h1 branch June 26, 2026 14:15
EffortlessSteven added a commit that referenced this pull request Jun 26, 2026
…tion_to_domain (#1447 review) (#1448)

Addresses droid-review findings on #1447:

1. (HIGH) Boundary check sampled only .first() related evidence, so a
   dynamic boundary tied to a SECOND/subsequent test's file was silently
   missed (ordering dependency). Now checks EVERY related evidence via
   .any(); the change still blocks if any related test's file has a
   blocking boundary. New adversarial test
   h1_boundary_check_is_ordering_independent_across_related_tests pins
   this (two related tests, boundary on the second test's file → still
   StaticUnknown).

4. Refactor perl_relation_to_domain from two match statements + early
   return + unreachable arms into a single exhaustive match (cleaner,
   no duplicate unreachable arms).

Dismissed (verified against the toolchain):
  #2/#3 claim `let_chains` is unstable — false. The repo pins Rust
  1.95.0 (rust-toolchain.toml); let_chains stabilized in 1.87 and is
  already used in value_resolution.rs, json/report.rs, and
  review_comments.rs. CI rust-tests-junit passed.

Validation (feature-gated, lang-perl is non-default):
  cargo test -p ripr --features lang-perl --lib analysis::language::perl
    → 52 passed / 0 failed
  cargo fmt --check → clean
  clippy within feature → my code clean

Campaign 31 (#1379).
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