Repository navigation
feat: start OpenCode delivery in role MCP lifecycle - #80
Conversation
OBenner
left a comment
There was a problem hiding this comment.
Ревью dev — принять. Прочитал по коду в review-worktree (f110a34), не только по описанию.
Контракт arch (пункты 1–5) — соответствует дословно:
ownership: "exclusive"— опционально; атомарный отказ внутриwrite()-транзакцииSessionStore.registerпри непросроченном lease, ВКЛЮЧАЯ тот же sessionId (проверка идёт первой, до same-session ветки). Просроченный lease пропускает. ✓- Фикс серверный, в существующей транзакции — клиентских pre-check нет. ✓
- MCP child регистрируется с
ownership:"exclusive"+ surfaceopencode-mcp(отличим от ручногоopencodeв аудите); manual CLI — без флага. ✓ - Takeover:
UNAUTHORIZEDв heartbeat →revoked=true, abort,onUnauthorized→ lifecycle single-flight stop, auto-re-register запрещён (проверкиrevoked/blockedво всех точках входа: start/ping/currentState/submitDelivery). ✓ closeSchema += optional generation, fencing через существующийobserve; stale close глотается (UNAUTHORIZED/NOT_FOUND) — ребёнок не закроет successor'а. ✓
Отдельно отмечу:
- Регистрация в
runOpenCodeAdapterсверяет project/agentId/sessionId ответа с конфигом — защита от молчаливого mismatch, сверх контракта, хорошо. - Диагностика старта сознательно не выводит raw host error text (может содержать service credentials) — правильная паранойя.
- Ограничение «немедленный рестарт при непросроченном lease fail-closed до 15 с» — задокументировано, приемлемо для v1.
- Doctor:
openCodeRegistrationsиз полного аудита с честной пометкой «исторический факт, не текущий liveness» — корректно.
CI 3/3. Передаю arch на wire-хунк (src/transport/http-{client,server}.ts, src/storage/session-store.ts), затем CTO. Live-окно по docs/testing/opencode-mcp-sidecar.md — отдельным шагом после мержа.
OBenner
left a comment
There was a problem hiding this comment.
Wire review (arch, scope: http-client.ts / http-server.ts / session-store.ts registration+close hunks only):
Verdict: accept. Verified against the agreed contract:
registerSchema += ownership: z.literal("exclusive").optional()andcloseSchema += generation optional— additive optional fields, both schemas stay.strict(). Backward compatible in the old-client → new-server direction (absent fields = old behavior). Same change class assurfacein #54; adapter-facing API, protocol v1 envelope untouched.- Exclusive lease check sits inside the
withTransactionwrite inSessionStore.register— the check and the generation update are atomic, as required. Client-side pre-check is correctly absent. - Semantics match the contract exactly: exclusive + unexpired lease →
DUPLICATE_SESSIONincluding same sessionId; expired lease = dead owner, rebind allowed;replace: truebypasses the exclusive check, keeping replace-session as the escape hatch; the cross-role session-owner check stays unconditional. closenow forwardsgenerationintoobserve, so a stale child getsUNAUTHORIZEDon close — the takeover protection holds. Old clients omitting generation keep prior behavior (documented legacy gap).- Test hunk in
test/transport/http.test.tscovers the takeover matrix (stale close/heartbeat/exclusive re-register rejected, manual non-exclusive register succeeds and bumps generation) — exactly the right cases.
One non-blocking deployment note for the merge description: new MCP child (ownership: "exclusive") against an old relay will hard-fail on the strict schema (unknown field). In our single-dist contour this self-heals on relay restart and fails loud, which is acceptable — but worth one line in the PR body so nobody is surprised during a rolling update window.
(GitHub won't let this account self-approve since the PR is opened under the same account — recording as COMMENT; the wire verdict is ACCEPT.)
Generated OpenCode MCP channels previously started the relay and tools but no delivery runner. The role's MCP child now discovers the desktop endpoint and starts OpenCodeAdapter + HttpAdapterRunner after exclusive registration. Live manual sidecars win; takeover stops the child transport without re-registration, while MCP tools retain their writer checks.
The HTTP amendment for Architect review is isolated in
src/transport/http-{client,server}.tsandsrc/storage/session-store.ts: optional exclusive register and optional close generation. No message envelope, reason-code, constant, prompt API, or capability-flag changes. ADR 0003 is unchanged; ADR 0005 records composition A. This is an additive adapter-facing API amendment under v1 §9, as approved by arch/dev.Approved contract (verbatim, points 1–5)
ownership: "exclusive"(дефолт = текущее поведение). При exclusive — АТОМАРНЫЙ отказ на сервере, если по (project, agentId) есть владелец с непросроченным lease (lease_expires_at > now), ВКЛЮЧАЯ тот же sessionId. Просроченный lease = мёртвый владелец → регистрация разрешена (replace-session остаётся запасным перехватом).Behavior and limitations
openCodeRegistrationis historical, not current runtime liveness; normal lease/state/host fields remain relevant.docs/testing/opencode-mcp-sidecar.md. Codex/Claude implementation remains separate.Verification
pnpm install --frozen-lockfile: passed, no dependency/lockfile changes.pnpm verify: passed — format, import hygiene, typecheck, 89 test files / 797 tests, build.git diff --check: clean. Additional security documentation formatting check passed.Checklist
pnpm verifyis green (format + typecheck + tests + build).docs/security/threat-model.md.Refs #67. Review chain: dev → arch (HTTP amendment) → CTO. Live acceptance remains a separate gate.