Skip to content

fix(mcp): gate sends until Cloud search tools are ready - #2779

Merged
reachjalil merged 5 commits into
different-ai:devfrom
reachjalil:feature/cloud-mcp-send-readiness
Jul 15, 2026
Merged

reachjalil merged 5 commits into
different-ai:devfrom
reachjalil:feature/cloud-mcp-send-readiness

Conversation

@reachjalil

@reachjalil reachjalil commented Jul 15, 2026 •

Copy link
Copy Markdown
Member

This is the single combined Cloud MCP fix and supersedes #2773.

This PR prevents a message from starting an agent run while search_capabilities or execute_capability may be missing from the selected provider/model. It combines the original Cloud MCP silent-failure diagnostics with a graceful pre-send readiness gate: users can keep typing, editing, changing models, and attaching files while OpenWork verifies or restores the tools, but the queued message is not released until the exact Cloud tool projection is proven.

Why this fixes the silent missing-search failure

The previous session maintenance path could collapse an unusable reconcile result into skipped, swallow startup/reload errors, and consider generic endpoint health sufficient. That could leave the assistant without the Cloud search tool after restart while the UI provided no durable explanation.

The first commit makes restoration failures visible and retryable. The second commit closes the send-time race: run-start analytics, telemetry, attachment conversion, commands, and promptAsync now remain behind the readiness decision. A failed check therefore creates no agent run and does not clear the draft.

Readiness contract and engine gap

connected transport status is not enough. The gate requires all of the following for the active workspace, provider, and model:

  1. The engine reports the exact openwork-cloud registration as connected and the overall Cloud health check has no failure.
  2. A direct MCP tools/list probe returns both search_capabilities and execute_capability.
  3. The provider/model-scoped OpenCode tool listing returns both openwork-cloud_search_capabilities and openwork-cloud_execute_capability.

The current health endpoint can prove selected-model projection only when OpenCode's provider/model tool-list endpoint enumerates MCP tools. Some engine versions omit MCP tools there and fall back to /provider, which proves only that the model supports tool calling in general. This PR explicitly rejects that fallback with provider_tool_projection_unverified; generic tool-calling support is never treated as proof that the two Cloud tools were injected.

That is the strongest honest check available without a stronger engine contract. A future OpenCode contract should expose an authoritative provider/model-scoped effective tool manifest on every supported engine version.

Submission behavior

  • Ready tools send immediately.
  • Repairable failures keep the exact submitted draft and attachments in place, show Preparing connected service tools…, reconcile with bounded retries after 1 second and 3 seconds, then send exactly once after proof succeeds.
  • The composer editor, attachment controls, and model picker remain usable during preparation; only the already-queued send action is deduplicated.
  • If the user edits while preparation runs, the original snapshot is sent after readiness and the newer composer contents are not cleared.
  • Permanent failures do not send. The safe reason remains visible with Retry and Open Connect actions.
  • Workspace, organization, server, sign-in state, explicit Agent-access state, and provider/model are part of the queue scope. A scope change cancels the stale queued release.
  • Signed-out, no-organization, explicitly disabled, and explicitly removed states retain the existing non-Cloud send behavior. A server-reported disabled configuration also bypasses the gate.
  • Shell submissions retain their existing direct behavior because they do not create an agent tool run.

End-to-end evidence

The user-facing cloud-mcp-submit-readiness fraimz ran against an isolated macOS Electron app, OpenWork server, OpenCode 1.17.11 sidecar, local Den API/MySQL, and a live openwork-cloud MCP registration. The flow first proved that the transport was connected and the direct endpoint listed both tools. It then observed the bundled engine's real provider_capability fallback, delayed only the health request to make the transient UI state observable, and let the real response continue.

The result passed with 1 flow, 0 failures, 0 skips. It proved the composer remained editable, attachment access remained enabled, repeated clicks produced one readiness check, no user message or agent run existed before readiness, and the real unprovable projection failed closed with the edited draft preserved.

Preparing without blocking the composer

OpenWork composer remains editable while connected service tools are prepared

Safe failure preserves the draft and recovery actions

OpenWork preserves the draft and shows Retry and Open Connect when projection cannot be proven

Full claim → action → assertion evidence is posted in the fraimz PR comment and can be reproduced with:

pnpm fraimz --flow cloud-mcp-submit-readiness --cdp-url <electron-cdp-url>

