Skip to content

perf(classify): prime the workspace macro-site scan before the classify fan-out (#9211) - #9237

Merged
EffortlessSteven merged 1 commit into
mainfrom
fix/9211-classify-prime-macro-scan
Oct 21, 2026
Merged

EffortlessSteven merged 1 commit into
mainfrom
fix/9211-classify-prime-macro-scan

Conversation

@EffortlessSteven

@EffortlessSteven EffortlessSteven commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Summary

The first workspace_macro_site lookup in classification ran complete_workspace_site_scan in line on one ripr-classify-* worker, parsing the whole corpus single-threaded while holding the SyncMemo lock; every sibling worker slept on that mutex (trusted_macro_ambiguities). nested_parallelism_allowed() is false on pool workers (#8756), so the scan could never fan out there.

The scan is now paid once, before any probe is queued, from a classify-pool thread: RelatedTestCandidateIndex::prime_workspace_macro_scan -> OwnerPinSyntax::prime_workspace_macro_scan -> complete_workspace_site_scan (which runs the ambiguity pass first), called at the top of the existing pool.install in language/rust/mod.rs with the caller's cancellation token and committed-source overlay. A scoped thread-local lets map_scans fan out over that pool for the duration of the prime only; it is safe where the #8756 guard refuses because no sibling probe is queued yet, so nothing can be stolen onto a thread that holds the memo lock. The scan runs on the classify pool (16 MiB workers) rather than the global pool (2 MiB), because the parse recurses over source nesting. Memo contents are exactly what the first consumer would have produced, so output is unchanged.

Swarm / Source Boundary

  • ordinary feature, analyzer, editor, docs, spec, fixture, badge, dependency, or repo-ops development for ripr-swarm

Source-of-truth Links

Proposal: none
Spec: RIPR-SPEC-0240 (site-selection semantics preserved)
ADR: none
Plan item: none
Governing issue or accepted claim: #9211
Acceptance delta (one sentence): The workspace macro-site scan runs once, fanned out over the classify pool before the probes, instead of in line on one worker while the others block on the memo lock, with byte-identical findings.

Candidate Relationships

Candidate branch: fix/9211-classify-prime-macro-scan
Stack parent or prerequisite PR (if any): none
Related, not equivalent: #8772 (Draft, retained macro-site disclosure parity) touches the same scan body but not its scheduling; #8262 (merged) bounded the pass count. Expect merge-main conflicts in owner_pin.rs with concurrent #9209/#9210 work; no overlap in intent.

Scope

Scheduling of one existing scan; no semantic change.

Scope Classification

  • One production behavior

Production delta:

  • owner_pin.rs: prime_workspace_macro_scan, scoped PrimedScanFanOut guard, scan_fans_out() used by map_scans.
  • related_tests.rs: pass-through. language/rust/mod.rs: one call inside pool.install.

Evidence/support delta:

  • Unit test priming_fans_the_workspace_macro_scan_out_once_and_lookups_only_read_it; end-to-end test the_classify_run_fans_the_workspace_macro_scan_out_before_its_probes; changelog.d/9211-prime-classify-macro-scan.md.

Single acceptance criterion:

  • No macro-site scan runs in line on a classify worker for a run that classifies probes.

Non-goals:

Support-tier Impact

  • none

Policy Impact

  • none

Proof

cargo test -p ripr --lib -- priming_fans the_classify_run_fans nested_scans the_workspace_macro_scan_runs refusal_site_lookups seam_walk_pays classified_findings_are_identical   # 7 passed
cargo test -p ripr --lib -- owner_pin proximity_reach
cargo xtask precommit   # exit 0 (goldens check skipped: no output-surface change)

Mutation checks (each reverted): removing the prime call fails the end-to-end test (a scan ran in line on a classify worker: [false]); making the guard not set the fan-out flag fails both the unit test (Some(false) vs Some(true)) and the end-to-end test. The unprimed control in the unit test asserts the pre-fix behavior (in-line on a worker).

Not measured here: wall-clock speedup (the issue's gdb sampling was not re-run).

Claim Boundary

May claim: the scan no longer runs in line on a classify worker and findings are unchanged by construction (same memo contents; existing parity test across 1/2/4/8 classify threads passes). Must not claim: a measured speedup.

Rollback

Revert the squash; no state, schema or cache change.

Spec-Test-Code Traceability

Static Language Check

  • Static output avoids killed, survived, untested, proven, and adequate.
  • Unknowns include stop reasons where applicable.

CI Economics

n/a

Engineering Check

  • No new panic, unwrap, expect, todo, or unimplemented in production code.
  • No new panic, unwrap, expect, todo, or unimplemented in tests.
  • Errors are reported with actionable context.

Generated by Claude Code


Devin Review

…fy fan-out (#9211)

The first workspace_macro_site lookup ran complete_workspace_site_scan in
line on one classify worker while holding the SyncMemo lock, parsing the
whole corpus single-threaded while its siblings slept on the mutex. Pay
the scan once from the classify pool before any probe is queued, so it
fans out; workers then only read the memo. Output is unchanged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019WPmWp4vdysYyymwvPKycS
@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 Oct 21, 2026

Copy link
Copy Markdown

Warning

Review limit reached

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

  • Ask an admin to enable usage-based reviews

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Next included review available in 44 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available. Your 88 included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Essentials
  • Run ID: 2f7881ee-6cd2-4482-9a8d-f0f01da22246
📥 Commits

Reviewing files that changed from the base of the PR and between 7a44b39 and 817ddd1.

📒 Files selected for processing: 7
  • changelog.d/9211-prime-classify-macro-scan.md
  • crates/ripr/src/analysis/classify/mod.rs
  • crates/ripr/src/analysis/classify/owner_pin.rs
  • crates/ripr/src/analysis/classify/owner_pin/tests.rs
  • crates/ripr/src/analysis/classify/related_tests.rs
  • crates/ripr/src/analysis/language/rust/mod.rs
  • crates/ripr/src/analysis/language/rust/proximity_reach_tests.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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 2 potential issues.

Devin Review

@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

  • ripgrep/ast-grep family scan for sibling entry points that might invoke classification outside RustAdapter::run_classify (e.g. xtask, language registry, MCP, LSP, CLI subcommands) was not exhaustively run by this lane; sibling-paths lane owns broader coverage. If a second classification entry point exists and skips the prelude, the prime will not run there and the scan will revert to the in-line behavior — this is not in itself a regression but is a source-route gap worth flagging.
  • The only added lifetime-sensitive surface is the per-call SCAN_LOG Mutex + Vec<u64,bool> on the #[cfg(test)] path. On the e2e test, classic rayon or sequential use keeps the lock for O(N_files) pushes per scan; under heavy pool parallelism the contention scales with N×P. Not production-visible; mutex itself does not deadlock since the lock is not held across .par_iter drains.

Verification questions

  • Confirm searched for sibling callers/invokers of prime_workspace_macro_scan, workspace_macro_site, complete_workspace_site_scan, and PrimedScanFanOut. Only the new route plus pre-existing internal use of workspace_macro_site in classification paths. No second prime site, no other entry point reaching the scan ahead of classification.

Refuted

  • The change exposes memory corruption, OOB access, use-after-free, type confusion, or secret disclosure.; refuted because: The reviewed delta changes scheduling and a thread-local flag; unsafe-review reports no new gaps, the guard restores state via Drop, and no raw pointer, lifetime, unsafe block, allocation of externally sized data, or secret-bearing path is introduced.
  • Holding the SyncMemo (RefCell<Option>) interior mutability across an unbounded par_iter is a memory-lifetime risk in the prime path; refuted because: complete_workspace_site_scan returns the memo in the same shape it would have had on first consumer; it borrows &self (RefCell borrow is dynamically checked, no nested borrow across threads). The sync_memo cell is owned by OwnerPinSyntax (a struct field), lifetime tied to the syntax value, not to the thread-local. No new Ref/RefMut cycles introduced.
  • The diff introduces or relies on ArrayBuffer/ResizableBuffer/TypedArray resize, detach, transfer, or stale-length-snapshot semantics.; refuted because: Diff is pure Rust / rayon scheduling; no JS object model, no ArrayBuffer, no resize, no detach, no transfer, no view-vs-backing-store separation exists in the changed code. The 'view' lane focus does not apply.

Evidence gaps

  • Model proof intent was rejected by deterministic validation.
  • The scheduled cargo-test evidence is absent and the ripr sensor failed with exit code 2, so runtime verification remains an external follow-up.

Parked follow-ups

  • The test-only re-export of SCAN_LOG in classify/mod.rs is paired exactly with the prior nested_parallelism_allowed re-export, so the public(crate) surface used by proximity_reach_tests.rs stays one symbol longer; no other crate-internal consumer is silently re-exporting SCAN_LOG.
  • Cancellation and committed-source context cover the newly added blocking priming operation, but no focused test proves cancellation stops or safely unwinds this pre-probe phase.
  • Cancellation is restored for the prime but does not visibly stop the workspace scan before probes begin, leaving workload-based denial of service as a bounded residual concern.
  • scope control consistent with #8756 guard: priming happens before any seeded_probes.par_iter, so no sibling probe can be stolen onto a thread holding the memo; no gating on the guard itself (a stated non-goal).

Copy link
Copy Markdown
Member Author

Review of record, head 817ddd1.

Angles: (1) correctness/deadlock, (2) perf regression, (3) test discrimination. Independent read-only reviewer plus my own measurements.

  • Correctness: no blocking findings. The prime runs before any probe is queued, so nothing but the scan's own closures can be stolen onto the thread holding the memo lock; the thread-local restores on drop; memo contents equal the lazy path.
  • Perf: the prime is unconditional for any run with a seeded probe (non-blocking). Measured on a 2-line Rust diff of ripr-swarm, ripr check --base HEAD~1: main 36.9 s cold / 25.6 s warm, main + this PR 36.9 s / 25.4 s, so no regression there. Cold ripr pilot on ripr-swarm: 128.7 s vs 125.6 s (noise-level). This PR removes a serialization but is not where the time goes; the dominant costs are evidence evaluation and dependent-scope work. Not measured: a repo with no macros, or a macro-heavy repo with a tiny diff.
  • Tests: discriminating (unprimed control, pass count, post-prime lookups read only). Non-blocking: the leak check in the unit test can run on a different worker than the prime; the changelog wording overstates the gating.
  • Required Ripr Rust Small Result was green on this head.

Merging on merit: correct, no measured regression, removes a lock-held serial scan. Follow-ups, if wanted, are gating the prime and tightening the leak check.


Generated by Claude Code

@EffortlessSteven
EffortlessSteven merged commit f1dfe64 into main Oct 21, 2026
57 checks passed
@EffortlessSteven
EffortlessSteven deleted the fix/9211-classify-prime-macro-scan branch October 21, 2026 23:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants