fix: tighten disconnect recovery guards

This commit is contained in:
Bohdan Triapitsyn
2026-04-17 19:00:44 +03:00
parent f5535dcaf1
commit 2766327a68
2 changed files with 21 additions and 1 deletions
@@ -10,6 +10,18 @@ import {
sendMessageStreamWsFrame,
} from './protocol.js';
function shouldTriggerUpstreamHealthCheck(upstream) {
if (!upstream) {
return true;
}
if (!upstream.body) {
return upstream.ok || upstream.status >= 500;
}
return upstream.status >= 500;
}
export function createGlobalUiEventBroadcaster({
sseClients,
wsClients,
@@ -151,7 +163,9 @@ export function createMessageStreamWsRuntime({
message: `OpenCode event stream unavailable (${upstream.status})`,
});
socket.close(1011, 'OpenCode event stream unavailable');
triggerHealthCheck?.();
if (shouldTriggerUpstreamHealthCheck(upstream)) {
triggerHealthCheck?.();
}
return;
}