Skip to content

feat(mcp): cloud MCP doctor — direct probe trace, engine refresh, advanced diagnostics - #2975

Merged
reachjalil merged 2 commits into
different-ai:devfrom
reachjalil:feature/cloud-mcp-doctor
Jul 22, 2026
Merged

reachjalil merged 2 commits into
different-ai:devfrom
reachjalil:feature/cloud-mcp-doctor

Conversation

@reachjalil

@reachjalil reachjalil commented Jul 22, 2026 •

Copy link
Copy Markdown
Member

Why

Field reports showed the Agent access card stuck on Degraded — "Couldn't apply Cloud access to this workspace" with no way to see what actually broke. Three structural problems make this failure opaque:

  1. OpenCode never retries a failed MCP connection. A failed remote connect is stored as {status:"failed"} and the client is dropped; there is no timer, no on-tool-call reconnect, no on-session reconnect. It stays failed until something external re-drives it. Dynamically-registered entries are also lost entirely on an engine state rebuild.
  2. OpenCode keeps only Error.message. A TLS/proxy/network failure collapses to the literal string fetch failed; the cause chain (code, errno, syscall) is discarded and is not written to the engine log either.
  3. The desktop never exercises the one path that can recover the real cause. The server can already probe the Cloud endpoint directly (probe=1), but "Test now" never requested it, and none of the rich health detail (failure code/stage, raw engine error, delivery revisions) was visible anywhere near the card.

What

Server (apps/server)

  • Probe step trace: the direct endpoint probe records initialize → initialized_notice → tools_list with HTTP status, per-step latency, endpoint serverInfo/protocol, and — on transport failure — the full error cause chain that the engine discards (tools.direct.trace, failure.details.transport).
  • POST /workspace/:id/mcp/openwork-cloud/engine-refresh: explicit engine-side retry. Disconnects the engine's openwork-cloud client (closing a wedged transport), re-registers from the persisted desired config (an unconditional fresh connect on the engine side), polls to connected, and returns ordered refresh steps plus fully probed health. Also recovers the "entry lost after engine restart" case.
  • engineInspection: health now includes the engine's full MCP server map (per-server status + raw error), read over the OpenCode SDK. Support can now distinguish everything failed (engine host network path) from only openwork-cloud failed (endpoint/token) from entry not registered (lost dynamic registration).
  • Health gains durationMs; reconcilePersistedOpenworkCloudMcp accepts providerModel.

App (apps/app)

  • "Test now" now verifies the endpoint directly (probe=1) from the OpenWork server, independent of the engine's cached state. The Advanced settings page refresh does the same.
  • Advanced diagnostics on the card (collapsed by default — zero change to the default UI): failure code/stage/retryability + message + request/reference IDs, the raw engine error string, delivery state with desired/applied revisions and last attempt, the probe step trace with latencies, the engine MCP server map, token presence/expiry, org, and app/server/engine versions.
  • "Refresh engine connection" button (in Advanced) driving the new endpoint, with per-step outcome display.
  • "Copy sanitized diagnostic": one-click redacted JSON support bundle (health + refresh trace + workspace/org context) for support tickets.
  • New pure helper module cloud-mcp-diagnostics.ts (rows/trace/bundle formatting), fully unit-tested.

Behavior impact: none outside diagnostics (audited, not just intended)

  • No agent-context or prompt bloat. The new fields (tools.direct.trace, engineInspection, durationMs) live only in the health JSON consumed by the settings card, the Advanced settings page, and the clipboard bundle. Nothing reaches the model: no system-prompt, plugin, instruction, or tool-surface changes; openwork-cloud tool registration is untouched.
  • No new automatic actions. The passive mount auto-check and the online-reconnect repair issue byte-identical requests to before. The direct probe runs only on two explicit user actions (card Test now, Advanced page Refresh); the engine refresh runs only from its button. No timers or background retries were added on the OpenWork side.
  • Existing endpoints unchanged. GET …/health without probe and POST …/reconcile behave exactly as before; all new fields are additive/optional (older clients ignore them, older servers simply omit them). The engine-refresh endpoint is new and opt-in.
  • Errors are recorded, never swallowed. The probe's step trace records and rethrows; engine-refresh records a failed disconnect step and continues (deliberate — re-registration is the authoritative step), preserving the failure in refresh.steps and the health verdict. On the new endpoint an empty body is allowed but malformed JSON is a hard 400.
  • Guarded against verdict drift from richer engine errors. Current or future engines that stop collapsing Error.cause can emit cert/TLS strings containing "expired"/"auth"/"revoked"; inferFailedStatus now explicitly keeps those classified as connection failures instead of newly misclassifying them as token/session problems (regression-tested in both directions).
  • The chat submission gate is unaffected. firstFailure feeds the chat send gate (useCloudMcpSubmitReadiness / ensureCloudMcpSubmissionReadiness) and background session maintenance; both consume only usable, usableByCurrentModel, and the code-derived fixed sentences (failure.message/recommendedAction) — never raw engine strings, which stay in details (Advanced/bundle only). Neither path requests the probe (their health calls are unchanged), and with the classification guard above, gate decisions, banner text, and token-remint triggers stay byte-identical for transport failures.
  • One deliberate diagnostic-verdict change, on explicit action only: "Test now" now truly verifies the endpoint (initialize + tools/list) instead of echoing the engine's cached state, so it can surface a real endpoint failure attestation missed — that is the button's purpose. The passive health check keeps the old cheap semantics.

