{"record":{"id":"a482d420acb9c766","repo":"different-ai/openwork","slug":"failed-to-sync-connector-instance-response-stat","errorCode":null,"errorMessage":"Failed to sync connector instance (${response.status}).","messagePattern":"Failed to sync connector instance \\((.+?)\\)\\.","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"ee/apps/den-web/app/(den)/dashboard/_components/integration-data.tsx","lineNumber":1032,"sourceCode":"  });\n}\n\nexport function useSyncConnectorInstanceNow() {\n  const queryClient = useQueryClient();\n  const { runReauthableAction } = useOrgDashboard();\n\n  return useMutation({\n    mutationFn: async (connectorInstanceId: string) => {\n      let enqueuedCount: number | null = null;\n      await runReauthableAction(\"sync-connector-instance\", async () => {\n        const { response, payload } = await requestJson(\n          `/v1/connector-instances/${encodeURIComponent(connectorInstanceId)}/sync-now`,\n          { method: \"POST\" },\n          15000,\n        );\n\n        if (!response.ok) {\n          throw getRequestError(payload, response, `Failed to sync connector instance (${response.status}).`);\n        }\n\n        const item = isRecord(payload) && isRecord(payload.item) ? payload.item : null;\n        if (!item || typeof item.enqueuedCount !== \"number\") {\n          throw new Error(\"Connector sync response was incomplete.\");\n        }\n        enqueuedCount = item.enqueuedCount;\n      });\n      if (enqueuedCount === null) {\n        throw new Error(\"Connector sync response was incomplete.\");\n      }\n      return enqueuedCount;\n    },\n    onSuccess: (_result, connectorInstanceId) => {\n      queryClient.invalidateQueries({ queryKey: integrationQueryKeys.all });\n      queryClient.invalidateQueries({\n        queryKey: integrationQueryKeys.connectorInstanceConfiguration(connectorInstanceId),\n      });","sourceCodeStart":1014,"sourceCodeEnd":1050,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/ee/apps/den-web/app/(den)/dashboard/_components/integration-data.tsx#L1014-L1050","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nif (!response.ok) {\n  throw getRequestError(payload, response, `Failed to sync connector instance (${response.status}).`);\n}\n// after\nif (!response.ok) {\n  if (response.status === 409) {\n    throw new Error(\"A sync is already in progress for this connector.\");\n  }\n  throw getRequestError(payload, response, `Failed to sync connector instance (${response.status}).`);\n}","handlingStrategy":"try-catch","validationCode":"// before sync\nif (!connectorInstanceId) throw new Error(\"connectorInstanceId is required.\");\nif (syncInFlight.has(connectorInstanceId)) throw new Error(\"Sync already running.\");","typeGuard":"function isReauthError(e: unknown): e is ReauthRequiredError {\n  return e instanceof ReauthRequiredError;\n}","tryCatchPattern":"try {\n  const id = await syncNowMutation.mutateAsync({ connectorInstanceId });\n  toast(`Queued ${id ?? 0} items.`);\n} catch (error) {\n  if (isReauthError(error)) { startReauth(); return; }\n  if (/\\(409\\)/.test(error.message)) { showToast(\"Sync already in progress.\"); return; }\n  if (/\\(404\\)/.test(error.message)) { queryClient.invalidateQueries(connectorKeys.list); return; }\n  showToast(error.message);\n}","preventionTips":["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."],"tags":["http","connectors","den-api","react-query"],"backgroundTag":"http-non-ok-response","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}