| name | firebase-cloud-functions |
| description | Complete Cloud Functions for Firebase skill — 2nd gen (Cloud Run) mandatory, idempotency, infinite loop prevention, scaling, secrets, and deployment. Use when writing or reviewing any Cloud Function. |
| compatibility | Requires Firebase CLI (`npm install -g firebase-tools`). 2nd gen (Cloud Run + Eventarc) is the standard. 1st gen is legacy only. |
Cloud Functions for Firebase
Serverless backend functions triggered by Firebase events (Firestore, Auth, Storage, HTTP, Pub/Sub, Scheduler, etc.). 2nd gen (Cloud Run) is mandatory for all new code.
Critical Rule: 2nd Gen Only
Agent MUST use firebase-functions/v2 imports. If 1st gen syntax is detected, convert to 2nd gen. See gen_comparison.md.
References
Agent Pre-Function Checklist
Before generating ANY Cloud Function:
- 2nd gen? →
firebase-functions/v2 import. 1st gen = reject.
- Trigger type? → Firestore onUpdate/onWrite = high loop risk.
- Idempotency guards? → Event age check + before/after guard + transaction. ALL THREE for retry-enabled functions.
- Same document write? → Guard is MANDATORY. No unconditional
update() in Firestore triggers.
- Retry enabled? → Without idempotency = REJECT the function. Never ship retry + non-idempotent.
- Concurrency + minInstances? → HTTP: concurrency >= 200. Background: >= 80. Set minInstances to avoid cold start.
- Secrets? →
defineSecret() + Secret Manager. NEVER functions.config() (deprecated, removed March 2027).
- Timeout/memory/CPU? → Set realistic values in options.
- Quota risk? → Loop + retry = potential $1000s bill. Always cap with maxInstances.
Prohibitions
- Unconditional
update() / set() inside Firestore onUpdate/onWrite
retry: true without idempotency guards
functions.config() (deprecated)
- 1st gen syntax in new code
setTimeout / background activity after response sent