Skip to content

Commit b0b712b

Browse files
fix(session_peek): scan full file when size ≤10KB
1 parent e3ab28b commit b0b712b

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

docs/architecture.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ In `utils/tool_dispatch.py`, tool results are classified through `_parse_tool_re
7575

7676
When adding a new tool renderer:
7777

78-
1. Add predicate + builder pair in the dispatch table in the correct order (specific before generic).
79-
2. Add or extend a JSONL fixture under `tests/fixtures/` if needed.
80-
3. Run `pytest tests/test_jsonl_parser.py -v`.
78+
1. Add a `(predicate, builder)` pair to `_TOOL_RESULT_DISPATCH` in `utils/tool_dispatch.py`, preserving existing predicate order unless you also update fixtures and ordering tests (`tests/test_jsonl_parser.py`, `tests/test_real_session_fixtures.py`). Order is **not**specific before generic” in general — the first match wins. `_tool_result_pred_task_message` is the intentional broad-before-narrow exception (`task_id` or `message` before retrieval/completed/async).
79+
2. Add or extend a JSONL fixture under `tests/fixtures/` (especially for overlaps with existing predicates).
80+
3. Run `pytest tests/test_jsonl_parser.py tests/test_real_session_fixtures.py -v`.
8181

8282
## Export state machine
8383

utils/session_peek.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
from models.session import QuickSessionInfoDict
77
from utils.jsonl_helpers import entry_message, extract_text, strip_system_tags
88

9+
_TAIL_READ_MIN_BYTES = 10 * 1024
10+
_MAX_HEAD_LINES = 80
11+
912

1013
def quick_session_info(filepath: str) -> QuickSessionInfoDict:
1114
"""Lightweight peek at a session file -- returns title and last_timestamp
@@ -17,13 +20,15 @@ def quick_session_info(filepath: str) -> QuickSessionInfoDict:
1720
title = None
1821
first_ts = None
1922
last_ts = None
23+
file_size = os.path.getsize(filepath)
2024

2125
# --- Pass 1: read first lines to find the title and first_timestamp ---
2226
with open(filepath, "r", encoding="utf-8", errors="replace") as f:
2327
lines_read = 0
2428
for line in f:
2529
lines_read += 1
26-
if lines_read > 80:
30+
# Large files use pass-2 tail read for last_timestamp; cap head scan only then.
31+
if file_size > _TAIL_READ_MIN_BYTES and lines_read > _MAX_HEAD_LINES:
2732
break
2833
line = line.strip()
2934
if not line:
@@ -49,8 +54,7 @@ def quick_session_info(filepath: str) -> QuickSessionInfoDict:
4954
title = first_line
5055

5156
# --- Pass 2: read last chunk for the last timestamp ---
52-
file_size = os.path.getsize(filepath)
53-
if file_size > 10000:
57+
if file_size > _TAIL_READ_MIN_BYTES:
5458
# Only bother with tail-read for non-tiny files
5559
chunk_size = min(file_size, 32768)
5660
with open(filepath, "rb") as f:

0 commit comments

Comments
 (0)