fix(settings): stop engine reloads on settings open (MCP re-mint, provider-sync race, workspace re-select) - #2544
Merged
Conversation
Three residual paths reloaded the OpenCode engine when the Settings screen opened (verified live on a Daytona repro): - cloud MCP re-mint: the one-attempt-per-unhealthy-episode guard was a closure variable in a store recreated on every settings mount, so a persistently unhealthy openwork-cloud MCP re-minted its token (runtime config write + reload) on every settings open. The attempt marker is now persisted (org-scoped) and cleared when the entry connects or the user forces a refresh. - cloud provider sync could run before the OpenWork server target resolved; the baseline read then fell back to an empty source and re-imported every org provider (auth PUT + config PATCH + dispose churn). The pass now requires the resolved target up front - imports and persistence need it anyway. - selecting the already-active workspace in the settings workspace menu POSTed /workspaces/:id/activate, which reloaded the engine unconditionally. Same-id selections now return early in the app, and the server skips the reload when the workspace is already active (switch reloads stay, #870).
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Summary
Follow-up to #2530 (the provider-sync engine dispose/create loop). This fixes the remaining family the same customer reported: the OpenCode engine reloads when the Settings screen opens (and when clicking the current workspace in the settings menu). All three paths were identified by code-tracing every settings-mount effect, then verified live on the same Daytona repro rig as #2530 (seeded Acme Robotics cloud, signed in as
alex@acme.test, org provider imported,openwork-cloudMCP stuckfailed— matching the customer's failing-MCP environment).The three paths
syncCloudControlMcp(mounted only by the settings route) re-mints theopenwork-cloudMCP token when the entry is unhealthy, guarded to once per unhealthy episode. But the guard (cloudMcpUnhealthyRemintAttempted) was a closure variable in a store recreated on every settings mount, so a persistently unhealthy cloud MCP (revoked org token, blocked URL) re-minted →POST /workspace/:id/mcp→ runtime config write →markReloadRequired("mcp")→ engine reload on every settings open, forever. Fix: persist the attempt marker (org-scoped,openwork.den.mcp.unhealthyRemintAttempt) with the module's existing storage pattern; cleared when the entry reports connected or when the user hits the user-facing Refresh (force).performCloudProviderSyncnow requires the resolved OpenWork server target up front — imports and persistence need it anyway (patchRuntimeProvidersthrows without it)./workspaces/:id/activate, and the server reloaded the engine unconditionally for local workspaces. Fix: same-id selections return early in the app, and the server skips the reload when the workspace is already first (workspace-switch reloads stay, per [Bug]: Permissions in opencode.jsonc are ignored on every launch #870).Live verification (before → after, same environment)
PATCH /config+ 3 reloadsPOST /workspaces/:id/activate→ engine reloadEngine instance create-count stayed flat (13 → 13) across opens #2/#3 and the workspace re-select, with the
openwork-cloudMCP still genuinelyfailed. Full request-log evidence: #2530 (comment)Tests
pnpm --filter openwork-server test -- src/workspace-activate.e2e.test.ts src/runtime-config-patch-reload.e2e.test.ts— pass, 7 tests (new: engine stub counts/instance/dispose— activate reloads on switch only, re-activating the active workspace does not)pnpm --filter @openwork/app exec bun test src/react-app/domains/connections/cloud-mcp-user-state.test.ts— pass, 3 tests (episode marker helpers: round-trip, corrupt JSON, clear)pnpm --filter @openwork/app typecheck/pnpm --filter openwork-server typecheck— cleanScreen-recording note: verification was request-log + engine-log based (writes and dispose counts per settings open, tables above); the #2530 fraimz covers the surrounding user journey on this rig.