← Back to Pull requests

Fix Missing Connection Metadata #232

Open
0xTim opened this pull request with 74 lines diff across 5 files
View on GitHub
0xTim 0xTim commented on Sep 24, 2026 15:19 UTC
Author

Resolves https://github.com/vapor/fluent-postgres-driver/issues/230

The only metadata that is set in the stack is the connection ID, so make sure we copy that over into a new logger. Can't do the other way around in case we pollute other loggers. I'll be glad when we can remove all these hacks and just use task locals...

Diff: 74 lines (+66 / -8) across 5 files Reviewer: ptoffy Review duration: 20053m
All Vouch review confidence checks passed
Residual risk 0.03 = Change Risk (0.35) × (1 − Review Confidence (0.90)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.35 · 74 lines diff across 5 files
0.35
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.89 · 5 substantive comment(s)
0.89
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
90%
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.258
Real PR Conversation Timeline
8 items
codecov[bot] codecov[bot] commented on Sep 24, 2026 15:24 UTC
Bot

Codecov Report


:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 65.09%. Comparing base (26fe819) to head (4e64aa3).

<details><summary>Additional details and impacted files</summary>

@@            Coverage Diff             @@
##             main     #232      +/-   ##
==========================================
+ Coverage   64.36%   65.09%   +0.72%     
==========================================
  Files          12       12              
  Lines         609      616       +7     
==========================================
+ Hits          392      401       +9     
+ Misses        217      215       -2     

| Files with missing lines | Coverage Δ | |
|---|---|---|
| ...tPostgresDriver/FluentPostgresClientDatabase.swift | 88.34% <100.00%> (+0.34%) | :arrow_up: |
| .../FluentPostgresDriver/FluentPostgresDatabase.swift | 70.49% <100.00%> (+5.57%) | :arrow_up: |
</details>
<details><summary> :rocket: New features to boost your workflow: </summary>

  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

  • </details>

    ptoffy ptoffy commented on code on Sep 29, 2026 10:30 UTC
    Code Review
    Sources/FluentPostgresDriver/FluentPostgresDatabase.swift:1
    @@ -38,10 +38,10 @@ extension _FluentPostgresDatabase: Database {
         }
     
         func withConnection<T>(_ closure: @escaping @Sendable (any Database) -> EventLoopFuture<T>) -> EventLoopFuture<T> {
    -        self.withConnection { (underlying: any PostgresDatabase) in
    +        self.withConnection { (connection: PostgresConnection) in
                 closure(
                     _FluentPostgresDatabase(
    -                    database: underlying.logging(to: self.logger).sql(
    +                    database: connection.logging(withConnectionIDTo: self.logger).sql(
    ptoffy ptoffy commented on code on Sep 29, 2026 10:31 UTC
    Code Review
    Sources/FluentPostgresDriver/FluentPostgresClientDatabase.swift:1
    @@ -91,7 +91,7 @@ extension _FluentPostgresClientDatabase: Database {
         private func scoped(to conn: PostgresConnection, inTransaction: Bool? = nil) -> Self {
             .init(
                 source: .connection(conn
    -                .logging(to: self.logger)
    +                .logging(withConnectionIDTo: self.logger)

    Here as well

    ptoffy ptoffy requested changes on Sep 29, 2026 10:31 UTC
    Changes Requested Reviewer

    We should not be using PostgresDatabase anymore

    0xTim 0xTim commented on code on Sep 29, 2026 11:40 UTC
    Code Review
    Sources/FluentPostgresDriver/FluentPostgresDatabase.swift:1
    @@ -11,6 +11,7 @@ struct _FluentPostgresDatabase<E: PostgresJSONEncoder, D: PostgresJSONDecoder> {
         let encodingContext: PostgresEncodingContext<E>
         let decodingContext: PostgresDecodingContext<D>
         let inTransaction: Bool
    +    let connection: PostgresConnection?

    We had to add this to avoid a crash in withConnection in a transaction

    ptoffy ptoffy commented on code on Sep 29, 2026 13:23 UTC
    Code Review
    Sources/FluentPostgresDriver/FluentPostgresDatabase.swift:1
    @@ -11,6 +11,7 @@ struct _FluentPostgresDatabase<E: PostgresJSONEncoder, D: PostgresJSONDecoder> {
         let encodingContext: PostgresEncodingContext<E>
         let decodingContext: PostgresDecodingContext<D>
         let inTransaction: Bool
    +    let connection: PostgresConnection?

    We don't need this, Sorry, I was on mobile and misread. Only the FluentPostgresClientDatabase should use the new .sql method taking a logger. The current FluentPostgresDatabase can stay as it is, with the new major it will be deprecated along with PostgresDatabase

    0xTim 0xTim commented on code on Oct 02, 2026 13:33 UTC
    Code Review
    Sources/FluentPostgresDriver/FluentPostgresDatabase.swift:1
    @@ -11,6 +11,7 @@ struct _FluentPostgresDatabase<E: PostgresJSONEncoder, D: PostgresJSONDecoder> {
         let encodingContext: PostgresEncodingContext<E>
         let decodingContext: PostgresDecodingContext<D>
         let inTransaction: Bool
    +    let connection: PostgresConnection?

    Done!

    Reviewers
    Assignees
    0xTim 0xTim
    Labels
    risk: low confidence: 90.4% reviewed
    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: 34.7% (LOW) · Higher = larger blast radius
    34.7%
    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: 90.4% · Lower = rushed or shallow review
    90.4%
    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: 3.3% · Safe to merge
    3.3%