Repository navigation
fix(sessions): read session titles from top-level transcript entries - #1427
mertkayacs wants to merge 2 commits into
Conversation
Somay-kousis
left a comment
There was a problem hiding this comment.
Ran this locally on c89e009 (based on main 7b790c7). The fix does what it says. One narrow regression from switching to whole-line parsing, details below.
What I ran
- The 3 new tests: 3 passed on the PR head. With
src/reverted to 7b790c7 and the new tests kept, all 3 fail with the nested value winning ('Nested tool value' == 'My Custom Title','Nested tool value (fork)' == 'Original title (fork)'). So they catch the bug. tests/test_sessions.py tests/test_session_mutations.py: 178 passed.- Full suite: 1631 passed, 6 skipped.
ruff check src/ tests/ scripts/,ruff format --check src/ tests/ scripts/,mypy src/ scripts/: clean.- Store path for the same input (
list_sessions_from_storewith a top-level custom-title entry followed by a tool_use whose input hascustomTitle): already returns the real title on main, sincesession_summary.pyreads top-level keys. This PR brings the local-disk path in line with it.
Finding (worth considering): a title line cut by the tail window is now dropped
_extract_last_top_level_json_string_field (sessions.py:254) only accepts lines that parse as JSON. tail is the last 64 KiB of the file, so its first line is usually a fragment. The old regex scan still found "customTitle":"..." inside that fragment. The new code skips it, and if the file is over 128 KiB the head fallback does not have it either.
Repro (probe_1427.py, case 1): a session of 136083 bytes whose only custom-title line starts at byte 70542, with the tail window starting at byte 70547.
- main:
custom_title = 'Straddle title' - this PR:
custom_title = None
It needs a large file, no later title entry, and the window boundary landing in the few bytes before the key, so it is rare. Possible fix: for the first line of tail only, if json.loads fails and the fragment contains "type":"custom-title" or "type":"ai-title", fall back to _extract_last_json_string_field on that fragment. Or accept the tradeoff and note it in the docstring. I did not check whether the CLI re-appends title entries near the end of the file, which would make this moot.
Nit
session_mutations.py:565: the docstring still says precedence matches _extract_last_json_string_field. That helper is no longer used for titles.
Same bug class, not in this PR
summary, lastPrompt and gitBranch still use the any-depth scan (sessions.py:470-471, 480). A tool_use input with a summary key becomes the session summary when there is no title, and one with gitBranch becomes git_branch. Same output on main and this PR (probe_1427.py cases 2 and 3). Maybe a follow-up, since summary is a common tool input field name.
Not checked
Performance on large transcripts (the new code json.loads every line that contains the key). Windows line endings. Python 3.10.
c89e009 to
b4d8f9a
Compare
|
@Somay-kousis Good catch, thanks for the repro. When the first line in the tail window is cut, the title is now taken only if it sits at the top level of that entry, so nested tool values still lose. Your exact file returns "Straddle title" again, and it's a test now. I also fixed the old docstring in session_mutations.py. |
|
Reran on b4d8f9a: my straddle file returns |
Summary
list_sessions(),get_session_info()andfork_session()readcustomTitleandaiTitleby scanning the raw transcript text for the key at any depth. When a custom MCP tool's input has acustomTitlefield, that value replaces the title the user set, and the default fork title is derived from it too.customTitleandaiTitleonly from top-level JSONL entriesTesting
python -m pytest tests/(1631 passed, 6 skipped)python -m ruff check src/ tests/python -m ruff format --check src/ tests/python -m mypy src/