fix: preserve prompt text on network error and allow offline typing (#276)

* fix: preserve prompt text on network error and allow offline typing

* fix: preserve prompt on network error, swallow 524 to avoid duplicate sends

* feat: add service worker precaching with app shell and runtime cache strategies

* fix: copy frontend/plugins into Docker build context

* fix: improve service worker update checks with visibility and focus handlers

* fix: add connect timeout to event stream to recover from failed connections

* fix: remove optimistic message insert, keep prompt in input until server confirms
This commit is contained in:
Chris Scott authored and GitHub committed 2026-06-17 17:28:59 -04:00
1 parent a7d0c13f9a
commit 3e617c2df8
18 files changed
+569 -57

No files matched your search

@@ -44,6 +44,20 @@ describe('OpenCodeEventStream', () => {
expect(healthStates.at(-1)).toMatchObject({ isConnected: true, isHealthy: true, isStalled: false })
})
it('recovers when a connection never opens', async () => {
const transport = new TestEventStreamTransport()
const stream = new OpenCodeEventStream({ transport })
stream.subscribeGlobalMonitor({ directories: [], onEvent: vi.fn() })
expect(transport.openedUrls).toHaveLength(1)
await vi.advanceTimersByTimeAsync(10_000)
expect(transport.closeCount).toBeGreaterThan(0)
await vi.advanceTimersByTimeAsync(1_000)
expect(transport.openedUrls.length).toBeGreaterThan(1)
})
it('reconnects when the watchdog detects a stall', async () => {
const transport = new TestEventStreamTransport()
const stream = new OpenCodeEventStream({ transport })
@@ -21,7 +21,7 @@ interface OpenCodeEventStreamOptions {
transport?: EventStreamTransport
}
const { RECONNECT_DELAY_MS, MAX_RECONNECT_DELAY_MS, STALL_THRESHOLD_MS, WATCHDOG_TICK_MS } = DEFAULTS.SSE
const { RECONNECT_DELAY_MS, MAX_RECONNECT_DELAY_MS, CONNECT_TIMEOUT_MS, STALL_THRESHOLD_MS, WATCHDOG_TICK_MS } = DEFAULTS.SSE
export class OpenCodeEventStream {
private connection: { close(): void } | null = null
@@ -30,6 +30,7 @@ export class OpenCodeEventStream {
private directoryRefCounts = new Map<string, number>()
private pendingDirectories = new Set<string>()
private reconnectTimeout: ReturnType<typeof setTimeout> | null = null
private connectTimeout: ReturnType<typeof setTimeout> | null = null
private reconnectDelay: number = RECONNECT_DELAY_MS
private connected = false
private subscriberIdCounter = 0
@@ -194,9 +195,26 @@ export class OpenCodeEventStream {
onConnected: (data) => this.handleConnected(data),
onHeartbeat: () => this.markActivity(),
})
this.startConnectTimeout()
}
private startConnectTimeout(): void {
this.clearConnectTimeout()
this.connectTimeout = setTimeout(() => {
this.connectTimeout = null
this.handleError()
}, CONNECT_TIMEOUT_MS)
}
private clearConnectTimeout(): void {
if (this.connectTimeout) {
clearTimeout(this.connectTimeout)
this.connectTimeout = null
}
}
private handleOpen(): void {
this.clearConnectTimeout()
this.connected = true
this.reconnectDelay = RECONNECT_DELAY_MS
this.startWatchdog()
@@ -205,6 +223,7 @@ export class OpenCodeEventStream {
}
private handleError(): void {
this.clearConnectTimeout()
this.connected = false
this.clientId = null
this.upstreamConnectedCount = null
@@ -250,6 +269,7 @@ export class OpenCodeEventStream {
this.clientId = null
}
this.clearConnectTimeout()
this.connected = true
this.startWatchdog()
this.markActivity()
@@ -263,6 +283,7 @@ export class OpenCodeEventStream {
this.reconnectTimeout = null
}
this.clearConnectTimeout()
this.stopWatchdog()
this.connection?.close()
this.connection = null
@@ -289,6 +310,7 @@ export class OpenCodeEventStream {
this.reconnectTimeout = null
}
this.clearConnectTimeout()
this.stopWatchdog()
this.connection?.close()
this.connection = null