Skip to content

fix(code-tidying): make audit-comment-residue --added-since cost track added lines, not file length #8764

Closed

Description

@kyle-sexton

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/main with 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 280 with no output
    (exit 143).
  • git diff -U0 <merge-base>..HEAD -- '*.cs' '*.razor' | grep over the same range returned
    instantly. The expected report was empty.

Cause, on current main (code-tidying 0.30.3):

  • audit_file runs shape detection on every line of every in-scope file, then checks scope.
    plugins/code-tidying/skills/audit-comment-residue/scripts/detect.sh:323 computes
    shapes="$(cr_detect_shapes ...)" for each line. The in_scope filter 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_lines and cr_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 reported T1=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.sh with 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

  1. 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 at detect.sh:334 reads the previous comment text. Keep prev_line current so
    cr_line_skipped (the comment-residue-ignore marker on the previous line) still works.
  2. Stop forking per line. Have cr_comment_text and cr_detect_shapes_text return results
    through a variable such as REPLY, or a nameref, instead of stdout. Then the hot loop and the
    pre-passes use no command substitution. This also speeds the non---added-since path, which
    pays the same per-line cost on whole files.
  3. Optional: restrict the pre-passes. Under --added-since, cr_run_lines_with still 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 in comment-shapes.sh are 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.sh gains 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 (existing acr-weak-cues-wrapped behavior).
    Check: detect.test.sh holds a case for each of the two shapes; the PR's CI runs it and it
    passes.
  • The comment-residue-ignore marker on a line just before an added line still suppresses it.
    Check: detect.test.sh holds a case for it; the PR's CI runs it and it passes.
  • Every existing detect.test.sh case passes unchanged. The acr-* 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 in detect.test.sh; the PR's CI runs it
    and it passes.
  • cr_detect_shapes/cr_comment_text are no longer invoked through $(...) in the per-line
    loop of audit_file or in cr_run_lines_with.
    Check: a read of audit_file in detect.sh and of cr_run_lines_with in
    lib/comment-shapes.sh in the lane's work tree shows no $(cr_detect_shapes or
    $(cr_comment_text; scripts/check-affected.sh --uncommitted (shellcheck) passes.

Constraints and gotchas

  • .razor is not in cr_is_code_file (comment-shapes.sh:18-25), so of the reported 51 files
    only the .cs ones were ever audited. Whether .razor should 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 with scripts/new-changelog-fragment.sh and 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

  1. added
    agent-ready
    on Oct 21, 2026
  2. github-actions commented on Oct 21, 2026

    @github-actions
    Contributor

    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-since runs 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.

  3. removed
    agent-ready
    on Oct 21, 2026
  4. kyle-sexton commented on Oct 21, 2026

    @kyle-sexton
    MemberAuthor

    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.

  5. github-actions commented on Oct 26, 2026

    @github-actions
    Contributor

    The triage sweep dispatched intake triage for this issue (attempt 1 of 2).

  6. added
    status: ready
    on Oct 26, 2026
  7. added
    admission-deferred
    agent-ready
    and removed
    admission-deferred
    on Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-readystatus: ready

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions