opencode-skills-collection 1.0.185 → 1.0.187

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/bundled-skills/.antigravity-install-manifest.json +5 -1
  2. package/bundled-skills/3d-web-experience/SKILL.md +152 -37
  3. package/bundled-skills/agent-evaluation/SKILL.md +1088 -26
  4. package/bundled-skills/agent-memory-systems/SKILL.md +1037 -25
  5. package/bundled-skills/agent-tool-builder/SKILL.md +668 -16
  6. package/bundled-skills/ai-agents-architect/SKILL.md +271 -31
  7. package/bundled-skills/ai-product/SKILL.md +716 -26
  8. package/bundled-skills/ai-wrapper-product/SKILL.md +450 -44
  9. package/bundled-skills/algolia-search/SKILL.md +867 -15
  10. package/bundled-skills/autonomous-agents/SKILL.md +1033 -26
  11. package/bundled-skills/aws-serverless/SKILL.md +1046 -35
  12. package/bundled-skills/azure-functions/SKILL.md +1318 -19
  13. package/bundled-skills/browser-automation/SKILL.md +1065 -28
  14. package/bundled-skills/browser-extension-builder/SKILL.md +159 -32
  15. package/bundled-skills/bullmq-specialist/SKILL.md +347 -16
  16. package/bundled-skills/clerk-auth/SKILL.md +796 -15
  17. package/bundled-skills/computer-use-agents/SKILL.md +1870 -28
  18. package/bundled-skills/context-window-management/SKILL.md +271 -18
  19. package/bundled-skills/conversation-memory/SKILL.md +453 -24
  20. package/bundled-skills/crewai/SKILL.md +252 -46
  21. package/bundled-skills/discord-bot-architect/SKILL.md +1207 -34
  22. package/bundled-skills/docs/integrations/jetski-cortex.md +3 -3
  23. package/bundled-skills/docs/integrations/jetski-gemini-loader/README.md +1 -1
  24. package/bundled-skills/docs/maintainers/repo-growth-seo.md +3 -3
  25. package/bundled-skills/docs/maintainers/skills-update-guide.md +1 -1
  26. package/bundled-skills/docs/users/bundles.md +1 -1
  27. package/bundled-skills/docs/users/claude-code-skills.md +1 -1
  28. package/bundled-skills/docs/users/gemini-cli-skills.md +1 -1
  29. package/bundled-skills/docs/users/getting-started.md +1 -1
  30. package/bundled-skills/docs/users/kiro-integration.md +1 -1
  31. package/bundled-skills/docs/users/usage.md +4 -4
  32. package/bundled-skills/docs/users/visual-guide.md +4 -4
  33. package/bundled-skills/email-systems/SKILL.md +646 -26
  34. package/bundled-skills/faf-expert/SKILL.md +221 -0
  35. package/bundled-skills/faf-wizard/SKILL.md +252 -0
  36. package/bundled-skills/file-uploads/SKILL.md +212 -11
  37. package/bundled-skills/firebase/SKILL.md +646 -16
  38. package/bundled-skills/gcp-cloud-run/SKILL.md +1117 -32
  39. package/bundled-skills/graphql/SKILL.md +1026 -27
  40. package/bundled-skills/hubspot-integration/SKILL.md +804 -19
  41. package/bundled-skills/idea-darwin/SKILL.md +120 -0
  42. package/bundled-skills/inngest/SKILL.md +431 -16
  43. package/bundled-skills/interactive-portfolio/SKILL.md +342 -44
  44. package/bundled-skills/langfuse/SKILL.md +296 -41
  45. package/bundled-skills/langgraph/SKILL.md +259 -50
  46. package/bundled-skills/micro-saas-launcher/SKILL.md +343 -44
  47. package/bundled-skills/neon-postgres/SKILL.md +572 -15
  48. package/bundled-skills/nextjs-supabase-auth/SKILL.md +269 -21
  49. package/bundled-skills/notion-template-business/SKILL.md +371 -44
  50. package/bundled-skills/personal-tool-builder/SKILL.md +537 -44
  51. package/bundled-skills/plaid-fintech/SKILL.md +825 -19
  52. package/bundled-skills/prompt-caching/SKILL.md +438 -25
  53. package/bundled-skills/rag-engineer/SKILL.md +271 -29
  54. package/bundled-skills/salesforce-development/SKILL.md +912 -19
  55. package/bundled-skills/satori/SKILL.md +54 -0
  56. package/bundled-skills/scroll-experience/SKILL.md +381 -44
  57. package/bundled-skills/segment-cdp/SKILL.md +817 -19
  58. package/bundled-skills/shopify-apps/SKILL.md +1475 -19
  59. package/bundled-skills/slack-bot-builder/SKILL.md +1162 -28
  60. package/bundled-skills/telegram-bot-builder/SKILL.md +152 -37
  61. package/bundled-skills/telegram-mini-app/SKILL.md +445 -44
  62. package/bundled-skills/trigger-dev/SKILL.md +916 -27
  63. package/bundled-skills/twilio-communications/SKILL.md +1310 -28
  64. package/bundled-skills/upstash-qstash/SKILL.md +898 -27
  65. package/bundled-skills/vercel-deployment/SKILL.md +637 -39
  66. package/bundled-skills/viral-generator-builder/SKILL.md +132 -37
  67. package/bundled-skills/voice-agents/SKILL.md +937 -27
  68. package/bundled-skills/voice-ai-development/SKILL.md +375 -46
  69. package/bundled-skills/workflow-automation/SKILL.md +982 -29
  70. package/bundled-skills/zapier-make-patterns/SKILL.md +772 -27
  71. package/package.json +1 -1
@@ -1,22 +1,38 @@
1
1
  ---
2
2
  name: gcp-cloud-run
3
- description: "When to use: ['Web applications and APIs', 'Need any runtime or library', 'Complex services with multiple endpoints', 'Stateless containerized workloads']"
3
+ description: Specialized skill for building production-ready serverless
4
+ applications on GCP. Covers Cloud Run services (containerized), Cloud Run
5
+ Functions (event-driven), cold start optimization, and event-driven
6
+ architecture with Pub/Sub.
4
7
  risk: unknown
