One session, two transcripts: jsonl_path is decided by scan order, so Chat can render a stale copy indefinitely (looks like a hang)

Author: gcdevukCreated Aug 18, 2026Updated Sep 28, 2026
LabelsNP

Summary

When one Claude session has more than one transcript file on disk under the same session id, sessions.jsonl_path is decided by whichever file the indexer wrote last — there is no recency comparison. The Chat view reads that column and only that column, so it can end up rendering the stale copy indefinitely while the session runs to completion in the other one.

The visible symptom is a session that looks hung: output stops mid-turn, the spinner never clears, and the page stays that way until something else happens to re-index the other file. The session itself finished normally.

This is the same class of corruption that #854 fixed for subagents/ transcripts. The comment added by that fix describes it exactly:

Those files repeat the parent session's sessionId, so indexing them as standalone sessions overwrites the parent row's jsonl_path and corrupts the main session record.

subagents/ is skipped by path. Any other way of producing a second file with the same session id is not.

Environment

  • CloudCLI 1.37.1 (mechanism verified against current main — see code references below; all three are unchanged at HEAD)
  • Provider: claude
  • Platform: Linux x64

How a second file appears

Claude Code keys its project directory off the session's working directory:

~/.claude/projects/<cwd with non-alphanumerics replaced by ->/<session-id>.jsonl

So any cwd change during a session starts a second transcript under the same session id. cding into a git worktree does it, and so does anything that relocates or copies a transcript between project directories to keep resume working. Both files are real, both are appended to at different times, and both fire watcher events.

Mechanism

  1. server/modules/providers/list/claude/claude-session-synchronizer.provider.ts → synchronizeFile() upserts with the triggering filePath. It skips subagents/, and otherwise passes whatever fired the event straight through.

  2. server/modules/database/repositories/sessions.db.ts → createSession() sets jsonl_path = ? unconditionally on the existing row. No comparison against the current value, the file's timestamps, or the transcript's contents. Last writer wins.

  3. server/modules/providers/list/claude/claude-sessions.provider.ts → getSessionMessages() does not search for the transcript. It reads sessionsDb.getSessionById(sessionId)?.jsonl_path and renders that file, plus agent-*.jsonl from path.dirname() of it.

Because (2) has no ordering rule, the winner is effectively filesystem scan order. When it lands on the copy that is behind, (3) faithfully renders a transcript that stops mid-turn.

Reproduction

  1. Start a Claude session in CloudCLI Chat in some repo.
  2. In that session, change the working directory — e.g. add a git worktree and cd into it — and run a few turns there.
  3. Let the session's writes return to the original project directory (a new turn launched at the original cwd will do it).
  4. Inspect the row:
sql
select jsonl_path, updated_at from sessions where provider_session_id = '<uuid>';
  1. Compare against the files actually on disk:
ls -l ~/.claude/projects/*/<uuid>.jsonl
  1. When jsonl_path names the copy that is not the furthest along, reload the session in the browser. The transcript ends mid-turn and the page shows a spinner that never resolves, while the last record in the other file is a normal stop_reason: end_turn assistant message.

Observed on a machine where sessions routinely cd into worktrees: eight sessions were mispointed over roughly a week, two of which were reported as "hung" by the user before the cause was known.

Why mtime is not a safe tie-break

Worth flagging for whoever fixes this. Tooling that copies transcripts between project directories to keep resume working will commonly use something like shutil.copy2/cp -p, which preserves the source mtime. The duplicate is then indistinguishable from its original by timestamp, so "newest file wins" has no defined answer precisely where it is needed, and resolution falls back to directory order again.

Ordering on transcript content is stable: last record timestamp, then file size as a tie-break, and on a genuine tie keep the value already stored so the row cannot flap against the indexer.

Interaction with #1067 — this stops being cosmetic

Today a mispointed row is a display bug: the file it names still exists, and nothing acts on its absence.

#1067 adds an unlink handler that resolves the row to delete via getSessionByJsonlPath(jsonlPath) — matching on the path, not the session id, with disk treated as the source of truth for whether a session exists.

Combined with this bug, that becomes session loss. If a row is pinned to the stale copy and that copy is later removed — Claude Code's own cleanupPeriodDays sweep removes transcripts on a timer, and tidying up a finished worktree removes a whole project directory — the handler deletes the row for a session whose real transcript is intact on disk. The session disappears from the sidebar and there is nothing to reconcile it back.

Worth resolving the two together rather than separately.

Suggested fix

Either of these closes it; the first is smaller:

  1. Make createSession() refuse to move jsonl_path backwards. Only accept a new path when it is the same file, or when the incoming transcript is at least as far along as the stored one. This keeps the fix in one place and also protects against any future source of duplicate-id files.

  2. Resolve duplicates at index time. When more than one <session-id>.jsonl exists across project directories, pick one deterministically by content rather than indexing whichever fired last — the same shape as the subagents/ skip, generalised.

Either way it would also be worth having getSessionMessages() degrade visibly rather than silently: if jsonl_path names a file whose last record is not a turn boundary while a sibling with the same id is further along, the current behaviour is indistinguishable to the user from a model that stopped responding.

Related

  • #854 — the subagents/ case of the same corruption, fixed by skipping.
  • #1067 — unlink handling; see above.
  • #1148 — a different session-forking failure (parentUuid branches within a single file). Same family, distinct mechanism; neither fix addresses the other.