← Back to Kontasks
Fixed EventSource Event Handler Bug
EventSource log handler was only processing 'output' events, missing others like 'connected'
Output
🐛 Bug Found and Fixed
Found the root cause of EventSource reconnection issues.
The Problem
EventSource log event handler was only checking for:
if (wrapper.event === 'output') { ... } else if (wrapper.event === 'exit') { ... } else if (wrapper.type === 'error') { ... } // Wrong field!
Missing handlers for: connected, error (correct field), kontext, session_captured
Why This Broke Reconnection
- Navigate away → POST stream breaks
- Navigate back → EventSource connects to
/events - Server replays buffered events wrapped as
event: log - First buffered event is
connected→ ignored! - No
sse_eventdispatch → status stays "Ready" - Text events have
event: output→ should work but...
The Fix
Updated EventSource log handler to properly route ALL event types:
output→handleStreamEvent(wrapper)exit→ Close and check for kontaskerror→ Show error messageconnected→ Dispatchsse_eventto update statuskontext,session_captured→ Log and ignore- Unknown → Log warning
Test It
Konui restarted. Try navigating away and back - status should update and events should stream properly after reconnection.
Quick Actions
Original Request
No layout configured
Details
Type
General
Status
Completed
Scope
vibetools
Tags
consolessebugfix
Created
2 Jan 2026, 7:57 pm
Updated
2 Jan 2026, 7:57 pm
Created By
claude
Raw Data
{
"id": "7012a3dd-546f-436d-927c-f50d502392b9",
"type": "general",
"status": "completed",
"title": "Fixed EventSource Event Handler Bug",
"description": "EventSource log handler was only processing 'output' events, missing others like 'connected'",
"context": {
"output": "<div style=\"background:#1e1e1e;color:#e0e0e0;padding:20px;border-radius:8px;font-family:'Consolas','Monaco',monospace;\"><h2 style=\"font-family:sans-serif;color:#fff;margin:0 0 16px 0;\">🐛 Bug Found and Fixed</h2><p style=\"color:#9ca3af;margin:0 0 16px 0;\">Found the root cause of EventSource reconnection issues.</p><div style=\"background:#2d2d2d;padding:16px;border-radius:6px;margin-bottom:16px;\"><h4 style=\"margin:0 0 12px 0;color:#f97316;\">The Problem</h4><p style=\"color:#e0e0e0;margin:0 0 8px 0;\">EventSource <code>log</code> event handler was only checking for:</p><pre style=\"background:#1e1e1e;padding:12px;border-radius:4px;overflow-x:auto;font-size:0.85rem;margin:0;\"><span style=\"color:#c678dd;\">if</span> (wrapper.event === <span style=\"color:#98c379;\">'output'</span>) { ... }\n<span style=\"color:#c678dd;\">else if</span> (wrapper.event === <span style=\"color:#98c379;\">'exit'</span>) { ... }\n<span style=\"color:#c678dd;\">else if</span> (wrapper.type === <span style=\"color:#98c379;\">'error'</span>) { ... } <span style=\"color:#7f848e;\">// Wrong field!</span></pre><p style=\"color:#9ca3af;margin:12px 0 0 0;\">Missing handlers for: <code>connected</code>, <code>error</code> (correct field), <code>kontext</code>, <code>session_captured</code></p></div><div style=\"background:#2d2d2d;padding:16px;border-radius:6px;margin-bottom:16px;\"><h4 style=\"margin:0 0 12px 0;color:#61afef;\">Why This Broke Reconnection</h4><ol style=\"margin:0;padding-left:20px;color:#e0e0e0;line-height:1.8;\"><li>Navigate away → POST stream breaks</li><li>Navigate back → EventSource connects to <code>/events</code></li><li>Server replays buffered events wrapped as <code>event: log</code></li><li>First buffered event is <code>connected</code> → <strong>ignored!</strong></li><li>No <code>sse_event</code> dispatch → status stays \"Ready\"</li><li>Text events have <code>event: output</code> → should work but...</li></ol></div><div style=\"background:#2d2d2d;padding:16px;border-radius:6px;margin-bottom:16px;\"><h4 style=\"margin:0 0 12px 0;color:#98c379;\">The Fix</h4><p style=\"color:#e0e0e0;margin:0;\">Updated EventSource log handler to properly route ALL event types:</p><ul style=\"margin:8px 0 0 0;padding-left:20px;line-height:1.8;\"><li><code>output</code> → <code>handleStreamEvent(wrapper)</code></li><li><code>exit</code> → Close and check for kontask</li><li><code>error</code> → Show error message</li><li><code>connected</code> → Dispatch <code>sse_event</code> to update status</li><li><code>kontext</code>, <code>session_captured</code> → Log and ignore</li><li>Unknown → Log warning</li></ul></div><div style=\"background:#2d2d2d;padding:16px;border-radius:6px;\"><h4 style=\"margin:0 0 8px 0;color:#fff;\">Test It</h4><p style=\"color:#9ca3af;margin:0;\">Konui restarted. Try navigating away and back - status should update and events should stream properly after reconnection.</p></div></div>",
"requestedAt": "2026-01-02T09:45:00Z",
"requestId": "d3b72fa9-f3fc-4cbe-8391-6bbac69a57d3"
},
"createdBy": "claude",
"createdAt": "2026-01-02T09:57:38.469Z",
"updatedAt": "2026-01-02T09:57:38.595Z",
"requestId": "d3b72fa9-f3fc-4cbe-8391-6bbac69a57d3",
"scope": "vibetools",
"tags": [
"console",
"sse",
"bugfix"
],
"targetUser": "claude"
}