Repository navigation
Closed
Labels
Description
Fleet prod OpenCode service is not the systemd unit's binary — unit restarts exit 0 without binding
Found 2026-11-10 ~14:48 CST during the code#8086 generation-555 switch (fork pin fafff70).
What is true on the wire (all verified on the laptop, host amd)
- The systemd user unit
opencode.service(home-manager managed) points at the current generation's wrapped binary and its ExecStartPre (env-key materialize) succeeds, but asystemctl --user restartstarts the new binary, which exits 0 after ~1.4s without binding port 13420 and without writing~/.local/state/opencode/service-prod.json. Unit showsinactive (dead), MainPID 0. Restart=on-failure does not retry (exit 0). - Port 13420 is instead held by pid 2374724, binary
/nix/store/dbi4bx5zd06x172m82534xpwq4ddfdsc-opencode-2.0.30+8ed9d6c/bin/.opencode-wrapped— fork main as of 2026-11-08 (generation 548's build). Its parent chain: pid 1059342/run/current-system/sw/bin/opencode(started Sun Nov 8 15:55:50) → parent pid 1059341 → laptop-agent.service (the resident fleet execution agent, code#5343). So the production server was (re)launched by laptop-agent tooling on Nov 8 under the then-current system profile, and that instance has owned the port since 2026-11-10 14:32:17 CST (its own start; service-prod.json id ee5fd03f, version 2.0.30+8ed9d6c). - That 8ed9d6c instance is healthy and serving the fleet: it holds the live
~/.local/share/opencode/opencode.db(fd + fresh WAL writes), route_attempt rows advancing in real time. It predates BOTH the docs(id): match audit investigation — netcode log format, replay validation, cheating signals (#2038) #2252 plant (c43145b) and the feed-stamp fix (fafff70). - The managed-service code path explains the unit's exit:
packages/cli/src/server-process.ts— in service mode,Service.incumbent(...)checks whether a registered service already answers at the URL; if an incumbent exists, the new process returns silently (exit 0) without registering or binding.ServiceRegistration.registeronly runs inonListen, i.e. only for the process that actually binds. - Consequence for the previous switch: generation 554's activation (2026-11-10 17:30:44Z) restarted the unit, the c43145b binary likewise deferred to the incumbent, and the recorded "running server 2.0.30+c43145b pid 1487125" was a transient process, not the port owner. The port owner before 14:32 CST today is unidentified; pid 1487125 no longer exists. A full process sweep at 14:47 CST shows no c43145b and no fafff70 opencode process running (only 8ed9d6c ×3 incl. children, ff9858a ×1, 4b2fc8a cockpit daemon, two stale 1add729).
- The watchdog (
opencode-watchdog.service, code#7780) sees the port serving and the unit state does not trip it, so nothing alerts: the fleet has been running a two-generations-old server while generations 554/555 reported switched.
Impact
- Every generation switch since the laptop-agent instance took the port has been a no-op for the actual fleet server. Route/telemetry evidence gathered "post-switch" in that window describes the 8ed9d6c binary (which contains fork mcpx testing: inventory every feature against its integration tests, and guard that each has one #1978's release and per-model skips, but NOT docs(id): match audit investigation — netcode log format, replay validation, cheating signals (#2038) #2252's gathered plant and NOT the feed-stamp fix).
- The cline-pass credential bench lapses ~2026-11-11; the gathered plant (the only pre-attempt hold for that leg once the bench lapses) is not in the running binary until the port actually changes hands.
Fix shape (for the owning lane)
- Make the switch procedure verify the PORT OWNER's binary path + service-prod.json version/pid after restart, not the unit's ExecStart or a transient pid.
- Decide the takeover path: gracefully stop the incumbent (its registration shutdown hook) or kill the laptop-agent-spawned instance, then start the unit so the new binary binds and registers. Sessions in flight on the incumbent are the consideration — pick a natural break or accept the restart the unit restart already implies.
- Stop laptop-agent tooling from launching a competing
--serviceinstance (or make it launch through the unit), so the port cannot silently revert to a stale binary again. - Consider making the incumbent-defer path log loudly / exit non-zero when the incumbent's version differs from the starter's, so a version-mismatched defer can never pass as a successful switch.
Evidence gathered during code#8086 follow-up lane, 2026-11-10.
Activity
developing-today commentedon Nov 10, 2026
CODE-2453
Merge pull request #8308 from developing-today/chore/8255-opencode-pi…
Merge pull request #8295 from developing-today/fix/8255-watchdog-buil…
dezren39 commentedon Nov 10, 2026
Cycle stopped; deploy of the fixed build re-contested — state at 22:28Z (switch lane, live)
Cycle: STOPPED. The churning minder sampled 22:00–22:07Z was driven by the Nov 8 system-profile client pid 133699 (alive since Nov 8 20:11Z) re-seating its own vintage via
ensure()whenever the unit left the port (final round: it spawned 8ed9d6c pid 3169640 at 22:05:23Z after the unit's starts at 16:05:21/16:05:24 CST exited 130; by 22:08Z the unit was dead and 8ed9d6c held 13420). SIGTERM was not honored; SIGKILL to 133699 + 3169640, then a unit start. Proof: pid 3193272 (3497ea2, unit MainPID) held 13420 continuously 22:09:42Z → 22:21:40Z with attempts flowing (post-22:11 max gap 28s). Evidence on #8261 (comment 6780837598).Machinery landed: fork PR #2258 (takeover fix) merged
6a4793c0; pin PR #8308 merged25edc830— code mainflake.lockopencode rev is now6a4793c059…. Watchdog build-identity check PR #8295 merged6c154d20. A full home-manager generation build from this main is currently BLOCKED by an unrelated failure:atlas-coretest targetshardsfails to compile (E0063) insidehome-manager-path— the opencode packages themselves built fine (opencode-2.0.30+6a4793c+-wrappedare in the store).Deploy attempt + new contest (honest): the unit file was repointed to the evaluated 6a4793c wrapped package (the derivation
nix evalresolves for the unit's ExecStart on current code main) and the fastlane drop-in removed, then the unit restarted at 22:21:40Z. The new build did take and register the seat (registration +/api/info=2.0.30+6a4793c, pid 3263149) — but a SECOND stale client, pid 3377477 (another Nov 8 system-profile client, parent shell 3377476), had already re-seated ff9858a pid 3259487, and the fight continued: the unit server exited 130 at 22:22:46Z (systemd auto-restart seated 3270691 cleanly), the ff9858a was killed with its supervisor at ~22:22Z, and at 22:26:54Z a THIRD actor appeared — the just-finished build-8260 lane's activation (system-path link landed 22:26Z) — whose client pid 3344136 (cb3968e binary) seated cb3968e pid 3349436, which holds the port at this minute while the unit's 6a4793c contender (MainPID 3360314, third auto-restart) waits on the addressInUse backstop.Root pattern, now three times in one evening: any long-lived client process on an old binary acts as a shadow supervisor for the prod seat — killing them one at a time is whack-a-mole while other lanes keep spawning/activating clients. This is #8261's defect class, and the fork fix only disciplines starts that reach the binary; already-running old clients are outside its reach. The switch lane is coordinating the endgame with the concurrently-deploying lanes rather than fighting them for the seat; the acceptance numbers (session continuity, attempt gap) will be posted when the seat settles on the pinned build.
dezren39 commentedon Nov 10, 2026
Acceptance — the fixed build is on the seat and holding (switch lane, 2026-11-10 ~22:48Z)
Final state (wire): unit
opencode.serviceactive, MainPID 3478388 (since 22:42:22Z), exe…-opencode-2.0.30+6a4793c/bin/opencode— the exact packagenix evalresolves for the unit's ExecStart on code main after pin PR #8308 (flake.lockrev6a4793c059…). Registrationservice-prod.json= pid 3478388 /2.0.30+6a4793c. The fastlane drop-in is removed; the unit file itself carries the pinned build. No otherserve --serviceprocess exists besides the two known Nov 61add729test servers (ports 13498/13499, never the prod seat).How the seat settled (the fight, resolved): after the 22:21:40Z restart, the seat was contested by two more shadow supervisors — a second Nov 8 system-profile client (pid 3377477 → ff9858a) and the build-8260 lane's activation client (pid 3344136 → cb3968e, seated 22:26:56Z). Both supervisors were killed; the unit's own contender (started 22:27Z) then won the port from the addressInUse backstop the moment the cb3968e seat exited, and has held it since 22:28:37Z (first as pid 3360314, then across a deliberate same-build restart as 3478388 — see the no-op proof below). No supervisor remains to re-seat an old build: three distinct stale clients (Nov 8 ×2, build-8260's) were the entire population found; each is dead.
Drew's acceptance, both cases:
systemctl --user restart opencode.serviceon the SAME build (6a4793c → 6a4793c) at ~22:42Z: new pid 3478388 bound and registered the same version; worst attempt gap across it 54s (vs pm-dispatch sessions never advance after a prod OpenCode service restart — attempts freeze while service stays up #8257's ~14-minute freeze); 97 of 97 sessions active in the 30 min before the restart attempted again in the window after it — continuity 100% at the attempt level.Floor, stated plainly: the fork fix (PR #2258) disciplines deliberate starts and makes a stale build a takeover target; it cannot reach clients that are ALREADY running — an old client process is a standing shadow supervisor until it dies or is killed. Killing the three found today is the blunt half; the watchdog's build-identity check (PR #8295, merged) is what makes any future wrong-build seat loud within its grace window instead of silent for days. A further hardening — clients refusing to
ensure()a seat for a channel owned by a systemd unit — is a fork design question, not shipped here.Watchdog note: PR #8295's expectedVersion wiring activates with the next successful home-manager generation; the generation build is currently blocked by the unrelated
atlas-coreshardstest compile failure (E0063) insidehome-manager-path— the opencode/watchdog derivations themselves evaluate and the opencode packages build. Filed on the record here rather than silently pending.dezren39 commentedon Nov 10, 2026
Lane close-out (the closing comment raced with an earlier close — recorded here instead)
Drew's acceptance met on the wire for both cases, with the floor stated on the record (comment 6781448345):
2.0.30+6a4793ctook the seat from 3497ea2 and held it (unit-owned; registration +/api/infoagree); the transition's worst gaps (257s/353s) were the shadow-supervisor fight — that actor class is dead (see Shadow supervisor (pid 1059342, stale system profile) respawns prod OpenCode service within seconds of any stop — port version decided by rebind race #8261, closed) and now trips the watchdog's build-identity alert (PR fix(watchdog): alert when a wrong build holds the opencode port (#8255) #8295) instead of sitting silently.flake.lock== running build ==6a4793c059…(PR chore(flake): opencode pin -> 6a4793c0 (service takeover fix, #8255) #8308); fastlane drop-in removed.Open residuals, deliberately not blocking: (1) the watchdog's expectedVersion wiring activates with the next home-manager generation — the generation build is blocked by the unrelated atlas-core
shardstest compile failure; (2) hardening clients to refuseensure()on unit-owned channels is a fork design question for a follow-up, not shipped here.dezren39 commentedon Nov 10, 2026
Addendum — true port handover is available in this codebase (Drew's 2026-11-10 follow-up)
Drew asked whether service restarts can pass the port over (socket handover) so clients don't die. Full analysis with the per-death attribution is on #8261 (comment 6781597758); the design conclusion for this issue:
packages/cli/src/systemd.ts), sd_notify readiness, a shared-socket-aware listener (packages/server/src/inherited-socket.ts), and a bounded drain (in-flight requests finish; 30s default grace). No deployment layer uses any of it — the unit binds the port itself and noopencode.socketunit exists.opencode.socket(ListenStream=127.0.0.1:13420) + socket-activatedType=notifyservice. Zero server code changes. The adopting restart is the last die-and-rebind restart.Merge pull request #8343 from developing-today/fix/8255-watchdog-vers…
dezren39 commentedon Nov 11, 2026
Addendum: socket activation adopted + changed-build switch proven (2026-11-11)
Full evidence is on #8261, comment 6784017786. Summary of the proof numbers:
opencode.socketowns127.0.0.1:13420(ListenStream=127.0.0.1:13420);opencode.serviceisType=notify+Requires=opencode.socket. Zero server code changes. The adopting restart (2026-11-11T00:07:55Z) was the last die-and-rebind: probe recorded a 3.11s refused window (31 failed probes), then the listener moved to the process's inherited fd 3.6a4793c-> fork main01148f78via code PR flake: pin opencode to fork main 01148f78 (socket-activation switch proof, code#8255) #8372 (the opencode pin bump), merged 2026-11-11T00:51:14Z (999b41828f10). Unit ExecStart repointed to the new wrapped build (72ghrggn...-opencode-2.0.30+01148f7-wrapped), restart T0 00:54:10.395Z, returned 00:54:22.218Z. MainPID 62542 -> 480147; build 2.0.30+6a4793c -> 2.0.30+01148f7; listener on fd 3 throughout. Continuous probe (4,150 connects over 420s): zero failures — no refused window across a build change.6a4793c059) and deployed as the incumbent build before this work began.dezren39 commentedon Nov 16, 2026
Findings (task 17438, lane code-i, 2026-11-16): Nov-10 laptop OpenCode server stop/start ~21:56–22:18Z — journal evidence recovered.
Source: archived systemd journal on this laptop, directory
fc4a5f60cc444920908d44566a9bbfe2(the current boot journal does NOT cover 2026-11-10; the archived directory does). All times below are America/Chicago (UTC-6) as journaled, with UTC in parentheses.(1) What stopped and started the server.
15:59:37—pm-git-sync.servicefails (exit 1); unrelated to the server.16:01:05(22:01:05Z) —opencode.service: Main process exited, code=killed, status=9/KILL;Failed with result 'signal';Consumed 22min 57.204s CPU time over 58min 10.981s wall clock, 14.6G memory peak, 1G memory swap peak. That is an out-of-band SIGKILL of the standing server, not a clean stop.16:01:05—Scheduled restart job, restart counter is at 1;16:01:06—Started OpenCode server (standing, --service).16:01:15exit (1.4s CPU),16:05:21start →16:05:23exitstatus=130,16:05:24start,16:08:56start,16:09:16start →16:09:19server listening on http://127.0.0.1:13420(PID 3193272). Next exit16:21:27(status=130), i.e. just after the questioned window.16:05–16:09is the ~8-minute dark interval inside the window. No OOM-killer orsystemd-oomdjournal line appears in the window — the SIGKILL sender is not attributed in the journal; the OpenCode watchdog ran every 60s and only restarts after 120s dark, and here systemd itself had already scheduled the restart.(2) Handover ran or was bypassed. No handover unit, script, or log line appears anywhere in the window: bypassed/not-run. The only coordinated-drain component that ran was
drain-wrapper.sh.(3) Sessions/jobs dropped. The SIGKILL terminated the whole service cgroup, so every in-flight session in that instance was dropped — the journal carries no per-session shutdown record, so the exact live-session count at kill time is not recoverable from this evidence. Queue work was not lost:
drain-wrapper.shshowsacked: 0with three reposcoalesced_pendingat15:58:35and16:03:34, then{"events": 37, "fetched": ["developing-today/code", "dezren39/hatch-personal", "dezren39/openclaw-personal"], "failed": [], "dropped_foreign": 0, "acked": 37}at16:09:08— the outbox drained after the restart with zero failed and zero dropped_foreign.Related: #8261 (respawn/rebind races — the restart churn above), #8257 (sessions freezing after a restart), #8264 (stale binary served by the unit), #8255.