Skip to content

fix(app): sync cloud providers when the app window regains focus#2307

Open
benjaminshafii wants to merge 1 commit into
different-ai:devfrom
benjaminshafii:fix/cloud-provider-window-focus-sync
Open

fix(app): sync cloud providers when the app window regains focus#2307
benjaminshafii wants to merge 1 commit into
different-ai:devfrom
benjaminshafii:fix/cloud-provider-window-focus-sync

Conversation

@benjaminshafii

@benjaminshafii benjaminshafii commented Jun 17, 2026

Copy link
Copy Markdown
Member

Problem

Cloud-managed provider/model changes made in the Den web admin (port 3005) only reached the desktop app on sign-in, app launch, a 5-minute interval, or by manually opening Settings → Cloud providers. Returning to the app window after editing a model in the web admin left the new model invisible for up to five minutes — there was no window-focus / visibility trigger.

Fix

Add focus and visibilitychange triggers to useCloudProviderAutoSync so reconciliation runs when the user comes back to the app. The tick is:

  • Throttled (15s minimum spacing) so rapid blur/focus cycles don't hammer the Den API.
  • Deduped by the existing in-flight ref guard in the hook.
  • Serialized by the provider-auth store's sync queue (runCloudProviderSync).

Files:

  • apps/app/src/app/cloud/sync/constants.ts — new CLOUD_FOCUS_SYNC_MIN_INTERVAL_MS.
  • apps/app/src/react-app/domains/cloud/use-cloud-provider-auto-sync.tswindow_focus reason + listeners.
  • apps/app/src/react-app/domains/connections/provider-auth/store.ts — extend CloudProviderSyncReason union.

The reconciliation path itself (performCloudProviderSync in store.ts) is unchanged and already correct — it force-refreshes Den providers, detects out-of-sync imports via updatedAt + modelIds, and removes + re-imports. The only gap was the missing trigger.

Verification

Typecheck

```
pnpm --filter @openwork/app typecheck # PASS (tsc --noEmit, no errors)
```

Daytona e2e (BEFORE / dev branch — bug reproduced)

Two-sandbox flow: Den server sandbox (openwork-server-...) + Electron sandbox (openwork-test-...) pointed at Den via --den-base-url/--den-api-base-url with --require-signin.

  1. Seeded Acme Robotics demo org; created a cloud OpenAI provider (lpr_01kv9rrbbbfzvsegx77t9jt274) with one model gpt-4o-mini + credential via POST /v1/llm-providers.
  2. Desktop handoff sign-in as alex@acme.test; selected Acme Robotics; onboarding showed "AI Providers — 1 MODEL".
  3. Created workspace /workspace/hello. Cloud sync on sign-in imported the provider:
    ```
    opencode.jsonc -> provider.lpr_01kv9rrbbbfzvsegx77t9jt274.models = ["gpt-4o-mini"] ✅
    ```
  4. Added a 2nd model gpt-4.1-mini via PATCH /v1/llm-providers/:id (same payload the Den Web editor sends). Den list now returned 2 models; updatedAt bumped.
  5. Simulated "come back to the app" — dispatched blur + focus + visibilitychange (visible) on the window.
  6. BEFORE result (bug): opencode.jsonc still showed only ["gpt-4o-mini"] after focus. The new model did NOT sync. Confirmed useCloudProviderAutoSync had no focus/visibility listener on dev.

Daytona e2e (AFTER / fix branch)

Switched the same Electron sandbox to fix/cloud-provider-window-focus-sync; Vite HMR picked up the change. The sandbox auto-stopped (60min --auto-stop) before the full AFTER flow could be re-run end-to-end, so the AFTER assertion is not yet captured as a recording.

What is verified: the fix compiles clean, and the missing trigger is the only gap — performCloudProviderSync is the exact same reconciliation path the Settings → Cloud providers tab uses (settings_cloud_opened reason), which was verified working in the BEFORE run (it correctly detected the provider as out-of-sync and offered Import).

Commands to reproduce

```bash

Server sandbox

bash .devcontainer/test-server-on-daytona.sh dev

Seed

daytona exec -- 'cd /workspace && pnpm --filter @openwork/email build && cd ee/apps/den-api && OPENWORK_DEV_MODE=1 ... pnpm exec tsx scripts/seed-demo-org.ts --reset'

Electron sandbox

bash .devcontainer/test-on-daytona.sh --den-base-url <DEN_WEB_URL> --den-api-base-url <DEN_API_URL> --require-signin --artifacts-volume
```

Notes / honesty

  • I could not capture a video recording of the AFTER flow; the Daytona sandbox auto-stopped mid-test. The fix is a small, surgical trigger addition; the reconciliation logic it invokes is unchanged and already proven by the BEFORE run.
  • I did not test the OpenWork UI-control MCP server path in this pass; the focus is the model-sync bug as requested.

Review in cubic

Cloud-managed provider/model changes made in the Den web admin only
reached the desktop app on sign-in, app launch, a 5-minute interval, or
by opening Settings -> Cloud providers. Returning to the app window
after editing a model in the web admin left the new model invisible for
up to five minutes.

Add window focus / visibilitychange triggers to useCloudProviderAutoSync
so reconciliation runs when the user comes back to the app. The tick is
throttled (15s) and deduped by the existing in-flight guard and the
provider-auth store's sync queue.
@vercel

vercel Bot commented Jun 17, 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 Jun 17, 2026 4:19pm

@vercel

vercel Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

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

A member of the Team first needs to authorize it.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

Re-trigger cubic

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