QuantumNous/new-api · error · Error

Failed to reset usage

Error message

Failed to reset usage

What it means

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.

Source

Thrown at web/src/features/channels/components/dialogs/codex-usage-dialog.tsx:1037

      setIsResetting(false)
      setResetActionError('')
      setResetActionMessage('')
    }
    onOpenChange(nextOpen)
  }

  const handleConfirmReset = async () => {
    if (!channelId || isResetting || !canResetCodexUsage) {
      return
    }

    setIsResetting(true)
    setResetActionError('')
    setResetActionMessage('')
    try {
      const res = await resetCodexUsage(channelId)
      if (!res.success) {
        throw new Error(res.message || t('Failed to reset usage'))
      }

      const resetPayload = res.data as
        | { windows_reset?: number; code?: string }
        | undefined
      const windowsReset = Number(resetPayload?.windows_reset)
      setResetActionMessage(
        Number.isFinite(windowsReset)
          ? `${t('Reset completed. Latest usage has been refreshed.')} ${t(
              'Affected windows:'
            )} ${windowsReset}`
          : t('Reset completed. Latest usage has been refreshed.')
      )
      setResetConfirmOpen(false)
      await Promise.resolve(onRefresh?.())
      await loadResetCredits(true)
    } catch (error) {
      setResetActionError(

View on GitHub (pinned to e2c7aa7b10)

Solutions

  1. Read resetActionError in the dialog — res.message from the backend overrides the generic text and names the real cause
  2. Refresh usage first, confirm the credential still works (errors 41/42 would also fire), then retry the reset
  3. Check backend logs for the upstream reset call status at that timestamp
  4. If the endpoint 404s, update the backend to a version that supports Codex usage reset

Example fix

// before
const res = await resetCodexUsage(channelId)
if (!res.success) {
  throw new Error(res.message || t('Failed to reset usage'))
}
// after - refresh stale data after failure so UI stays consistent
const res = await resetCodexUsage(channelId)
if (!res.success) {
  throw new Error(res.message || t('Failed to reset usage'))
}
setResetCreditsResponse(null) // force re-fetch of windows after reset
Defensive patterns

Strategy: try-catch

Validate before calling

if (!channelId || isResetting || !canResetCodexUsage) return

Try / catch

setIsResetting(true)
setResetActionError('')
try {
  const res = await resetCodexUsage(channelId)
  if (!res.success) throw new Error(res.message || t('Failed to reset usage'))
  // success path: parse windows_reset and set message
} catch (error) {
  setResetActionError(error instanceof Error ? error.message : t('Failed to reset usage'))
} finally {
  setIsResetting(false)
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of QuantumNous/new-api@e2c7aa7b10 (2026-08-15). Data as JSON: /api/errors/824a32e2239c90ad. Report an issue: GitHub.