Repository navigation
Conversation
eshurakov
force-pushed
the
eshurakov/session-recovery-backoff
branch
2 times, most recently
from
December 1, 2026 19:24
201e3fd to
7f67f68
Compare
rgbkrk
approved these changes
Dec 1, 2026
rgbkrk
left a comment
Member
There was a problem hiding this comment.
The bounded window (15s/30s/60s passes, give up at 90s into the window) with since carried across passes is the right shape, and transport-recovery.ts as a pure module with the alarm wiring thin on top is easy to reason about. The answered-without-progress path (not_ready → ready, or same-attempt prepare) correctly ends the window instead of failing the message, and every exit path leaves exactly one of {open window, status check, backstop} armed. Docs, telemetry, mobile copy and the protocol enum are updated consistently.
Worth a staging soak before relying on the ~2 minute figure — the wall-clock numbers come from the fake clock, not a real stall.
Name the case where queued transport recovery gets no answer from the Sandbox DO. The reason has user text, a pre-dispatch sandbox-connect classification, and maps to existing connection copy in the mobile app.
…ded window A recovery pass that the Sandbox DO did not answer was consumed and never re-armed, so a queued message waited for the 45 min queued backstop after a single Sandbox or Session DO reset. An unanswered pass now arms the next one, 15 s, 30 s and then 60 s apart. The stored obligation keeps `since`, the start of the window, so the delay comes from `now - since` and not from a counter. The first unanswered pass at least 90 s into the window fails queued work as `sandbox_unreachable`. Accepted work keeps its backstop. A bare due time from an earlier deploy reads as a window opened one delay earlier. Each pass logs one bounded `session_transport_recovery` diagnostic. The policy lives in `transport-recovery.ts`; `session-do.ts` only wires it. The tests and the spec that asserted "no self-rearm" change on purpose.
…ails queued work The give-up after an unanswered recovery window emitted a `cloud.status` error even when the route was ready or reconnecting. An accepted turn can still run on that route, so the status must stay ready. The failed queued message carries its own terminal reason.
…read Option C of the recovery handover. A lost route notification, for example a terminal `failed` while preparing, or a rolled-back acceptance left queued work waiting for the 45 min queued backstop. While work is queued and no recovery pass is due, the one recovery obligation is now a status check 60 s later, stored without `since`. It reads the passive view and acts on it like a recovery pass. The same preparing or reconnecting attempt only arms the next check, so its status and step detail stay. An unanswered check opens the bounded recovery window. An `unknown` notification now arms the alarm, so queued work on a ready route is prepared again. The spec sentence "not periodic preparation polling" and the tests that expected no obligation while work stays queued change on purpose.
…er-not_ready comment
…rs without progress A not_ready delivery followed by a ready prepare, and a prepare that returns the same failed attempt, are answers from the Sandbox DO. They extended the unanswered window and could fail queued work as sandbox_unreachable. They now end any open window, and queued work waits on the status check and the queued backstop.
…dbox RPC returns A window pass that made no RPC, because the backstop or a retired attempt settled the queued work first, logged outcome answered. The pass now records answered where a status, prepare or deliver call returns, and unanswered stays final.
…notifications Each preparing or reconnecting view deleted the stored obligation, and the next alarm arm wrote a new 60 s check, so every step notification cost two extra storage writes. An owner view now ends only an open window; a stored status check keeps its due time.
…eparing notifications" This reverts commit 2dac405. A preparing or reconnecting view must move the 60 s status check forward: then no status read reaches a busy Sandbox DO while notifications already show progress. Two local storage writes per notification cost less than one cross-DO read per minute during preparation.
eshurakov
force-pushed
the
eshurakov/session-recovery-backoff
branch
from
December 1, 2026 21:08
7f67f68 to
550b54f
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
After a Sandbox DO or Session DO reset, a queued message could wait 45 min 10 s and then fail with a generic
preparation_timeout. The Session DO tried transport recovery only once and did not re-arm it. After that, only the 45-minute backstop could settle the message. In one burst of resets, 7 of 30 affected sessions hung this way: 5 timed out and 2 were stopped by the user.This PR keeps recovery armed while a message is queued, with a bounded schedule:
sandbox_unreachablefailure reason (951c0be). It names the case where queued recovery gets no answer from the Sandbox DO. Telemetry classifies it as a pre-dispatch sandbox-connect failure, so external callbacks still get the existingsandbox_connect_failedcode. Mobile maps it to the existing "connection lost" copy, because a new key needs all 87 catalogs.sandbox_unreachable. Each pass has a 2 s deadline. The policy is in a new pure module,session/transport-recovery.ts, which has unit tests.session-do.tshas only the wiring.cloud.statuserror, because an accepted turn can still run there.failedorreadynotification without a reset.Follow-up commits from review:
not_readythen areadyview, or a prepare that returns the same failed attempt). Before this commit, those answers extended the window and could fail the message assandbox_unreachable, which is wrong because the Sandbox did answer. Queued work on those paths now waits on the 60 s status check and the queued backstop, as onmain.The 45-minute backstop is unchanged and stays the last resort.
Rebased head and verification
e5cf8884f66705ddac53a62e76dc5e1f3d99e783. Rebased ontoc7e978863f83895d76505f252c8f4b0762397cdfwithout changing the ten recovery patches.chore(db): refresh ACL fingerprints for session recovery files, refreshes only the five reviewed Browser ACL fingerprints. All five retain dispositionnone. No SQL access changed.git diff --check.test/e2e/fake-llm-core.ts:1455is outside this PR.Historical verification (before rebase)
No manual test and no test on a deployed stack. The tests move a fake clock. They do not reproduce a real storage stall or output-gate behavior. These earlier results came from running the
ci.ymlandkilo-app-ci.ymlsteps for the changed paths locally (Bun 1.4.4). Every failure below also occurs onorigin/main(5cba3273a1) or has a local cause.build:wrapper,test:aws-runtime-bundle,test:checkers,check:duplication,test:runtime-ciand the wrapperprocess.test.ts(7/7) pass.pnpm --filter cloud-agent-next test: 8,767/8,768. The Sentry source-map test passes whenTMPDIRis a real path.test:integration: 1,320/1,321.control-plane-workspace-snapshots"lets a new sibling restore…" also fails onorigin/main.bun teststep: 26 failures, the same as onorigin/main.test:postgres(58/58) and the web jest suite (35,474/35,474), each on a database for this branch.check:i18n,check:classesandcheck:unusedpass. The mobile tests have 3 time-zone failures that pass withTZ=UTC.scripts/typecheck-all.sh --group weband--group packages,scripts/lint-all.sh --group rest,pnpm run format:checkandcheck:md-table-paddingpass.pnpm --filter cloud-agent-next lintexits 1 ontest/e2e/fake-llm-core.ts:1455. The same error occurs onorigin/main, and the file is not in this diff.2dac40582b. The final tree equals375389b560. On it, the Session DO suites (375/375), typecheck andformat-changed.shpass.Failure UX (wall-clock numbers come from the timers, not from a real stall):
preparation_timeoutsandbox_unreachable. If the Sandbox already has a terminal reason, the message gets that reason.Visual Changes
N/A. Mobile reuses existing copy for the new reason.
Reviewer Notes
sandbox_unreachableis used only insidecloud-agent-nextand in the mobile copy map, which takes a string key. A search found no other strict consumer ofCONTROL_PLANE_FAILURE_REASON_VALUES.not_readythen areadyview, or a prepare that returns the same failed attempt. On those paths,sandbox_unreachablewould be wrong, so queued work waits on the 60 s status check and the queued backstop instead. The first retry afternot_ready→readymoves from 15 s to at most 60 s. If the Sandbox keeps answering without progress, the message still waits up to 45 minutes, as onmain. A specific reason for that case would need a new failure reason. Notifications never movedueAtorsince.statusread per queued session per minute while notifications are silent. Grant issuance can hold the Sandbox queue for about 11 s, so one check can fail and open a window. A give-up still needs at least 90 s without an answer.preparing, and the list status isfailed. A latepreparingnotification can show "preparing" with nothing queued. The same thing happens aftercancelQueuedMessage.{dueAt: 20}unit case. The spec sentences "no self-rearm" and "not periodic preparation polling" change for the same reason.session-do.tsis about 5,100 lines, and this PR adds about 135 lines of wiring to it. Proposed follow-up: movescheduleTransportRecovery,failUnansweredQueued, the clear function and the alarm branch into a small recovery controller.unknownor a stalepreparing(option C handles both by design), and whether the wrapper drops a repeatedsession.prompt.