@@ -0,0 +1,93 @@
1+# Restart Errored Mysis Investigation
2+
3+**Date:** 2026-02-06
4+**Issue:** Restarting errored mysis flashes "running" then immediately back to "errored"
5+**Status:** ✅ FIXED
6+
7+---
8+
9+## Root Cause
10+
11+**Start() launched async initial SendMessage that could fail AFTER Start() returned success.**
12+
13+Timeline:
14+1. User presses 'r' to restart errored mysis
15+2. Start() returns success → TUI shows "running"
16+3. Async SendMessage goroutine executes
17+4. Goroutine encounters error (provider, DB, account, etc.)
18+5. setError() called → state becomes "errored"
19+6. **User sees: running → errored flash**
20+
21+---
22+
23+## Investigation Method
24+
25+**10-agent systematic debugging investigation**
26+
27+Agents deployed:
28+1. Agent 1-2: Traced Start() and SendMessage flow
29+2. Agent 3-7: Ruled out contributing factors (accounts, provider, DB, MCP, cleanup)
30+3. Agent 8: Created reproduction test
31+4. Agent 9: Designed solution (4 options analyzed)
32+5. Agent 10: Integration lead - provided fix
33+
34+---
35+
36+## Solution
37+
38+**Move initial nudge from Start() into run() loop**
39+
40+Before:
41+```go
42+func (m *Mysis) Start() error {
43+ go a.run(ctx)
44+ go a.SendMessage(...) // ← ASYNC, can fail after Start() returns
45+ return nil
46+}
47+```
48+
49+After:
50+```go
51+func (m *Mysis) Start() error {
52+ go a.run(ctx)
53+ return nil // Fast return, no async work
54+}
55+
56+func (m *Mysis) run(ctx context.Context) {
57+ // Send initial nudge internally
58+ select {
59+ case a.nudgeCh <- struct{}{}:
60+ default:
61+ }
62+ // ... rest of loop
63+}
64+```
65+
66+---
67+
68+## Benefits
69+
70+- Start() is fast (returns immediately)
71+- No async race between Start() success and message failure
72+- Clear separation: Start() = lifecycle, run() = work
73+- Consistent error handling (first message = nth message)
74+- If first message fails, transitions running → errored inside run() (expected behavior)
75+
76+---
77+
78+## Files Modified
79+
80+- internal/core/mysis.go:267-268 - Removed async SendMessage
81+- internal/core/mysis.go:1030-1036 - Added initial nudge to run()
82+
83+---
84+
85+## Test Results
86+
87+- All state machine tests: PASS
88+- TestCommanderRestartErroredMysis: PASS
89+- Full suite: PASS (77.3% coverage)
90+
91+---
92+
93+**Fixed in commit:** b66624a