Skip to content

opencode handover not in effect: socket unit disabled, same-build switch darkened port ~16s and cut drain at 40ms (2026-11-16) #10639

Open

Description

@dezren39

Defect: OpenCode server handover is not in effect on the laptop — socket unit disabled, same-build switch darkened the port ~16s and cut the drain at 40ms

Drew's standing design: a server switch/restart passes the port and sessions over without dropping anything; a same-code switch needs no restart at all. Measured live during the 2026-11-16 agy 1.5.9 system switch (nixos-rebuild switch, SWITCH_EXIT=0, system generation 558 → 559):

Evidence (all 2026-11-16, UTC)

  • The opencode build did not change in this switch: 2.0.30+5b65c2a, store path bdkm7bd1gbx4i0cmk92zrzwc5x16ms00-opencode-2.0.30+5b65c2a before and after. The service restarted anyway: pid 967757 → 3365330, new instance start 08:24:14Z.
  • A 2-second-interval probe of http://127.0.0.1:13420/api/config across the switch recorded the port refused from 08:23:58Z through 08:24:12Z, answering again at 08:24:14Z — ~16 seconds dark (479 healthy samples vs 8 refused in the run).
  • Server log, old instance: 08:23:57.964Z draining running sessions and requests sessions=["ses_e5e1c9ad3c3ffeWx7ITHH5v49w","ses_e5e1c8eefd0ffehalIMX1R225d"] requests=0 grace=30000 — then 40ms later, 08:23:58.004Z shutdown ended with sessions or requests still running; interrupting them. The announced 30s drain grace was not honored; something ended the drain almost immediately (the fork's drain ends early on a second termination signal — source of the second signal not yet identified).
  • opencode.socket: ActiveState=inactive, UnitFileState=disabled; the 13420 listener is owned by the server process itself (ss: pid 3365330, fd 8). Socket activation is not in effect, which contradicts the 2026-11-11 follow-up on Shadow supervisor (pid 1059342, stale system profile) respawns prod OpenCode service within seconds of any stop — port version decided by rebind race #8261 recording socket activation as adopted after the 2026-11-10 cascade. Either the adoption regressed or it never landed in the deployed unit set.

Impact today: interruption, not loss

  • Session store intact: session_v2 held 22,937 ids before the switch; after: 0 lost, 26 gained.
  • Both interrupted sessions were re-warmed by the new instance (scheduled session warming 08:24:19Z) and produced successful route attempts from 08:24:20Z; the conductor's 08:25Z sweep lists both as progressing with 0 errors. No job permanently failed.
  • But the guarantee Drew specified does not hold: the port went dark and in-flight turns were interrupted on a switch that changed nothing about the server.

Fix asks

  1. Enable opencode.socket so the port survives process swaps (or establish why the Nov 11 adoption did not stick and close that gap).
  2. Find and remove the second-signal source that cuts the drain; the 30s grace must be honored.
  3. Skip restarting the opencode service when the build/store path is unchanged across a switch.

Refs: #8261 (2026-11-10 cascade; adoption claim), #1822 (socket activation audit), #8255 (incumbent-defer cutover).

Acceptance criteria

  • The opencode handover failure mode named in the title (socket unit disabled, same-build switch darkening the port and cutting drain) is fixed or explicitly dispositioned, with a live handover probe demonstrating the corrected behaviour recorded here.
  • Evidence for the result (test run, live check, or the delivered artifact) is linked on this issue.
  • Follow-on work, if any remains, is filed as its own issue and linked here.

Activity

  1. developing-today commented on Nov 16, 2026

    @developing-today
    Contributor
  2. dezren39 commented on Nov 16, 2026

    @dezren39
    MemberAuthor

    Read-only comparison on amd: neither generation 558 nor 559 declares opencode.socket or its sockets.target.wants link in the generated Home Manager unit set. The live socket is a regular file dating to Nov 10, with no enablement link; it was inactive and disabled at 08:42Z. The live service is a generation-managed symlink replaced at 08:23:57Z. Its generated unit differs between 558 and 559: ExecStart is unchanged, but ExecStartPre points at a different store derivation. The journal independently shows systemd stopping and starting the service at that boundary. This is a concrete activation lead, not proof of who disabled the socket or sent the second termination signal. For the fix, prove three independent invariants: an unrelated switch (including a helper-only diff) leaves the serving PID stable; a changed build inherits the declared socket across cutover; and the drain respects its configured grace without an accidental second signal. Electrical TCP continuity and uninterrupted/resumable streams should be measured separately. No service or configuration changes made.

  3. dezren39 commented on Nov 16, 2026

    @dezren39
    MemberAuthor

    Findings: 2026-11-10 ~21:56–22:18Z prod OpenCode server window (left-on-the-ground half, reported 2026-11-16)

    Scope: what stopped/started the prod server (127.0.0.1:13420) in the window, whether the handover procedure ran, whether sessions/jobs were dropped. The agy-switch subagent pulled the journal for this but filed no report; this comment closes that half. All four linked issues (#8255, #8261, #8257, #8264) are CLOSED, so findings go here as the open handover successor.

    0. Journal verdict first: the journal no longer reaches 2026-11-10 — re-derivation from journal is impossible, no guessing done

    • journalctl --list-boots (system and --user): single boot 9d27c8dd, first entry 2026-11-14T18:13:38-06:00. Nothing earlier exists on this machine id (6f220f57…; other /var/log/journal/* dirs are stale foreign machine-ids, newest mtime Mar 2026).
    • journalctl --since 2026-11-10 --until 2026-11-11 → No entries. journalctl --user-unit opencode.service --since 2026-11-01 --until 2026-11-12 → No entries.
    • Shared server log ~/.local/share/opencode/log/opencode.log (50M) starts 2026-11-15T21:02:47Z. opencode-local.db.route_attempt holds 23 rows, ~Nov 14+. Both postdate the window.
    • Partial evidence that DOES still reach back: (a) the contemporaneous wire record on Shadow supervisor (pid 1059342, stale system profile) respawns prod OpenCode service within seconds of any stop — port version decided by rebind race #8261 (per-death attribution + cycle-stop comments, written 2026-11-10/11 while the journal reached back); (b) ~/.local/state/opencode/fastlane/state.json (activated_at 2026-11-10T20:57:44Z); (c) the main ledger ~/.local/share/opencode/opencode.db.route_attempt — 722,101 rows spanning 2026-10-24→today, queried read-only today (all timestamps below recomputed 2026-11-16, window = unix ms 1794347760000–1794349080000).

    1. What stopped and started the server in-window (from the surviving contemporaneous record, not re-derived)

    Per #8261's per-death table + cycle-stop comment (comment 6780837598), which cite the then-live user journal + server-log registration lines:

    • 21:56–22:00Z: attempts flowing, no gap ≥60s (ledger, recomputed today — only ≥60s gap near the window opens at 21:41:15Z). No stop/start in this slice in any surviving record.
    • ~22:00:36–22:01:05Z: unit seat 2586083/3497ea2 displaced by contender 3135375/ff9858a via registration flip, then SIGKILL (sender unrecorded, no OOM). Cascade of ~1 seat/min followed (ff9858a → c43145b → ff9858a → … → 8ed9d6c), matching the minder's 22:00–22:07Z churn sample.
    • 22:05:21Z: watchdog started the unit once after the port sat dark 121s (its designed reaction, not a cause).
    • ~22:08:5xZ: switch lane SIGTERM→SIGKILL to stale supervisor pid 133699 (Nov 8 system-profile client) + its seat 3169640/8ed9d6c, then systemctl --user start opencode.service → seat 3193272/3497ea2, held continuously 22:09:42Z, 22:13:42Z, 22:18:42Z, 22:19:49Z (~10 min, zero churn).
    • Initiators, plainly: (a) stale long-lived client processes' ensure()+stop escalation winning a rebind race (the dominant stopper); (b) the switch lane's deliberate kills + manual unit start (the stopper/starter that ended it); (c) watchdog (one start). Two SIGKILL senders remain unattributed in the surviving record (rows 1 and 9 of the table — row 9 is post-window).

    2. Handover: not in effect — die-and-rebind was the mechanism that night

    3. Sessions/jobs: attempt-level continuity 100%, in-flight rate collapsed mid-window, one in-memory job provably dropped

    Recomputed today from opencode.db.route_attempt (times UTC):

    Verdict

    Journal re-derivation: impossible (journal + server log + local ledger all postdate the window; stated exactly, not guessed). From surviving contemporaneous record + today's ledger recomputation: the 21:56–22:18Z window covers the tail of the stale-client rebind cascade (stopped by contender displacement, 381s attempt gap from ~22:00:45Z) and its deliberate end (lane SIGKILLs + manual unit start, 198s gap ending 22:11:29Z, then a stable seat). No handover procedure ran — none existed yet; die-and-rebind ruled. Sessions: 95/95 continuity at the attempt level; in-flight jobs (in-memory OAuth attempt begun 22:17:50Z) were dropped. Session store itself was never at risk (server-side state, none deleted).

  4. dezren39 commented on Nov 16, 2026

    @dezren39
    MemberAuthor

    Fleet-minder run580 evidence (2026-11-16 ~05:29–05:40 CST): the handover/self-heal gap bit again.

    • 05:29:37 CST: opencode.service main process exited code=killed status=9/KILL after consuming 58.2G memory peak (3h19m CPU over 2h44m wall). Cause of the SIGKILL not proven from the journal alone.
    • systemd scheduled a restart; the new unit start exited cleanly at 05:29:40 CST claiming "managed service version 2.0.30+5b65c2a is already running; this build is already current" — and the unit has stayed ActiveState=inactive/SubState=dead since (NRestarts=1, ExecMainStatus=0). service-prod.json was absent and port 13420 dark at 05:30–05:38 CST checks; all ~20 active sessions froze (attention feed flipped to needs-poke x60).
    • By ~05:39 CST a replacement opencode serve --service process (current-system 2.0.30 build, outside the systemd unit) was listening on 13420, the auth file was regenerated, and sessions resumed: active count 16 at 05:39Z recheck, 27 by 05:40Z, all advancing, no question-blocked.
    • Net fleet stall ~9 minutes. The persisting abnormal state: the systemd unit remains dead while the fleet runs on the replacement process — the exact handover-not-in-effect condition this issue names.

    Minder took no server action (report + file route per its charter). Related: #8729 (restart = dead server), #8777 (SIGTERM treated as clean, no self-heal).

  5. dezren39 commented on Nov 16, 2026

    @dezren39
    MemberAuthor

    Fleet-minder run586 evidence (2026-11-16 ~13:03-13:11Z): opencode.service main process SIGKILLed repeatedly — 06:58:01 CST (20.2G mem peak), 07:02:10, 07:03:18 CST; the 07:03:19 restart exited cleanly after 22s leaving the unit inactive/dead, service-prod.json absent, port 13420 dark. Watchdog (code#7780) grace window started 07:05:42 CST and restarted the unit 07:07:43 CST (listening 07:08:13), but the server was refusing connections again by 13:10:40Z under extreme laptop load: load average ~9,846, 7,127 processes, of which ~6,122 are pool.test (5,534 defunct + 588 live) plus 333 go / 56 compile — a runaway Go test binary is exhausting the laptop and the OpenCode server is collateral. laptop-agent broker path also failing (HTTP 502 RemoteDisconnected x3); minder fell back to real SSH. Census ACTIVE was already 0 at 13:03:46Z; attention feed is carrying last-good entries. This exceeds the run580 transient pattern: kill loop + external resource exhaustion, fleet-stalling while it persists.

  6. dezren39 commented on Nov 16, 2026

    @dezren39
    MemberAuthor

    Related evidence 2026-11-16 (pool lane): the standing server instance is being SIGKILLed on a ~25–35 min cycle today, consistent with the handover not draining — each kill is a hard cutover with a short dark window.

    • 08:45:50 CST: main process killed (status 9/KILL) after 41.8G memory peak, 2h29m CPU over 33m49s wall. systemd restart; launcher exited 0 with "managed service (pid 922860) is already running". route_attempt log gaps 08:44:02–08:46:58 CST.
    • 09:09:34 CST: killed again (status 9/KILL) after 17G memory peak, 1h16m CPU over 20m20s wall. Restart found pid 1095257 already running; that pid has since been replaced too (current server pid 1122972, serving on 127.0.0.1:13420, probe-verified via a routed workhorse session at ~09:16 CST).
    • The systemd unit reads inactive (dead) between events because its ExecStart is a launcher that hands off to the self-managed service and exits 0 — expected under this design, but it makes the churn invisible to unit-state monitoring.
    • The memory ballooning itself (a 2.0.30+5b65c2a instance reaching 17–42G RSS within ~30 min of start) needs a cause: leak vs the config-reload route-rebuild loop observed at 08:45:46 (the same four "resolve to no models" route warnings repeated ~10x in 2s during a reload).
  7. dezren39 commented on Nov 16, 2026

    @dezren39
    MemberAuthor

    Related evidence 2026-11-16 (later): the standing instance's quota path wedged while sessions stayed healthy.

    • From ~11:15 CST, quota-gatherer ticks failed repeatedly: opencode quota subcommand failed: Command failed: /run/current-system/sw/bin/opencode quota --json — the subcommand hung ~4 min per attempt (heartbeat durationMs 241601). quota-current.json froze at the 10:08 CST generation for ~1.5h.
    • The instance (pid 1122972, up since ~09:16 CST) was otherwise healthy: /api/config answered in 8ms (401), 243 route attempts in the prior 10 min, latest seconds before the check. A sampled hung subcommand process sat sleeping with no TCP sockets.
    • Fix applied live: SIGTERM to the instance + systemctl --user start opencode.service. On the fresh instance opencode quota --json completes, and a manually started gather tick refreshed quota-current.json at 11:37 CST (Meta weekly then read 92%).
    • Root cause of the quota-path wedge not pinned; noted here because it is the same instance-lifecycle surface: long-lived 2.0.30+5b65c2a instances degrade (balloon/OOM at 08:45 and 09:09; quota wedge by ~11:15 on the next instance).
  8. added
    kind/infrastructure
    task/small-fix
    priority/high
    effort/l
    on Nov 17, 2026
  9. dezren39 commented on Nov 17, 2026

    @dezren39
    MemberAuthor

    agent-note:v1
    state: triaged
    task: 19336 (repo-health-code-pilot, lane code-d)
    issue: #10639 — opencode handover not in effect: socket unit disabled, same-build switch darkened port ~16s and cut drain at 40ms (2026-11-16)

    Inline triage (issue was OPEN with no labels and no hard stops when claimed; fresh-verified 2026-11-17):

    • Work kind: task/small-fix. Kind: kind/infrastructure. Priority: priority/high — the OpenCode server is the fleet's primary work door and its specified handover guarantee does not hold; measured impact was interruption, not loss (0 of 22,937 sessions lost, both interrupted sessions recovered), so high rather than critical. Effort: effort/l — three fix asks spanning the darwin-nix unit declarations and the fork's drain/signal handling, each needing a live-switch proof. All four labels applied.
    • The defect is fully evidenced in the issue itself: same-build switch (generations 558 to 559, store path unchanged) restarted the service, port dark 08:23:58Z-08:24:12Z, 30s drain grace cut at ~40ms by an unidentified second signal; opencode.socket inactive/disabled and absent from both generations' generated unit sets (read-only comparison already posted on this issue).
    • First concrete step for the fix: evaluate a fresh generation's unit set for opencode.socket + its sockets.target.wants link, then trace the drain's second signal in the fork before changing either.
    • Acceptance: the issue's three invariants, proven live — unrelated switch leaves the serving PID stable; changed build inherits the declared socket across cutover; drain respects its configured grace with no second signal.
    • Follow-on: fix packet enqueued as task 20671 (repo-health-code-pilot, kind small_fix, priority 30; packet preserved at hidden_files/19336-fix-packet-10639.json in the goal workspace). The fix is a separate scoped packet because it needs live switch experiments on the laptop and PRs in two other repos; it does not belong inside this triage claim.

    Disposition: task 19336 completes as triaged with follow-on task 20671 named. Issue #10639 stays OPEN for the fix.

  10. dezren39 commented on Nov 18, 2026

    @dezren39
    MemberAuthor

    state: parked
    task: 20671 (repo-health-code-pilot, lane oc-code-03)
    issue: #10639 — opencode handover: socket unit, drain grace, no restart on unchanged build

    Fresh check 2026-11-18: issue OPEN, priority/high, effort/l. Three fix asks span the darwin-nix unit declarations and the fork drain/signal handling, each needing a live-switch proof. Too large for an unattended lane.

    Resume brief: implement the three asks in a dedicated session, with a live same-build switch proof per ask. Parked for that session; no packet filed here.

  11. dezren39 commented on Nov 18, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note — scheduled lane recheck; parked for dedicated live-switch work

  12. 52 remaining items

  13. developing-today-fleet commented on Nov 27, 2026

    @developing-today-fleet
    Contributor

    Lane 2107-H (charlie ADVANCE, 2026-11-26 21:07 CST) premise check: read issue + all 34 comments. Repo slices all merged (#12299 unchanged-build no-restart, #12781 socket + KillMode=process, #13678 deploy cutover helper); only the one-time live cutover + three live proofs remain (same-build PID stability, changed-build socket continuity, 30s drain with no second signal).

    Quiet-window condition is FALSE at this run: sibling lanes are actively running through opencode.service right now (queue task 26056 checkpoint diagnosing 2026-11-27T03:06Z, task 23803 claimed 03:02Z, this work-loop run spawning lanes). A cutover now would terminate active sessions — the exact harm this issue exists to prevent. No host change, no repo edits by this lane.

    Disposition: queue task 20671 PARKED by this lane (verified status=parked, parked 2026-11-27T03:20:12Z, not_before 2026-11-27T03:40:12Z; broker ready-condition recorded as external / quiet window). Full wake condition: no nix/home-manager builds running AND ~10min quiet window (no active OpenCode sessions, no established 127.0.0.1:13420 connections) AND executing session outside opencode.service cgroup; then detached cutover (stop service, start socket, start service) + the three live proofs.

  14. developing-today-fleet commented on Nov 27, 2026

    @developing-today-fleet
    Contributor

    Lane any-n, task 20671 — read-only preflight 2026-11-27 04:56 CST: live configuration has advanced: opencode.service is active, PID 2093774, KillMode=process; opencode.socket is active/enabled on 127.0.0.1:13420 and service reports TriggeredBy=opencode.socket. Laptop route is reachable; no build/deploy processes detected. There are 10 established server-side connections and this executor is inside opencode.service, so the existing quiet-window predicate is false. No host or source changes made. Parking on execution state, not owner approval. Still required: same-build serving-PID stability, changed-build socket continuity, and full 30-second drain without a second signal. Resume from a detached executor outside the service once the quiet-window predicate holds.

  15. developing-today-fleet commented on Nov 27, 2026

    @developing-today-fleet
    Contributor

    Lane oc-code-08, task 20671 — read-only probe 2026-11-27 ~07:45 CST, no host or source changes.

    Live: opencode.socket active/enabled since Nov 26 16:16 CST, Listen 127.0.0.1:13420; opencode.service active MainPID 4064432 since 06:31:49 CST, KillMode=process, TriggeredBy=opencode.socket. Repo declarations on main unchanged (X-RestartIfChanged=false, KillMode=process, sockets.opencode). Quiet window false: 26 established port-13420 connections, executor inside opencode.service cgroup, sibling lanes active — no cutover, no live proofs attempted.

    New second-signal evidence (journal, opencode.service, today):

    • 05:30:58 and 05:45:28: server logs 'received SIGTERM again during shutdown; exiting' — drain still cut.
    • 06:30:47: Main process exited code=killed status=9/KILL (explicit SIGKILL, not a timeout; TimeoutStopSec is 90s), followed by dozens of 'Unit process remains running' lines for lane-worker processes.
    • Unit has Restart=on-failure, NRestarts=14 and counting — the service is crash-restarting through the morning, each restart another drain cut for attached sessions.

    Candidate mechanism for the second SIGTERM, from home/common/opencode-deploy.sh: on a build-change activation it runs 'systemctl --user stop opencode.service' (SIGTERM 1, drain starts), starts the socket, then immediately 'systemctl --user restart opencode.service' (SIGTERM 2 via the restart stop phase, with no grace wait in between). If that stop/restart back-to-back survives, the 30s drain can never hold on a deploy path. Suggested fix direction: wait for the drain (poll for MainPID exit up to the grace) between stop and restart, or collapse stop+restart into a single start-or-restart after the socket owns the port.

    Still required: same-build PID stability, changed-build socket continuity, full 30s drain with no second signal — all need a quiet window with an executor outside opencode.service. Parking on execution state.

  16. added
    stray-work
    stray/needs-parent
    on Nov 27, 2026
  17. developing-today-fleet commented on Nov 27, 2026

    @developing-today-fleet
    Contributor

    Lane oc-code-05, task 20671 — read-only probe 2026-11-27 ~12:05 CST, no host or source changes. Fresh second-signal occurrence same day, exact log lines:

    • 11:56:07 CST: old MainPID 4033491 logged received SIGTERM again during shutdown; exiting with a child still pending (10.3s child 2200925 running: git ... diff-files --name-status), then Main process exited, code=exited, status=1/FAILURE.
    • systemd: Scheduled restart job, restart counter is at 18 (Restart=on-failure); new MainPID 2204279. Unclean termination left dozens of processes in the cgroup (Found left-over process ... while starting unit).
    • Live now: service active (PID 2204279, KillMode=process), socket active/enabled on 127.0.0.1:13420, but the listener is still server-owned (.opencode-wrapp fd, not systemd-held); 98 established :13420 connections; executor inside opencode.service.

    Cutover + acceptance proofs not attempted: quiet-window false (98 conns, executor in-service). Repo slices #12299 #12781 #13678 already merged; no source edits needed. Resume: quiet window, executor outside opencode.service, then detached cutover + 3 acceptance proofs.

  18. developing-today-fleet commented on Nov 29, 2026

    @developing-today-fleet
    Contributor

    Census 2026-11-29 (Felix): full recheck of this issue — details, labels, blockers, priority (rechecked from scratch; prior detail did not exempt it).

    STRENGTHS:

    GAPS FOUND:

    • no explicit acceptance criteria / checklist in the body
    • no concrete file/module pointers in the body

    FIXES I APPLIED:

    • none needed

    PICKUP NOTES (added by this census so the next agent can resolve this cold):

    REMAINS: nothing — ready for pickup

  19. added
    priority/high
    and removed
    priority/low
    on Nov 29, 2026
  20. added
    priority/normal
    and removed
    priority/high
    on Nov 29, 2026
  21. developing-today-fleet commented on Nov 29, 2026

    @developing-today-fleet
    Contributor

    Priority validation 2026-11-29 (Felix): priority/high → priority/normal — all repo slices are merged and live probes since 2026-11-26 show socket activation in effect (opencode.socket active/enabled, TriggeredBy present); the remainder is supervised switch-acceptance observation on the laptop — still a real drain risk to watch (2026-11-27 SIGTERM signal), so normal rather than low, but no longer time-sensitive lane work

  22. added
    area/infra
    on Nov 29, 2026
  23. developing-today-fleet commented on Nov 29, 2026

    @developing-today-fleet
    Contributor

    Issue census — 2026-11-29

    Wave-2 residual pass. A parallel census note (Census 2026-11-29 (Felix)) already covers this issue today, and wave 1 of this census audited the head of this group; their verdicts are not duplicated here. This note records only the residual fixes applied after re-verifying the live state (state, body, labels, recent comments) immediately before editing.

    Residual gaps found: no app/*/area/* label although the owning project is clear from the title/body; no acceptance-criteria section.

    Actions taken: labels added: area/infra; appended ## Acceptance criteria (original body text unchanged above it).

    Priority: priority/normal retained — matches the work's urgency as evidenced on the issue; no band change in this pass.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/infraeffort/lkind/infrastructurepriority/normalqueue/parkedstatus/parkedstray-workstray/needs-parenttask/small-fixwork/assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions