Skip to content

fix(local): resolve a duplicated session id to its most recently modified copy - #87

Open
malihashar wants to merge 1 commit into
skillsynchq:mainfrom
malihashar:fix/duplicate-session-id
Open

malihashar wants to merge 1 commit into
skillsynchq:mainfrom
malihashar:fix/duplicate-session-id

Conversation

@malihashar

@malihashar malihashar commented Oct 17, 2026 •

Copy link
Copy Markdown

Closes #88

What is wrong

Sometimes the same session id exists in more than one folder, for example when a session is resumed from another directory. When you run view, export, continue or crop with that id, txcript has to pick one copy.

The code comments say it picks the newest copy. It does not. The list of sessions is sorted by start time only, and copies of the same session have the same start time. So the winner is decided by the order the folders are read from disk, which is arbitrary. You can silently get an older, shorter copy, with no message.

How to see it

  1. Make a Claude Code session and copy it to a second project folder.
  2. Add two later messages to the copy.
  3. Run txcript query "<text from the later messages>". It finds the text.
  4. Run txcript view <id>, export <id> or continue <id>. The later messages are missing, because the older copy was loaded.

What this PR changes

Among copies with the same start time, the one that was changed most recently now comes first. This is a second sort key in src/local.rs, using the file modification time that txcript already records. Because every command picks the first match from that list, all of them get the fix at once. If the modification time is missing or equal, the order stays the same as before.

Nothing else changes: no new option, no new dependency, and different ids that share a prefix are still reported as ambiguous. I also added one sentence to docs/usage.md and an entry in CHANGELOG.md.

How it was tested

  • 3 unit tests for the sort order, in src/local.rs.
  • 5 end-to-end tests in the new cli/tests/duplicate_ids.rs. They run the real binary on synthetic sessions with four copies, where the modification times are set on purpose so they do not match the folder order. They cover view, export, prefix lookup, still-ambiguous different ids, and equal modification times.
  • Before the fix, the view, export and prefix tests fail. After the fix, everything passes. I ran them five times each with the same result.
  • The full test suite passes, and cargo fmt and cargo clippy are clean.

What I could not test

  • How real Claude Code creates copies when a session is resumed from another directory. I relied on the comments already in the code.
  • Linux and Windows. The tests do not depend on the order the folders are read, so they should hold there too.
  • The MCP read_session tool and the interactive picker. They use the same lookup, but I did not run them directly.

Questions for the maintainer

  1. Should list show each copy as a separate row (as now), or collapse them into one?
  2. Should txcript warn when several copies exist?
  3. When two copies have the same modification time, is the current fallback fine?
  4. Is cli/tests/ an acceptable place for tests that run the binary? I added a short note about it in tests/README.md.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When the same session id exists in several folders, view, export and continue can load an old copy

1 participant