koala73/worldmonitor · error · Error
Redis refresh-attempt consume returned an invalid response
Error message
Redis refresh-attempt consume returned an invalid response
What it means
Thrown by `rawRedisBeginRefreshAttempt` in api/oauth/_refresh-recovery.ts:254 when the EVAL succeeded at the HTTP/Lua level but the returned payload is not the expected array `[0|1, ...]`. The Lua script always returns `{0, exists, pointer}` or `{1, value}`, so a non-array result or a leading element other than 0/1 means Upstash mangled the reply (e.g. RESP3 attributes, bulk-string coercion of the array, or an API change in reply encoding).
Source
Thrown at api/oauth/_refresh-recovery.ts:254
'if value then',
' local ok, decoded = pcall(cjson.decode, value)',
" if ok and type(decoded) == 'table' and decoded.kind == 'refresh_attempt' then",
" return {0, redis.call('EXISTS', KEYS[2]), redis.call('GET', KEYS[3]) or false}",
' end',
" redis.call('SET', KEYS[2], ARGV[1], 'EX', ARGV[3])",
" redis.call('SET', KEYS[1], ARGV[2], 'EX', ARGV[3])",
' return {1, value}',
'end',
"return {0, redis.call('EXISTS', KEYS[2]), redis.call('GET', KEYS[3]) or false}",
].join('\n');
const result = await rawRedisEval(
script,
[refreshKey, attemptKey, pointerKey],
[attemptValue, attemptMarker, REFRESH_ATTEMPT_TTL_SECONDS],
);
if (!Array.isArray(result) || (result[0] !== 0 && result[0] !== 1)) {
throw new Error('Redis refresh-attempt consume returned an invalid response');
}
if (result[0] === 1) {
return { kind: 'consumed', refreshData: parseStoredJson(result[1]), attemptValue };
}
return {
kind: 'miss',
recoveryPending: result[1] === 1,
familyId: result[2] ? familyIdFromRefreshPointer(parseStoredJson(result[2])) : null,
};
}
export async function rawRedisRestoreRefreshAttempt(
refreshToken: string,
attemptValue: string,
refreshData: unknown,
familyId: string | null,
): Promise<boolean> {
const script = [View on GitHub (pinned to a96956387a)
Solutions
- Capture and log the actual `result` payload from the EVAL response to see its real shape
- Check Upstash status/changelogs for REST reply-format changes; pin or verify the endpoint and account settings
- If the result is a stringified array, that indicates response re-encoding — remove the intermediary or report the format change; until fixed the refresh fails retryable-safe
Defensive patterns
Strategy: retry
Type guard
function isInvalidConsumeResponse(e: unknown): boolean {
return e instanceof Error && e.message === 'Redis refresh-attempt consume returned an invalid response';
} Try / catch
try {
await beginRefreshAttempt(token, id);
} catch (e) {
if (isInvalidConsumeResponse(e)) {
// reply was mangled: retry with backoff; recovery flow keeps the token safe
await retryWithBackoff();
} else throw e;
} Prevention
- Capture and log the raw EVAL result when this fires to build evidence of reply-format changes
- Avoid intermediaries that re-encode Upstash REST responses
When it happens
Trigger: An OAuth refresh attempt whose EVAL response comes back as a stringified array, a nested object, or `nil` — most plausibly from an Upstash REST reply-format change or an intermediate proxy re-encoding the JSON.
Common situations: Upstash API behavior/version changes; proxies or service workers mutating response bodies; severe payload corruption between Upstash and the Edge runtime.
Understand the failure class
Background: "invalid response format", "malformed payload", "missing data field": when an API returns 200 but the response shape is wrong — this error's family across 23 libraries.
Related errors
- Redis EVAL returned an invalid response
- Redis refresh-attempt restore returned an invalid response
- Redis not configured
- Redis HTTP ${resp.status}
- Redis EVAL failed: ${data.error}
AI-assisted analysis of koala73/worldmonitor@a96956387a (2026-08-27).
Data as JSON: /api/errors/c44ec282eb6eb8e0.
Report an issue: GitHub.