different-ai/openwork · error · Error
Failed to sync connector instance (${response.status}).
Error message
Failed to sync connector instance (${response.status}). What it means
Thrown when the "sync now" action for a connector instance fails. The code POSTs to /v1/connector-instances/{id}/sync-now (15s timeout) and throws getRequestError on non-ok. Note the second validation after this throw: a 200 response lacking numeric item.enqueuedCount raises "Connector sync response was incomplete." instead.
Source
Thrown at ee/apps/den-web/app/(den)/dashboard/_components/integration-data.tsx:1032
});
}
export function useSyncConnectorInstanceNow() {
const queryClient = useQueryClient();
const { runReauthableAction } = useOrgDashboard();
return useMutation({
mutationFn: async (connectorInstanceId: string) => {
let enqueuedCount: number | null = null;
await runReauthableAction("sync-connector-instance", async () => {
const { response, payload } = await requestJson(
`/v1/connector-instances/${encodeURIComponent(connectorInstanceId)}/sync-now`,
{ method: "POST" },
15000,
);
if (!response.ok) {
throw getRequestError(payload, response, `Failed to sync connector instance (${response.status}).`);
}
const item = isRecord(payload) && isRecord(payload.item) ? payload.item : null;
if (!item || typeof item.enqueuedCount !== "number") {
throw new Error("Connector sync response was incomplete.");
}
enqueuedCount = item.enqueuedCount;
});
if (enqueuedCount === null) {
throw new Error("Connector sync response was incomplete.");
}
return enqueuedCount;
},
onSuccess: (_result, connectorInstanceId) => {
queryClient.invalidateQueries({ queryKey: integrationQueryKeys.all });
queryClient.invalidateQueries({
queryKey: integrationQueryKeys.connectorInstanceConfiguration(connectorInstanceId),
});View on GitHub (pinned to 2b7df46e8a)
Solutions
- On 409, inform the user a sync is already running and refresh the sync status instead of re-POSTing.
- On 404, invalidate the connector-instances query and remove the stale row from the UI.
- Check isReauthRequiredError(error) and route to sign-in for 403 reauth responses.
- On 429/5xx, back off and retry after the interval hinted by the server.
Example fix
// before
if (!response.ok) {
throw getRequestError(payload, response, `Failed to sync connector instance (${response.status}).`);
}
// after
if (!response.ok) {
if (response.status === 409) {
throw new Error("A sync is already in progress for this connector.");
}
throw getRequestError(payload, response, `Failed to sync connector instance (${response.status}).`);
} Defensive patterns
Strategy: try-catch
Validate before calling
// before sync
if (!connectorInstanceId) throw new Error("connectorInstanceId is required.");
if (syncInFlight.has(connectorInstanceId)) throw new Error("Sync already running."); Type guard
function isReauthError(e: unknown): e is ReauthRequiredError {
return e instanceof ReauthRequiredError;
} Try / catch
try {
const id = await syncNowMutation.mutateAsync({ connectorInstanceId });
toast(`Queued ${id ?? 0} items.`);
} catch (error) {
if (isReauthError(error)) { startReauth(); return; }
if (/\(409\)/.test(error.message)) { showToast("Sync already in progress."); return; }
if (/\(404\)/.test(error.message)) { queryClient.invalidateQueries(connectorKeys.list); return; }
showToast(error.message);
} Prevention
- Disable the Sync Now button while a sync mutation is pending to avoid 409s.
- Invalidate the connector-instances query on error so stale ids disappear.
- Retry with backoff on 429/5xx only.
- Verify the instance is still connected before offering Sync Now.
When it happens
Trigger: POST sync-now returns non-ok: 401/403 (session expired or reauth required), 404 (connector instance id invalid or removed), 409 (a sync is already in progress), 422 (instance not in syncable state — e.g. disconnected), 429 (sync rate limit), 5xx, or 15s timeout.
Common situations: User clicks Sync Now twice quickly hitting the in-progress conflict; connector was disconnected moments earlier; long queue on the Den worker causes 429 or timeout; stale connectorInstanceId from a cached list.
Related errors
- Failed to remove connector instance (${response.status}).
- Failed to connect GitHub repository (${response.status}).
- Failed to apply GitHub discovery (${response.status}).
- Failed to disconnect integration (${response.status}).
- Failed to delete provider (${response.status}).
AI-assisted analysis of different-ai/openwork@2b7df46e8a (2026-09-01).
Data as JSON: /api/errors/a482d420acb9c766.
Report an issue: GitHub.