{"record":{"id":"6ece51d1a3bd38c6","repo":"datawhalechina/hello-agents","slug":"patch-too-large-total-changed-changed-lines","errorCode":null,"errorMessage":"Patch too large: {total_changed} changed lines > {self.max_total_changed_lines}","messagePattern":"Patch too large: (.+?) changed lines > (.+?)","errorType":"exception","errorClass":"PatchApplyError","httpStatus":null,"severity":"warning","filePath":"Co-creation-projects/YYHDBL-HelloCodeAgentCli/code_agent/executors/apply_patch_executor.py","lineNumber":121,"sourceCode":"            \n        返回:\n            ApplyResult: 包含被修改文件和备份文件信息的结果对象\n            \n        异常:\n            PatchApplyError: 当补丁不符合格式、超出限制或应用失败时抛出\n        \"\"\"\n        # 解析补丁文本，提取操作列表\n        ops = self._parse_patch(patch_text)\n        \n        # 统计受影响的文件数量，检查是否超过限制\n        touched_files = [op[1] for op in ops if op[0] in {\"add\", \"update\", \"delete\"}]\n        if len(set(touched_files)) > self.max_files:\n            raise PatchApplyError(f\"Too many files in patch: {len(set(touched_files))} > {self.max_files}\")\n\n        # 估算补丁修改的总行数，检查是否超过限制\n        total_changed = self._estimate_changed_lines(ops)\n        if total_changed > self.max_total_changed_lines:\n            raise PatchApplyError(f\"Patch too large: {total_changed} changed lines > {self.max_total_changed_lines}\")\n\n        # 创建本次补丁应用的专属备份目录（时间戳命名）\n        backup_run_dir = self.backups_dir / datetime.now().strftime(\"%Y%m%d_%H%M%S\")\n        backup_run_dir.mkdir(parents=True, exist_ok=True)\n\n        # 初始化结果收集变量\n        files_changed: List[str] = []  # 记录被修改的文件路径\n        backups: List[str] = []  # 记录创建的备份文件路径\n\n        # 遍历所有解析出的操作，逐个执行\n        for kind, rel_path, payload in ops:\n            # 安全检查：确保路径在仓库内，防止路径遍历攻击\n            target = self._safe_path(rel_path)\n            \n            # 安全检查：确保文件后缀在允许的列表中\n            self._enforce_suffix(target)\n\n            if kind == \"add\":","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/datawhalechina/hello-agents/blob/606a07d341a47be773fab7f4b71177f53f96b2c3/Co-creation-projects/YYHDBL-HelloCodeAgentCli/code_agent/executors/apply_patch_executor.py#L103-L139","documentation":"PatchApplyError raised when the estimated total changed lines across all operations exceeds max_total_changed_lines. Like the file-count limit, it is a pre-execution size guardrail: nothing is written, so the working tree stays untouched.","triggerScenarios":"A patch whose estimated changed-line total (per _estimate_changed_lines over add/update/delete payloads) exceeds the configured cap — e.g. a single Add File with a very long payload.","commonSituations":"Agent generating a whole new large file in one patch; squashing many edits into one update; threshold tuned down after workflows depended on bigger patches.","solutions":["Break the change into sequential patches below the line budget (apply incrementally).","Reduce patch noise: drop unrelated formatting/hunk churn from the payload.","If legitimate, raise max_total_changed_lines in the executor configuration.","The message reports the estimated count so you can size the chunks."],"exampleFix":"# before\nexecutor.apply(huge_patch)  # 5000 changed lines > 3000 cap\n\n# after\nfor part in split_patch_by_lines(huge_patch, max_lines=executor.max_total_changed_lines):\n    executor.apply(part)","handlingStrategy":"validation","validationCode":"estimated = estimate_changed_lines(parse_patch(patch_text))\nassert estimated <= executor.max_total_changed_lines, \\\n    f\"patch too large ({estimated} lines); split it\"","typeGuard":null,"tryCatchPattern":"try:\n    executor.apply(patch_text)\nexcept PatchApplyError as e:\n    if str(e).startswith(\"Patch too large\"):\n        for part in split_patch_by_lines(patch_text, executor.max_total_changed_lines):\n            executor.apply(part)\n    else:\n        raise","preventionTips":["Budget patch size client-side using the same line-estimate rule as the executor.","Split big file additions into staged patches applied sequentially.","Keep unrelated formatting churn out of patches to stay under the cap."],"tags":["python","patching","guardrail","code-agent"],"backgroundTag":null,"analyzedSha":"606a07d341a47be773fab7f4b71177f53f96b2c3","analyzedAt":"2026-08-14T22:57:27.446Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}