Notes
Short engineering notes and code snippets from building production AI systems on Firebase and Google Cloud. Each one is a gotcha I hit and the fix that held. 7 notes, newest first.
| Date | Note | Tag |
|---|---|---|
A Stale File in public/ Silently Shadows Its Dynamic Astro RouteAstro serves public/ before src/pages/, and a same-named static file wins with no warning at build time. My generated robots.txt and podcast feed had never once been served. verifyNoShadowedRoutes.mjs | Astro, Static Assets, SEO | |
A Naive Quoted-String Regex Truncates at the First Escaped QuoteMy subtitle parser used [^"]+ and stopped dead at the first escaped inner quote. One social card shipped for weeks with a two-character subtitle reading "From \". parseQuoted.mjs | Regex, Build Tooling, Node.js | |
Atomic Idempotency Key Enforcement for Multi-Turn Agent Tool CallingWhen autonomous agents execute external tool calls (such as payment triggers or cloud resource provisioning), network blips or TCP disconnects frequently cause the agent client to retry the request. idempotencyMutex.ts | Firestore, AI Agents | |
TCP Chunk Tearing and Multi-Byte UTF-8 Reassembly in LLM StreamsLLM streaming endpoints emit UTF-8 text chunks over HTTP/2 or Server-Sent Events (SSE). Because TCP packet boundaries operate independently of UTF-8 character encoding, multi-byte sequences can tear cleanly across chunk boundaries. streamDecoder.js | Streaming, Node.js | |
Enforcing Firebase App Check on Cloud Run Endpoints Without SDK WrappersWhen deploying standalone containers on Cloud Run, you can verify incoming Firebase App Check JWTs at the Envoy ingress layer or inside Express/Fastify middleware by verifying the token against Google's public JWKS. appCheckMiddleware.ts | Cloud Run, App Check | |
Atomic Firestore Token Bucket Increments Under ConcurrencyTo prevent client retry loops from overwhelming per-UID token allowances, do not use read-then-write transactions. Instead, use FieldValue.increment(consumedTokens) within a Firestore document update. tokenCounter.ts | Firestore, Tokenomics | |
Preventing Prompt Loop Quota Exhaustion with 402 HTTP Circuit BreakersWhen a Google Cloud Spend Cap fuses, new API calls return a quota error. If your agent does not catch this explicitly, it can crash mid-execution and leave database state partially mutated. circuitBreaker.ts | Cloud Billing, Gemini API, Tokenomics |