fix(infra): cap Function scale-out to fit Postgres connections #549
All Vouch review confidence checks passed
Residual risk 0.28 = Change Risk (0.65) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.65 · 335 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.348
Shallow Review Depth
shallow_review_depth
0.289
Sensitive Paths
sensitive_paths
0.065
Real PR Conversation Timeline
1 comments
"Review active on #549"
general
weight: 0.35
mattmck
What
Caps how many Function App instances can run at once and makes a full Postgres server a retryable error. Closes #548
Why
A 65-source bulk ingestion on deployed dev (2026-11-25) failed nine jobs with
remaining connection slots are reserved for roles with the SUPERUSER attribute; six stayedrunningbecause the failure itself could not be written.Connections are already pooled and reused inside each instance (
PG_POOL_MAX, 10). The Consumption plan adds instances for a long queue with no upper limit, and each instance has its own pool. B1ms Postgres accepts 50 connections and reserves 15, so four busy instances exhaust it. A shared pooler (built-in PgBouncer) is not available on the Burstable tier.How
site_config.app_scale_limit = var.function_app_scale_limit(default 3, GitHub variableFUNCTION_APP_SCALE_LIMIT): 3 × 10 = 30 of 35 connections.function_app_scale_limit × pg_pool_maxexceedspg_app_connection_limit(35), so the two cannot drift apart.isRetryableConnectionErrorinsrc/lib/db.tsnow covers SQLSTATE 53300 / "remaining connection slots" / "too many clients", for the queries that were already retry-safe (SELECT,UPDATE ingestion_job).batchSizeis 1 per instance); the rest wait in the queue.Not verified against Azure: the plan has not been run;
terraform validatepasses locally.Checklist
npm run typecheckpasses (functions)npm run lintpasses (functions)npm run build:websucceeds (no web changes)npm run build:functionssucceedsterraform validate)docs/agents/environment-variables.md,infrastructure/README.md,docs/agents/completed-work.md)🤖 Generated with Claude Code
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
<!-- coderabbit-ai-generated:v1 -->
Summary by CodeRabbit
- Added a configurable Function App scaling limit, defaulting to 3 instances.
- Infrastructure plans now check that the app’s scale limit and database connection pool fit within the available PostgreSQL connections.
- PostgreSQL connection-limit errors are now treated as retryable, alongside connection timeouts.
- Updated infrastructure and environment-variable guidance to describe scaling limits, database connection capacity, and retry behavior.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->