xonecas.io
60255
Zn

Zoea-Nova / files

Zoea-Nova / documentation / architecture / INPUT_RESET_BEHAVIOR.md

7.9 KB
1# Input Reset Behavior
2
3**Version:** 1.0  
4**Last updated:** 2026-02-07
5
6## Purpose
7
8This document defines the truth table for input box reset behavior across all input modes in the Zoea Nova TUI.
9
10## Problem Statement
11
12When sending a direct message (press 'm', type message, press Enter), the input box shows the typed message text frozen during the entire async operation (tool calling + LLM reply), instead of showing the "Sending message..." animation. The expectation is that the input box should reset immediately after pressing Enter and display the sending indicator.
13
14## Expected Behavior
15
16When a user sends a message (broadcast or direct), the input box should:
171. Clear immediately after pressing Enter
182. Show a "Sending..." indicator while the async operation completes
193. Return to the inactive placeholder state after completion
20
21## Truth Table: Input State During Message Send
22
23| Event | `m.input.Mode()` | `m.input.Value()` | `m.sending` | `ViewAlways` Output |
24|-------|------------------|-------------------|-------------|---------------------|
25| **Before Enter** | `InputModeMessage` | `"hello"` | `false` | Input field showing `"hello"` |
26| **Enter pressed** | `InputModeMessage` ❌ | `"hello"` ❌ | `true` | Input field showing `"hello"` ❌ |
27| **During async** | `InputModeMessage` ❌ | `"hello"` ❌ | `true` | Input field showing `"hello"` ❌ |
28| **After async** | `InputModeNone` ✅ | `""` ✅ | `false` | Placeholder ✅ |
29
30**Expected state after Enter:**
31| Event | `m.input.Mode()` | `m.input.Value()` | `m.sending` | `ViewAlways` Output |
32|-------|------------------|-------------------|-------------|---------------------|
33| **Enter pressed** | `InputModeNone` ✅ | `""` ✅ | `true` | `"⬡ Sending message..."` ✅ |
34| **During async** | `InputModeNone` ✅ | `""` ✅ | `true` | `"⬡ Sending message..."` ✅ |
35| **After async** | `InputModeNone` ✅ | `""` ✅ | `false` | Placeholder ✅ |
36
37## Root Cause Analysis
38
39### ViewAlways Rendering Priority (input.go:185-202)
40
41The `ViewAlways` function has three rendering modes with **strict priority order**:
42
43```go
44func (m InputModel) ViewAlways(width int, sending bool, sendingLabel, spinnerView string) string {
45    // Priority 1: Active input mode (HIGHEST)
46    if m.mode != InputModeNone {
47        return inputStyle.Width(width - 2).Render(m.textInput.View())
48    }
49    
50    // Priority 2: Sending indicator
51    if sending {
52        indicator := fmt.Sprintf("%s %s", spinnerView, sendingLabel)
53        return inputStyle.Width(width - 2).Render(indicator)
54    }
55    
56    // Priority 3: Placeholder (LOWEST)
57    placeholder := dimmedStyle.Render("Press 'm' to message, 'b' to broadcast...")
58    return inputStyle.Width(width - 2).Render(placeholder)
59}
60```
61
62**Critical Issue:** ViewAlways checks `m.mode != InputModeNone` FIRST. If the input mode is still active (not reset), it ALWAYS shows the input field, regardless of the `sending` flag.
63
64### Message Send Flow (app.go:648-659)
65
66```go
67case InputModeMessage:
68    m.input.AddToHistory(value)
69    targetID := m.input.TargetID()
70    m.loadingSet[targetID] = true
71    m.netIndicator.SetActivity(NetActivityLLM)
72    m.sending = true                    // Set sending flag
73    m.sendingMode = InputModeMessage    // Set mode for label
74    cmd = m.sendMessageAsync(targetID, value)
75    if m.view == ViewFocus {
76        m.loadMysisLogs()
77    }
78    // NOTE: m.input.Reset() is NOT called here!
79    // Input mode remains InputModeMessage
80    // Input value remains in text field
81```
82
83**The Bug:** Input is NOT reset when Enter is pressed. The input mode remains `InputModeMessage` and the value remains in the text field.
84
85### Why "Sending message..." Never Shows
86
871. User presses Enter
882. `m.sending = true` is set
893. `m.sendingMode = InputModeMessage` is set
904. **BUT `m.input.Reset()` is NOT called**
915. Input mode remains `InputModeMessage` (not `InputModeNone`)
926. `ViewAlways` checks `m.mode != InputModeNone` → **TRUE**
937. Returns early with input field (line 193)
948. Never reaches the `if sending` check (line 195)
959. User sees frozen input with their typed text
96
97### When Reset Finally Happens (app.go:259-274)
98
99```go
100case sendMessageResult:
101    delete(m.loadingSet, msg.mysisID)
102    if msg.err != nil {
103        m.err = msg.err
104    }
105    if len(m.loadingSet) == 0 {
106        m.netIndicator.SetActivity(NetActivityIdle)
107        m.sending = false
108        m.sendingMode = InputModeNone
109        m.input.Reset()  // ← Reset ONLY after async completes
110    }
111```
112
113Reset is only called AFTER the async operation completes (which can take 5-10 seconds for LLM + tool calls).
114
115## Fix Requirements
116
117### Primary Fix: Reset Input Immediately After Enter
118
119**Location:** `internal/tui/app.go:648-659` (handleInputKey, InputModeMessage case)
120
121**Change:**
122```go
123case InputModeMessage:
124    m.input.AddToHistory(value)
125    targetID := m.input.TargetID()  // ← Save targetID BEFORE reset
126    m.input.Reset()                 // ← ADD THIS LINE
127    m.loadingSet[targetID] = true
128    m.netIndicator.SetActivity(NetActivityLLM)
129    m.sending = true
130    m.sendingMode = InputModeMessage
131    cmd = m.sendMessageAsync(targetID, value)
132    if m.view == ViewFocus {
133        m.loadMysisLogs()
134    }
135```
136
137**Important:** Must save `targetID` before calling `Reset()` because `Reset()` clears `m.targetID` (input.go:208).
138
139### Same Fix for Broadcast
140
141**Location:** `internal/tui/app.go:628-646` (handleInputKey, InputModeBroadcast case)
142
143**Change:**
144```go
145case InputModeBroadcast:
146    if value == "" {
147        m.input.Reset()
148        return m, nil
149    }
150    m.input.AddToHistory(value)
151    m.input.Reset()  // ← ADD THIS LINE
152    // Mark all running myses as loading
153    myses := m.commander.ListMyses()
154    for _, mysis := range myses {
155        if mysis.State() == core.MysisStateRunning {
156            m.loadingSet[mysis.ID()] = true
157        }
158    }
159    m.netIndicator.SetActivity(NetActivityLLM)
160    m.sending = true
161    m.sendingMode = InputModeBroadcast
162    cmd = m.broadcastAsync(value)
163```
164
165### Test Coverage
166
1671. Direct message with non-empty value → input clears immediately, shows "Sending message..."
1682. Broadcast with non-empty value → input clears immediately, shows "Broadcasting..."
1693. Multiple sequential messages → input clears between each send
170
171## Test Scenarios
172
173### Scenario 1: Send non-empty direct message
174**Given:** User is in dashboard, mysis selected  
175**When:** Press 'm', type "hello", press Enter  
176**Then:** 
177- Input box clears immediately (mode → None, value → "")
178- "⬡ Sending message..." indicator shows with animated spinner
179- Message is sent to mysis
180- Input returns to inactive placeholder after completion
181
182### Scenario 2: Send non-empty broadcast
183**Given:** User is in dashboard  
184**When:** Press 'b', type "hello", press Enter  
185**Then:** 
186- Input box clears immediately (mode → None, value → "")
187- "⬡ Broadcasting..." indicator shows with animated spinner
188- Message is broadcast to all myses
189- Input returns to inactive placeholder after completion
190
191### Scenario 3: Send multiple messages sequentially
192**Given:** User is in dashboard, mysis selected  
193**When:** 
1941. Press 'm', type "message 1", press Enter
1952. Wait for completion
1963. Press 'm', type "message 2", press Enter
197**Then:** 
198- First message: input clears, shows "Sending message...", completes
199- Second message: input clears, shows "Sending message...", completes
200- No text from previous message visible at any point
201
202## Implementation Plan
203
2041. **Fix direct message reset** - Add `m.input.Reset()` after saving targetID in InputModeMessage case
2052. **Fix broadcast reset** - Add `m.input.Reset()` after history in InputModeBroadcast case
2063. **Update existing tests** - Modify `input_reset_test.go` to verify "Sending..." indicator shows
2074. **Run tests** - Verify all scenarios pass
2085. **Manual testing** - Verify visual behavior matches expectations
209
210## References
211
212- `internal/tui/app.go:611-743` - `handleInputKey` function
213- `internal/tui/app.go:259-274` - `sendMessageResult` handler
214- `internal/tui/app.go:276-287` - `broadcastResult` handler
215- `internal/tui/input.go:204-212` - `Reset` method