Fix trajectory viewer race condition with request counter#171
Merged
khaliqgant merged 1 commit intomainfrom Jan 13, 2026
Merged
Fix trajectory viewer race condition with request counter#171khaliqgant merged 1 commit intomainfrom
khaliqgant merged 1 commit intomainfrom
Conversation
The bug occurred when clicking trajectories quickly - stale fetch responses could overwrite newer data, showing the wrong trajectory or overview data. Root cause: The previous fix used trajectory ID comparison to reject stale fetches, but this wasn't sufficient because: 1. Polling could start fetches that completed after selection changed 2. Multiple rapid clicks could have overlapping fetches 3. The same trajectory ID check wouldn't catch all race conditions Fix: - Added requestCounterRef to uniquely identify each fetch request - Increment counter in selectTrajectory() to immediately invalidate in-flight fetches when selection changes - Double-check both request ID AND trajectory ID before updating state - Added early return if clicking same trajectory (prevents re-fetch) - Removed redundant initial fetchSteps() call (refresh() handles it) - Only update error state if request is still current The request counter provides stronger protection than ID comparison alone because it catches ALL out-of-order responses, not just those for different trajectory IDs. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
🤖 My Senior Dev — Analysis Complete👤 For @khaliqgant📁 Expert in View your contributor analytics → 📊 1 file reviewed • 6 need attention
🚀 Open Interactive Review →The full interface unlocks features not available in GitHub:
💬 Chat here: 📖 View all 12 personas & slash commandsYou can interact with me by mentioning In PR comments or on any line of code:
Slash commands:
AI Personas (mention to get their perspective):
For the best experience, view this PR on myseniordev.com — includes AI chat, file annotations, and interactive reviews. |
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
Problem
When clicking trajectories quickly, users would see:
Root cause: Stale fetch responses could complete and update state after a newer selection was made. The previous fix using trajectory ID comparison wasn't sufficient for all race conditions.
Solution
Added
requestCounterRefpattern:selectTrajectory()increments counter to immediately invalidate in-flight fetchesTest plan
🤖 Generated with Claude Code