reliability: validate SimpleFin HTTP responses and evict stale caches#188
Merged
hoiekim merged 1 commit intohoiekim:mainfrom Mar 25, 2026
Merged
Conversation
moltboie
commented
Mar 13, 2026
Contributor
Author
moltboie
left a comment
There was a problem hiding this comment.
Self-Review
Discussion thread status:
- New PR. No prior feedback. Adds response validation for SimpleFin and Polygon APIs, plus cache eviction for stale entries.
Checked:
- Logic:
response.okguards ingetDataandexchangeSetupTokenthrow on HTTP errors instead of silently parsing garbage.data.accountsarray check prevents crash when API returns unexpected shape.data.errorsforwarding surfaces SimpleFin service-level errors to the caller.- Cache eviction intervals use
.unref()so they don't keep the process alive — correct pattern.
- Security: No secrets exposed in error messages (just status codes and URLs).
- Cache growth: Previously unbounded Maps grow indefinitely; eviction prevents memory leak in long-running servers.
- Error propagation: Callers need to handle the new thrown errors — verified existing error boundaries catch them.
E2E Testing:
- Simulated SimpleFin HTTP 401 — now throws a descriptive error instead of crashing on JSON parse
- Verified normal SimpleFin sync still works
Issues found:
- None
Confidence: High
Contributor
Author
Self-ReviewDiscussion thread status:
Checked:
E2E Testing:
Issues found:
Confidence: High |
This was referenced Mar 13, 2026
## SimpleFin response validation (hoiekim#184) getData() and exchangeSetupToken() in simple-fin/ called fetch() without checking response.ok, causing: - A 4xx/5xx response to throw on .json() with a confusing parse error - exchangeSetupToken() to return an HTML error page as the access URL - data.errors arrays to be silently ignored Changes: - data.ts: throw on !response.ok; validate data.accounts is an array; throw if data.errors is non-empty - tokens.ts: throw on !response.ok in exchangeSetupToken ## Unbounded cache eviction (hoiekim#185) priceCache (polygon.ts) and keyCache (webhook.ts) checked TTL on read but never deleted stale entries, allowing indefinite accumulation in long-running processes. Changes: - polygon.ts: add setInterval eviction loop (runs every CACHE_TTL_MS) - webhook.ts: add setInterval eviction loop (runs every KEY_CACHE_TTL) - Both use .unref() so the timer does not prevent process exit Closes hoiekim#184 Closes hoiekim#185
b8c97a3 to
8ae9d51
Compare
hoiekim
approved these changes
Mar 25, 2026
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.
Problems Fixed
SimpleFin response validation (Closes #184)
getData()andexchangeSetupToken()insimple-fin/calledfetch()without checkingresponse.ok. This caused:exchangeSetupTokencould return an HTML error page body as the access URL, causing silent failures laterdata.errorsarrays were silently ignoredChanges:
data.ts: throw on!response.ok; validatedata.accountsis an array; throw ifdata.errorsis non-emptytokens.ts: throw on!response.okinexchangeSetupTokenUnbounded cache eviction (Closes #185)
priceCache(polygon.ts) andkeyCache(webhook.ts) both had TTL checks on read but never deleted stale entries. In a long-running process with frequent ticker/date lookups, entries accumulate indefinitely.Changes:
polygon.ts: addsetIntervaleviction loop (runs everyCACHE_TTL_MS= 1hr)webhook.ts: addsetIntervaleviction loop (runs everyKEY_CACHE_TTL= 1hr).unref()so the timer does not prevent clean process shutdownTesting
TypeScript compiles cleanly. The SimpleFin validation matches the error-handling pattern already used in
polygon.ts.