Diagnostics and security

  • Structured inspector events cover readiness checks, repair attempts, timeouts, terminal failures, and context cancellation.
  • Events include only workspace/provider/model context, attempt counts, outcome, code, stage, and retryability.
  • Access tokens, authorization headers, connector payloads, and organization credentials are not recorded.
  • The change does not alter Den credential ownership, OAuth token storage, tenant authority, or provider calls.

Focused regression coverage

The new tests prove:

  1. Ready projected tools send immediately.
  2. A transient startup failure repairs and sends exactly once.
  3. A permanent injection failure creates no run and preserves the exact draft and attachment snapshot.
  4. Repeated clicks share one queued submission and cannot duplicate the send.
  5. Signed-out and explicitly disabled/removed Cloud bypass readiness entirely.
  6. Workspace/model changes cannot release an old queued message into the new context.
  7. Generic model tool-calling support is rejected as projection proof.

Validation

  • pnpm --filter @openwork/app typecheck — passed
  • pnpm --filter @openwork/app exec bun test --isolate tests/cloud-mcp-submit-readiness.test.ts tests/session-mcp-maintenance.test.ts tests/cloud-mcp-health.test.ts — 22 passed, 0 failed
  • pnpm --filter openwork-server typecheck — passed
  • pnpm --filter openwork-server exec bun test src/cloud-mcp-reconcile.e2e.test.ts src/mcp.engine-sync.e2e.test.ts — 34 passed, 0 failed
  • pnpm fraimz --flow cloud-mcp-submit-readiness --cdp-url http://127.0.0.1:43403 — passed, 2 validated screenshots
  • GitHub openwork-tests on Ubuntu and macOS — passed

Remaining verification

The bundled OpenCode 1.17.11 engine does not enumerate MCP tools in the provider/model-scoped experimental tool API, so it cannot produce an honest live automatic-release result for this strict gate. The automatic exactly-once release is covered by the focused deterministic tests; this PR does not fabricate an experimental_tool response to claim it passed end to end.

A packaged production desktop journey with an engine that exposes the authoritative selected-model tool manifest remains to be run. Windows/Linux coverage and video evidence were not collected. The PR remains a draft until that engine contract is available or the supported engine is qualified with equivalent projection proof.

@vercel

vercel Bot commented Jul 15, 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 15, 2026 3:23am
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
openwork-diagnostics Skipped Skipped Jul 15, 2026 3:23am

@vercel
vercel Bot temporarily deployed to Preview – openwork-diagnostics July 15, 2026 02:36 Inactive
@vercel

vercel Bot commented Jul 15, 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.

@reachjalil

reachjalil commented Jul 15, 2026 •

Copy link
Copy Markdown
Member Author

fraimz — ✅ PASSED

1 passed · 0 failed · 0 skipped — run 2026-07-15T02-57-22-314Z

Full frame proof with validated screenshots: evals/results/2026-07-15T02-57-22-314Z/fraimz.html (re-run: pnpm fraimz --flow cloud-mcp-submit-readiness)

✅ cloud-mcp-submit-readiness — Cloud submissions wait for selected-model tool proof and fail closed

