fix(db-part-3): bound cross-request shared promises against pool wedge#5021
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryMedium Risk Overview
OAuth token refresh and Vanta token exchange use Webhook undeploy paths gain docs that Reviewed by Cursor Bugbot for commit 3331547. Configure here. |
Greptile SummaryThis PR adds bounded settle deadlines to all cross-request shared promises to prevent hung producers from wedging callers indefinitely until process restart.
Confidence Score: 4/5Safe to merge once the hung-chain accumulation in withMcpOauthRefreshLock is understood and accepted as a known trade-off. All five fixes are correctly implemented and the new test coverage is comprehensive. The one gap worth attention is in withMcpOauthRefreshLock: if prev (the original hung link) never settles, the chain of unresolved promise links accumulates in inflightChains for the row until the process restarts. In normal operation the inner SDK/HTTP/Redis timeouts prevent this, but it is an implicit invariant with no explicit guard. apps/sim/lib/mcp/oauth/storage.ts — specifically the inflightChains growth path when prev is permanently hung. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[coalesceLocally called] --> B{Entry in inflight map?}
B -->|yes| C[Return existing promise - join producer]
B -->|no| D[Create async IIFE + settle timer]
D --> E[Promise.race: IIFE vs timer]
E --> F[inflight.set key to guarded]
F --> G[Return guarded to all callers]
G --> H{Who settles first?}
H -->|fn resolves| I[finally: clearTimeout + evict identity-check]
I --> J[guarded resolves - all joiners get value]
H -->|30s timer fires| K[evict before reject - clears inflight entry]
K --> L[guarded rejects with CoalesceSettleTimeoutError]
L --> M[All joiners get error - next caller mints fresh entry]
G2[withMcpOauthRefreshLock caller] --> Q[Chain next off prevSettled]
Q --> R[inflightChains.set key to next]
R --> S[await Promise.race prevSettled vs queueDeadline]
S -->|prevSettled wins| T[clearTimeout - return next - fn runs]
S -->|90s queueDeadline fires| U[queueTimedOut=true - throw error]
U --> V[next rejects with abandoned message when prev settles]
Reviews (2): Last reviewed commit: "address comments" | Re-trigger Greptile |
|
@greptile |
Summary
identity-checked eviction; defer fn() so a sync throw can't hit the TDZ
null-on-failure contract across all ~70 call sites
can't pile up callers; never aborts a running fn (would orphan the client)
poisoned forever); vanta: 15s token-exchange timeout
Type of Change
Testing
Tested manually
Checklist