Repository navigation
perf(classify): prime the workspace macro-site scan before the classify fan-out (#9211) - #9237
Conversation
…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
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
Warning Review limit reachedEnable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
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. View limit details
Comment |
There was a problem hiding this comment.
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).
|
Review of record, head 817ddd1. Angles: (1) correctness/deadlock, (2) perf regression, (3) test discrimination. Independent read-only reviewer plus my own measurements.
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 |
Summary
The first
workspace_macro_sitelookup in classification rancomplete_workspace_site_scanin line on oneripr-classify-*worker, parsing the whole corpus single-threaded while holding theSyncMemolock; 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 existingpool.installinlanguage/rust/mod.rswith the caller's cancellation token and committed-source overlay. A scoped thread-local letsmap_scansfan 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
ripr-swarmSource-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-scanStack 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.rswith concurrent #9209/#9210 work; no overlap in intent.Scope
Scheduling of one existing scan; no semantic change.
Scope Classification
Production delta:
owner_pin.rs:prime_workspace_macro_scan, scopedPrimedScanFanOutguard,scan_fans_out()used bymap_scans.related_tests.rs: pass-through.language/rust/mod.rs: one call insidepool.install.Evidence/support delta:
priming_fans_the_workspace_macro_scan_out_once_and_lookups_only_read_it; end-to-end testthe_classify_run_fans_the_workspace_macro_scan_out_before_its_probes;changelog.d/9211-prime-classify-macro-scan.md.Single acceptance criterion:
Non-goals:
Support-tier Impact
Policy Impact
Proof
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)vsSome(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
owner_pin/tests.rs,language/rust/proximity_reach_tests.rsanalysis/classify/owner_pin.rs,related_tests.rs,language/rust/mod.rsStatic Language Check
killed,survived,untested,proven, andadequate.CI Economics
n/a
Engineering Check
panic,unwrap,expect,todo, orunimplementedin production code.panic,unwrap,expect,todo, orunimplementedin tests.Generated by Claude Code