Fix critical race conditions in auto-flush feature

Fixed three critical issues identified in code review:

1. Race condition with store access: Added storeMutex and storeActive
   flag to prevent background flush goroutine from accessing closed
   store. Background timer now safely checks if store is active before
   attempting flush operations.

2. Missing auto-flush in import: Added markDirtyAndScheduleFlush()
   call after import completes, ensuring imported issues sync to JSONL.

3. Timer cleanup: Explicitly set flushTimer to nil after Stop() to
   prevent resource leaks.

Testing confirmed all fixes working:
- Debounced flush triggers after 5 seconds of inactivity
- Immediate flush on process exit works correctly
- Import operations now trigger auto-flush
- No race conditions detected

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Steve Yegge
2025-10-13 22:34:12 -07:00
parent 00b0292514
commit 97d78d264f
5 changed files with 260 additions and 3 deletions

View File

@@ -35,6 +35,9 @@ var depAddCmd = &cobra.Command{
os.Exit(1)
}
// Schedule auto-flush
markDirtyAndScheduleFlush()
if jsonOutput {
outputJSON(map[string]interface{}{
"status": "added",
@@ -62,6 +65,9 @@ var depRemoveCmd = &cobra.Command{
os.Exit(1)
}
// Schedule auto-flush
markDirtyAndScheduleFlush()
if jsonOutput {
outputJSON(map[string]interface{}{
"status": "removed",