From dbe0ad1988f675a592b55b3fd74c33b3a4a2e992 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Sun, 22 Nov 2026 20:40:07 -0600 Subject: [PATCH 1/2] Enable socket activation for OpenCode handover --- home/common/default.nix | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/home/common/default.nix b/home/common/default.nix index 48383fdb8c..a3e589718d 100644 --- a/home/common/default.nix +++ b/home/common/default.nix @@ -7,6 +7,7 @@ ... }: let + opencodeServerPort = 13420; # Local proxy ports, each defined ONCE. Each value flows to the systemd # user service that binds it, to the shell session (_PROXY_PORT), # and — for the proxies opencode talks to — into opencode.jsonc's @@ -1173,6 +1174,17 @@ in # Home Manager still reloads the unit; the activation below owns build # changes explicitly, using only the serving package's store path as key. systemd.user.services.opencode.Unit."X-RestartIfChanged" = false; + # Keep the listening port outside the server process so it survives a + # service handover. The OpenCode fork adopts systemd's fd 3 via + # LISTEN_FDS/LISTEN_PID; the socket is enabled through sockets.target. + systemd.user.sockets.opencode = { + Unit.Description = "OpenCode server listener (handover-safe)"; + Socket = { + ListenStream = "127.0.0.1:${toString opencodeServerPort}"; + Service = "opencode.service"; + }; + Install.WantedBy = [ "sockets.target" ]; + }; home.activation.opencodeDeploy = lib.hm.dag.entryAfter [ "reloadSystemd" ] '' run ${pkgs.bash}/bin/bash ${./opencode-deploy.sh} \ '${opencodeCascade}' \ From 2d0442a3d600b9d2e96a4ea7cd2a234495a0819f Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Sun, 22 Nov 2026 22:03:22 -0600 Subject: [PATCH 2/2] fix(opencode): avoid duplicate drain signals from systemd --- home/common/default.nix | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/home/common/default.nix b/home/common/default.nix index a3e589718d..e4ec12c803 100644 --- a/home/common/default.nix +++ b/home/common/default.nix @@ -1174,6 +1174,12 @@ in # Home Manager still reloads the unit; the activation below owns build # changes explicitly, using only the serving package's store path as key. systemd.user.services.opencode.Unit."X-RestartIfChanged" = false; + # The package launcher forwards TERM from the systemd main process to the + # serving child. With the default control-group kill mode, systemd also + # signals that child directly, so one stop becomes two TERM deliveries and + # the fork's second-TERM drain escape ends the grace window early (#10639). + # Signal only the launcher; it forwards exactly one TERM to the child. + systemd.user.services.opencode.Service.KillMode = "process"; # Keep the listening port outside the server process so it survives a # service handover. The OpenCode fork adopts systemd's fd 3 via # LISTEN_FDS/LISTEN_PID; the socket is enabled through sockets.target.