git_show redacts the whole patch once per file header, on unbounded output

未关闭
#181 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
go

调研方向

Start with internal/agent/tools/git.go at patchFile and the redaction loop, then trace how internal/gitx/gitx.go buffers Show output and how internal/agent/tools/tools.go limits the final result. Check existing tests around git_show and redaction first. Done means output is size limited, each file section is redacted once with cancellation checks, and a 1,000 file commit test completes within a bounded time.

由索引模型根据 Issue 内容生成。

描述

good first issue performance severity: medium

Summary

The git_show tool runs a full redaction pass over the entire git show output for every ---/+++ header in it, on output that is not bounded, to produce at most 24 KB. A commit that touches many files stalls the run.

Where

  • internal/agent/tools/git.go:122 (patchFile)
  • internal/agent/tools/git.go:155-167 (loop of redact.ApplyIn over the whole output)
  • internal/gitx/gitx.go:366, :549 (Show output buffered without a limit)
  • internal/agent/tools/tools.go:250-258 (finish redacts again and cuts to 24,000 bytes)

Details

gitx.Show returns the whole git show --stat --patch <rev> output. The tool then loops over every header and calls redact.ApplyIn(file, out) on the entire output each time. A modified file has both headers, so the same name is applied twice. Each call is a full scan: a lower-cased copy of the text, every gated regular expression, the remembered-value search and a rebuilt string. The loop does not check the context. Cost is O(H x S) for H header lines and S patch bytes.

Impact

An investigator, reviewer, prover or fixer that calls git_show on a commit touching many files (an initial commit, a vendoring or formatting commit, a large merge) stalls. Estimate, not measured: 1,000 changed files with a 5 MB patch is about 2,000 passes over 5 MB, many minutes for one tool call. The wall-time cap is only checked between model calls, so it does not interrupt this. git_log lists such commits by default.

Steps to reproduce

  1. In a repository whose latest commit adds about 1,000 text files, run an agentic scan.
  2. Have the model call git_show with that commit's hash and no path.
  3. The tool call does not return for minutes while one core is busy in redaction.

Suggested fix

Bound the output first (read git show through a limit of a few MB, since only 24 KB is ever returned). Then redact each file's section once with its own name: split on diff --git boundaries and call ApplyIn(file, section) per section, which is O(S) in total. Check ctx.Err() between sections.

Acceptance criteria

  • git show output is read through a size limit
  • Each file section is redacted once, with its own file name
  • The loop honors cancellation
  • A test with a 1,000-file commit returns in bounded time

Getting started

  • Relevant files: internal/agent/tools/git.go, internal/agent/tools/tools.go, internal/gitx/gitx.go
  • How to run tests: make test-short (Unix) or .\make.ps1 test-short (Windows PowerShell); make lint before you call it done
  • Related docs: CONTRIBUTING.md, docs/ARCHITECTURE.md

Filed by repo-audit/full-audit at 50e92ec. Severity: medium. Effort: S. audit-key: performance|internal/agent/tools/git.go|gitShowTool

主要语言
Go
星标
0
派生
1
平均合并
8 小时 14 分钟
30 天内合并 PR
3

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

TMHSDigital/Spackle 的其他 Issue

查看 TMHSDigital/Spackle 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。