fix: transient error matching, usage month boundary and webhook signature compare - #4
Open
manpreet171 wants to merge 1 commit into
Open
Conversation
…ompare - isTransientError() only lowercased the non-Error branch, so the non-transient keyword list never matched a real Error. Auth and validation failures could be retried when the message also looked transient. - getUserUsage() built the month boundary in server local time, so on a non-UTC host the window included part of the previous month. - The Cashfree webhook compared signatures with !==. Switched to timingSafeEqual with a length guard. - Dropped the hardcoded Gemini key fallback in the judge route and fail with a config error when GEMINI_API_KEY is unset.
|
@manpreet171 is attempting to deploy a commit to the tharagesh's projects Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Four small independent fixes found while reading through the codebase.
isTransientError()—lib/brain/retry.ts.toLowerCase()binds to the else branch only, so for a realErrorthe message keeps its casing. The non-transient keyword list right below is all lowercase, so"unauthorized","conflict"and"validation"never matched anError. An error likeRequest Timeout: Unauthorized upstreamfell through to the transient patterns and got retried three times with backoff.The existing tests only pass lowercase messages, so this stayed green. Added a case that covers it.
Usage month boundary —
lib/usage.tsnew Date(y, m, 1).toISOString()builds the boundary from the server's local midnight. On a UTC+5:30 host that resolves toJun 30 18:30Z, pulling five and a half hours of the previous month'scredit_usageinto the current month's totals. Switched toDate.UTC, matching thecreated_attimestamps being compared against.Webhook signature compare —
app/api/webhooks/cashfree/route.ts!==on an HMAC compares byte by byte and returns early. Switched tocrypto.timingSafeEqualwith a length guard, since it throws on mismatched lengths.Gemini key fallback —
app/api/sdk/evals/judge/route.tsThe route fell back to a key literal in the source when
GEMINI_API_KEYwas unset. Removed it and moved the lookup out of the loop so the route returns a config error instead of sending an unusable request per criterion.Full suite: 167 passed, and
tsc --noEmitis clean.