Skip to content

feat: add WebSocket session lifecycle protocol and provider rebind#186

Closed
bbsngg wants to merge 1 commit intosplit/c-server-config-migrationfrom
split/b-server-lifecycle
Closed

feat: add WebSocket session lifecycle protocol and provider rebind#186
bbsngg wants to merge 1 commit intosplit/c-server-config-migrationfrom
split/b-server-lifecycle

Conversation

@bbsngg
Copy link
Copy Markdown
Contributor

@bbsngg bbsngg commented Apr 15, 2026

Summary

  • Add standardized WebSocket session lifecycle messages: session-accepted, session-busy, session-state-changed
  • Extract session lifecycle helpers to server/utils/sessionLifecycle.js (provider inference, projectName resolution, payload enrichment)
  • WebSocketWriter auto-enriches session events and emits lifecycle state transitions
  • All 7 providers: store writer reference, add rebindXxxSessionWriter() for reconnect, include projectName in session-created
  • Fix cursor-cli to emit cursor-complete (was incorrectly claude-complete)

Part of the session lifecycle PR split (4/6). Depends on #185 (config migration) for encodeProjectPath.

Test plan

  • node --check server/index.js server/claude-sdk.js server/cursor-cli.js server/gemini-cli.js server/openai-codex.js passes
  • npx vitest run server/__tests__/session-lifecycle.test.mjs server/__tests__/codex-session-events.test.mjs passes
  • WebSocket messages include session-accepted before provider streaming begins
  • Reconnecting client rebinds to active session output

🤖 Generated with Claude Code

Add standardized session lifecycle protocol messages to the WebSocket
layer so clients can track session state transitions reliably.

Server changes:
- Extract session lifecycle helpers to server/utils/sessionLifecycle.js
  (provider inference, projectName resolution, payload enrichment)
- WebSocketWriter.send() auto-enriches session events with projectName
  and emits session-state-changed lifecycle messages
- Add sendSessionAccepted/sendSessionBusy/sendSessionStateChanged
  helpers in the chat connection handler
- Add WebSocket writer rebind on reconnect (replaceSocket) so active
  sessions survive client reconnections

Provider changes (all 7 providers):
- Store writer reference in active session map
- Add rebindXxxSessionWriter() for reconnect support
- Include projectName in session-created events
- Fix cursor-cli to emit cursor-complete (was claude-complete)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@bbsngg
Copy link
Copy Markdown
Contributor Author

bbsngg commented Apr 15, 2026

Split from #170 (4/6). Depends on #185 (config migration for encodeProjectPath export). See #170 for full split plan.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant