hermes - ✅(Solved) Fix patch tool hangs (4+ minutes) on large files — fuzzy matching without timeout [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
NousResearch/hermes-agent#20173Fetched 2026-05-06 06:38:16
View on GitHub
Comments
0
Participants
1
Timeline
5
Reactions
0
Author
Participants
Timeline (top)
labeled ×4cross-referenced ×1

Root Cause

In tools/fuzzy_match.py, strategies 8 (block_anchor) and 9 (context_aware) use SequenceMatcher which is O(n²) on large files. There was no timeout protection — on a 2342-line / 90KB file, matching can take 4+ minutes.

Fix Action

Fix / Workaround

Bug Description

The /patch command hangs for 4+ minutes when fuzzy matching is triggered on large files, making the CLI completely unresponsive.

Steps to Reproduce

  1. Run hermes CLI
  2. Patch a large TypeScript file (~90KB, 2000+ lines) with a string that requires fuzzy matching (not an exact match)
  3. The tool hangs for 4+ minutes before returning

Expected Behavior

Fuzzy matching should have a timeout and fail gracefully within seconds.

Root Cause

In tools/fuzzy_match.py, strategies 8 (block_anchor) and 9 (context_aware) use SequenceMatcher which is O(n²) on large files. There was no timeout protection — on a 2342-line / 90KB file, matching can take 4+ minutes.

Environment

  • OS: WSL Ubuntu 24.04
  • Hermes: latest (commit 7cc389fd8)
  • Python: 3.x

Debug Report

System info: https://paste.rs/KFWRA

PR fix notes

PR #20181: fix(patch): add timeout guard to fuzzy matching slow strategies

Description (problem / solution / changelog)

Summary

Fuzzy matching in tools/fuzzy_match.py had no timeout protection. Strategies 8 (block_anchor) and 9 (context_aware) use SequenceMatcher which is O(n^2) — on large files (~2000+ lines), this causes the patch tool to hang for 4+ minutes.

Fix

  • Added a timeout parameter (default 5s) to fuzzy_find_and_replace
  • Strategies 8 and 9 check elapsed time and abort with a clear error if they exceed the timeout
  • On timeout, falls back to a simple regex-based exact/substring search before giving up
  • patch_replace in file_operations.py passes timeout=5 to prevent CLI hangs

Testing

  • 57 fuzzy unit tests: all pass
  • 289 patch unit tests: all pass
  • Real-world test: 2342-line TypeScript file, non-existent string → fast failure (< 5s) instead of 4+ minute hang
  • Real-world test: 2342-line TypeScript file, existing string → instant exact match

Files Changed

  • tools/fuzzy_match.py — timeout guard + fallback strategy
  • tools/file_operations.py — pass timeout to fuzzy matching call

Related Issue

Fixes #20173

Changed files

  • .agents/skills/opencli-autofix/SKILL.md (added, +279/-0)
  • .agents/skills/opencli-browser/SKILL.md (added, +306/-0)
  • .agents/skills/opencli-explorer/SKILL.md (added, +278/-0)
  • .agents/skills/opencli-explorer/references/adapter-templates.md (added, +435/-0)
  • .agents/skills/opencli-explorer/references/advanced-patterns.md (added, +233/-0)
  • .agents/skills/opencli-explorer/references/record-workflow.md (added, +131/-0)
  • .agents/skills/opencli-oneshot/SKILL.md (added, +310/-0)
  • .agents/skills/opencli-usage/SKILL.md (added, +208/-0)
  • .agents/skills/opencli-usage/commands.md (added, +816/-0)
  • .agents/skills/opencli-usage/desktop.md (added, +103/-0)
  • .agents/skills/opencli-usage/plugins.md (added, +82/-0)
  • .agents/skills/smart-search/SKILL.md (added, +156/-0)
  • .agents/skills/smart-search/references/sources-ai.md (added, +74/-0)
  • .agents/skills/smart-search/references/sources-info.md (added, +43/-0)
  • .agents/skills/smart-search/references/sources-media.md (added, +50/-0)
  • .agents/skills/smart-search/references/sources-other.md (added, +42/-0)
  • .agents/skills/smart-search/references/sources-shopping.md (added, +31/-0)
  • .agents/skills/smart-search/references/sources-social.md (added, +51/-0)
  • .agents/skills/smart-search/references/sources-tech.md (added, +42/-0)
  • .agents/skills/smart-search/references/sources-travel.md (added, +20/-0)
  • .qwen/skills/opencli-autofix (added, +1/-0)
  • .qwen/skills/opencli-browser (added, +1/-0)
  • .qwen/skills/opencli-explorer (added, +1/-0)
  • .qwen/skills/opencli-oneshot (added, +1/-0)
  • .qwen/skills/opencli-usage (added, +1/-0)
  • .qwen/skills/smart-search (added, +1/-0)
  • agent/auxiliary_client.py (modified, +20/-4)
  • agent/context_compressor.py (modified, +23/-1)
  • agent/memory_manager.py (modified, +4/-0)
  • gateway/platforms/feishu.py (modified, +77/-7)
  • gateway/run.py (modified, +5/-0)
  • plugins/memory/openviking/__init__.py (modified, +4/-0)
  • run_agent.py (modified, +2/-2)
  • tools/file_operations.py (modified, +1/-1)
  • tools/fuzzy_match.py (modified, +53/-5)
RAW_BUFFERClick to expand / collapse

Bug Description

The /patch command hangs for 4+ minutes when fuzzy matching is triggered on large files, making the CLI completely unresponsive.

Steps to Reproduce

  1. Run hermes CLI
  2. Patch a large TypeScript file (~90KB, 2000+ lines) with a string that requires fuzzy matching (not an exact match)
  3. The tool hangs for 4+ minutes before returning

Expected Behavior

Fuzzy matching should have a timeout and fail gracefully within seconds.

Root Cause

In tools/fuzzy_match.py, strategies 8 (block_anchor) and 9 (context_aware) use SequenceMatcher which is O(n²) on large files. There was no timeout protection — on a 2342-line / 90KB file, matching can take 4+ minutes.

Environment

  • OS: WSL Ubuntu 24.04
  • Hermes: latest (commit 7cc389fd8)
  • Python: 3.x

Debug Report

System info: https://paste.rs/KFWRA

extent analysis

TL;DR

Implementing a timeout for fuzzy matching in tools/fuzzy_match.py can prevent the CLI from hanging indefinitely.

Guidance

  • Review the SequenceMatcher usage in strategies 8 and 9 to identify optimization opportunities or alternatives with better performance on large files.
  • Consider introducing a timeout mechanism to limit the execution time of fuzzy matching, allowing the CLI to fail gracefully and remain responsive.
  • Investigate the SequenceMatcher algorithm's complexity and potential workarounds, such as using a more efficient algorithm or processing the file in chunks.
  • Evaluate the feasibility of adding a configuration option to adjust the timeout value or disable fuzzy matching for large files.

Example

from SequenceMatcher import SequenceMatcher
import timeout_decorator

@timeout_decorator.timeout(5)  # 5-second timeout
def fuzzy_match(file_content, target_string):
    # existing fuzzy matching logic using SequenceMatcher
    pass

Notes

The provided solution assumes that introducing a timeout will sufficiently address the issue. However, the root cause of the performance problem may require further optimization of the fuzzy matching algorithm or its implementation.

Recommendation

Apply a workaround by introducing a timeout mechanism, as the current implementation of fuzzy matching is not scalable for large files. This will allow the CLI to remain responsive and provide a better user experience.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING