Skip to content

Fix trajectory viewer loading wrong data due to race condition#163

Merged
khaliqgant merged 1 commit intomainfrom
fix/trajectory-race-condition
Jan 12, 2026
Merged

Fix trajectory viewer loading wrong data due to race condition#163
khaliqgant merged 1 commit intomainfrom
fix/trajectory-race-condition

Conversation

@khaliqgant
Copy link
Copy Markdown
Member

Summary

  • Fixes race condition where selecting a trajectory displays wrong data
  • Root cause: Initial fetch with null ID could complete after selected trajectory's fetch, overwriting correct data
  • Added latestSelectionRef to track current selection and ignore stale fetches

Technical Details

When the user opened the trajectory panel and quickly clicked a trajectory:

  1. Initial fetch (null ID) started
  2. User clicked trajectory A
  3. Fetch for trajectory A started and completed
  4. Initial fetch completed and overwrote A's data with null's data

The fix:

  1. latestSelectionRef tracks the most recent trajectory selection
  2. selectTrajectory() updates the ref immediately (synchronously, before state update)
  3. fetchSteps() checks if the fetched ID matches latestSelectionRef.current before updating state
  4. Stale fetches are logged and discarded

Test plan

  • Open trajectory panel
  • Quickly click a trajectory from the list
  • Verify the correct trajectory's steps are displayed (not the initial/default)
  • Click different trajectories and verify each displays correctly

🤖 Generated with Claude Code

Added latestSelectionRef to track the most current trajectory selection
and prevent stale fetches from overwriting newer data.

Root cause: When the user quickly clicked a trajectory after opening the
panel, the initial fetch (with null ID) could complete after the selected
trajectory's fetch, overwriting the correct data with stale results.

Fix:
- Added latestSelectionRef to track current selection
- selectTrajectory updates the ref immediately (synchronously)
- fetchSteps checks if fetched ID matches current selection before
  updating state
- Stale fetches are now logged and discarded

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@my-senior-dev-pr-review
Copy link
Copy Markdown

🤖 My Senior Dev — Analysis Complete

👤 For @khaliqgant

📁 Expert in src/dashboard/react-components/ (5 edits) • ⚡ 21st PR this month

View your contributor analytics →


📊 1 file reviewed • 3 need attention

⚠️ Needs Attention:

  • src/dashboard/react-components/hooks/useTrajectory.ts — Improvements to state management introduce potential logic and error handling concerns that need careful validation.

🚀 Open Interactive Review →

The full interface unlocks features not available in GitHub:

  • 💬 AI Chat — Ask questions on any file, get context-aware answers
  • 🔍 Smart Hovers — See symbol definitions and usage without leaving the diff
  • 📚 Code Archeology — Understand how files evolved over time (/archeology)
  • 🎯 Learning Insights — See how this PR compares to similar changes

💬 Chat here: @my-senior-dev explain this change — or try @chaos-monkey @security-auditor @optimizer @skeptic @junior-dev

📖 View all 12 personas & slash commands

You can interact with me by mentioning @my-senior-dev in any comment:

In PR comments or on any line of code:

  • Ask questions about the code or PR
  • Request explanations of specific changes
  • Get suggestions for improvements

Slash commands:

  • /help — Show all available commands
  • /archeology — See the history and evolution of changed files
  • /profile — Performance analysis and suggestions
  • /expertise — Find who knows this code best
  • /personas — List all available AI personas

AI Personas (mention to get their perspective):

Persona Focus
@chaos-monkey 🐵 Edge cases & failure scenarios
@skeptic 🤨 Challenge assumptions
@optimizer Performance & efficiency
@security-auditor 🔒 Security vulnerabilities
@accessibility-advocate Inclusive design
@junior-dev 🌱 Simple explanations
@tech-debt-collector 💳 Code quality & shortcuts
@ux-champion 🎨 User experience
@devops-engineer 🚀 Deployment & scaling
@documentation-nazi 📚 Documentation gaps
@legacy-whisperer 🏛️ Working with existing code
@test-driven-purist Testing & TDD

For the best experience, view this PR on myseniordev.com — includes AI chat, file annotations, and interactive reviews.

@khaliqgant khaliqgant merged commit 7c4d276 into main Jan 12, 2026
6 checks passed
@khaliqgant khaliqgant deleted the fix/trajectory-race-condition branch January 12, 2026 11:45
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