Repository navigation
Description
Problem
skills/audit-comment-residue/scripts/detect.sh --added-since <base> does not finish in practical
time on Windows Git Bash for an ordinary pull request. In a large private .NET repository
(code-tidying 0.30.0, Windows 11, Git Bash), on a branch of 51 changed .cs/.razor files that
added zero comment lines:
detect.sh --added-since origin/mainwith no targets printed nothing for more than 10 minutes and
was stopped.- The same call with the 51 paths passed explicitly was killed by
timeout 280with no output
(exit 143). git diff -U0 <merge-base>..HEAD -- '*.cs' '*.razor' | grepover the same range returned
instantly. The expected report was empty.
Cause, on current main (code-tidying 0.30.3):
audit_fileruns shape detection on every line of every in-scope file, then checks scope.
plugins/code-tidying/skills/audit-comment-residue/scripts/detect.sh:323computes
shapes="$(cr_detect_shapes ...)"for each line. Thein_scopefilter is applied only afterwards,
at:334(joined pair) and:346(single line).- Each
$(...)is a forked subshell.cr_detect_shapes
(scripts/lib/comment-shapes.sh:158-160) runs a second one,$(cr_comment_text "$1"), inside
the first.cr_comment_text(comment-shapes.sh:35-79) walks every character of a non-comment
line in a bash loop before it returns empty. - Both pre-passes,
cr_license_block_linesandcr_justified_run_lines(detect.sh:303-310,
comment-shapes.sh:128-155), read the whole file. They fork$(cr_comment_text ...)once per
comment-only line.
So under --added-since the cost scales with the total length of every file that gained a line,
not
with the number of added lines. On Git for Windows a fork costs tens of milliseconds, which turns a
few thousand lines into minutes.
Evidence
Verified this pass, in a throwaway repository under the session scratchpad. It held detect.sh,
lib/comment-shapes.sh and added-lines.sh copied from origin/main 31eafaa, on Windows 11 with
Git Bash:
- Fixture: 5 C# files of about 205 lines each. One base commit; then a branch commit that appends 5
code lines (no comments) per file. detect.sh --added-since main: 55.0 s wall (13.6 s user, 17.0 s sys) for about 1,025 lines,
or about 54 ms per line. Every file reportedT1=0 T2=0 T3=0.- A bare loop of 1,000
x="$(f)"command substitutions on the same host: 19.0 s, so about
19 ms per substitution. - The same
detect.shwith one added line, placed before shape detection in the loop, ran in
4.0 s with identical output. The added line skips a line when neither it nor the next line is
an added line:
if [[ -n "$ADDED_SINCE" ]] && ! in_scope "$line_num" $((line_num + 1)); then prev_line="$line"; prev_ct=""; prev_shapes=""; continue; fi.
The remaining 4 s is mostly the two whole-file pre-passes and per-file process start-up. - Extrapolation (inferred, not measured): a 51-file C# change typically spans tens of thousands of
lines. At about 54 ms per line that is 15 minutes or more, which is consistent with the observed
hang.
Not reproduced: the original repository and branch are private. The figures above come from the
synthetic fixture. The item's "per-file or per-line process spawning" hypothesis is now measured,
not just inferred.
Also observed: the skill's own pre-computed context line, which covers uncommitted files only,
returned promptly with Summary total: files=0 in the original session. That is consistent with
cost following the number and size of files in scope.
Proposed approach
- Scope before detecting. In
audit_file, under--added-since, skip all work for a line
when neither it nor the following line is an added line. The following line is included because
the wrap-join atdetect.sh:334reads the previous comment text. Keepprev_linecurrent so
cr_line_skipped(thecomment-residue-ignoremarker on the previous line) still works. - Stop forking per line. Have
cr_comment_textandcr_detect_shapes_textreturn results
through a variable such asREPLY, or a nameref, instead of stdout. Then the hot loop and the
pre-passes use no command substitution. This also speeds the non---added-sincepath, which
pays the same per-line cost on whole files. - Optional: restrict the pre-passes. Under
--added-since,cr_run_lines_withstill has to
see whole comment runs, so it cannot simply skip lines. With step 2 in place it no longer forks,
which is probably enough. Measure before adding anything more.
Alternatives considered:
- Rewriting the detector in Python or awk would remove bash's per-character loop as well. That is
a larger change, and the shape regexes incomment-shapes.share shared semantics with the evals.
Prefer steps 1 and 2 and re-measure first. - Only clamping a timeout would hide the defect and still return nothing.
Files: plugins/code-tidying/skills/audit-comment-residue/scripts/detect.sh,
plugins/code-tidying/skills/audit-comment-residue/scripts/lib/comment-shapes.sh,
plugins/code-tidying/skills/audit-comment-residue/scripts/detect.test.sh, plugin version and
CHANGELOG.
Acceptance criteria
- Split to test(code-tidying): measure audit-comment-residue --added-since on Windows Git Bash and run the acr evals after #8764 #8848 (the Windows Git Bash timing on a 50-file, 1,000-line fixture). The in-lane
proxy is the next criterion. -
detect.test.shgains a case proving cost tracks added lines. Use a generous bound on a
"one very large file, one added line" fixture, or a count of detection calls, rather than a
tight wall-clock assert that flakes on shared CI runners.
Check: The PR's CI runs
plugins/code-tidying/skills/audit-comment-residue/scripts/detect.test.sh(test-bash) and
it passes. - Wrapped-phrase findings still report at the first line's number when only the second line of
the pair is added, and when only the first is (existingacr-weak-cues-wrappedbehavior).
Check:detect.test.shholds a case for each of the two shapes; the PR's CI runs it and it
passes. - The
comment-residue-ignoremarker on a line just before an added line still suppresses it.
Check:detect.test.shholds a case for it; the PR's CI runs it and it passes. - Every existing
detect.test.shcase passes unchanged. Theacr-*eval run is Split to
test(code-tidying): measure audit-comment-residue --added-since on Windows Git Bash and run the acr evals after #8764 #8848.
Check: the lane's diff changes no existing assertion indetect.test.sh; the PR's CI runs it
and it passes. -
cr_detect_shapes/cr_comment_textare no longer invoked through$(...)in the per-line
loop ofaudit_fileor incr_run_lines_with.
Check: a read ofaudit_fileindetect.shand ofcr_run_lines_within
lib/comment-shapes.shin the lane's work tree shows no$(cr_detect_shapesor
$(cr_comment_text;scripts/check-affected.sh --uncommitted(shellcheck) passes.
Constraints and gotchas
.razoris not incr_is_code_file(comment-shapes.sh:18-25), so of the reported 51 files
only the.csones were ever audited. Whether.razorshould be in scope is a separate question,
not part of this fix.- Arithmetic on parsed values must stay behind the digits-only guards (
detect.sh:139-143). Bash
evaluates array subscripts inside(( )). - Keep exit semantics: 0 on every audit path, 2 on usage errors.
- Measure on Windows Git Bash, where fork cost dominates. Linux CI will hide most of the
regression. The Windows measurement is Split to test(code-tidying): measure audit-comment-residue --added-since on Windows Git Bash and run the acr evals after #8764 #8848. - Bump the plugin version and add a CHANGELOG entry per the repository's release rules. Create the
fragment withscripts/new-changelog-fragment.shand check it with
scripts/check-changelog-fragments.sh --check.
Context
Source: local handoff item 20261014-code-tidying-comment-residue-hangs-windows.md (retired into this
issue), reported from a pull-request quality pass in a large private .NET repository on 2026-10-14.
Related: #4390 (guardrails hooks spawn many processes per fire) and #4372 (Windows kernel token leak
per child process) describe the same Windows process-cost class elsewhere. The Windows timing and the
paid acr-* eval run are split to #8848, because the automated lane runs on ubuntu and cannot
measure timings or run paid evals.
Activity
github-actions commentedon Oct 21, 2026
Proposed work class: work-class: scoped
Basis: automated intake triage; the lanes App applied this class.
Size: Medium
Complexity: Medium
Uncertainty: Known
Flags: none
Blocked by: none
Understood:
audit-comment-residue --added-sinceruns shape detection on every line of every touched file, using forked command substitutions. Cost therefore follows file length, not added lines, and the run is unusably slow on Windows Git Bash. The proposed fix has two parts. First, skip lines that are neither added nor the line before an added line. Second, return results through a variable so the hot loop and pre-passes fork nothing. The Windows timing and the paid eval run are already split to #8848. The remaining criteria can be checked in CI. No likely duplicates found among the open issues.Automated triage, applied by the lanes App.
kyle-sexton commentedon Oct 21, 2026
Issue Triage: this issue's 01:36Z lane run skipped (
issue-dimensions: not-assessed): Size, Complexity and Uncertainty were unset. Fields now set: Medium / Medium / Known. agent-ready is removed until: AC1 (a Windows Git Bash timing measurement; the lane runs on ubuntu) is split into a needs-human child. It is re-added at that point, which starts a new run.github-actions commentedon Oct 26, 2026
The triage sweep dispatched intake triage for this issue (attempt 1 of 2).