5
- source: "vibeship-spawner-skills (Apache 2.0)"
6
- date_added: "2026-02-27"
8
+ source: vibeship-spawner-skills (Apache 2.0)
9
+ date_added: 2026-02-27
7
10
  ---
8
11
 
9
12
  # GCP Cloud Run
10
13
 
14
+ Specialized skill for building production-ready serverless applications on GCP.
15
+ Covers Cloud Run services (containerized), Cloud Run Functions (event-driven),
16
+ cold start optimization, and event-driven architecture with Pub/Sub.
17
+
18
+ ## Principles
19
+
20
+ - Cloud Run for containers, Functions for simple event handlers
21
+ - Optimize for cold starts with startup CPU boost and min instances
22
+ - Set concurrency based on workload (start with 8, adjust)
23
+ - Memory includes /tmp filesystem - plan accordingly
24
+ - Use VPC Connector only when needed (adds latency)
25
+ - Containers should start fast and be stateless
26
+ - Handle signals gracefully for clean shutdown
27
+
11
28
  ## Patterns
12
29
 
13
30
  ### Cloud Run Service Pattern
14
31
 
15
32
  Containerized web service on Cloud Run
16
33
 
17
- **When to use**: ['Web applications and APIs', 'Need any runtime or library', 'Complex services with multiple endpoints', 'Stateless containerized workloads']
34
+ **When to use**: Web applications and APIs,Need any runtime or library,Complex services with multiple endpoints,Stateless containerized workloads
18
35
 
19
- ```javascript
20
36
  ```dockerfile
21
37
  # Dockerfile - Multi-stage build for smaller image
22
38
  FROM node:20-slim AS builder
@@ -106,16 +122,44 @@ steps:
106
122
  - '--cpu=1'
107
123
  - '--min-instances=1'
108
124
  - '--max-instances=100'
109
-
125
+ - '--concurrency=80'
126
+ - '--cpu-boost'
127
+
128
+ images:
129
+ - 'gcr.io/$PROJECT_ID/my-service:$COMMIT_SHA'
110
130
  ```
111
131
 
132
+ ### Structure
133
+
134
+ project/
135
+ ├── Dockerfile
136
+ ├── .dockerignore
137
+ ├── src/
138
+ │ ├── index.js
139
+ │ └── routes/
140
+ ├── package.json
141
+ └── cloudbuild.yaml
142
+
143
+ ### Gcloud_deploy
144
+
145
+ # Direct gcloud deployment
146
+ gcloud run deploy my-service \
147
+ --source . \
148
+ --region us-central1 \
149
+ --allow-unauthenticated \
150
+ --memory 512Mi \
151
+ --cpu 1 \
152
+ --min-instances 1 \
153
+ --max-instances 100 \
154
+ --concurrency 80 \
155
+ --cpu-boost
156
+
112
157
  ### Cloud Run Functions Pattern
113
158
 
114
159
  Event-driven functions (formerly Cloud Functions)
115
160
 
116
- **When to use**: ['Simple event handlers', 'Pub/Sub message processing', 'Cloud Storage triggers', 'HTTP webhooks']
161
+ **When to use**: Simple event handlers,Pub/Sub message processing,Cloud Storage triggers,HTTP webhooks
117
162
 
118
- ```javascript
119
163
  ```javascript
120
164
  // HTTP Function
121
165
  // index.js
@@ -186,15 +230,13 @@ gcloud functions deploy process-uploads \
186
230
  --trigger-event-filters="bucket=my-bucket" \
187
231
  --region us-central1
188
232
  ```
189
- ```
190
233
 
191
234
  ### Cold Start Optimization Pattern
192
235
 
193
236
  Minimize cold start latency for Cloud Run
194
237
 
195
- **When to use**: ['Latency-sensitive applications', 'User-facing APIs', 'High-traffic services']
238
+ **When to use**: Latency-sensitive applications,User-facing APIs,High-traffic services
196
239
 
197
- ```javascript
198
240
  ## 1. Enable Startup CPU Boost
199
241
 
200
242
  ```bash
@@ -258,36 +300,1079 @@ gcloud run deploy my-service \
258
300
  --cpu 2 \
259
301
  --region us-central1
260
302
  ```
