Skip to content

tech-debt: analyze_diff is 117 body lines against a 65 threshold, and it blocked a security fix in a function it does not touch #16186

Description

@mrveiss

analyze_diff is 117 body lines, and it is blocking a security fix in a file it does not touch

autobot-backend/api/analytics_code_review.py — analyze_diff has 117 body
lines
against function-length-check's threshold of 65.

Measured on origin/Dev_new_gui and on a branch that changes a different function
in the same file: identical, 117 both sides, zero hunks mentioning it.

Why this is filed now

It blocked the last of the seven unscrubbed git call sites from #16179.

That change is two lines — route get_git_diff through start_git(), the canonical
scrubbed-environment runner — and it makes the file smaller (972 → 971). It
cannot land, because staging the file makes the commit answerable for
analyze_diff, which the diff never reads.

So six of seven git call sites are now scrubbed and one is not, for a reason
unrelated to git, security, or the change itself.

Acceptance criteria

  • analyze_diff is under the 65-line threshold, by extraction rather than by raising the threshold
  • Each extracted helper is named for what it decides, not _part_1/_part_2 — the function is long because it does several things, and the split should say which
  • Behaviour is unchanged: verified by the existing tests for this endpoint passing without modification, and by a diff review that the extraction is a pure move
  • The security(git): seven production call sites run git with an unscrubbed environment, and the checker cannot see any of them #16179 call site lands in the same PR or immediately after — the security fix is the reason this is being done now, and it should not be left behind again

Not the fix

Raising the threshold. 65 is the repo's number and analyze_diff is 80% over
it; the constant is not the problem.

Bypassing the hook. --no-verify is prohibited, and correctly.

Related

#16178 — the structural issue: three different hooks failed three commits tonight
for violations they did not introduce, because each reads the changed file whole
rather than the changed lines. This is the instance that cost a security fix.
#620 is the function-length guideline itself.

Activity

  1. mrveiss commented on Sep 10, 2026

    @mrveiss
    OwnerAuthor

    Filed the pattern this is an instance of: #16191 — Function Length Check (#620) is whole-file, so a legacy long function blocks every unrelated change to its file.

    Second instance hit today: _execute_claimed (159 body lines) in autobot-backend/a2a/task_executor.py blocked a one-line isort fix needed to unblock #16175. Splitting it to get the isort fix through nearly shipped an inverted eval gate — a dropped else: would have marked every task that PASSED self-eval as FAILED, and that version was green on flake8, isort, black and the repo-wide F821 audit.

    That is the cost this issue's 2-line security fix is also paying, and it is why #16191 argues the guard should be scoped or ratcheted rather than have its threshold raised.

    This issue stays the instance and is still being fixed on its own terms — analyze_diff gets extracted, and the last unscrubbed git call site (#16179) lands in the same PR.

  2. github-actions commented on Sep 10, 2026

    @github-actions
    Contributor

    PR #16212 (merged to Dev_new_gui) references this issue with a close keyword.

    refactor(analytics): move analyze_diff's halves out so the file can take its security fix (#16186, #16179)

    If this issue is fully resolved, close it manually. If work remains, no action is needed.

  3. mrveiss commented on Sep 11, 2026

    @mrveiss
    OwnerAuthor

    Closing: all four criteria verified against base 8e7d16918, delivered by #16212

    #16212 merged with Closes #16186. Closing keywords never fire on this branch, so this is the closure by hand. Each criterion was checked against merged code, not against the PR.

    Criterion (verbatim) Verdict Evidence
    analyze_diff is under the 65-line threshold, by extraction rather than by raising the threshold ✅ analyze_diff is 57 body lines. The code moved to a new module, analytics_code_review_diff.py. #16212 changed no guard or threshold: its only other files are the two size-ceiling entries, which it lowered to match a smaller file
    Each extracted helper is named for what it decides, not _part_1/_part_2 ✅ collect_file_comments and persist_review
    Behaviour is unchanged: verified by the existing tests for this endpoint passing without modification, and by a diff review that the extraction is a pure move ✅ No endpoint test was modified: the only test-tree file #16212 touched is the size-ratchet baseline, a ceiling, not a test of this endpoint. Its CI was green at merge. Diff review, computed rather than eyeballed: of 49 non-blank, non-comment lines removed from analytics_code_review.py, 43 appear verbatim in the new module. 5 are the raw create_subprocess_exec git call replaced by start_git, which is the next row's security fix, not extraction drift. 1 ("total_comments": len(all_comments)) was parameterised: persist_review receives len(all_comments) and writes it as comment_count, so the value is the same
    The #16179 call site lands in the same PR or immediately after ✅ get_git_diff runs git through start_git, the scrubbed-environment runner. It landed in #16212 itself

    The structural cause, hooks that read whole changed files, is not this issue. It's tracked under umbrella #16238, with #16191 for function length specifically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions