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 six-character subtitle reading "From \". parseQuoted.mjs | Regex, Build Tooling, Node.js | |
A Retried Agent Tool Call Runs Twice Without an Idempotency KeyWhen 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 | |
A TCP Chunk Can Split One UTF-8 Character: Buffer the Bytes Before You DecodeLLM 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 | |
Cloud Run Can Verify Firebase App Check Tokens Without the Admin SDKWhen deploying standalone containers on Cloud Run, you can verify incoming Firebase App Check JWTs inside Express/Fastify middleware by checking the token against Google's public JWKS. appCheckMiddleware.ts | Cloud Run, App Check | |
Count Agent Tokens With FieldValue.increment Instead of a TransactionWhen an agent fires tool calls in parallel, a read-then-write transaction on one usage document retries under contention. FieldValue.increment adds each call's tokens in a single write, so no count is lost. tokenCounter.ts | Firestore, Tokenomics | |
When the Spend Cap Trips, Return a 402 So the Agent Can CheckpointWhen a Firebase spend cap trips, your client-side app will start throwing errors for that service. If your agent does not catch them explicitly, it can crash mid-execution and leave database state partially mutated. circuitBreaker.ts | Cloud Billing, Gemini API, Tokenomics |
Get the next essay by email
One email per new essay: a production failure, taken apart, and the code that fixed it. Reply to any of them to unsubscribe.