Skip to content

fix(app): coalesce Den sync requests#2690

Draft
reachjalil wants to merge 1 commit into
different-ai:devfrom
reachjalil:codex/den-sync-coalesce
Draft

fix(app): coalesce Den sync requests#2690
reachjalil wants to merge 1 commit into
different-ai:devfrom
reachjalil:codex/den-sync-coalesce

Conversation

@reachjalil

Copy link
Copy Markdown
Collaborator

Problem

The provider auto-sync hook prevented overlapping network requests with an in-flight boolean. That guard also discarded every Den settings-change event received while a request was running. Switching organizations at the wrong moment could therefore leave providers and cloud MCP state on the previous settings until the periodic interval fired.

State and ordering contract

  • Never run more than one reconciliation at a time.
  • While one is running, retain one pending pass for the newest settings state.
  • Coalesce a burst into one immediate follow-up, using the latest reason.
  • Cancel pending work on sign-out or unmount.
  • A failed pass must release the runner and allow already-pending current state to reconcile.

Implementation

  • Replaced the drop-on-in-flight guard with a small serialized sync runner.
  • Each signal updates one pending reason; the drain loop consumes it after the active request settles.
  • The hook still keeps the latest sync closure without restarting its interval on render.
  • Cancellation clears pending work but does not attempt to abort an already-owned request.
  • Errors remain owned by the existing stores and do not create an automatic retry loop.

Regression proof

Tests hold the first request open, send several settings changes, and prove:

  • no second request starts concurrently;
  • the burst produces exactly one follow-up using the newest reason;
  • cancellation removes the pending pass;
  • a failed first request still releases the queued current-state pass.

Validation

  • bun test apps/app/scripts/cloud-provider-auto-sync.test.ts — 3 passed, 0 failed
  • pnpm --filter @openwork/app typecheck — passed
  • pnpm fraimz --flow den-sync-coalesce — Passed, 4 proof frames plus voiceover coverage

Evidence limitations

The fraimz run is an internal concurrency proof backed by deterministic deferred promises. It is not a live UI recording and does not exercise a production Den tenant or real network latency.

Human review still required

This draft is intentionally not ready to merge until a human reviewer confirms:

  • latest-reason coalescing is correct for both provider sync consumers mounted by Settings;
  • one follow-up per in-flight window is the desired behavior under sustained settings-event traffic;
  • clearing pending work without aborting the active request is correct on sign-out/unmount;
  • swallowed promise failures remain correctly surfaced by each owning store;
  • a manual organization switch during a deliberately slow sync refreshes current providers and MCP state immediately after the active request settles;
  • the branch remains appropriate against the latest dev head.

Scope and mergeability

This is independent from the stale-snapshot identity guard and other remote reliability drafts. It can be reviewed and merged separately.

@vercel

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

@vercel

vercel Bot commented Jul 12, 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 12, 2026 4:45pm

@reachjalil

Copy link
Copy Markdown
Collaborator Author

Review map: independent state and sync reliability drafts

These drafts address separate ownership/order boundaries and are intended to be reviewed independently against dev:

There is no required merge order. Each PR body includes its own validation, evidence limitations, and a Human review still required checklist. Internal fraimz proofs in this set are test-backed ordering evidence, not live UI recordings.

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