{"record":{"id":"824a32e2239c90ad","repo":"QuantumNous/new-api","slug":"failed-to-reset-usage","errorCode":null,"errorMessage":"Failed to reset usage","messagePattern":"Failed to reset usage","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"web/src/features/channels/components/dialogs/codex-usage-dialog.tsx","lineNumber":1037,"sourceCode":"      setIsResetting(false)\n      setResetActionError('')\n      setResetActionMessage('')\n    }\n    onOpenChange(nextOpen)\n  }\n\n  const handleConfirmReset = async () => {\n    if (!channelId || isResetting || !canResetCodexUsage) {\n      return\n    }\n\n    setIsResetting(true)\n    setResetActionError('')\n    setResetActionMessage('')\n    try {\n      const res = await resetCodexUsage(channelId)\n      if (!res.success) {\n        throw new Error(res.message || t('Failed to reset usage'))\n      }\n\n      const resetPayload = res.data as\n        | { windows_reset?: number; code?: string }\n        | undefined\n      const windowsReset = Number(resetPayload?.windows_reset)\n      setResetActionMessage(\n        Number.isFinite(windowsReset)\n          ? `${t('Reset completed. Latest usage has been refreshed.')} ${t(\n              'Affected windows:'\n            )} ${windowsReset}`\n          : t('Reset completed. Latest usage has been refreshed.')\n      )\n      setResetConfirmOpen(false)\n      await Promise.resolve(onRefresh?.())\n      await loadResetCredits(true)\n    } catch (error) {\n      setResetActionError(","sourceCodeStart":1019,"sourceCodeEnd":1055,"githubUrl":"https://github.com/QuantumNous/new-api/blob/e2c7aa7b102c2075eae2377df3508658d45e88dc/web/src/features/channels/components/dialogs/codex-usage-dialog.tsx#L1019-L1055","documentation":"Thrown by handleConfirmReset in codex-usage-dialog when resetCodexUsage(channelId) returns success=false. The handler is gated on channelId, isResetting, and canResetCodexUsage; on failure it throws the backend message or this fallback, which is caught and written to resetActionError.","triggerScenarios":"Clicking confirm on the reset-usage action for a Codex channel where the backend refuses the reset (upstream 4xx, credential invalid, usage service unavailable) or the request fails at the network layer.","commonSituations":"Credential expired between opening the dialog and confirming; upstream rate-limited or rejected the reset; concurrent reset from another admin already mutated state; backend version mismatch where the reset endpoint does not exist yet.","solutions":["Read resetActionError in the dialog — res.message from the backend overrides the generic text and names the real cause","Refresh usage first, confirm the credential still works (errors 41/42 would also fire), then retry the reset","Check backend logs for the upstream reset call status at that timestamp","If the endpoint 404s, update the backend to a version that supports Codex usage reset"],"exampleFix":"// before\nconst res = await resetCodexUsage(channelId)\nif (!res.success) {\n  throw new Error(res.message || t('Failed to reset usage'))\n}\n// after - refresh stale data after failure so UI stays consistent\nconst res = await resetCodexUsage(channelId)\nif (!res.success) {\n  throw new Error(res.message || t('Failed to reset usage'))\n}\nsetResetCreditsResponse(null) // force re-fetch of windows after reset","handlingStrategy":"try-catch","validationCode":"if (!channelId || isResetting || !canResetCodexUsage) return","typeGuard":null,"tryCatchPattern":"setIsResetting(true)\nsetResetActionError('')\ntry {\n  const res = await resetCodexUsage(channelId)\n  if (!res.success) throw new Error(res.message || t('Failed to reset usage'))\n  // success path: parse windows_reset and set message\n} catch (error) {\n  setResetActionError(error instanceof Error ? error.message : t('Failed to reset usage'))\n} finally {\n  setIsResetting(false)\n}","preventionTips":["Disable the confirm button while isResetting to prevent double submit","Gate the action on canResetCodexUsage so unauthorized users never reach the API","After success, clear cached usage/reset-credits responses so windows re-fetch"],"tags":["api-error","codex","reset-usage","dialog","mutation"],"backgroundTag":null,"analyzedSha":"e2c7aa7b102c2075eae2377df3508658d45e88dc","analyzedAt":"2026-08-15T10:35:18.111Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}