User-facing flow demo

  • ✅ The live Cloud transport and direct endpoint are healthy before the submission proof.
  • ✅ The live Cloud endpoint directly lists search_capabilities and execute_capability.
  • ✅ The bundled engine exposes only generic model tool-calling support and cannot prove the selected-model Cloud tool projection.
  • ✅ The submission proof starts from a task with no messages or agent run.
  • ✅ A bounded eval delay makes the real pre-send readiness state observable.
  1. Submission preparation keeps the draft editable and prevents duplicate sends before any run starts

    🎙 After I submit, OpenWork prepares my connected service tools without locking the composer. My message stays visible, I can keep editing, and repeated clicks cannot start another submission.

    • ✅ Only the queued send action is disabled while connected service tools are prepared.
    • ✅ The editor remains editable, the user's edit is visible, and attachment access is not disabled.
    • ✅ No user message or agent run was created while readiness was still checking.
    • ✅ Repeated clicks share the original queued readiness check instead of creating duplicate submissions.
  2. The queued submission shows Preparing connected service tools while the edited draft remains in the usable composer.

    🎙 After I submit, OpenWork prepares my connected service tools without locking the composer. My message stays visible, I can keep editing, and repeated clicks cannot start another submission.

    • 📸 cloud-mcp-submit-readiness-01-cloud-submit-preparing-editable.png — 8 validations passed
    Editable composer while connected service tools are prepared
  3. An unprovable selected-model projection creates no run and preserves the draft with safe recovery actions

    🎙 This bundled engine can prove the Cloud endpoint is connected, but it cannot enumerate the two tools for the selected model. OpenWork fails closed: no task starts, my edited draft remains, and Retry and Open Connect explain the safe next steps.

    • ✅ The exact visible edited draft remains available after readiness fails.
    • ✅ Permanent projection failure created no user message and no agent run.
    • ✅ A non-retryable engine projection gap stops after the honest readiness check.
  4. The selected-model projection gap fails closed with the draft preserved and Retry/Open Connect actions.

    🎙 This bundled engine can prove the Cloud endpoint is connected, but it cannot enumerate the two tools for the selected model. OpenWork fails closed: no task starts, my edited draft remains, and Retry and Open Connect explain the safe next steps.

    • 📸 cloud-mcp-submit-readiness-02-cloud-submit-projection-failure-preserves-draft.png — 10 validations passed
    Projection failure preserves the draft and shows recovery actions
    • ✅ Script frame 1 narrated: "After I submit, OpenWork prepares my connected service tools without locking the compose"
    • ✅ Script frame 2 narrated: "This bundled engine can prove the Cloud endpoint is connected, but it cannot enumerate t"

@reachjalil
reachjalil merged commit 9024033 into different-ai:dev Jul 15, 2026
5 checks passed
benjaminshafii added a commit that referenced this pull request Jul 15, 2026
Rebased onto the structured-maintenance rewrite (#2779). A stale
disabled/removed intent (including the legacy raw-string format migrated
from old builds) permanently skipped ALL cloud MCP token maintenance, so
the 7-day first-party token expired with nothing to remint it and the
engine dropped the MCP at connect (field incident).

Recorded intent now only blocks provisioning: when an enabled
openwork-cloud entry exists in the engine, the maintenance loop and the
reconciler keep its token fresh regardless of recorded intent. Absent or
explicitly disabled entries honor intent as before.
benjaminshafii pushed a commit that referenced this pull request Jul 15, 2026
…nce (#2777)

Rebased onto the structured-maintenance rewrite (#2779). A stale
disabled/removed intent (including the legacy raw-string format migrated
from old builds) permanently skipped ALL cloud MCP token maintenance, so
the 7-day first-party token expired with nothing to remint it and the
engine dropped the MCP at connect (field incident).

Recorded intent now only blocks provisioning: when an enabled
openwork-cloud entry exists in the engine, the maintenance loop and the
reconciler keep its token fresh regardless of recorded intent. Absent or
explicitly disabled entries honor intent as before.
benjaminshafii added a commit that referenced this pull request Jul 15, 2026
Rebased onto the structured-maintenance rewrite (#2779), slimmed to the
two pieces #2779 does not cover:

- runSessionMcpMaintenanceTask races the task against a timeout so one
  hung await cannot wedge every future tick for a target until app
  restart (field incident); a run token keeps a late-settling task from
  releasing a newer run's lock
- each run persists its last outcome (ok/error/timed_out, capped detail)
  per target under openwork.den.mcp.lastMaintenanceOutcome with a reader
  for the diagnostics UI — complementing #2779's ephemeral inspector
  events and React state with a cross-restart signal
benjaminshafii pushed a commit that referenced this pull request Jul 15, 2026
#2778)

Rebased onto the structured-maintenance rewrite (#2779), slimmed to the
two pieces #2779 does not cover:

- runSessionMcpMaintenanceTask races the task against a timeout so one
  hung await cannot wedge every future tick for a target until app
  restart (field incident); a run token keeps a late-settling task from
  releasing a newer run's lock
- each run persists its last outcome (ok/error/timed_out, capped detail)
  per target under openwork.den.mcp.lastMaintenanceOutcome with a reader
  for the diagnostics UI — complementing #2779's ephemeral inspector
  events and React state with a cross-restart signal

This branch was successfully deployed

1 active and 1 inactive (outdated) deployments
Preview – openwork-landing — a6ae8f6d Deployed Jul 15, 2026 by vercel[bot]
Preview – openwork-diagnostics — 50099197 Deployed Jul 15, 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