refactor: split process_mode_tuned into per-mode render_* helpers (cc 129 -> thin dispatcher) - #769
Merged
yvgude merged 2 commits intoJul 9, 2026
Conversation
process_mode_tuned was a 557-line match (cognitive complexity 129), the hottest ctx_read path. Extract the 5 large arms (signatures, map, aggressive, entropy, task) into standalone render_* functions taking a Copy RenderCtx bundle (file_ref/short/ext/file_path/original_tokens/crp_mode/line_count/task); tuning is threaded only to the arms that use it. The dispatcher is now a thin match. Behaviour is byte-identical (bodies moved verbatim, then rustfmt-reindented); each mode arm is now independently testable and the per-function complexity is far lower.
yvgude
approved these changes
Jul 9, 2026
yvgude
left a comment
Owner
There was a problem hiding this comment.
Reviewed the ctx_read process_mode_tuned refactor in detail.
Verified:
RenderCtx<'a>is a cleanCopybundle that keeps helper signatures under clippy'stoo-many-argumentsthreshold- All 5 extracted
render_*helpers (signatures,map,aggressive,entropy,task) are verbatim moves with rustfmt-reindentation only - The thin dispatcher correctly delegates with one-liners; small arms (
raw,auto,full,anchored,reference,lines:,density:) stay inline — sensible scope tuningis threaded only toentropyandtask(the arms that need it)- Byte-identical output —
process_mode_output_is_byte_stable_across_callsdeterminism test passes, protecting prompt-cache stability (#498) - 70/70 ctx_read tests green
rules_overhead.rsclippy fix is identical to what landed in #765
No behavioral changes, pure structural improvement. CC 129 → thin dispatcher.
Approved.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #770.
process_mode_tuned(rust/src/tools/ctx_read/render.rs) was a 557-linematch modeblock — cognitive complexity 129, and the hottestctx_readpath. This splits it into a thin dispatcher plus onerender_*helper per non-trivial mode.signatures,map,aggressive,entropy,task— into standalone functions.CopyRenderCtx<'a>bundle (file_ref/short/ext/file_path/original_tokens/crp_mode/line_count/task) so each helper takes 2-3 params instead of 10 (stays undertoo-many-arguments-threshold).tuningis threaded only to the arms that use it (entropy,task).matchis now a thin dispatcher; the small arms (raw/auto/full/anchored/reference/lines:/density:/unknown) are unchanged.Behaviour is byte-identical: the arm bodies were moved verbatim and only rustfmt-reindented (hence the large diff). Each mode is now independently testable and per-function complexity is far lower.
Test plan
cargo test --lib -- tools::ctx_read-> 70 passed, 0 failed (incl.process_mode_output_is_byte_stable_across_callsdeterminism test and the per-mode tests)cargo build --libcargo fmt --checkcargo clippy --lib --all-features -- -D warningsclean forrender.rs(the only remaining error is the unrelated pre-existingrules_overhead.rs:143lint onmain, fixed by fix: silence clippy::map_unwrap_or in rules_overhead (unblocks Clippy CI) #767)Notes for reviewers
render_*.