Skip to content

fix stale conversation id for activity timeline#1656

Open
shagun-singh-inkeep wants to merge 3 commits intomainfrom
TI-4
Open

fix stale conversation id for activity timeline#1656
shagun-singh-inkeep wants to merge 3 commits intomainfrom
TI-4

Conversation

@shagun-singh-inkeep
Copy link
Collaborator

No description provided.

@changeset-bot
Copy link

changeset-bot bot commented Jan 30, 2026

⚠️ No Changeset found

Latest commit: 785390d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link

vercel bot commented Jan 30, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
agents-api Ready Ready Preview, Comment Jan 30, 2026 2:30pm
agents-manage-ui Ready Ready Preview, Comment Jan 30, 2026 2:30pm
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
agents-docs Skipped Skipped Jan 30, 2026 2:30pm

Request Review

@claude
Copy link
Contributor

claude bot commented Jan 30, 2026

Claude finished @shagun-singh-inkeep's task —— View job


Code Review Analysis

Conducting comprehensive TypeScript Staff Engineer review of this stale conversation ID fix.

Review Tasks:

  • Understand the existing conversation ID and activity polling architecture
  • Analyze the specific changes made in both files
  • Review for engineering best practices and potential issues
  • Check consistency with existing patterns and codebase conventions
  • Evaluate customer impact and edge cases
  • Provide actionable feedback and recommendations

Overall Assessment: LGTM with Minor Observations

This is a well-engineered fix addressing race conditions in conversation polling. The changes are focused, effective, and follow good React patterns.


🎯 What This Fixes

The PR addresses a race condition bug where stale polling requests could overwrite newer conversation data in the activity timeline. This happened when:

  1. User switches to a new conversation (conversation ID changes)
  2. Old polling request completes after the switch
  3. Stale data overwrites the new conversation's activities

🔍 Technical Review

Excellent Design Decisions:

React Key Pattern (playground.tsx:161)

  • Adding key={conversationId} to TimelineWrapper is a best practice for forcing component remount
  • Consistent with existing codebase patterns (found 3 other similar usages)
  • Ensures clean state reset when conversation changes

Race Condition Prevention (use-chat-activities-polling.ts:36-83)

  • currentConversationIdRef pattern is architecturally sound
  • Comparing requestConversationId === currentConversationIdRef.current prevents stale updates
  • Proper separation of request capture vs. response validation

State Management Hygiene

  • Lines 177-198: Proper cleanup when conversation changes
  • Maintains referential integrity with existing polling/abort logic

Code Quality:

  • Naming: Clear, semantic variable names (requestConversationId, currentConversationIdRef)
  • Comments: Well-documented race condition logic
  • Error Handling: Preserves existing error boundaries
  • Performance: Minimal overhead (single ref + effect)

🏗️ Architectural Considerations

Patterns & Consistency:

  • ✅ Follows existing React ref patterns in codebase
  • ✅ Maintains API contract compatibility
  • ✅ Consistent with component lifecycle management

Edge Cases Handled:

  • ✅ Component unmounting during request
  • ✅ Multiple rapid conversation switches
  • ✅ Abort controller cleanup
  • ✅ Error states preserved

🚀 Customer Impact

Positive Impact:

  • Eliminates confusing UI behavior where old conversation data would briefly appear
  • Improves perceived performance by preventing visual flickers
  • Maintains data integrity in multi-conversation workflows

Risk Assessment:

  • Low risk - Changes are defensive and non-breaking
  • No API changes - purely internal state management
  • Backwards compatible - existing functionality preserved

💡 Minor Considerations

Changeset Requirement:

The bot correctly identified this needs a changeset since it's a user-facing bug fix in agents-manage-ui. Consider:

pnpm bump patch --pkg agents-manage-ui "Fix stale conversation ID in activity timeline"

Testing Opportunity:

While not required for this focused fix, the race condition scenario could be valuable to test:

  • Rapid conversation switching
  • Network latency simulation
  • Component unmount during polling

📋 Conclusion

This PR demonstrates excellent engineering practices:

  • Identifies root cause (closure-based stale data)
  • Implements minimal, targeted fix
  • Uses established React patterns
  • Maintains backwards compatibility
  • Addresses real user experience issues

Recommendation: Approve

The fix is technically sound, follows best practices, and solves the stated problem effectively. The combination of React key forcing remount + ref-based race condition prevention is a robust solution.

@vercel vercel bot temporarily deployed to Preview – agents-docs January 30, 2026 14:26 Inactive
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