Skip to content

perf(cold): index target-affinity evidence candidates - #3839

Merged
EffortlessSteven merged 3 commits into
mainfrom
perf/3838-cold-target-affinity-index
Sep 22, 2026
Merged

EffortlessSteven merged 3 commits into
mainfrom
perf/3838-cold-target-affinity-index

Conversation

@EffortlessSteven

@EffortlessSteven EffortlessSteven commented Sep 22, 2026 •

Copy link
Copy Markdown
Member

Fixes #3838
Parent: #3794
Measurement authority: #3795
Warm/incremental sibling: #3796

What changed

The repo-evidence target-affinity matcher no longer scans every indexed test for every eligible seam.

CompactGripContext now builds one deterministic reverse index:

target-affinity owner-call name -> test indexes

and match_target_affinity_owner_call resolves candidates from that index before applying the existing target-token predicate.

Why this is cold-path work

On the large whole-repo path, evidence construction is a dominant cold phase. The old matcher retained an O(seams × tests) candidate-selection term even though target-affinity owner-call names were already materialized per test.

Rust file parsing is already Rayon-parallel, and classified-seam cache sharding already exists. This PR removes a demonstrated redundant whole-test scan before considering broader evidence parallelism.

Semantics preserved

Unchanged:

  • relation reason and priority;
  • package/prefix filtering;
  • target-token matching;
  • related-test deduplication and ranking;
  • activation/oracle/classification behavior;
  • cancellation;
  • cache identity;
  • output/schema/golden/fixture contracts;
  • support claims.

The reverse-index vectors preserve test enumeration order, and each test's owner names come from a BTreeSet, so candidate membership/order matches the prior scan.

Governance

Adds .allow/spec-system/slices/ripr.slice.cold-target-affinity-index.v1.toml as a refactor slice under RIPR-SPEC-0005. It explicitly forbids golden/output/classification-decision changes.

Proof

Existing target-affinity evidence coverage includes positive and negative multi-owner, module-qualified, crate-qualified, direct-import, wrong-target, and ambiguity guards.

Expected protected proof:

cargo test -p ripr test_grip_evidence -- --test-threads=1
cargo xtask goldens check
cargo xtask check-output-contracts
cargo xtask check-static-language
cargo xtask check-pr
git diff --check

After #3795's phase/reuse receipts are available, the cold self-dogfood replay should compare the evidence phase at this exact head. This PR alone does not make a universal wall-clock claim.

Non-goals


Devin Review

@gemini-code-assist

Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@coderabbitai

coderabbitai Bot commented Sep 22, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 58 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 109fdae3-ef48-4f03-bf7a-cee2c13f3cd2

📥 Commits

Reviewing files that changed from the base of the PR and between dc66cec and 8bffc5b.

📒 Files selected for processing (3)
  • .allow/spec-system/slices/ripr.slice.cold-target-affinity-index.v1.toml
  • crates/ripr/src/analysis/test_grip_evidence/related_tests.rs
  • crates/ripr/src/analysis/test_grip_evidence/related_tests/context.rs

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.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Devin Review found 1 potential issue.

Devin Review

Copy link
Copy Markdown
Member Author

Current exact-head qualification state

Candidate head:

8bffc5b31d9fcbd6179f304bb0b85a08360d7edd

Current hosted observations:

PR Plan             success      run 35688229456
Security            success      run 35688229481
Source of Truth     success      run 35688229521
Routed Rust Small   in_progress  run 35688229672
ub-review            in_progress  run 35688229475
Droid Auto Review   queued       run 35688229604

#3838 is now marked status/partial in the 0.11 milestone. Terminal PR green is necessary but not sufficient: release acceptance still requires semantic/output parity, substantive exact-head review, and an exact-head cold replay handoff to #3794/#3795. Preserve the bounded claim—removal of one O(seams × tests) candidate-selection term—without promoting it to a universal wall-clock or whole-cold-path claim.

Any head movement invalidates these run identities. No merge/candidate/qualification/source/publication state is implied while required runs and measurement handoff remain nonterminal.

Copy link
Copy Markdown
Member Author

Review finding — implementation has no discriminating index regression proof

The production change is appropriately small, but this PR changes only the context/index implementation and slice declaration; it adds no focused test or structural guard.

