Skip to content

Fleet prod OpenCode service is not the systemd unit's binary — unit restarts exit 0 without binding (incumbent defer) #8255

Closed

Description

@dezren39

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 a systemctl --user restart starts the new binary, which exits 0 after ~1.4s without binding port 13420 and without writing ~/.local/state/opencode/service-prod.json. Unit shows inactive (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.register only runs in onListen, 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

Fix shape (for the owning lane)

  1. 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.
  2. 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.
  3. Stop laptop-agent tooling from launching a competing --service instance (or make it launch through the unit), so the port cannot silently revert to a stale binary again.
  4. 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

  1. developing-today commented on Nov 10, 2026

    @developing-today
    Contributor
  2. added 2 commits that reference this issue on Nov 10, 2026
  3. dezren39 commented on Nov 10, 2026

    @dezren39
    MemberAuthor

    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 merged 25edc830 — code main flake.lock opencode rev is now 6a4793c059…. Watchdog build-identity check PR #8295 merged 6c154d20. A full home-manager generation build from this main is currently BLOCKED by an unrelated failure: atlas-core test target shards fails to compile (E0063) inside home-manager-path — the opencode packages themselves built fine (opencode-2.0.30+6a4793c + -wrapped are in the store).

    Deploy attempt + new contest (honest): the unit file was repointed to the evaluated 6a4793c wrapped package (the derivation nix eval resolves 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.

  4. dezren39 commented on Nov 10, 2026

    @dezren39
    MemberAuthor

    Acceptance — the fixed build is on the seat and holding (switch lane, 2026-11-10 ~22:48Z)

    Final state (wire): unit opencode.service active, MainPID 3478388 (since 22:42:22Z), exe …-opencode-2.0.30+6a4793c/bin/opencode — the exact package nix eval resolves for the unit's ExecStart on code main after pin PR #8308 (flake.lock rev 6a4793c059…). Registration service-prod.json = pid 3478388 / 2.0.30+6a4793c. The fastlane drop-in is removed; the unit file itself carries the pinned build. No other serve --service process exists besides the two known Nov 6 1add729 test 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:

    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-core shards test compile failure (E0063) inside home-manager-path — the opencode/watchdog derivations themselves evaluate and the opencode packages build. Filed on the record here rather than silently pending.

  5. dezren39 commented on Nov 10, 2026

    @dezren39
    MemberAuthor

    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):

    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 shards test compile failure; (2) hardening clients to refuse ensure() on unit-owned channels is a fork design question for a follow-up, not shipped here.

  6. dezren39 commented on Nov 10, 2026

    @dezren39
    MemberAuthor

    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:

    • The fork already implements systemd socket activation (fd 3 via LISTEN_PID/LISTEN_FDS, 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 no opencode.socket unit exists.
    • Smallest change: add opencode.socket (ListenStream=127.0.0.1:13420) + socket-activated Type=notify service. Zero server code changes. The adopting restart is the last die-and-rebind restart.
    • Survival: (a) port never closes — yes; (b) established connections — yes, within the drain; (c) streaming — the stream still ends at process exit (code is explicit: drains don't wait for open-ended event streams) and the client reconnects; the session survives (server-side state — proven across every handover on 2026-11-10). Full (c) needs a stream-resumability protocol; that's the floor.
    • Recommendation: adopt socket activation as the follow-up deploy step to this issue's fix — it makes "changed code → port handed over" literal, and removes the rebind prize from any future rogue contender.
  7. added a commit that references this issue on Nov 10, 2026
  8. dezren39 commented on Nov 11, 2026

    @dezren39
    MemberAuthor

    Addendum: socket activation adopted + changed-build switch proven (2026-11-11)

    Full evidence is on #8261, comment 6784017786. Summary of the proof numbers:

    • Socket activation adopted for the prod seat: opencode.socket owns 127.0.0.1:13420 (ListenStream=127.0.0.1:13420); opencode.service is Type=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.
    • Same-build proof restart: 0.88s, MainPID 53746 -> 62542, zero new failed probes — no refused window.
    • Real changed-build switch under Drew's spec: pin advanced 6a4793c -> fork main 01148f78 via 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.
    • Sessions: baseline 15,597 ids before adoption; after adoption 15,694; after the same-build proof 15,696; after the changed-build switch 15,734 — baseline-missing = 0 at every step.
    • Drain (honest floor): each restart logged the bounded drain with requests=0; running sessions were interrupted at the stream level only (no in-flight HTTP requests existed to drain). Sessions are server-side state and all survived. Full stream resumability remains the known level-(c) floor.
    • Fork id: design: hosted provisioning + SSO→ID binding spec — account/binding records, challenge ceremony, delayed rebind, metering, export (from #2045) #2258 (classify-then-act) was already merged (2026-11-10T21:38:16Z, 6a4793c059) and deployed as the incumbent build before this work began.
  9. dezren39 commented on Nov 16, 2026

    @dezren39
    MemberAuthor

    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.service fails (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).
    • Restart churn: 16:01:15 exit (1.4s CPU), 16:05:21 start → 16:05:23 exit status=130, 16:05:24 start, 16:08:56 start, 16:09:16 start → 16:09:19 server listening on http://127.0.0.1:13420 (PID 3193272). Next exit 16:21:27 (status=130), i.e. just after the questioned window.
    • 16:05–16:09 is the ~8-minute dark interval inside the window. No OOM-killer or systemd-oomd journal 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.sh shows acked: 0 with three repos coalesced_pending at 15:58:35 and 16:03:34, then {"events": 37, "fetched": ["developing-today/code", "dezren39/hatch-personal", "dezren39/openclaw-personal"], "failed": [], "dropped_foreign": 0, "acked": 37} at 16: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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions