Reliability guards + dead-code / console / unused-dep cleanup#5
Open
joaquinOEF wants to merge 3 commits into
Open
Reliability guards + dead-code / console / unused-dep cleanup#5joaquinOEF wants to merge 3 commits into
joaquinOEF wants to merge 3 commits into
Conversation
… OpenAI timeout The /api/chat/* and /api/osm/* endpoints called OpenAI / Overpass with no auth, no rate limit, no input validation, and no body-size cap — anyone could run up the OpenAI bill, use us as a free proxy, or OOM the server with a huge payload. - express-rate-limit (40/min/IP) on /api/chat and /api/osm - zod-validate /api/chat/query (string ≤500 chars + optional bbox tuple); cap index-assets (≤5000), index-geojson features (≤20000), overpass query length (≤10k) - express.json/urlencoded limit 1mb - OpenAI client timeout 15s + maxRetries 2 (a hung call can't block the server) - health check no longer leaks OPENAI_API_KEY presence - .gitignore .env* Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…, bigger embed batch - generateSummary: gpt-4o → gpt-4o-mini (~50× cheaper, fast; summary is short prose) - compression() middleware → the ~1.9MB GeoJSON ships gzipped (~200-300KB) - express.static maxAge 1d → repeat visits don't re-download the static assets/GeoJSON - osmService: load the 6 risk-zone files in parallel (Promise.all) instead of sequentially - embedding batch 50 → 500 (far fewer OpenAI round-trips → faster startup indexing) Deferred (needs a persistent vector store to be reliable on Replit cold starts, so not a low-risk one-liner): persisting embeddings so the server doesn't re-embed on every boot. Mitigated here by the larger batch size. Tracked as a follow-up. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- cosineSimilarity: guard against zero-magnitude vectors (return 0, not NaN) - bboxToH3Cells: reject inverted/degenerate bbox (was silently returning an empty filter that behaves like "no spatial filter") - delete dead code left after the chat refactor: mapActionSchema, enhanceMapActionWithCoordinates, enhanceResponseWithGeography - strip 45 standalone console.log statements across aiChat.ts, MapView.tsx, osmService.ts (kept console.error / console.warn) - remove unused deps: overpass-ts, h3-js (never imported) No behavior change beyond the two guards. Deferred shared/config.ts (centralizing the duplicated PoA bbox/center) — it touches many files, so it belongs in its own pass, not this low-risk batch. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Low-risk hygiene + two defensive guards.
cosineSimilarityreturns 0 (not NaN) for zero-magnitude vectors;bboxToH3Cellsrejects an inverted/degenerate bbox (which previously produced an empty filter that silently behaved like no spatial filter).mapActionSchema,enhanceMapActionWithCoordinates,enhanceResponseWithGeography.console.logs stripped acrossaiChat.ts,MapView.tsx,osmService.ts(keptconsole.error/warn).overpass-ts,h3-js.No behavior change beyond the two guards;
npm run buildpasses (bundle shrank ~42→38 KB).Deferred
shared/config.tsto centralize the PoA bbox/center literals (duplicated 8+ places) — it touches many files, so it deserves its own pass rather than riding in the low-risk batch.🤖 Generated with Claude Code