Skip to content

Commit 16032e4

Browse files
fix(autocompact): resolve NameError and naming bug (#792)
- Add missing Log runtime import in autocompact_hook (fixes NameError at line 472) - Update backup name regex to handle any alphanumeric suffix (not just 4 hex chars) - Fixes Issue #75 auto-compact bugs The naming bug occurred when conversation names had non-hex suffixes (e.g., -before-compact-test), causing the regex to fail matching and resulting in duplicate suffixes like 'conv-before-compact-test-before-compact-a7b9'. Updated regex now uses \w+ to match any alphanumeric suffix, handling: - Manual renames (e.g., -before-compact-test) - Different suffix formats beyond 4 hex characters - Multiple repeated compact operations correctly All 14 autocompact tests passing.
1 parent 7c67616 commit 16032e4

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

gptme/tools/autocompact.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from ..util.output_storage import create_tool_result_summary
1616

1717
if TYPE_CHECKING:
18-
from ..logmanager import Log, LogManager
18+
from ..logmanager import LogManager
1919

2020
logger = logging.getLogger(__name__)
2121

@@ -308,7 +308,12 @@ def _get_backup_name(conversation_name: str) -> str:
308308

309309
base_name = conversation_name
310310
while True:
311-
new_name = re.sub(r"-before-compact(-[0-9a-f]{4})?$", "", base_name)
311+
# Match -before-compact with optional suffix (any alphanumeric characters)
312+
# This is more permissive than the original [0-9a-f]{4} to handle:
313+
# - Manual renames (e.g., -before-compact-test)
314+
# - Different suffix formats
315+
# - Ensure we strip any backup suffix, not just hex-based ones
316+
new_name = re.sub(r"-before-compact(-\w+)?$", "", base_name)
312317
if new_name == base_name: # No more changes
313318
break
314319
base_name = new_name
@@ -344,6 +349,7 @@ def autocompact_hook(
344349
import time
345350

346351
from ..llm.models import get_default_model
352+
from ..logmanager import Log
347353
from ..message import len_tokens
348354

349355
global _last_autocompact_time

0 commit comments

Comments
 (0)