Support-call flow this enables

Open the card → expand Advanced diagnostics → read three signals side by side:

Signal Meaning when failing
Direct endpoint check (server-side probe) Den endpoint/token/network path from the OpenWork server
Engine MCP status + raw error what OpenCode itself experienced (with the probe supplying the cause OpenCode drops)
Engine MCP servers map scope: one MCP vs all MCPs vs entry missing entirely

Then Refresh engine connection (engine drop + fresh connect) or Repair and test (token remint + re-apply), and Copy sanitized diagnostic into the ticket.

Verification

  • apps/server: bun test src/cloud-mcp-health.test.ts src/cloud-mcp-reconcile.e2e.test.ts — 38 pass (11 new: probe trace, 401 step capture, transport cause chain, engine inspection map, engine-refresh e2e happy path / desired-missing / engine-down / malformed-body 400, cert-error classification guard in both directions).
  • apps/server: bun test src/mcp.engine-sync.e2e.test.ts src/extensions-connect-gating.test.ts — 25 pass.
  • apps/app: bun test tests/cloud-mcp-diagnostics.test.ts tests/cloud-mcp-health.test.ts tests/connect-view.test.ts — 33 pass (new: advanced rows incl. lost-registration flag and transport cause, trace/refresh line formatting, bundle redaction, probe flag passthrough, engine-refresh runner mapping).
  • tsc --noEmit clean in apps/server and apps/app; git diff --check clean.

Deliberately out of scope: no engine modifications

Everything here lives in apps/server and apps/app — the OpenCode engine is intentionally untouched, and its known gaps are compensated from outside:

  • Engine collapses errors to Error.message ("fetch failed") → the server-side direct probe recovers the transport cause chain independently, on our own network path.
  • Engine never retries a failed initial connect → re-registration is an unconditional fresh connect on the engine side, and OpenWork already re-drives it in four places: the chat send gate's repair retries, background session maintenance, the online-reconnect listener, and now the explicit engine-refresh action.
  • Mid-session connection drops → upstream OpenCode dev already contains bd738a0a7 ("reconnect closed remote MCP clients"), which OpenWork inherits with a future engine version pin — no fork patch needed.
  • No automatic background retry loop was added beyond the existing ones: this PR adds the explicit retry lever and the visibility to know when to pull it.

🤖 Generated with Claude Code

…ed diagnostics

The openwork-cloud meta-MCP fails opaquely today: OpenCode stores only
Error.message for a failed remote connect (a TLS/proxy failure collapses to
the literal "fetch failed"), never retries on its own, and the desktop card
reduces everything to "Couldn't apply Cloud access to this workspace".

Server:
- Direct endpoint probe now records a per-step trace (initialize,
  initialized notice, tools/list) with HTTP status, latency, endpoint server
  info, and — on transport errors — the full cause chain (code/errno/syscall)
  that the engine discards.
- New POST /workspace/:id/mcp/openwork-cloud/engine-refresh: disconnects the
  engine's MCP client, re-registers from the persisted desired config
  (an unconditional fresh connect on the engine side), and returns ordered
  refresh steps plus probed health.
- Health now carries engineInspection — the engine's full MCP server map with
  per-server states and raw error strings — so support can tell "everything
  failed" (host network path) from "only openwork-cloud failed" (endpoint or
  token) from "entry lost after an engine restart".
- Health gains durationMs; reconcilePersistedOpenworkCloudMcp accepts
  providerModel.

App:
- Test now requests probe=1, verifying the Cloud endpoint directly from the
  OpenWork server instead of only reading the engine's cached state; the
  Advanced settings page refresh does the same.
- The Agent access card gains a collapsed-by-default Advanced diagnostics
  section: failure code/stage/retryability, the raw engine error, delivery
  revisions, probe step trace, engine MCP server map, token expiry, versions,
  a Refresh engine connection action, and a redacted copyable support bundle.

Co-Authored-By: Claude Fable 5 <[email protected]>
@vercel

vercel Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
openwork-landing Ready Ready Preview, Comment, Open in v0 Jul 22, 2026 5:23am
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
openwork-diagnostics Skipped Skipped Jul 22, 2026 5:23am

@vercel
vercel Bot temporarily deployed to Preview – openwork-diagnostics July 22, 2026 05:05 Inactive
@vercel

vercel Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

@reachjalil is attempting to deploy a commit to the Different AI Team on Vercel.

A member of the Team first needs to authorize it.

…rors

Two hardening guards from a behavior-impact audit:

- inferFailedStatus: certificate/TLS transport errors (which can contain
  "expired", "auth"(ority), or "revoked" wording — especially once engines
  preserve error cause chains) are never classified as token or session
  problems; they stay generic connection failures. Prevents richer engine
  error strings from changing the repair verdict.
- engine-refresh route: an empty body stays allowed, but malformed JSON is
  now a hard 400 instead of being silently treated as empty.

Co-Authored-By: Claude Fable 5 <[email protected]>
@vercel
vercel Bot temporarily deployed to Preview – openwork-diagnostics July 22, 2026 05:22 Inactive
@reachjalil
reachjalil merged commit e967b25 into different-ai:dev Jul 22, 2026
5 checks passed

This branch was successfully deployed

1 active and 1 inactive deployments
Preview – openwork-landing — 97f8d81a Deployed Jul 22, 2026 by vercel[bot]
Preview – openwork-diagnostics — 97f8d81a Deployed Jul 22, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant