Skip to content

Commit 24e9969

Browse files
jahoomaclaude
andcommitted
Add server-side restart ping functionality
- Add request-restart action type to SERVER_ACTION_SCHEMA - Add sendRequestRestart() function to broadcast restart signals to all clients - Add client-side handler to display restart message and exit process cleanly - Follows existing request-reconnect pattern for consistency 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent d010156 commit 24e9969

3 files changed

Lines changed: 17 additions & 0 deletions

File tree

backend/src/websockets/server.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,12 @@ export function sendRequestReconnect() {
172172
}
173173
}
174174

175+
export function sendRequestRestart() {
176+
for (const ws of SWITCHBOARD.clients.keys()) {
177+
sendMessage(ws, { type: 'action', data: { type: 'request-restart' } })
178+
}
179+
}
180+
175181
export function waitForAllClientsDisconnected() {
176182
return SWITCHBOARD.waitForAllClientsDisconnected()
177183
}

common/src/actions.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ export const SERVER_ACTION_SCHEMA = z.discriminatedUnion('type', [
162162
// The server is imminently going to shutdown, and the client should reconnect
163163
type: z.literal('request-reconnect'),
164164
}),
165+
z.object({
166+
// The server is requesting the client to restart codebuff
167+
type: z.literal('request-restart'),
168+
}),
165169
])
166170

167171
type ServerActionAny = z.infer<typeof SERVER_ACTION_SCHEMA>

npm-app/src/client.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,13 @@ export class Client {
909909
this.reconnectWhenNextIdle()
910910
})
911911

912+
// Used to handle server requests to restart codebuff
913+
this.webSocket.subscribe('request-restart', () => {
914+
console.log('\n' + yellow('🔄 Codebuff needs to be restarted. Please restart the application.'))
915+
console.log(red('Exiting...'))
916+
this.exit()
917+
})
918+
912919
// Handle subagent streaming messages
913920
this.webSocket.subscribe('subagent-response-chunk', (action) => {
914921
const { userInputId, agentId, agentType, chunk, prompt } = action

0 commit comments

Comments
 (0)