Skip to content

fix(claude-sync): skip subagent JSONL files to prevent main session corruption#737

Open
kamioj wants to merge 1 commit intositeboon:mainfrom
kamioj:fix/claude-sync-skip-subagent
Open

fix(claude-sync): skip subagent JSONL files to prevent main session corruption#737
kamioj wants to merge 1 commit intositeboon:mainfrom
kamioj:fix/claude-sync-skip-subagent

Conversation

@kamioj
Copy link
Copy Markdown

@kamioj kamioj commented May 4, 2026

Summary

ClaudeSessionSynchronizer walks ~/.claude/projects/<project>/ for
.jsonl files and indexes each one as a session row. Claude Code writes
subagent transcripts under a subagents/ subdirectory but shares the
parent session's sessionId
in those files. The current scan picks them
up and upserts them into the sessions DB with the same sessionId, which
overwrites the parent row and breaks session resume / history listing.

Reproduction

  1. Run a Claude Code session that spawns at least one subagent (Task tool, /agent, etc.).
  2. Layout becomes:
    ~/.claude/projects/<encoded-cwd>/<sid>.jsonl                  ← parent
    ~/.claude/projects/<encoded-cwd>/subagents/<sid>-<n>.jsonl    ← subagent (same sid)
    
  3. Trigger session sync (initial scan or filesystem watcher).
  4. The sessions row for <sid> now reflects the subagent file's metadata; opening the session in the UI shows the subagent transcript instead of the parent.

Fix

Skip any path containing /subagents/ (or \subagents\ on Windows) in:

  • synchronize() — the bulk scan loop
  • synchronizeFile() — the watcher-driven entry point

Both code paths use the same cross-platform separator-aware guard.

Notes

  • +15 / -0, single file
  • No behavior change for setups without subagents
  • No new dependencies / no schema migration

Summary by CodeRabbit

  • Bug Fixes
    • Improved session synchronization to properly exclude subagent transcript files from being stored, ensuring cleaner data management and preventing redundant session artifacts.

…orruption

Subagent transcripts under `~/.claude/projects/.../<project>/subagents/`
share their parent's sessionId. Indexing them as standalone sessions
overwrites the parent's row in the sessions DB, which breaks session
resume and history listing.

Skip them in both the bulk `synchronize()` scan and the watcher-driven
`synchronizeFile()` entry point. Path check covers Windows backslash and
POSIX slash so the same guard works regardless of how findFilesRecursively
emits the path.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 4, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 03b26043-210f-4907-8460-4a0134466d77

📥 Commits

Reviewing files that changed from the base of the PR and between 392c73b and 5f103cb.

📒 Files selected for processing (1)
  • server/modules/providers/list/claude/claude-session-synchronizer.provider.ts

📝 Walkthrough

Walkthrough

The Claude session synchronizer now explicitly filters out transcript files located in subagents/ directories during both bulk synchronization and single-file ingestion, preventing these artifacts from being written to the sessions database.

Changes

Subagent File Filtering

Layer / File(s) Summary
Filter Logic
server/modules/providers/list/claude/claude-session-synchronizer.provider.ts (lines 37–47)
Bulk synchronize method now skips .jsonl files under subagents/ paths, accounting for both OS and POSIX-style separators.
Single-File Filter
server/modules/providers/list/claude/claude-session-synchronizer.provider.ts (lines 76–82)
synchronizeFile method returns null early for any .jsonl path under subagents/, mirroring bulk synchronization behavior.

Suggested reviewers

  • blackmammoth

Poem

🐰 A rabbit hops through files with care,
Filtering subagents here and there,
No shared sessionIds shall pass,
Only pure transcripts reach the class! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: skipping subagent JSONL files in Claude synchronization to prevent session corruption.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

1 participant