-
Notifications
You must be signed in to change notification settings - Fork 15.3k
Closed
Description
Problem
When the gateway restarts, the TUI reconnects (exponential backoff works correctly), but doesn't reload conversation history if historyLoaded was already true before the disconnect. This means:
- Messages exchanged during the outage are lost from the TUI view
- Session state (agent, current session) may not restore properly
- Only manual actions like
/statusor/historycan catch up
Steps to Reproduce
- Start TUI:
clawdbot tui - Load some history (messages appear in chat log)
- Restart gateway:
clawdbot gateway restart(or via SIGUSR1) - Wait for TUI to reconnect (shows "gateway reconnected")
- Messages sent during the outage are missing from TUI view
Expected Behavior
On onConnected, the TUI should:
- Call
loadHistory()to fetch messages sincelastSeq(or reload full history) - Restore current agent/session state
- Show a clearer reconnection state (progress, attempt count, etc.)
Current Behavior (from code review)
In tui.js (lines ~510-545):
client.onConnected()callsloadHistory()only if!historyLoaded- If
historyLoaded === true, it just shows "gateway reconnected" without fetching missed events - This means any messages exchanged during disconnect are invisible in TUI
Suggested Fixes
Option 1: Always reload history after reconnect (simpler)
client.onConnected = () => {
isConnected = true;
setConnectionStatus("connected");
void (async () => {
await refreshAgents();
updateHeader();
// Always reload history on reconnect to catch missed events
await loadHistory();
setConnectionStatus("gateway reconnected", 4000);
tui.requestRender();
// ...
})();
};Option 2: Reload only if disconnect was detected (more efficient)
let wasDisconnected = false;
client.onDisconnected = (reason) => {
isConnected = false;
wasDisconnected = true;
// ...
};
client.onConnected = () => {
isConnected = true;
setConnectionStatus("connected");
void (async () => {
await refreshAgents();
updateHeader();
// Reload history only if we had a disconnect
if (wasDisconnected) {
await loadHistory();
wasDisconnected = false;
}
// ...
})();
};Option 3: Fetch events since last known sequence (most efficient)
- Track
lastSeqfrom incoming events - On reconnect, call
chat.historywithsinceSeqparameter if available - This would only fetch messages exchanged during the outage
Environment
- Clawdbot version: 2026.1.22+ (from main)
- OS: Linux (Raspberry Pi 5)
- Terminal: (not specified)
- Gateway: local mode (loopback)
Notes
- Exponential backoff in
GatewayClientworks correctly (scheduleReconnect()ingateway/client.js) - The
onGaphandler exists for detecting event gaps, but is called during normal operation, not on reconnect - The protocol includes
seqnumbers for ordering; this could be leveraged for delta sync
Metadata
Metadata
Assignees
Labels
No labels