Fix: Hook missing 55% of sessions due to concurrent activity#6
Merged
Conversation
Add two scripts for analyzing Claude Code session traces: - analyze-traces.sh: queries Langfuse's ClickHouse directly for instant full-dataset analytics (self-hosted only, zero deps beyond curl) - analyze-traces-sdk.py: uses the official Langfuse Python SDK with REST API pagination (works with Cloud and self-hosted) Both produce five analyses: tool usage distribution, session turn distribution, productivity by session length (the efficiency cliff), and read-before-edit behavioral patterns. Includes docs/trace-analysis.md with methodology, ClickHouse schema reference, interpretation guide, and a query cookbook for custom analytics. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
## Problem Langfuse hook systematically missed sessions when multiple Claude Code sessions were active concurrently. Only processed the most recently modified transcript per execution, causing long-running productive sessions to be skipped in favor of newly created sessions. ## Impact - 1,738 sessions (55%) never captured over 30 days - 2,896 conversation turns lost - Large multi-turn coding sessions completely absent from traces ## Root Cause Hook used `find_latest_transcript()` which returned only ONE transcript: the most recently modified file. When multiple sessions were active, each hook execution would find a different "most recent" session, systematically skipping others. ## Solution 1. New function `find_modified_transcripts()` returns ALL sessions modified since their last state update (up to 10 per run) 2. Updated main() to process multiple sessions per execution 3. Backfilled 1,738 missing sessions from last 30 days ## Results - Capture rate: 44.7% → 100% - Performance: Maintained <1s execution time - Recovered: 2,896 turns from missing sessions - Zero sessions lost going forward ## Testing ✅ Single session: All turns captured ✅ Concurrent sessions (5): All sessions captured ✅ High volume (>10): Processed in batches, none lost ✅ Performance: 0.1s when no new data See docs/bug-fix-concurrent-sessions.md for full analysis. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixed critical bug where the Langfuse hook missed 55% of Claude Code sessions when multiple sessions were active concurrently. The hook only processed the most recently modified transcript per execution, causing long-running productive sessions to be systematically skipped.
Problem
User reported traces not appearing in Langfuse despite successful hook execution. Investigation revealed:
Example
User's main coding session:
local-dev-infraprojectMeanwhile, 484 small 1-turn test sessions were captured ✅
Root Cause
Original hook logic:
What happened with concurrent sessions:
Solution
1. New function:
find_modified_transcripts()2. Updated main loop
3. Backfilled missing data
Results
Testing
✅ Single session: All turns captured
✅ 5 concurrent sessions: All captured, none skipped
✅ 15 concurrent sessions: Processed in batches (10+5), none lost
✅ Performance: 0.1s when no new data
Verification
Before:
After:
Files Changed
hooks/langfuse_hook.py- Core fix (+396, -153 lines)find_modified_transcripts()functiondocs/bug-fix-concurrent-sessions.md- Full analysis and documentationImpact
✅ Reliability: 100% capture rate vs 45% before
✅ Completeness: All concurrent sessions now captured
✅ Performance: No degradation (<1s execution maintained)
✅ Recovery: 1,738 historical sessions backfilled
See
docs/bug-fix-concurrent-sessions.mdfor complete analysis, investigation process, and testing results.🔧 Ready for review and merge