Fix incident selection synchronization issues#138
Merged
Conversation
This commit addresses multiple bugs where selectedIncident didn't properly sync with the highlighted table row when navigating or returning from views, causing user actions to operate on the wrong incident ID. ## Critical Fixes 1. **Add re-sync after Escape key** (msgHandlers.go:400) - Call syncSelectedIncidentToHighlightedRow() when returning from incident view - Ensures selectedIncident matches the current table cursor position 2. **Fix pointer aliasing** (model.go:219-221) - Copy incident struct instead of storing pointer to slice element - Prevents dangling pointers when incidentList is reallocated 3. **Add race condition guard** (tui.go:246-253) - Use explicit boolean check in gotIncidentMsg handler - Prevents late-arriving messages from overwriting when user navigated away 4. **Invalidate cache on timestamp changes** (tui.go:434-453) - Compare LastStatusChangeAt to detect stale cache entries - Invalidate cache when incidents update, not just when they disappear 5. **Improve cache freshness detection** (model.go:200-241) - Compare cached incident timestamp with list data - Use fresh list data for basic info while preserving expensive API data - Create copies to avoid pointer issues 6. **Fix boundary conditions** (model.go:177-184) - Clear selection when scrolling out of bounds regardless of viewing state - Add debug logging for troubleshooting 7. **Add defensive nil check** (tui.go:526-530) - Check selectedIncident before accessing in loginMsg handler ## Additional Improvements - Refactored getHighlightedIncident() into syncSelectedIncidentToHighlightedRow() - Now a single source of truth for incident selection - Always called after navigation events (Up/Down/Top/Bottom/Escape) - Handles caching, staleness detection, and pointer safety - Added comprehensive tests - TestEscapeKeySyncsToHighlightedRow: Verifies Escape key re-sync - TestSelectedIncidentSurvivesListUpdate: Verifies pointer aliasing fix - UI refinements - Improved help layout (3 columns, help at top) - Action log table styling matches main table - Better window size handling All tests pass successfully. 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.
Problem Summary
The srep binary had multiple bugs where
selectedIncidentdidn't properly sync with the highlighted table row when navigating or returning from views. This caused user actions to operate on the wrong incident ID.Root Causes Fixed
1. Missing re-sync after Escape
When returning from incident view (pressing Escape), the code cleared
selectedIncidentbut didn't re-establish which incident is now under the cursor.2. Pointer aliasing to slice elements
Using
&m.incidentList[i]created pointers that became invalid when the slice was reallocated.3. Race condition in async message handling
Late-arriving
gotIncidentMsgcould overwriteselectedIncidentwhen user had navigated away.4. Stale cache with no TTL
Cached incident data never invalidated based on age or list updates.
5. Boundary condition when viewing
Scrolling table out of bounds while viewing didn't clear selection properly.
Changes Made
Critical Synchronization Fixes
1. Add re-sync after returning from incident view (
msgHandlers.go:400)syncSelectedIncidentToHighlightedRow()after Escape key2. Fix pointer aliasing (
model.go:219-221)incidentListis reallocated3. Add race condition guard (
tui.go:246-253)gotIncidentMsghandler4. Invalidate cache on timestamp changes (
tui.go:434-453)LastStatusChangeAtto detect stale cache entries5. Improve cache freshness detection (
model.go:200-241)6. Fix boundary conditions (
model.go:177-184)7. Add defensive nil check (
tui.go:526-530)selectedIncidentbefore accessing inloginMsghandlerAdditional Improvements
Refactored incident selection logic
getHighlightedIncident()→syncSelectedIncidentToHighlightedRow()UI refinements
Tests Added
TestEscapeKeySyncsToHighlightedRow: Verifies Escape key re-sync behaviorTestSelectedIncidentSurvivesListUpdate: Verifies pointer aliasing fixTesting
All tests pass:
Verification
Manual testing should verify:
Fixes multiple reported issues with incident selection bugs.