Repository navigation
Description
Summary
scripts/install.sh swaps the on-disk binary but never retires a running server or reaps the runtime socket/lock. As a result, an "upgrade" can leave the old code in charge (a surviving daemon), and a leftover dead socket can wedge the client into a connect-retry loop. This is the same class of problem that let #277 persist past the on-disk fix.
This is not a regression in the #277 reload-loop fix — that fix is sound (v0.17.0+, 5fa0360d), and the client-side circuit breaker shipped in v0.17.1 makes the catastrophic flicker much less likely. This is about upgrade hygiene and one remaining sharp edge.
What I hit
On Omarchy (Arch), XDG_RUNTIME_DIR=/run/user/1000:
jcode --version→v0.17.0 (unknown)jcode debug list→Running jcode servers: /run/user/1000/jcode.sock (✗ not responding (stale socket?))- Symptom: flicker on launch — the client repeatedly tries to hand off to the dead socket and never completes (same surface symptom as jcode badly broken on Omarchy #277, different cause).
jcode correctly detects the socket as stale ("✗ not responding (stale socket?)"), but a normal launch doesn't appear to reap it — so the bad state persists across restarts until the socket is removed by hand.
What fixed it
A manual clean — kill any process, remove the stale socket + lock, clear old build dirs, reinstall:
pkill -9 -f jcode
rm -f /run/user/1000/jcode.sock /run/user/1000/jcode-debug.sock /run/user/1000/jcode-daemon.lock
rm -rf ~/.jcode/builds/{current,stable,versions}
curl -fsSL .../install.sh | bash # → v0.17.1
JCODE_NO_UPDATE=1 jcode # clean, no flickerThe decisive step in my case was removing the stale socket — none of this is something install.sh does today.
Two gaps
install.shdoesn't retire a running daemon on upgrade. It only copies binaries into~/.jcode/builds/{stable,current,versions}, so a previously-running server keeps executing old code until the user manually kills it.- A stale socket isn't auto-reaped on launch. The runtime already knows the socket is dead (it prints "stale socket?"), but doesn't clean it up and rebind, so the bad state survives restarts.
Possible fixes (your call on direction)
Option A — binary-side (probably the more robust fix): on startup, when the socket at storage::runtime_dir()/jcode.sock exists but has no live listener (you already detect this in server/socket.rs), remove it + the sibling debug socket + jcode-daemon.lock and rebind. Optionally add a jcode server stop subcommand that install.sh can call for a graceful, cross-platform daemon shutdown — cleaner than the installer killing processes.
Option B — installer-side (quick, self-contained): have install.sh retire a surviving daemon and clear the stale socket/lock on upgrade. Candidate patch below. Caveat: it matches the server by its builds/ path via pgrep -f (intentionally narrow, so it doesn't kill an unrelated foreground jcode), which is a bit blunt — Option A is cleaner if you'd rather the binary own this.
Candidate install.sh patch (Option B)
@@ after the info()/err() helpers @@
+# --- runtime dir resolution: mirror storage::runtime_dir() in the Rust source ---
+jcode_runtime_dir() {
+ if [ -n "${JCODE_RUNTIME_DIR:-}" ]; then printf '%s\n' "$JCODE_RUNTIME_DIR"; return; fi
+ if [ -n "${XDG_RUNTIME_DIR:-}" ]; then printf '%s\n' "$XDG_RUNTIME_DIR"; return; fi
+ if [ "$(uname -s)" = "Darwin" ] && [ -n "${TMPDIR:-}" ]; then printf '%s\n' "$TMPDIR"; return; fi
+ # Fallback mirrors storage::fallback_runtime_dir(): temp_dir()/jcode-<euid>
+ printf '%s\n' "${TMPDIR:-/tmp}/jcode-$(id -u)"
+}
+
+# Retire any jcode server left running from a previous install so the freshly
+# installed binary serves the next launch, and clear the runtime socket/lock.
+stop_running_daemon() {
+ [ "$IS_WINDOWS" = true ] && return 0
+ local rt sock dbg lock pids
+ rt="$(jcode_runtime_dir)"
+ sock="$rt/jcode.sock"; dbg="$rt/jcode-debug.sock"; lock="$rt/jcode-daemon.lock"
+ # Match the server by its builds path, not every running 'jcode'.
+ pids="$(pgrep -f "$builds_dir/" 2>/dev/null || true)"
+ if [ -n "$pids" ]; then
+ info "Retiring jcode server(s) from the previous install (pids: $pids)"
+ # shellcheck disable=SC2086
+ kill -TERM $pids 2>/dev/null || true
+ for _ in 1 2 3 4 5 6 7 8 9 10; do
+ [ -z "$(pgrep -f "$builds_dir/" 2>/dev/null || true)" ] && break
+ sleep 0.3
+ done
+ pids="$(pgrep -f "$builds_dir/" 2>/dev/null || true)"
+ # shellcheck disable=SC2086
+ [ -n "$pids" ] && kill -KILL $pids 2>/dev/null || true
+ fi
+ rm -f "$sock" "$dbg" "$lock" 2>/dev/null || true
+}
@@ after the binary is installed + symlinks updated, before the Darwin xattr block @@
+# Retire a pre-upgrade daemon now that the new binary is in place.
+if [ -n "$EXISTING" ]; then
+ stop_running_daemon
+fijcode_runtime_dir() mirrors storage::runtime_dir() exactly, including the temp_dir()/jcode-<euid> fallback and the macOS $TMPDIR branch.
Note on (unknown) version (not a bug — for anyone else who trips on it)
The Linux x86_64 release reports v0.X.Y (unknown) because it's built in the manylinux2014 container where git rev-parse isn't available, so the cosmetic hash falls back to "unknown" (jcode-build-meta/build.rs). macOS builds natively and shows a real hash. The absence of a -dev suffix confirms it's a genuine JCODE_RELEASE_BUILD=1 release; the label has no bearing on the compiled code. Might be worth passing JCODE_BUILD_GIT_HASH=${{ github.sha }} in release.yml so Linux artifacts show the hash too — minor, but it'd avoid the "is my binary legit?" confusion.
Activity
fix(server): auto-reap stale sockets and add `jcode server stop` (#291)
fix(server): make "server has newer binary" directional, not channel-…
1jehuang commentedon May 31, 2026
Both gaps you identified have since been addressed in current code, and the issue text itself notes the underlying #277 fix (5fa0360) is sound.
install.sh now retires a running daemon on upgrade.
scripts/install.shhas an explicit block (commentedissue #291) that, after installing the new binary, runs"$reload_bin" server reloadto hand a running server onto the freshly installed version. It uses the graceful reload path (live headless/swarm sessions are handed to a newly-exec'd server rather than dropped) and only reloads when the running server is genuinely older. It is best-effort and skipped when no server is running / whenJCODE_SKIP_SERVER_RELOAD=1.Stale sockets are auto-reaped on launch.
reap_stale_socket_if_dead()lives incrates/jcode-app-core/src/server/socket.rsand is called from the launch/handoff paths (src/cli/dispatch.rs,src/cli/commands.rs). It only unlinks the socket pair + lock when the socket is provably dead (no live listener), then rebinds. There's also ajcode server stopsubcommand (src/cli/args.rs) for graceful, cross-platform daemon shutdown - the Option A direction you suggested.This closely matches the "Option A (binary-side)" + installer retirement you proposed. The
(unknown)version cosmetic note is a separate minor item and not blocking.Thanks for the thorough writeup and candidate patch. If you still hit a wedged connect-retry loop on a current build after an upgrade, please reopen with
jcode --versionandjcode debug listoutput.fix(#291): add graceful `jcode server reload` and wire installers to it
release: v0.18.0
fix(#295): client-side detection of stale pre-self-heal servers
fix(server): auto-reap stale sockets and add `jcode server stop` (1je…
fix(server): make "server has newer binary" directional, not channel-…
fix(1jehuang#291): add graceful `jcode server reload` and wire instal…
release: v0.18.0
fix(1jehuang#295): client-side detection of stale pre-self-heal servers
fix(server): auto-reap stale sockets and add `jcode server stop` (1je…
fix(server): make "server has newer binary" directional, not channel-…
fix(1jehuang#291): add graceful `jcode server reload` and wire instal…
release: v0.18.0
fix(1jehuang#295): client-side detection of stale pre-self-heal servers