Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(relay): T3 Connect links no longer fail on colliding prepared statements #15411

Mergedjuliusmarmingemerged 1 commit intomain fromrefs/pull/15411/headmerged by juliusmarminge View on GitHub

juliusmarmingecommented

Problem

Since the relay deploy of #9386 on 2026-09-25 at 00:18 UTC, about 40% of managed endpoint provisions fail. Roughly two thirds of new T3 Connect links fail with managed_endpoint_provisioning_failed (#14070). Every trace reported in the issue fails the same way, at stage record-dns on the lock-tunnel query:

bind message supplies 5 parameters, but prepared statement "effect10" requires 0

@effect/sql-pg rc.115 names prepared statements effect1..N from a counter that restarts on each connection, and Alchemy builds a new pool for every Worker request. Behind Hyperdrive's transaction-mode pool, a statement Bind inside a transaction (the withClaimedTunnel SELECT … FOR UPDATE that #9386 added) can land on another request's statement registered under the same name. This is upstream Effect-TS/effect#8320. Statements outside transactions have not failed. About 1.2k errors a day are invalid input syntax for type integer: "<uuid>": collisions where the parameter counts matched, so a Bind reached another query's plan.

Change

  • The relay's PgClient uses prepare: false, so every statement is unnamed and cannot collide. Alchemy's Drizzle.Postgres only forwards url and ssl, so the existing alchemy patch gains an optional third argument of PgClient options.
  • Provisioning failures that have no underlying error now set reason (claim-lost, endpoint-mismatch, invalid-tunnel-response), exported as error.reason. The biggest cause-less group (about 4.4k a day at mark-allocation-ready) currently says nothing about why the stage failed.

This is a stopgap. sql-pg 4.0.0 (via #14914) mints random per-connection names, but prepare: false stays the setting that does not depend on Hyperdrive tracking named statements. The cost is the backend plan cache: the reporter of Effect-TS/effect#8320 measured +21ms p50. The unnamed path still sends Parse/Bind/Execute in one write.

Scope and approval

Fixes #14070. Triage, with Axiom trace lookups for every reported trace ID, was requested by a maintainer. This PR does not cover the unlink failures in the same thread (Cloudflare refuses to delete a tunnel with active connections) or the client-side Unauthorized: Tunnel not found match.

Verification

  • Statement naming against a local Postgres 17 with log_statement=all, through the patched Drizzle.Postgres:
    • default: execute effect1 … execute effect4 (BEGIN/COMMIT are named too)
    • prepare: false: only execute <unnamed>
  • Collision repro: two requests share one backend session through a small proxy, as Hyperdrive does. The default setting fails with prepared statement "effect1" already exists. With prepare: false, both succeed.
  • The worker bundle built with the worker resolve condition contains the patched PgClient.layer({ ...pgClient, ... }) call and prepare: false.
  • vp test run on the relay ManagedEndpointProvider, ManagedEndpointAllocations, observability, and http tests: 79 passed. Claim-loss tests now assert reason: "claim-lost".
  • tsc --noEmit for infra/relay passes.

Not verified: production effect. That needs the relay deploy, which runs on merge to main. After deploy, record-dns failures with 08P01 in t3-code-relay-traces-prod should drop to zero.

🤖 Generated with Claude Code (Claude Opus 5.5)


Devin Review
    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    2. juliusmarminge removed labelsvouch:trusted

    3. juliusmarminge added labelsmacroscope-review

    4. Approvability

      Verdict: Not approved

      Macroscope's review found this PR not approvable — The PR changes the relay's production database behavior by disabling prepared statements for all requests, with an acknowledged performance tradeoff and no production-effect verification yet. The accompanying error metadata and tests are low risk, but the runtime default change warrants human review.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    5. Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire4.9 KiB4.9 KiB0 B (0.0%)6.8 KiB✅
      CodexThread snapshot wire3.7 KiB3.7 KiB0 B (0.0%)4.9 KiB✅
      CodexLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
      CodexLive turn WebSocket decoded20.4 KiB20.4 KiB0 B (0.0%)29.3 KiB✅
      CodexLive turn messages220 (0.0%)8✅
      ClaudeTotal thread wire4.9 KiB4.9 KiB0 B (0.0%)6.8 KiB✅
      ClaudeThread snapshot wire3.7 KiB3.7 KiB0 B (0.0%)4.9 KiB✅
      ClaudeLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
      ClaudeLive turn WebSocket decoded20.8 KiB20.8 KiB0 B (0.0%)29.3 KiB✅
      ClaudeLive turn messages220 (0.0%)8✅

      Baseline: 2a45557 · PR result: 11938ea · Source CI: success

      Scenario and decoded snapshot size

      10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

      • Codex decoded thread snapshot: 106.1 KiB
      • Claude decoded thread snapshot: 106.4 KiB

      Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

    6. Review in Change Stack →

      Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration
      • Configuration used: Repository: pingdotgg/t3code/.coderabbit.yaml
      • Review profile: CHILL
      • Plan: Team
      • Run ID: 52851c08-0712-4445-8c89-5eaa0689d4c7
      📥 Commits

      Reviewing files that changed from the base of the PR and between 2a455570e6ee70a59241c30126b50c7df1696a6a and 11938eaec6d57588db28d4edf06859458f56cdba.

      ⛔ Files ignored due to path filters (1)
      • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
      📒 Files selected for processing (4)
      • infra/relay/src/environments/ManagedEndpointProvider.test.ts
      • infra/relay/src/environments/ManagedEndpointProvider.ts
      • infra/relay/src/worker.ts
      • patches/alchemy@2.0.0-beta.79.patch

      Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.


      📝 Walkthrough

      Walkthrough

      The relay adds reason codes to managed-endpoint provisioning failures. The Postgres patch adds optional client settings, and the relay worker disables prepared statements for its database client.

      Changes

      Managed endpoint provisioning reasons

      Layer / File(s)Summary
      Define and classify provisioning failures
      infra/relay/src/environments/ManagedEndpointProvider.ts
      ManagedEndpointProvisioningFailed gains an optional reason. Endpoint verification failures receive endpoint-mismatch, and invalid tunnel responses receive invalid-tunnel-response.
      Mark lost allocation claims
      infra/relay/src/environments/ManagedEndpointProvider.ts, infra/relay/src/environments/ManagedEndpointProvider.test.ts
      Provisioning and origin reconciliation identify lost or missing claimed updates as claim-lost. Three provisioning test expectations check this reason.

      Postgres client options

      Layer / File(s)Summary
      Configure Postgres client connections
      patches/alchemy@2.0.0-beta.79.patch, infra/relay/src/worker.ts
      The Postgres API accepts optional client settings and merges them with URL-derived settings, which take precedence. The relay worker sets prepare: false.

      Priority: ➖ Normal

      Estimated code review effort: 3 (Moderate) | ~20 minutes

      Change: Bug fix · Severity of issue fixed: Medium

      Suggested reviewers: t3dotgg

      Merge Risk: ⚪ Minimal · up to 11938

      No actionable issue remains before merge. The Hyperdrive fix still needs production validation, but there is no evidence that it fails.

      🚥 Pre-merge checks | ✅ 4 | ❌ 1

      ❌ Failed checks (1 warning)

      Check nameStatusExplanationResolution
      Out of Scope Changes check⚠️ WarningThe patch also changes Vitest hook imports to vite-plus/test in source and built test modules. These test-runner import changes have no stated connection to fixing relay provisioning or forwarding P…Remove the unrelated test-runner import changes from the Alchemy patch, or provide evidence that they are required for the PgClient-options change.
      ✅ Passed checks (4 passed)
      Check nameStatusExplanation
      Title check✅ PassedThe title clearly summarizes the primary fix: preventing prepared-statement collisions that cause T3 Connect links to fail.
      Description check✅ PassedThe description covers the problem, change, scope and approval, and verification. It includes focused test results and clearly states that production behavior remains unverified pending deployment.
      Linked Issues check✅ Passed[ #14070 ] The relay uses prepare: false to avoid named-statement collisions during provisioning through Hyperdrive. The Alchemy patch forwards PgClient options, and provisioning failures now includ…
      Docstring Coverage✅ PassedNo functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 3…
      Full details: Out of Scope Changes check

      Explanation

      The patch also changes Vitest hook imports to vite-plus/test in source and built test modules. These test-runner import changes have no stated connection to fixing relay provisioning or forwarding PgClient options.

      • Fix all pre-merge checks with AI
      ✨ Finishing Touches
      📝 Generate docstrings
      • Commit to this branch
      • Create a new PR
      🧪 Generate unit tests (beta)
      • Commit to this branch
      • Create a new PR
      • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

      Comment `@coderabbitai help` to get the list of available commands.
    7. juliusmarminge merged this4059607

    8. juliusmarminge closed this

    9. this was not fixed btw defaulting back to claude and codex desktop, i cannot use T3 if i cannot use it on my phone.

      CleanShot 2026-10-04 at 8 57 05 AM@2x

Sign in to join this conversation.