303
+
304
+ ### Optimization_impact
305
+
306
+ - Startup_cpu_boost: 50% faster cold starts
307
+ - Min_instances: Eliminates cold starts for traffic spikes
308
+ - Distroless_image: Smaller attack surface, faster pull
309
+ - Lazy_init: Defers heavy loading to first request
310
+
311
+ ### Concurrency Configuration Pattern
312
+
313
+ Proper concurrency settings for Cloud Run
314
+
315
+ **When to use**: Need to optimize instance utilization,Handle traffic spikes efficiently,Reduce cold starts
316
+
317
+ ## Understanding Concurrency
318
+
319
+ ```bash
320
+ # Default concurrency is 80
321
+ # Adjust based on your workload
322
+
323
+ # For I/O-bound workloads (most web apps)
324
+ gcloud run deploy my-service \
325
+ --concurrency 80 \
326
+ --cpu 1
327
+
328
+ # For CPU-bound workloads
329
+ gcloud run deploy my-service \
330
+ --concurrency 1 \
331
+ --cpu 1
332
+
333
+ # For memory-intensive workloads
334
+ gcloud run deploy my-service \
335
+ --concurrency 10 \
336
+ --memory 2Gi
337
+ ```
338
+
339
+ ## Node.js Concurrency
340
+
341
+ ```javascript
342
+ // Node.js is single-threaded but handles I/O concurrently
343
+ // Use async/await for all I/O operations
344
+
345
+ // GOOD - async I/O
346
+ app.get('/api/data', async (req, res) => {
347
+ const [users, products] = await Promise.all([
348
+ fetchUsers(),
349
+ fetchProducts()
350
+ ]);
351
+ res.json({ users, products });
352
+ });
353
+
354
+ // BAD - blocking operation
355
+ app.get('/api/compute', (req, res) => {
356
+ const result = heavyCpuOperation(); // Blocks other requests!
357
+ res.json(result);
358
+ });
359
+ ```
360
+
361
+ ## Python Concurrency with Gunicorn
362
+
363
+ ```dockerfile
364
+ FROM python:3.11-slim
365
+ WORKDIR /app
366
+ COPY requirements.txt .
367
+ RUN pip install --no-cache-dir -r requirements.txt
368
+ COPY . .
369
+
370
+ # 4 workers for concurrency
371
+ CMD exec gunicorn --bind :$PORT --workers 4 --threads 2 main:app
372
+ ```
373
+
374
+ ```python
375
+ # main.py
376
+ from flask import Flask
377
+ app = Flask(__name__)
378
+
379
+ @app.route('/api/data')
380
+ def get_data():
381
+ return {'status': 'ok'}
382
+ ```
383
+
384
+ ### Concurrency_guidelines
385
+
386
+ - Concurrency=1: Only for CPU-bound or unsafe code
387
+ - Concurrency=8 20: Memory-intensive workloads
388
+ - Concurrency=80: Default, good for I/O-bound
389
+ - Concurrency=250: Maximum, for very lightweight handlers
390
+
391
+ ### Pub/Sub Integration Pattern
392
+
393
+ Event-driven processing with Cloud Pub/Sub
394
+
395
+ **When to use**: Asynchronous message processing,Decoupled microservices,Event-driven architecture
396
+
397
+ ## Push Subscription to Cloud Run
398
+
399
+ ```bash
400
+ # Create topic
401
+ gcloud pubsub topics create orders
402
+
403
+ # Create push subscription to Cloud Run
404
+ gcloud pubsub subscriptions create orders-push \
405
+ --topic orders \
406
+ --push-endpoint https://my-service-xxx.run.app/pubsub \
407
+ --ack-deadline 600
408
+ ```
409
+
410
+ ```javascript
411
+ // Handle Pub/Sub push messages
412
+ const express = require('express');
413
+ const app = express();
414
+ app.use(express.json());
415
+
416
+ app.post('/pubsub', async (req, res) => {
417
+ // Verify the request is from Pub/Sub
418
+ if (!req.body.message) {
419
+ return res.status(400).send('Invalid Pub/Sub message');
420
+ }
421
+
422
+ try {
423
+ // Decode message data
424
+ const message = req.body.message;
425
+ const data = message.data
426
+ ? JSON.parse(Buffer.from(message.data, 'base64').toString())
427
+ : {};
428
+
429
+ console.log('Processing order:', data);
430
+
431
+ await processOrder(data);
432
+
433
+ // Return 200 to acknowledge
434
+ res.status(200).send('OK');
435
+ } catch (error) {
436
+ console.error('Processing failed:', error);
437
+ // Return 500 to trigger retry
438
+ res.status(500).send('Processing failed');
439
+ }
440
+ });
441
+ ```
442
+
443
+ ## Publishing Messages
444
+
445
+ ```javascript
446
+ const { PubSub } = require('@google-cloud/pubsub');
447
+ const pubsub = new PubSub();
448
+
449
+ async function publishOrder(order) {
450
+ const topic = pubsub.topic('orders');
451
+ const messageBuffer = Buffer.from(JSON.stringify(order));
452
+
453
+ const messageId = await topic.publishMessage({
454
+ data: messageBuffer,
455
+ attributes: {
456
+ type: 'order_created',
457
+ priority: 'high'
458
+ }
459
+ });
460
+
461
+ console.log(`Published message ${messageId}`);
462
+ return messageId;
463
+ }
464
+ ```
465
+
466
+ ## Dead Letter Queue
467
+
468
+ ```bash
469
+ # Create DLQ topic
470
+ gcloud pubsub topics create orders-dlq
471
+
472
+ # Update subscription with DLQ
473
+ gcloud pubsub subscriptions update orders-push \
474
+ --dead-letter-topic orders-dlq \
475
+ --max-delivery-attempts 5
476
+ ```
477
+
478
+ ### Cloud SQL Connection Pattern
479
+
480
+ Connect Cloud Run to Cloud SQL securely
481
+
482
+ **When to use**: Need relational database,Migrating existing applications,Complex queries and transactions
483
+
484
+ ```bash
485
+ # Deploy with Cloud SQL connection
486
+ gcloud run deploy my-service \
487
+ --add-cloudsql-instances PROJECT:REGION:INSTANCE \
488
+ --set-env-vars INSTANCE_CONNECTION_NAME="PROJECT:REGION:INSTANCE" \
489
+ --set-env-vars DB_NAME="mydb" \
490
+ --set-env-vars DB_USER="myuser"
491
+ ```
492
+
493
+ ```javascript
494
+ // Using Unix socket connection
495
+ const { Pool } = require('pg');
496
+
497
+ const pool = new Pool({
498
+ user: process.env.DB_USER,
499
+ password: process.env.DB_PASS,
500
+ database: process.env.DB_NAME,
501
+ // Cloud SQL connector uses Unix socket
502
+ host: `/cloudsql/${process.env.INSTANCE_CONNECTION_NAME}`,
503
+ max: 5, // Connection pool size
504
+ idleTimeoutMillis: 30000,
505
+ connectionTimeoutMillis: 10000,
506
+ });
507
+
508
+ app.get('/api/users', async (req, res) => {
509
+ const client = await pool.connect();
510
+ try {
511
+ const result = await client.query('SELECT * FROM users LIMIT 100');
512
+ res.json(result.rows);
513
+ } finally {
514
+ client.release();
515
+ }
516
+ });
517
+ ```
518
+
519
+ ```python
520
+ # Python with SQLAlchemy
521
+ import os
522
+ from sqlalchemy import create_engine
523
+
524
+ def get_engine():
525
+ instance_connection_name = os.environ["INSTANCE_CONNECTION_NAME"]
526
+ db_user = os.environ["DB_USER"]
527
+ db_pass = os.environ["DB_PASS"]
528
+ db_name = os.environ["DB_NAME"]
529
+
530
+ engine = create_engine(
531
+ f"postgresql+pg8000://{db_user}:{db_pass}@/{db_name}",
532
+ connect_args={
533
+ "unix_sock": f"/cloudsql/{instance_connection_name}/.s.PGSQL.5432"
534
+ },
535
+ pool_size=5,
536
+ max_overflow=2,
537
+ pool_timeout=30,
538
+ pool_recycle=1800,
539
+ )
540
+ return engine
541
+ ```
542
+
543
+ ### Best_practices
544
+
545
+ - Use connection pooling (max 5-10 per instance)
546
+ - Set appropriate idle timeouts
547
+ - Handle connection errors gracefully
548
+ - Consider Cloud SQL Proxy for local development
549
+
550
+ ### Secret Manager Integration
551
+
552
+ Securely manage secrets in Cloud Run
553
+
554
+ **When to use**: API keys, database passwords,Service account keys,Any sensitive configuration
555
+
556
+ ```bash
557
+ # Create secret
558
+ echo -n "my-secret-value" | gcloud secrets create my-secret --data-file=-
559
+
560
+ # Mount as environment variable
561
+ gcloud run deploy my-service \
562
+ --update-secrets=API_KEY=my-secret:latest
563
+
564
+ # Mount as file volume
565
+ gcloud run deploy my-service \
566
+ --update-secrets=/secrets/api-key=my-secret:latest
567
+ ```
568
+
569
+ ```javascript
570
+ // Access mounted as environment variable
571
+ const apiKey = process.env.API_KEY;
572
+
573
+ // Access mounted as file
574
+ const fs = require('fs');
575
+ const apiKey = fs.readFileSync('/secrets/api-key', 'utf8');
576
+
577
+ // Access via Secret Manager API (when not mounted)
578
+ const { SecretManagerServiceClient } = require('@google-cloud/secret-manager');
579
+ const client = new SecretManagerServiceClient();
580
+
581
+ async function getSecret(name) {
582
+ const [version] = await client.accessSecretVersion({
583
+ name: `projects/${projectId}/secrets/${name}/versions/latest`
584
+ });
585
+ return version.payload.data.toString();
586
+ }
587
+ ```
588
+
589
+ ## Sharp Edges
590
+
591
+ ### /tmp Filesystem Counts Against Memory
592
+
593
+ Severity: HIGH
594
+
595
+ Situation: Writing files to /tmp directory in Cloud Run
596
+
597
+ Symptoms:
598
+ Container killed with OOM error.
599
+ Memory usage spikes unexpectedly.
600
+ File operations cause container restarts.
601
+ "Container memory limit exceeded" in logs.
602
+
603
+ Why this breaks:
604
+ Cloud Run uses an in-memory filesystem for /tmp. Any files written
605
+ to /tmp consume memory from your container's allocation.
606
+
607
+ Common scenarios:
608
+ - Downloading files temporarily
609
+ - Creating temp processing files
610
+ - Libraries caching to /tmp
611
+ - Large log buffers
612
+
613
+ A 512MB container that downloads a 200MB file to /tmp only has
614
+ ~300MB left for the application.
615
+
616
+ Recommended fix:
617
+
618
+ ## Calculate memory including /tmp usage
619
+
620
+ ```yaml
621
+ # cloudbuild.yaml
622
+ steps:
623
+ - name: 'gcr.io/cloud-builders/gcloud'
624
+ args:
625
+ - 'run'
626
+ - 'deploy'
627
+ - 'my-service'
628
+ - '--memory=1Gi' # Include /tmp overhead
629
+ - '--image=gcr.io/$PROJECT_ID/my-service'
630
+ ```
631
+
632
+ ## Stream instead of buffering
633
+
634
+ ```python
635
+ # BAD - buffers entire file in /tmp
636
+ def process_large_file(bucket_name, blob_name):
637
+ blob = bucket.blob(blob_name)
638
+ blob.download_to_filename('/tmp/large_file')
639
+ with open('/tmp/large_file', 'rb') as f:
640
+ process(f.read())
641
+
642
+ # GOOD - stream processing
643
+ def process_large_file(bucket_name, blob_name):
644
+ blob = bucket.blob(blob_name)
645
+ with blob.open('rb') as f:
646
+ for chunk in iter(lambda: f.read(8192), b''):
647
+ process_chunk(chunk)
648
+ ```
649
+
650
+ ## Use Cloud Storage for large files
651
+
652
+ ```python
653
+ from google.cloud import storage
654
+
655
+ def process_with_gcs(bucket_name, input_blob, output_blob):
656
+ client = storage.Client()
657
+ bucket = client.bucket(bucket_name)
658
+
659
+ # Process directly to/from GCS
660
+ input_blob = bucket.blob(input_blob)
661
+ output_blob = bucket.blob(output_blob)
662
+
663
+ with input_blob.open('rb') as reader:
664
+ with output_blob.open('wb') as writer:
665
+ for chunk in iter(lambda: reader.read(65536), b''):
666
+ processed = transform(chunk)
667
+ writer.write(processed)
668
+ ```
669
+
670
+ ## Monitor memory usage
671
+
672
+ ```python
673
+ import psutil
674
+ import logging
675
+
676
+ def log_memory():
677
+ memory = psutil.virtual_memory()
678
+ logging.info(f"Memory: {memory.percent}% used, "
679
+ f"{memory.available / 1024 / 1024:.0f}MB available")
680
+ ```
681
+
682
+ ### Concurrency=1 Causes Scaling Bottlenecks
683
+
684
+ Severity: HIGH
685
+
686
+ Situation: Setting concurrency to 1 for request isolation
687
+
688
+ Symptoms:
689
+ Auto-scaling creates many container instances.
690
+ High latency during traffic spikes.
691
+ Increased cold starts.
692
+ Higher costs from more instances.
693
+
694
+ Why this breaks:
695
+ Setting concurrency to 1 means each container handles only one
696
+ request at a time. During traffic spikes:
697
+
698
+ - 100 concurrent requests = 100 container instances
699
+ - Each instance has cold start overhead
700
+ - More instances = higher costs
701
+ - Scaling takes time, requests queue up
702
+
703
+ This should only be used when:
704
+ - Processing is truly single-threaded
705
+ - Memory-heavy per-request processing
706
+ - Using thread-unsafe libraries
707
+
708
+ Recommended fix:
709
+
710
+ ## Set appropriate concurrency
711
+
712
+ ```bash
713
+ # For I/O-bound workloads (most web apps)
714
+ gcloud run deploy my-service \
715
+ --concurrency=80 \
716
+ --max-instances=100
717
+
718
+ # For CPU-bound workloads
719
+ gcloud run deploy my-service \
720
+ --concurrency=4 \
721
+ --cpu=2
722
+
723
+ # Only use 1 when absolutely necessary
724
+ gcloud run deploy my-service \
725
+ --concurrency=1 \
726
+ --max-instances=1000 # Be prepared for many instances
727
+ ```
728
+
729
+ ## Node.js - use async properly
730
+
731
+ ```javascript
732
+ // With high concurrency, ensure async operations
733
+ const express = require('express');
734
+ const app = express();
735
+
736
+ app.get('/api/data', async (req, res) => {
737
+ // All I/O should be async
738
+ const data = await fetchFromDatabase();
739
+ const enriched = await enrichData(data);
740
+ res.json(enriched);
741
+ });
742
+
743
+ // Concurrency 80+ is safe for async I/O workloads
744
+ ```
745
+
746
+ ## Python - use async framework
747
+
748
+ ```python
749
+ from fastapi import FastAPI
750
+ import asyncio
751
+ import httpx
752
+
753
+ app = FastAPI()
754
+
755
+ @app.get("/api/data")
756
+ async def get_data():
757
+ # Async I/O allows high concurrency
758
+ async with httpx.AsyncClient() as client:
759
+ response = await client.get("https://api.example.com/data")
760
+ return response.json()
761
+
762
+ # Concurrency 80+ safe with async framework
763
+ ```
764
+
765
+ ## Calculate concurrency
766
+
767
+ ```
768
+ concurrency = memory_limit / per_request_memory
769
+
770
+ Example:
771
+ - 512MB container
772
+ - 20MB per request overhead
773
+ - Safe concurrency: ~25
774
+ ```
775
+
776
+ ### CPU Throttled When Not Handling Requests
777
+
778
+ Severity: HIGH
779
+
780
+ Situation: Running background tasks or processing between requests
781
+
782
+ Symptoms:
783
+ Background tasks run extremely slowly.
784
+ Scheduled work doesn't complete.
785
+ Metrics collection fails.
786
+ Connection keep-alive breaks.
787
+
788
+ Why this breaks:
789
+ By default, Cloud Run throttles CPU to near-zero when not actively
790
+ handling a request. This is "CPU only during requests" mode.
791
+
792
+ Affected operations:
793
+ - Background threads
794
+ - Connection pool maintenance
795
+ - Metrics/telemetry emission
796
+ - Scheduled tasks within container
797
+ - Cleanup operations after response
798
+
799
+ Recommended fix:
800
+
801
+ ## Enable CPU always allocated
802
+
803
+ ```bash
804
+ # CPU allocated even outside requests
805
+ gcloud run deploy my-service \
806
+ --cpu-throttling=false \
807
+ --min-instances=1
808
+
809
+ # Note: This increases costs but enables background work
810
+ ```
811
+
812
+ ## Use startup CPU boost for initialization
813
+
814
+ ```bash
815
+ # Boost CPU during cold start only
816
+ gcloud run deploy my-service \
817
+ --cpu-boost \
818
+ --cpu-throttling=true # Default, throttle after request
819
+ ```
820
+
821
+ ## Move background work to Cloud Tasks
822
+
823
+ ```python
824
+ from google.cloud import tasks_v2
825
+ import json
826
+
827
+ def create_background_task(payload):
828
+ client = tasks_v2.CloudTasksClient()
829
+ parent = client.queue_path(
830
+ "my-project", "us-central1", "my-queue"
831
+ )
832
+
833
+ task = {
834
+ "http_request": {
835
+ "http_method": tasks_v2.HttpMethod.POST,
836
+ "url": "https://my-service.run.app/process",
837
+ "body": json.dumps(payload).encode(),
838
+ "headers": {"Content-Type": "application/json"}
839
+ }
840
+ }
841
+
842
+ client.create_task(parent=parent, task=task)
843
+
844
+ # Handle response immediately, background via Cloud Tasks
845
+ @app.post("/api/order")
846
+ async def create_order(order: Order):
847
+ order_id = await save_order(order)
848
+
849
+ # Queue background processing
850
+ create_background_task({"order_id": order_id})
851
+
852
+ return {"order_id": order_id, "status": "processing"}
853
+ ```
854
+
855
+ ## Use Pub/Sub for async processing
856
+
857
+ ```yaml
858
+ # Move heavy processing to separate service
859
+ steps:
860
+ # Main service - responds quickly
861
+ - name: 'gcr.io/cloud-builders/gcloud'
862
+ args: ['run', 'deploy', 'api-service',
863
+ '--cpu-throttling=true']
864
+
865
+ # Worker service - processes messages
866
+ - name: 'gcr.io/cloud-builders/gcloud'
867
+ args: ['run', 'deploy', 'worker-service',
868
+ '--cpu-throttling=false',
869
+ '--min-instances=1']
870
+ ```
871
+
872
+ ### VPC Connector 10-Minute Idle Timeout
873
+
874
+ Severity: MEDIUM
875
+
876
+ Situation: Cloud Run service connecting to VPC resources
877
+
878
+ Symptoms:
879
+ Connection errors after period of inactivity.
880
+ "Connection reset" or "Connection refused" errors.
881
+ Sporadic failures to VPC resources.
882
+ Database connections drop unexpectedly.
883
+
884
+ Why this breaks:
885
+ Cloud Run's VPC connector has a 10-minute idle timeout on connections.
886
+ If a connection is idle for 10 minutes, it's silently closed.
887
+
888
+ Affects:
889
+ - Database connection pools
890
+ - Redis connections
891
+ - Internal API connections
892
+ - Any persistent VPC connection
893
+
894
+ Recommended fix:
895
+
896
+ ## Configure connection pool with keep-alive
897
+
898
+ ```python
899
+ # SQLAlchemy with connection recycling
900
+ from sqlalchemy import create_engine
901
+
902
+ engine = create_engine(
903
+ DATABASE_URL,
904
+ pool_size=5,
905
+ max_overflow=2,
906
+ pool_recycle=300, # Recycle connections every 5 minutes
907
+ pool_pre_ping=True # Validate connection before use
908
+ )
909
+ ```
910
+
911
+ ## TCP keep-alive for custom connections
912
+
913
+ ```python
914
+ import socket
915
+
916
+ sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
917
+ sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
918
+ sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, 60)
919
+ sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPINTVL, 60)
920
+ sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPCNT, 5)
921
+ ```
922
+
923
+ ## Redis with connection validation
924
+
925
+ ```python
926
+ import redis
927
+
928
+ pool = redis.ConnectionPool(
929
+ host=REDIS_HOST,
930
+ port=6379,
931
+ socket_keepalive=True,
932
+ socket_keepalive_options={
933
+ socket.TCP_KEEPIDLE: 60,
934
+ socket.TCP_KEEPINTVL: 60,
935
+ socket.TCP_KEEPCNT: 5
936
+ },
937
+ health_check_interval=30
938
+ )
939
+ client = redis.Redis(connection_pool=pool)
940
+ ```
941
+
942
+ ## Use Cloud SQL Proxy sidecar
943
+
944
+ ```yaml
945
+ # Use Cloud SQL connector which handles reconnection
946
+ # requirements.txt
947
+ cloud-sql-python-connector[pg8000]
948
+ ```
949
+
950
+ ```python
951
+ from google.cloud.sql.connector import Connector
952
+ import sqlalchemy
953
+
954
+ connector = Connector()
955
+
956
+ def getconn():
957
+ return connector.connect(
958
+ "project:region:instance",
959
+ "pg8000",
960
+ user="user",
961
+ password="password",
962
+ db="database"
963
+ )
964
+
965
+ engine = sqlalchemy.create_engine(
966
+ "postgresql+pg8000://",
967
+ creator=getconn
968
+ )
969
+ ```
970
+
971
+ ### Container Startup Timeout (4 minutes max)
972
+
973
+ Severity: HIGH
974
+
975
+ Situation: Deploying containers with slow initialization
976
+
977
+ Symptoms:
978
+ Deployment fails with "Container failed to start".
979
+ Service never becomes healthy.
980
+ "Revision failed to become ready" errors.
981
+ Works locally but fails on Cloud Run.
982
+
983
+ Why this breaks:
984
+ Cloud Run expects your container to start listening on PORT within
985
+ 4 minutes (240 seconds). If it doesn't, the instance is killed.
986
+
987
+ Common causes:
988
+ - Heavy framework initialization (ML models, etc.)
989
+ - Waiting for external dependencies at startup
990
+ - Large dependency loading
991
+ - Database migrations on startup
992
+
993
+ Recommended fix:
994
+
995
+ ## Enable startup CPU boost
996
+
997
+ ```bash
998
+ gcloud run deploy my-service \
999
+ --cpu-boost \
1000
+ --startup-cpu-boost
1001
+ ```
1002
+
1003
+ ## Lazy initialization
1004
+
1005
+ ```python
1006
+ from functools import lru_cache
1007
+ from fastapi import FastAPI
1008
+
1009
+ app = FastAPI()
1010
+
1011
+ # Don't load at import time
1012
+ model = None
1013
+
1014
+ @lru_cache()
1015
+ def get_model():
1016
+ global model
1017
+ if model is None:
1018
+ # Load on first request, not at startup
1019
+ model = load_heavy_model()
1020
+ return model
1021
+
1022
+ @app.get("/predict")
1023
+ async def predict(data: dict):
1024
+ model = get_model() # Loads on first call only
1025
+ return model.predict(data)
1026
+
1027
+ # Startup is fast - model loads on first request
1028
+ ```
1029
+
1030
+ ## Start listening immediately
1031
+
1032
+ ```python
1033
+ import asyncio
1034
+ from fastapi import FastAPI
1035
+ import uvicorn
1036
+
1037
+ app = FastAPI()
1038
+
1039
+ # Global state for async initialization
1040
+ initialized = asyncio.Event()
1041
+
1042
+ @app.on_event("startup")
1043
+ async def startup():
1044
+ # Start background initialization
1045
+ asyncio.create_task(async_init())
1046
+
1047
+ async def async_init():
1048
+ # Heavy initialization happens after server starts
1049
+ await load_models()
1050
+ await warm_up_connections()
1051
+ initialized.set()
1052
+
1053
+ @app.get("/ready")
1054
+ async def ready():
1055
+ if not initialized.is_set():
1056
+ raise HTTPException(503, "Still initializing")
1057
+ return {"status": "ready"}
1058
+
1059
+ @app.get("/health")
1060
+ async def health():
1061
+ # Always respond - health check passes
1062
+ return {"status": "healthy"}
1063
+ ```
1064
+
1065
+ ## Use multi-stage builds
1066
+
1067
+ ```dockerfile
1068
+ # Build stage - slow
1069
+ FROM python:3.11 as builder
1070
+ WORKDIR /app
1071
+ COPY requirements.txt .
1072
+ RUN pip wheel --no-cache-dir --wheel-dir /wheels -r requirements.txt
1073
+
1074
+ # Runtime stage - fast startup
1075
+ FROM python:3.11-slim
1076
+ WORKDIR /app
1077
+ COPY --from=builder /wheels /wheels
1078
+ RUN pip install --no-cache /wheels/* && rm -rf /wheels
1079
+ COPY . .
1080
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080"]
1081
+ ```
1082
+
1083
+ ## Run migrations separately
1084
+
1085
+ ```bash
1086
+ # Don't migrate on startup - use Cloud Build
1087
+ steps:
1088
+ # Run migrations first
1089
+ - name: 'gcr.io/cloud-builders/gcloud'
1090
+ entrypoint: 'bash'
1091
+ args:
1092
+ - '-c'
1093
+ - |
1094
+ gcloud run jobs execute migrate-job --wait
1095
+
1096
+ # Then deploy
1097
+ - name: 'gcr.io/cloud-builders/gcloud'
1098
+ args: ['run', 'deploy', 'my-service', ...]
1099
+ ```
1100
+
1101
+ ### Second Generation Execution Environment Differences
1102
+
1103
+ Severity: MEDIUM
1104
+
1105
+ Situation: Migrating to or using Cloud Run second-gen execution environment
1106
+
1107
+ Symptoms:
1108
+ Network behavior changes.
1109
+ Different syscall support.
1110
+ File system behavior differences.
1111
+ Container behaves differently than in first-gen.
1112
+
1113
+ Why this breaks:
1114
+ Cloud Run's second-generation execution environment uses a different
1115
+ sandbox (gVisor) with different characteristics:
1116
+
1117
+ - More Linux syscalls supported
1118
+ - Full /proc and /sys access
1119
+ - Different network stack
1120
+ - No automatic HTTPS redirect
1121
+ - Different tmp filesystem behavior
1122
+
1123
+ Recommended fix:
1124
+
1125
+ ## Explicitly set execution environment
1126
+
1127
+ ```bash
1128
+ # First generation (legacy)
1129
+ gcloud run deploy my-service \
1130
+ --execution-environment=gen1
1131
+
1132
+ # Second generation (recommended for most)
1133
+ gcloud run deploy my-service \
1134
+ --execution-environment=gen2
1135
+ ```
1136
+
1137
+ ## Handle network differences
1138
+
1139
+ ```python
1140
+ # Second-gen doesn't auto-redirect HTTP to HTTPS
1141
+ from fastapi import FastAPI, Request
1142
+ from fastapi.responses import RedirectResponse
1143
+
1144
+ app = FastAPI()
1145
+
1146
+ @app.middleware("http")
1147
+ async def redirect_https(request: Request, call_next):
1148
+ # Check X-Forwarded-Proto header
1149
+ if request.headers.get("X-Forwarded-Proto") == "http":
1150
+ url = request.url.replace(scheme="https")
1151
+ return RedirectResponse(url, status_code=301)
1152
+ return await call_next(request)
1153
+ ```
1154
+
1155
+ ## GPU access (second-gen only)
1156
+
1157
+ ```bash
1158
+ # GPUs only available in second-gen
1159
+ gcloud run deploy ml-service \
1160
+ --execution-environment=gen2 \
1161
+ --gpu=1 \
1162
+ --gpu-type=nvidia-l4
1163
+ ```
1164
+
1165
+ ## Check execution environment
1166
+
1167
+ ```python
1168
+ import os
1169
+
1170
+ def get_execution_environment():
1171
+ # Second-gen has different /proc structure
1172
+ try:
1173
+ with open('/proc/version', 'r') as f:
1174
+ version = f.read()
1175
+ if 'gVisor' in version:
1176
+ return 'gen2'
1177
+ except:
1178
+ pass
1179
+ return 'gen1'
261
1180
  ```
262
1181
 
263
- ## Anti-Patterns
1182
+ ### Request Timeout Configuration Mismatch
264
1183
 
265
- ### ❌ CPU-Intensive Work Without Concurrency=1
1184
+ Severity: MEDIUM
266
1185
 
267
- **Why bad**: CPU is shared across concurrent requests. CPU-bound work
268
- will starve other requests, causing timeouts.
1186
+ Situation: Long-running requests or background processing
269
1187
 
270
- ### ❌ Writing Large Files to /tmp
1188
+ Symptoms:
1189
+ Requests terminated before completion.
1190
+ 504 Gateway Timeout errors.
1191
+ Processing stops unexpectedly.
1192
+ Inconsistent timeout behavior.
271
1193
 
272
- **Why bad**: /tmp is an in-memory filesystem. Large files consume
273
- your memory allocation and can cause OOM errors.
1194
+ Why this breaks:
1195
+ Cloud Run has multiple timeout configurations that must align:
1196
+ - Request timeout (default 300s, max 3600s for HTTP, 60m for gRPC)
1197
+ - Client timeout
1198
+ - Downstream service timeouts
1199
+ - Load balancer timeout (for external access)
1200
+
1201
+ Recommended fix:
1202
+
1203
+ ## Set consistent timeouts
1204
+
1205
+ ```bash
1206
+ # Increase request timeout (max 3600s for HTTP)
1207
+ gcloud run deploy my-service \
1208
+ --timeout=900 # 15 minutes
1209
+ ```
274
1210
 
