← Back to Pull requests

fix(infra): cap Function scale-out to fit Postgres connections #549

Closed
unknown closed this pull request without merging on Nov 26, 2026 02:47 UTC
View on GitHub
unknown unknown commented on Nov 26, 2026 02:37 UTC
Author

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 stayed running because 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 variable FUNCTION_APP_SCALE_LIMIT): 3 × 10 = 30 of 35 connections.

  • A Terraform precondition fails the plan when function_app_scale_limit × pg_pool_max exceeds pg_app_connection_limit (35), so the two cannot drift apart.

  • isRetryableConnectionError in src/lib/db.ts now covers SQLSTATE 53300 / "remaining connection slots" / "too many clients", for the queries that were already retry-safe (SELECT, UPDATE ingestion_job).

  • Effect on ingestion: at most three jobs run at once (queue batchSize is 1 per instance); the rest wait in the queue.
  • Not verified against Azure: the plan has not been run; terraform validate passes locally.

    Checklist

  • PR title follows Conventional Commits

  • npm run typecheck passes (functions)

  • npm run lint passes (functions)

  • npm run build:web succeeds (no web changes)

  • npm run build:functions succeeds

  • Tested locally (new unit test; terraform validate)

  • Updated relevant docs (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

  • New Features

  • - 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.
  • Bug Fixes

  • - PostgreSQL connection-limit errors are now treated as retryable, alongside connection timeouts.
  • Documentation

  • - 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 -->

    Diff: 335 lines (+251 / -84) across 4 files Reviewer: mattmck Review duration: 10m
    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
    0.65
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 65.4% (HIGH) · Higher = larger blast radius
    65.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 28.3% · Safe to merge
    28.3%