The existing semantic related-test fixtures can pass under both implementations:

old: scan every context.tests row and filter
new: look up owner-name candidates, then filter target tokens

They therefore show output parity but do not establish the new acceptance proposition that the reverse index contains all and only the intended test indexes, preserves deterministic order/deduplication, or that this matcher no longer regresses to a per-seam full-corpus scan.

Before merge, add a focused discriminator that would fail when the index is missing, incomplete, duplicated, or misordered. A suitable unit fixture can build multiple tests with:

same owner + matching target
same owner + wrong target
other owner + matching target
duplicate owner evidence in one test

and assert the exact reverse-index vector plus unchanged final related-test output/order. Also add the least brittle available guard that the target-affinity matcher consumes tests_by_target_affinity_owner_call_name rather than iterating context.tests end to end; if a source-shape guard is rejected, record why and retain another measurable discriminator.

This is a missing_discriminating_proof finding under #3807, not a semantic-failure claim. The current required run may still go green because the old algorithm satisfied the same output fixtures.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Confirmed findings

  • Sibling memory-shape concern: tests_by_target_affinity_owner_call_name stores Vec with the same per-key growth and zero-trim behavior as tests_by_call_name and tests_by_helper_owner_call_name. If those siblings carry no documented pruning contract, neither does the new index; a per-test BTreeSet membership blob is duplicated by value into the index (owner_name.clone() per emit) and again into tests_by_helper_owner_call_name for tests whose helper set non-empty, so total cold-path memory doubles only on the owner-name union. Not a blocker for a refactor slice, but worth tracking before activation/oracle work reuses this index.
  • CompactGripContext::new now performs an extra BTreeMap insert loop per owner name on every cold construction; PR claims this is net-positive but does not bound new allocation cost for very large owner-name sets.

Refuted

  • replacement index could drop tests whose owner-call name appears multiple times due to Vec dedup; refuted because: the diff uses .or_default().push(test_index) inside the per-test BTreeSet loop; duplicates per test do not exist (BTreeSet dedupes) and tests with the same owner name each appear once in the order they appear in context.tests.
  • get(&owner.name) returning Some would skip tests whose target_affinity_owner_call_names did not contain owner.name before; refuted because: Both prior scan and new lookup gate on the same contains-equality; the index is built from the same BTreeSet so membership is identical.
  • Borrowing &target_affinity_owner_call_names while extending tests_by_target_affinity_owner_call_name could create a self-referential BTreeMap entry that aliases the source vector; refuted because: owner_name.clone() inserts an owned String key; the pushed usize is Copy. No reference into the source set is retained in the map, so no self-referential aliasing or later invalidation is possible.
  • Relation reason, priority, or RelationReason::HelperOwnerCall classification might drift due to index refactor.; refuted because: insert_related_candidate call site is unchanged in arguments: candidates, context, prefix, *test_index, RelationReason::HelperOwnerCall. Only the candidate enumeration source changed; downstream logic untouched.
  • If Rust tests do not cover the cold-path target-affinity evidence phase, the refactor could regress behavior undetected by goldens.; refuted because: PR body and tokmd receipts enumerate target-affinity evidence guards (positive/negative multi-owner, module-qualified, crate-qualified, direct-import, wrong-target, ambiguity). Slice TOML forbids golden/output/classification changes, and cargo test -p ripr test_grip_evidence -- --test-threads=1 is listed as protected proof. Coverage for the changed path already exists.

Evidence gaps

  • artifact-verifier exited 2; claimed output/golden/fixture contracts preserved but no verifier receipt attests this.
  • build/cargo-test receipts are scheduled-late; oracle strength cannot be finalized until sensor-cargo-test lands.
  • Model proof intent was rejected by deterministic validation.

Parked follow-ups

  • Sibling helper-owner-call matcher (match_helper_owner_call) still uses context.tests_by_helper_owner_call_name, confirming this PR does not regress the analogous indexed path; no shared caller of the removed scan exists elsewhere.
  • Broader evidence-parallelism (Rayon over seams, semantic-unit caching) is a real sibling but explicitly parked as non_goal in the slice; not in scope for this PR.

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.

perf(cold): eliminate per-seam full-test scans in repo evidence matching

1 participant