275
- ### Long-Running Background Tasks
1211
+ ## Handle long-running with webhooks
276
1212
 
277
- **Why bad**: Cloud Run throttles CPU to near-zero when not handling
278
- requests. Background tasks will be extremely slow or stall.
1213
+ ```python
1214
+ from fastapi import FastAPI, BackgroundTasks
1215
+ import httpx
279
1216
 
280
- ## ⚠️ Sharp Edges
1217
+ app = FastAPI()
1218
+
1219
+ @app.post("/process")
1220
+ async def process(data: dict, background_tasks: BackgroundTasks):
1221
+ task_id = create_task_id()
1222
+
1223
+ # Start background processing
1224
+ background_tasks.add_task(
1225
+ long_running_process,
1226
+ task_id,
1227
+ data,
1228
+ data.get("callback_url")
1229
+ )
1230
+
1231
+ # Return immediately
1232
+ return {"task_id": task_id, "status": "processing"}
1233
+
1234
+ async def long_running_process(task_id, data, callback_url):
1235
+ result = await heavy_computation(data)
1236
+
1237
+ # Callback when done
1238
+ if callback_url:
1239
+ async with httpx.AsyncClient() as client:
1240
+ await client.post(callback_url, json={
1241
+ "task_id": task_id,
1242
+ "result": result
1243
+ })
1244
+ ```
1245
+
1246
+ ## Use Cloud Tasks for reliable long-running
1247
+
1248
+ ```python
1249
+ from google.cloud import tasks_v2
1250
+
1251
+ def create_long_running_task(data):
1252
+ client = tasks_v2.CloudTasksClient()
1253
+ parent = client.queue_path(PROJECT, REGION, "long-tasks")
1254
+
1255
+ task = {
1256
+ "http_request": {
1257
+ "http_method": tasks_v2.HttpMethod.POST,
1258
+ "url": "https://worker.run.app/process",
1259
+ "body": json.dumps(data).encode(),
1260
+ "headers": {"Content-Type": "application/json"}
1261
+ },
1262
+ "dispatch_deadline": {"seconds": 1800} # 30 min
1263
+ }
1264
+
1265
+ return client.create_task(parent=parent, task=task)
1266
+ ```
281
1267
 
