fix(webapp): retry branch environment lookups that race replica lag - #4857
fix(webapp): retry branch environment lookups that race replica lag#4857myftija wants to merge 1 commit into
Conversation
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review. 📜 Recent review details⏰ Context from checks skipped due to timeout. (35)
🧰 Additional context used📓 Path-based instructions (9)Never use `request.signal` to detect client disconnects. Use `getRequestAbortSignal()` from `app/services/httpAsyncStorage.server.ts`, which is wired to Express response close events.📄 CodeRabbit inference engine (apps/webapp/CLAUDE.md) Files:
For dashboard changes, visually verify the running Remix app with Chrome DevTools MCP, using snapshots, screenshots, interaction, and console-message checks as appropriate.📄 CodeRabbit inference engine (apps/webapp/CLAUDE.md) Files:
**Prefer static imports over dynamic imports.** Only use dynamic `import()` when:📄 CodeRabbit inference engine (AGENTS.md) Files:
Add crumbs as you write code — not just when debugging. Mark lines with📄 CodeRabbit inference engine (AGENTS.md) Files:
Use zod for validation in packages/core and apps/webapp📄 CodeRabbit inference engine (.github/copilot-instructions.md) Files:
Access environment variables through the `env` export of `env.server.ts` instead of directly accessing `process.env`📄 CodeRabbit inference engine (.cursor/rules/webapp.mdc) Files:
Use function declarations instead of default exports📄 CodeRabbit inference engine (.github/copilot-instructions.md) Files:
Use types over interfaces for TypeScript📄 CodeRabbit inference engine (.github/copilot-instructions.md) Files:
When creating or editing OTEL metrics (counters, histograms, gauges), ensure metric attributes have low cardinality by using only enums, booleans, bounded error codes, or bounded shard IDs📄 CodeRabbit inference engine (.cursor/rules/otel-metrics.mdc) Files:
🔇 Additional comments (1)
WalkthroughThe change adds a shared read-replica retry helper with jittered delays, primary fallback, outcome telemetry, and tests. Runtime environment resolution, personal access token authentication, organization access token authentication, and RBAC branch resolution use the retry path for missing branch environments. A changelog entry documents the fix for first deploys on newly created preview branches. Merge Risk: 🟡 Moderate · up to This PR reduces preview-branch authentication failures by retrying replica lookups and falling back to the primary, but it can briefly combine fresh branch data with stale authorization state during revocations or membership changes, while invalid branch requests can add primary-database load. Required branch-local instrumentation and test placement follow-up also remain outstanding, so merge requires explicit owner acceptance or fixes. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
The first deploy of a newly created branch upserts the branch environment and immediately authenticates with it, so the auth-time replica read can miss the just-committed row and the request fails. Branch lookups in API auth (PAT and OAT resolution, the RBAC bearer resolver, and the legacy API key resolver) now retry the replica once with jitter and fall back to the primary before reporting the branch missing. Installs without a dedicated read replica skip the retry entirely.
9591de6 to
ea07db3
Compare
Background
The first deploy of a newly created preview branch could fail because of a read-replica race: the deploy creates the branch environment on the primary and immediately authenticates with it, but auth-time branch resolution reads the replica, which may not have the row yet. The request then fails with "Branch not found" or "No matching branch env" even though the branch exists.
Fix
Branch environment lookups in API auth now retry the replica once with a short jittered delay and fall back to the primary before reporting the branch missing. The retry primitive follows the same replica-retry-then-primary approach as #3889.