You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Centralize all log filename generation into a single FilenameBuilder class to prevent naming divergence bugs and enable future configurability.
Background
Issue #15 revealed that having two independent filename generation functions (get_filename_context() and get_task_filename_context()) with slightly different separator conventions (_ vs __ before username) caused an infinite file proliferation cycle — 119+ files per session instead of one.
The immediate fix (removing get_task_filename_context()) solves the bug, but the broader architectural risk remains: filename strings are currently constructed in multiple independent locations that can drift apart.
Is the single source of truth for all filename construction — write paths, reconciliation targets, and regex patterns all derive from the same format specification
Encapsulates the format convention (separator characters, field ordering, sequence number format) in one place
Generates matching regex patterns from the same format spec, so detection always matches what generation produces
classFilenameBuilder:
"""Centralized log filename construction."""def__init__(self, shell: str, session_name: str, session_id: str, username: str):
self.shell=shellself.session_name=session_nameself.session_id=session_idself.username=usernamedefbuild(self, prefix: str, file_type: str, seq: int=None) ->str:
"""Build a filename. Used by both write paths and reconciliation."""
...
defmatch_pattern(self, prefix: str, file_type: str) ->re.Pattern:
"""Return regex that matches any file this builder could produce."""
...
defextract_name(self, filename: str) ->Optional[str]:
"""Extract session name from a filename."""
...
Value
Eliminates the class of bug where write paths and reconciliation paths diverge
Single place to update if filename format changes
Enables future user-configurable filename formats
Reduces regex duplication (5+ hand-written patterns → generated from format spec)
Summary
Centralize all log filename generation into a single
FilenameBuilderclass to prevent naming divergence bugs and enable future configurability.Background
Issue #15 revealed that having two independent filename generation functions (
get_filename_context()andget_task_filename_context()) with slightly different separator conventions (_vs__before username) caused an infinite file proliferation cycle — 119+ files per session instead of one.The immediate fix (removing
get_task_filename_context()) solves the bug, but the broader architectural risk remains: filename strings are currently constructed in multiple independent locations that can drift apart.Current State
Filename generation is spread across:
get_filename_context()_get_task_filename_context()__build_filename()__get_channel_path()find_session_files()regex\w+extract_session_name_from_file()regex__{session_id}find_max_sequence()regexreconcile_session_directory(){name}__{guid}_{user}_Proposal
Create a
FilenameBuilderclass that:__as a universal separatorPossible API sketch
Value
Related
2026-02-11__21-27-39__task-file-proliferation-analysis.mdfor root cause analysis