Overview
Concrete tool for hot-reloading the jcode daemon by exec-ing into a newer binary on the same Unix socket, preserving all live sessions.
Description
The handle_reload function processes a reload request from a connected client. It checks whether a strictly newer binary is available (unless forced), notifies all live sessions of the impending reload, marks the reload state, and delegates to prepare_server_exec which calls exec() to replace the running process with the new binary. The new binary inherits the listening socket, so all clients reconnect automatically.
Usage
- Graceful upgrade: Triggered by
jcode server reload or the /reload TUI command — only reloads if a newer binary exists.
- Forced reload: Triggered with
force=true — reloads unconditionally, even to an older binary.
- Self-dev reload: The self-dev session requests reload after a successful build.
Code Reference
Source Location
- Repository: jcode
- File: crates/jcode-app-core/src/server/client_session.rs
Signature
pub(super) async fn handle_reload(
id: u64,
force: bool,
client_session_id: &str,
agent: &Arc<Mutex<Agent>>,
swarm_members: &Arc<RwLock<HashMap<String, SwarmMember>>>,
client_event_tx: &mpsc::UnboundedSender<ServerEvent>,
)
Import
// Internal server function, called via Request::Reload dispatch:
// crates/jcode-app-core/src/server/client_session.rs
I/O Contract
Inputs
| Name |
Type |
Required |
Description
|
| id |
u64 |
Yes |
Request correlation ID for reply matching
|
| force |
bool |
Yes /// If true, reload unconditionally; if false, only if a newer binary exists
|
| client_session_id |
&str |
Yes |
Session ID of the requesting client
|
| agent |
Arc<Mutex<Agent>> |
Yes /// Locked agent for canary/self-dev check
|
| swarm_members |
Arc<RwLock<HashMap>> |
Yes /// Live swarm member registry for session notification
|
| client_event_tx |
mpsc::UnboundedSender |
Yes /// Channel to send ReloadProgress events to the requesting client
|
Outputs
| Name |
Type |
Description
|
| side effects |
process |
Notifies all live sessions via ServerEvent::Reloading, marks reload state, then exec()s into new binary
|
| client events |
ServerEvent |
Sends ReloadProgress and Done events to the requesting client
|
Usage Examples
Triggered via Client API
// The client sends a Request::Reload { id, force } over the socket.
// The server dispatches to handle_reload, which:
// 1. Checks server_has_newer_binary() unless force=true
// 2. Sends Reloading event to all live sessions
// 3. Calls prepare_server_exec() which exec()s into the new binary
SDK Triggered Reload
// From the TypeScript SDK:
const client = await JcodeClient.connect();
const session = await client.createSession({ workingDir: "/repo" });
await client.reload(session.session_id); // triggers handle_reload on server
Related Pages
Implements Principle
Requires Environment
Uses Heuristics
Page Connections
Double-click a node to navigate. Hold to expand connections.