reshape ensure seam + hardened lifecycle body (#376) #390

Closed
opened 2026-07-19 10:33:00 +02:00 by dries · 0 comments
Owner

Parent

#388 (spec), #376. Spec AD-2, AD-6, AD-8, AD-9.

What to build

Wire the ocruntime.Runtime into the host lifecycle and reshape the ensure seam so all callers get a reachable endpoint + opaque instance instead of a discovered port + tmux name. Registry persistence is a later ticket — this ticket may keep an in-memory map so it can land green.

  • Reshape EnsureProjectOpencodeResult to {Endpoint (full URL), RepoRoot, Runtime (ocruntime.Instance), Launched}. tmux session becomes Runtime.ID observability. Provide a Port() accessor for callers that still need the raw port.
  • local.Host holds an injected ocruntime.Runtime (default native) + a singleflight.Group.
  • EnsureProjectOpencode body: allocate free port → singleflight(repoRoot) → check current instance + Probe → healthy: return it, launch nothing → unhealthy/absent: Runtime.Launch(spec) → wait-for-Probe (reuse existing portWait budget) → return endpoint + instance.
  • Add HostCaps.OpencodeLaunch distinct from Tmux; surface via /api/capabilities.
  • Update all callers (worktree session create, MCP ProjectOpencodeEnsurer, tmux-UI launch, remote host + stubs) to the reshaped result. They stay behaviorally green.

Acceptance criteria

  • Concurrent ensure calls for one repo root launch at most one instance; all callers get the same healthy endpoint.
  • Sequential ensure reuses the healthy instance (launches nothing).
  • Manual (tmux UI) and automatic (worktree/MCP) paths cannot create competing managed instances (both route through the guarded ensure).
  • A stale/dead instance (Probe false) does not suppress relaunch.
  • Launch returns a reachable Endpoint + opaque Instance; managed path no longer depends on lsof.
  • Health verifies the OpenCode API (Probe), not listener presence.
  • HostCaps.OpencodeLaunch is reported independently of Tmux.
  • Existing tmux native behavior unchanged; all callers compile and pass. Tests: concurrency, reuse, stale-relaunch, health-timeout at the host seam.

Blocked by

  • #389 (ocruntime package + native runtime)
## Parent #388 (spec), #376. Spec AD-2, AD-6, AD-8, AD-9. ## What to build Wire the `ocruntime.Runtime` into the host lifecycle and reshape the ensure seam so all callers get a reachable endpoint + opaque instance instead of a discovered port + tmux name. Registry persistence is a later ticket — this ticket may keep an in-memory map so it can land green. - Reshape `EnsureProjectOpencodeResult` to `{Endpoint (full URL), RepoRoot, Runtime (ocruntime.Instance), Launched}`. tmux session becomes `Runtime.ID` observability. Provide a `Port()` accessor for callers that still need the raw port. - `local.Host` holds an injected `ocruntime.Runtime` (default native) + a `singleflight.Group`. - `EnsureProjectOpencode` body: allocate free port → `singleflight(repoRoot)` → check current instance + `Probe` → healthy: return it, launch nothing → unhealthy/absent: `Runtime.Launch(spec)` → wait-for-`Probe` (reuse existing portWait budget) → return endpoint + instance. - Add `HostCaps.OpencodeLaunch` distinct from `Tmux`; surface via `/api/capabilities`. - Update all callers (worktree session create, MCP `ProjectOpencodeEnsurer`, tmux-UI launch, remote host + stubs) to the reshaped result. They stay behaviorally green. ## Acceptance criteria - [ ] Concurrent ensure calls for one repo root launch at most one instance; all callers get the same healthy endpoint. - [ ] Sequential ensure reuses the healthy instance (launches nothing). - [ ] Manual (tmux UI) and automatic (worktree/MCP) paths cannot create competing managed instances (both route through the guarded ensure). - [ ] A stale/dead instance (Probe false) does not suppress relaunch. - [ ] Launch returns a reachable `Endpoint` + opaque `Instance`; managed path no longer depends on `lsof`. - [ ] Health verifies the OpenCode API (`Probe`), not listener presence. - [ ] `HostCaps.OpencodeLaunch` is reported independently of `Tmux`. - [ ] Existing tmux native behavior unchanged; all callers compile and pass. Tests: concurrency, reuse, stale-relaunch, health-timeout at the host seam. ## Blocked by - #389 (ocruntime package + native runtime)
dries closed this issue 2026-07-19 18:10:58 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
dries/ocman#390
No description provided.