282
- | Issue | Severity | Solution |
283
- |-------|----------|----------|
284
- | Issue | high | ## Calculate memory including /tmp usage |
285
- | Issue | high | ## Set appropriate concurrency |
286
- | Issue | high | ## Enable CPU always allocated |
287
- | Issue | medium | ## Configure connection pool with keep-alive |
288
- | Issue | high | ## Enable startup CPU boost |
289
- | Issue | medium | ## Explicitly set execution environment |
290
- | Issue | medium | ## Set consistent timeouts |
1268
+ ## Streaming for long responses
1269
+
1270
+ ```python
1271
+ from fastapi import FastAPI
1272
+ from fastapi.responses import StreamingResponse
1273
+
1274
+ @app.get("/large-report")
1275
+ async def large_report():
1276
+ async def generate():
1277
+ for chunk in process_large_data():
1278
+ yield chunk
1279
+
1280
+ return StreamingResponse(generate(), media_type="text/plain")
1281
+ ```
1282
+
1283
+ ## Validation Checks
1284
+
1285
+ ### Hardcoded GCP Credentials
1286
+
1287
+ Severity: ERROR
1288
+
1289
+ GCP credentials must never be hardcoded in source code
1290
+
1291
+ Message: Hardcoded GCP service account credentials. Use Secret Manager or Workload Identity.
1292
+
1293
+ ### GCP API Key in Source Code
1294
+
1295
+ Severity: ERROR
1296
+
1297
+ API keys should use Secret Manager
1298
+
1299
+ Message: Hardcoded GCP API key. Use Secret Manager.
1300
+
1301
+ ### Credentials JSON File in Repository
1302
+
1303
+ Severity: ERROR
1304
+
1305
+ Service account JSON files should not be in source control
1306
+
1307
+ Message: Credentials file detected. Add to .gitignore and use Secret Manager.
1308
+
1309
+ ### Running as Root User
1310
+
1311
+ Severity: WARNING
1312
+
1313
+ Containers should not run as root for security
1314
+
1315
+ Message: Dockerfile runs as root. Add USER directive for security.
1316
+
1317
+ ### Missing Health Check in Dockerfile
1318
+
1319
+ Severity: INFO
1320
+
1321
+ Cloud Run uses HTTP health checks, Dockerfile HEALTHCHECK is optional
1322
+
1323
+ Message: No HEALTHCHECK in Dockerfile. Cloud Run uses its own health checks.
1324
+
1325
+ ### Hardcoded Port in Application
1326
+
1327
+ Severity: WARNING
1328
+
1329
+ Port should come from PORT environment variable
1330
+
1331
+ Message: Hardcoded port. Use PORT environment variable for Cloud Run.
1332
+
1333
+ ### Large File Writes to /tmp
1334
+
1335
+ Severity: WARNING
1336
+
1337
+ /tmp uses container memory, large writes can cause OOM
1338
+
1339
+ Message: /tmp writes consume memory. Consider Cloud Storage for large files.
1340
+
1341
+ ### Synchronous File Operations
1342
+
1343
+ Severity: WARNING
1344
+
1345
+ Sync file ops block the event loop in async apps
1346
+
1347
+ Message: Synchronous file operations. Use async versions for better concurrency.
1348
+
1349
+ ### Global Mutable State
1350
+
1351
+ Severity: WARNING
1352
+
1353
+ Global state issues with concurrent requests
1354
+
1355
+ Message: Global mutable state may cause issues with concurrent requests.
1356
+
1357
+ ### Thread-Unsafe Singleton Pattern
1358
+
1359
+ Severity: WARNING
1360
+
1361
+ Singletons need thread safety for concurrency > 1
1362
+
1363
+ Message: Singleton pattern - ensure thread safety if using concurrency > 1.
1364
+
1365
+ ## Collaboration
1366
+
1367
+ ### Delegation Triggers
1368
+
1369
+ - user needs AWS serverless -> aws-serverless (Lambda, API Gateway, SAM)
1370
+ - user needs Azure containers -> azure-functions (Azure Container Apps, Functions)
1371
+ - user needs database design -> postgres-wizard (Cloud SQL design, AlloyDB)
1372
+ - user needs authentication -> auth-specialist (Firebase Auth, Identity Platform)
1373
+ - user needs AI integration -> llm-architect (Vertex AI, Cloud Run + LLM)
1374
+ - user needs workflow orchestration -> workflow-automation (Cloud Workflows, Eventarc)
291
1375
 
292
1376
  ## When to Use
293
- This skill is applicable to execute the workflow or actions described in the overview.
1377
+
1378
+ Use this skill when the request clearly matches the capabilities and patterns described above.