Repository navigation
AI-3506: one unreachable shard no longer stops sessions and bridges on the others - #2256
Conversation
…others A session with a generated id skips the cross-shard id check. A bridge claim and a placed call's lookup settle on the shards that answered when one of them returned the row, and log each shard that did not. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
/jeffery review |
|
Thanks for asking Jeffery for review. I'll stay on this PR until I can approve it. How it works
Commands (each as a whole comment)
|
…ts lines Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tles it Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Stream delivers it again, and nothing was acted on, so the delivery once every shard answers is dispatched. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The bridge may be on the shard that did not answer, so the vendor is told to fetch again rather than that the call is not waiting. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Withdrawing approval until 1cf18e8 is reviewed.
There was a problem hiding this comment.
✅ Approved 1cf18e8efb20 after 2 rounds · 1 dropped after discussion
Left open, your call:
- consider: Bridge claim can be deleted on a peer yet answered as retryable (
acceleration/internal/store/call_bridge.go:92) - consider: Peer that fails after the settling answer is never logged (
acceleration/internal/store/shards.go:174)
|
/jeffery review |
Nothing changed since round 2 on |
A settled read returns without cancelling the other shards' reads, which run on to their bound detached from the caller, so a shard that is down is logged once it fails rather than cut off unseen. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Round 2: one point fixed (a late peer failure is now logged, ab6a0a0). The other is kept as a trade-off: a claim's delete cut off by the 2 s peer bound can still turn a retry into a 404, and bounding the read is what keeps a partitioned peer from failing every fetch. Both threads have the details. |
Withdrawing approval until ab6a0a0 is reviewed.
… a claim 5 s A detached read held a peer pool connection for its whole bound. Only a shard that failed before the settle is logged. A claim's delete on a peer gets a longer bound, since one committed after the caller stopped waiting spends the bridge. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… ringing A call.session_started older than 45 s whose placement cannot be read is dropped and logged, as before, rather than answered 503: a delivery that lands once the shard is back would send a worker to a call nobody is on. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Withdrawing approval until 34692c4 is reviewed.
There was a problem hiding this comment.
Round 4 on 34692c43aeeb · 🆕 1 new
Still open: 1 should-fix. Full list on the checks tab.
| // agent on it. While the caller may still be ringing, Stream is told to deliver it again, | ||
| // and nothing has been acted on yet. Past that, a delivery that lands once the shard is | ||
| // back would send a worker to a call its caller has left, so it is dropped as before. | ||
| if at := eventTime(event.CreatedAt); !at.IsZero() && time.Since(at) <= arrivingCallRetryFor { |
There was a problem hiding this comment.
[Should Fix] Peer-shard outage answers 503 to every video call start
Issue: While a peer shard is down, every call.session_started in the app, video calls included, is answered 503 for 45 seconds after the call's created_at. Stream retries webhooks for calls no phone number reaches.
Cause: dispatchArrivingCall runs CallResources.Select at line 178, before the number lookup at line 203. The error branch at 184-188 returns 503. At ce41c39 a Select error was logged and answered 200.
Fix: Look up the number first and return the 503 only when a number reaches the call. Otherwise keep the log-and-200. Or: keep the order and accept the 503 on video calls, which costs retry traffic on calls that never involve telephony.
Evidence
- callhooks.go:178 Select runs for every call.session_started
- callhooks.go:184-188 a Select error within 45s of created_at returns false, which answers 503
- callhooks.go:203-210 number lookup comes after Select
- git show ce41c39: a Select error was logged and answered 200
There was a problem hiding this comment.
✅ Approved 34692c43aeeb after 4 rounds · 1 fixed · 2 dropped after discussion
Left open, your call:
- should-fix: Peer-shard outage answers 503 to every video call start (
acceleration/internal/api/callhooks.go:184)
|
/jeffery review |
Nothing changed since round 4 on |
…it cut off (#2379) **Problem** `CallBridges.Claim` and `CallResources.Select` read every shard at once and return as soon as one shard's answer settles the read; the other shards' reads are cancelled and not waited for (`answeringShards`, #2256). `TestABridgeIsClaimedOnceFromAnyShardAndSweptOnceExpired` and `TestCallResourceQueryBudgets` counted statements straight after the call returned, so in the sharded suite the cut-off read was sometimes not counted yet (1 for 2), and then landed in the next count (`Pin`, 3 for 2). Main's store job went red on it. **Fix** - The two budgets that wrap a settled read count with `countSettledReads`, which waits, up to a deadline, until a statement from every shard is in, then counts. No assertion changes: each still expects one statement a shard. - The code stays as it is. Waiting in `answeringShards` for the cancelled reads was tried and brings back the stall #2256 removed: pgdriver lets go of a read on a host that accepts and never answers only at its deadline, not on cancel, and `TestACallPlacedOnAShardThatAnswersIsFoundWithoutWaitingOnOneThatDoesNot` failed with it (2.0s against a 2s bound). **Tests** - On main, `-count=30` of the two tests in the sharded suite failed in at least five runs (the kept output does not hold the full count): `Select` expected 2, got 1, followed by `Pin` expected 2, got 3, and `Claim asks every shard once` expected 2, got 1. With the change, `-count=30` of both tests in both store suites passed. - A mutant that reads only this shard in `answeringShards` fails both budgets ("a statement from every shard" never satisfied).
Why
https://linear.app/stream/issue/AI-3506/one-unreachable-shard-stops-new-sessions-and-inbound-calls-on-every
On a deployment with peer shards, three paths asked every shard and failed when one did not answer, so one shard being down stopped work that belongs to the healthy ones.
What changed
session/manager.go): the id check (Sessions.Exists, plus the thread channel lookup) is skipped whenCreategenerated the id itself. A UUIDv7 made a moment ago cannot be taken, and it can never start withthread-. A voice session with a generated id that holds its own call, named after that id, also skips theCallResources.Pinread, since no line can have been made for that call yet. A caller-chosen id is still checked, so it is still refused while a peer is down: that shard may hold the id.CallBridges.Claim(store/call_bridge.go): the bridge is returned when any shard returned it, and each shard that did not answer is logged at warn (shard,error), at most once a minute per shard. Before this change, a bridge deleted on a healthy shard was thrown away with the error. The claim fails only when no shard returned the bridge and one did not answer. That failure isstore.ErrShardUnanswered, and the plan fetch (answerPhoneCall) answers it with a 503, not a 404, so the vendor fetches again.CallResources.Select): rows from any shard settle the question, and the shard that did not answer is logged at warn. A call the router placed on a healthy shard is now recognised as placed when a peer is down. When no shard has rows and one did not answer, the hook answers 503 (unavailable), as it already does for a join it could not record, so Stream delivers the event again. It does so only while the event is younger than 45 s (arrivingCallRetryFor, justified in a comment). An older one is dropped and logged as before, because a redelivery that lands after the shard recovers would send a worker to a call its caller has left. Nothing has been acted on by the time of the 503: the leg, the delivery record (acting) and the dispatch all come after it. A redelivery that arrives once every shard answers is therefore dispatched, and a test covers that.answeringShards): a read of another shard getspeerReadTimeout(2 s), except a bridge claim's, which getsclaimReadTimeout(5 s). The claim's read deletes the bridge: a delete that commits on a peer just after the caller stops waiting spends the bridge, and the longer bound narrows that window to a peer that is effectively down. I chose the longer bound over letting the delete outlive the cap, because a late commit would lose the bridge either way. As soon as one shard's answer settles the read (rows found, or a bridge claimed), the remaining reads are cancelled, so a slow peer frees its pool slot (8 connections) at once. Only a shard that failed before the settle is logged, since one cut off by it is not known to be down. A down shard still fails the reads that do need it, andcontext.Canceledis never logged as a shard failure. A host that accepts a connection and never answers would otherwise hold the call for pgdriver's 10 s read timeout.everyShardis unchanged and keeps its fail-closed contract for list pages.call_resourcesrow on any shard, so while any peer is down it is answered 503 for 45 s and then dropped. It is still not answered. Dispatching it means failing open, which is the open decision (commented on AI-3651).answerWithAgent(callhooks.go,spec.ID = callID) opens the session of a number's agent under the call id that Stream rendered.Createsees that id as caller-chosen, soExists(andPin) still fail while a peer is down. Such a call still is not answered, even with the bounded reads and the 503. This needs a decision, not a skip: the id comes from Stream, not this router, so a session under it on the shard that is down cannot be ruled out.deliverByPhone(scheduled_delivery.go) mintsuuid.NewString(), places the call, and only then opens the session with that id. With a peer down, the user's phone rings and the session is refused. Campaign and outboundphone.Callsessions follow the same order. Fixing that means carrying a "router-minted" flag fromapi/phoneintosession.Spec.Pinalso needs a different rule for these: it answers the newest row, so a result settled without the shard that is down could name the wrong Stream app.anotherCustomersSession(api/phone.go) has the sameExistsexposure.No overlap with #2177: it edits
OpenShardsandSessions.Upsert, and this PR edits neither.Tests
The tests use a peer shard whose DSN points at
127.0.0.1:1, where nothing listens, or at a local listener that accepts connections and never answers.store, in bothStoreSuiteandShardedStoreSuite:TestABridgeOnAShardThatAnswersIsClaimedWhileAnotherIsDownTestABridgeNoAnsweringShardHoldsIsNotClaimedWhileAnotherIsDown(nowErrShardUnanswered)TestACallPlacedOnAShardThatAnswersIsFoundWhileAnotherIsDownTestACallNoAnsweringShardPlacedIsNotAnsweredWhileAnotherIsDownTestACallPlacedOnAShardThatAnswersIsFoundWithoutWaitingOnOneThatDoesNot(silent listener)TestABridgeNoShardHoldsIsRefusedOnceASilentShardRunsOutOfTime(silent listener; about 5.0 s)TestOnlyAShardThatFailedBeforeTheReadSettledIsLogged(also covers the once-a-minute limit)session, inShardDownSuite:TestASessionWithAnIdTheRouterGeneratesOpensTestASessionWithAnIdTheCallerChoseIsNotOpenedTestAVoiceSessionWithAnIdTheRouterGeneratesOpensItsOwnCall(fails before thePinfix withstore: call pin: dial tcp 127.0.0.1:1: connect: connection refused)api:TestAnArrivingCallAShardThatIsDownMayHavePlacedIsDeliveredAgain: a young event gets a 503 from a node with a peer down and is not dispatched. The same delivery to a healthy node is dispatched.TestAnOldArrivingCallAShardThatIsDownMayHavePlacedIsDropped: an event older than the window gets a 200, is not dispatched, and is logged.TestAPlanFetchWhileAShardIsDownIsAnsweredForTheVendorToRetry: a 503 with a peer down, and a 404 with every shard answering.Pinskip, early settle, peer timeout, hook 503, its age bound, plan fetch 503).TestCallHooksSuite,TestCallStatusSuite,TestAppHooksSuiteandTestLogAppSuite(api), andTestAppsSuite(phone), pass.integration (api)on the first head failed only in tests that also fail onmain(the threeTestChannelsSuitecases, from AI-3575: keep internal error text from callers #2249's error text). It also failed inTestConnectorsSuite/TestAnAppNotMarkedInternalNeitherListsNorReadsNessy, where a fake connector leaked from a parallel test; that test passes locally.TestWritingToAChannelReachesTheLastConversationOnItand aSetupSuitedeadlock. Both tests pass alone.go vetandgofmtare clean.🤖 Generated with Claude Code