Repository navigation
feat: surface failed OpenCode MCP servers in doctor (#92) - #128
Merged
Merged
Conversation
The OpenCode backend service outlives the desktop GUI and never retries a failed MCP server until the backend restarts — a role stays nudged-off with no visible reason. The last per-server state is readable from the backend log (<data-home>/opencode/log/opencode.log): "mcp connected" vs "mcp connect failed"/"mcp transport error" lines (shape verified against a live OpenCode Desktop 2.2.7 log). doctor now reads a bounded 256 KiB tail of that log (no host contact, so it works without --check-host) and reports per opencode-bound role: mcp: connected | failed | unknown in the hostCheck. A failed server gets a note with the exact recovery steps (tray quit / kill opencode-cli serve) and the child exit code when the log carries one. Sanitization: only server name, state, timestamp and a narrowly extracted exit code leave the parser — raw error payloads never do. Offline-safe: missing or unreadable log degrades to "unknown". Known limitation: the parser is tied to the observed log shape; a future OpenCode release renaming those messages would degrade reporting to "unknown" (never a false "failed").
OBenner
commented
Nov 17, 2026
OBenner
left a comment
Owner
Author
There was a problem hiding this comment.
Code review (dev → #92): APPROVE (оставлено COMMENT-формой: все PR в репо от одного аккаунта, само-APPROVE GitHub не даёт; вердикт положительный, к финалу CTO).
Проверено по диффу (a387a12):
- Parser корректен: latest-wins по хронологии хвоста, скоуп
synloq-*исключает чужие серверы, transport-error после connect = failed (правильная семантика для «бэкенд не ретраит до рестарта»), обрезанная первая строка хвоста отбрасывается, bounded 256 KiB positioned read. - Санитизация: наружу только {server, state, at, exitCode}; узкий regex на exit code; assert «сырой payload не утекает в JSON» — есть. Контракт задокументирован в модуле.
- Offline-safe: missing/битый лог → empty map →
mcp: "unknown", doctor не падает; чтение только при наличии opencode-биндингов (лишнего IO нет); hermetic DI по паттерну discovery. - Тесты: 7 unit + 4 doctor integration покрывают заявленное, включая «нет exitCode → поле отсутствует» и реальный файловый тест bounded tail.
Нит (не блокер): при --check-host с unreachable-хостом note о failed-MCP перезаписывается note'ом про unreachable host — приемлемо (mcp-поле при этом сохраняется); если захотим оба факта одновременно — follow-up, не этот PR.
Ограничения в PR body честные: привязка к формату 2.2.7 (дрейф → unknown, не false-failed), live-прогон — отдельным операторским окном. verify 118 файлов / 1037 зелёный принимаю. Готово к финалу CTO.
This was referenced Nov 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Проблема (issue #92)
Backend OpenCode переживает GUI (
opencode-cli serve --service), владеет MCP-подключениями и никогда не ретраит failed-сервер до рестарта backend'а. Роль остаётся «выключенной» без видимой причины.Решение
Формат лога подтверждён по живому логу OpenCode Desktop 2.2.7 (live-окно #80, машина оператора):
src/host/opencode/backend-log.ts(новый):readOpenCodeMcpStates()— bounded tail 256 KiB (positioned read, обрезанная первая строка отбрасывается), latest-wins per server, скоуп толькоsynloq-*. Санитизация: наружу только{server, state, at, exitCode?}; exitCode — узким regexprocess exited with code (\d+), сырой текст ошибки не возвращается никогда. Отсутствующий/битый лог → пустая карта.OpenCodeHostCheck.mcp: "connected" | "failed" | "unknown"; приfailed— note: «MCP server failed (exit code N); restart the OpenCode backend (quit from tray or kill the opencode-cli serve process)». Чтение лога — локальный файл, поэтому работает и без--check-host. DIopenCodeMcpStatesдля герметичных тестов.Тесты
Полный
pnpm verifyзелёный: 118 файлов / 1037 тестов.Ограничения (честно)
unknown(ложногоfailedне будет).Closes #92 (live-часть — после операторского окна).