← Back to Pull requests

Database timeouts, encrypted authenticator secrets, session idle timeout #50

Closed
unknown closed this pull request without merging on Nov 10, 2026 20:04 UTC
View on GitHub
unknown unknown commented on Nov 10, 2026 19:53 UTC
Author

Three findings from the production-readiness review (O7, O8, O9), one commit each.

1. Database timeouts (O9)


  • The pool connects every session with statement_timeout 30 s and idle_in_transaction_session_timeout 60 s, so a query stuck behind a lock or an abandoned transaction can no longer hold locks and a pool slot indefinitely.

  • migrate() lifts the statement timeout for its own connection and restores it before the connection is reused, so a slow migration or the wait for another starter under the advisory lock is not cut short.

  • A cancelled statement (SQLSTATE 57014) answers 503 retry_later instead of 500.
  • 2. Authenticator secrets encrypted at rest (O7)


  • New optional MFA_ENCRYPTION_KEY (32 random bytes, base64). With it, TOTP secrets are sealed with AES-256-GCM, bound to their owner's id (lib/secretBox.ts).

  • Secrets stored earlier keep working and are sealed the next time they are used.

  • Without the key nothing changes and the API warns at start, so staging keeps booting until the secret is set. The key is added to the Fly secrets workflow options, the README and docs/18.

  • Losing or changing the key locks accounts with 2FA out; the docs say to keep a copy.
  • 3. Session idle timeout and cross-tab sign-out (O8)


  • Migration 031: sessions.last_seen_at. The API refuses a session unused for 14 days, or 30 minutes for a PreFlop team account. Use is recorded at most once a minute.

  • The console signs a team account out after 30 minutes without input in any console tab (activity is shared through localStorage).

  • Web and console follow a sign-out or sign-in made in another tab and clear what was cached for the previous account.

  • Shared helpers watchIdle and watchStorageKey live in @preflop/client.
  • Behaviour changes to know


  • Team sessions on staging older than 30 minutes are signed out when this deploys.

  • The console's polling keeps a team session alive on the server while a tab is open and visible; the 30-minute sign-out there comes from the console's own input timer.

  • Tokens still live in localStorage; moving them to httpOnly cookies is a larger change and is not part of this PR.
  • Test plan


  • API suite: 378 passed (Chromium end-to-end file excluded locally, covered by CI); new tests for pool timeouts, migration exemption, secret box, encrypted and legacy secrets, idle limits

  • Client 38, web 160, console 74, table 98 passed; repo typecheck clean

  • The console idle sign-out and cross-tab behaviour were not exercised in a browser, only through the unit-tested helpers

  • CI green
  • Diff: 322 lines (+241 / -81) across 4 files Reviewer: DansiDanutz Review duration: 11m
    All Vouch review confidence checks passed
    Residual risk 0.26 = Change Risk (0.65) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.65 · 322 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%
    60%
    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.346
    Shallow Review Depth shallow_review_depth
    0.289
    Sensitive Paths sensitive_paths
    0.065
    Real PR Conversation Timeline
    1 comments
    "Review active on #50"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% 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.1% (HIGH) · Higher = larger blast radius
    65.1%
    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: 60.5% · Lower = rushed or shallow review
    60.5%
    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: 25.7% · Safe to merge
    25.7%