Fix session error handling and add timeout protection#54
Merged
Conversation
- Fix fire-and-forget message POST in OpenCode (now properly awaited) - Add heartbeat monitoring for SSE connections (45s timeout) - Add session verification on pickup to detect expired sessions - Add timeout protection to Claude Code subprocess execution - Create shared SessionMonitor utility for timeout/activity tracking - Create SessionVerifier abstractions for session validation - Add comprehensive unit tests (50 new tests) - Add Playwright e2e tests for connection error handling Fixes hanging messages on mobile when session state is stale. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Comment on lines
+441
to
+451
| console.error( | ||
| `[opencode-server] No heartbeat received for ${timeSinceLastHeartbeat}ms, connection may be lost` | ||
| ); | ||
| this.streamError = new Error('Connection to OpenCode server lost (no heartbeat)'); | ||
| this.onMessage({ | ||
| type: 'error', | ||
| content: 'Connection to OpenCode server lost. Please try again.', | ||
| timestamp: new Date().toISOString(), | ||
| }); | ||
| proc.kill(); | ||
| resolveDone!(); |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SessionMonitorfor timeout/activity tracking andSessionVerifierabstractions reduce code duplicationTest plan
bun test test/chat/session-monitor.test.ts(26 tests)bun test test/chat/session-utils.test.ts(24 tests)cd web && playwright test e2e/connection-error-handling.spec.tsFiles Changed
src/chat/opencode-server.tssrc/chat/base-claude-session.tssrc/chat/session-monitor.tssrc/chat/session-utils.tstest/chat/session-monitor.test.tstest/chat/session-utils.test.tsweb/e2e/connection-error-handling.spec.ts🤖 Generated with Claude Code