Repository navigation
desk-hub: a machine's reconnect within a second, without a flap (#57) - #58
Merged
Merged
Conversation
Cloudflare replaces a Durable Object (a deploy's rollover about five
minutes after it, `wrangler tail`, a runtime update, a move) by routing new
requests to a successor while the old instance's in-flight request, the
machine's SSE stream, runs on and beats. The machine learned of it only when
its next POST, at worst the hb-ack 15 s later, reached the successor and was
refused 409 stale-generation: 27 of the 53 hub-side drops in both Macs'
logs (10-17/18) came 298-313 s after a deploy, both machines within 9 s.
- Machine: the instance holding a stream asks every second (PROBE_MS)
which instance its own id reaches (and reads storage, which throws on a
replaced instance) and ends the stream once it is another, so the machine
reconnects within about a second. A 409 for the generation the object
last opened says `replaced: true`. Every stream's open and end is logged
with its cause (`{"desk":"machine-stream",...}`).
- Project: a closed stream's lease holds the machine online for a grace of
one heartbeat (MachineContext.graceMs), so a reconnect never flaps its
presence; what the stream carried still ends at once. A subscribe in the
grace waits (route generation 0, a new value in the existing subs column)
and is carried to the next stream at its hello; an RPC in the grace fails
at once ("reconnecting: try again in a moment").
- Worker: an object call's exception is answered as JSON (503
hub-unavailable when retryable or overloaded, 500 hub-error otherwise)
instead of the runtime's bare 1101.
- DX4 chunk bodies may carry `t`, the bridge's stamp, for the web's latency
readout.
- Spec: DX2's lease paragraph, the POST answer, DX4's hub-ended
subscriptions, DX6's error code, and a Decision Log entry with the causes.
… passes the bridge's through (MAWS #57)
… call that never settles cannot stop the probing
…tream, as a subscription does; one that waits out the grace fails machine-offline (MAWS #57)
… printed each run (and to DESK_LATENCY_OUT), held to a loose bound
This was referenced Oct 18, 2026
SSFSKIM
added a commit
that referenced
this pull request
Oct 19, 2026
This was referenced Oct 21, 2026
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.
The hub's half of #57. With it, a machine's reconnect no longer flaps the machine's presence, and it starts within about a second of the hub losing the stream instead of at the next heartbeat's ack (up to 15 s). The web's half is in #(web PR). That PR keeps the transcript drawn through any disruption and stays quiet for a gap under 15 s.
Why the hub loses the stream
The evidence comes from both Macs'
daemon.log, 10-17 05:46Z to 10-18 19:13Z: 53 hub-side drops in all.wrangler tail. Each landed 298–313 s after a deploy, on both machines within 9 s of each other. At the 19:07:27 deploy, mini dropped at 19:12:28 and macbook at 19:12:36.409 stale-generation. Usually that POST was the hb-ack, sent up to 15 s later.Machine.end's own paths.500 error code: 1101came a minute after a deploy. It was astub.fetchexception the Worker did not catch.What changes
Machinefinds a replacement within about a second.instance(), preceded by a storage read that throws on a replaced instance. If the id reaches another instance, it ends the stream, and the machine reconnects at once.reconnect.test.ts: a live object's probe reaches itself.hellotakes the lease over, so a reconnect never shows the machine offline. What the stream carried still ends at once: its subscriptions endmachine-offline, and its RPCs becomeuncertain.subscribeor a new RPC in that grace waits for the next stream and is carried to it at itshello, so an answer, a decision or an interrupt sent in the gap is not lost or refused. If the grace runs out first, the subscription endsmachine-offlineatn0, and the RPC, which never reached the machine, failsmachine-offline. A retry of anuncertainRPC is answered from its record in the grace, as while offline."replaced": truewhen the POST names the generation the object last opened and the object holds no stream. The uplink already logs the body, sodaemon.logshows the cause.{"desk":"machine-stream",…}).newer-stream,client-closed,write-failed,undeliverable,directory,revokedandreplaced. A stale POST is logged too.wrangler tail(which itself forces a replacement), or in Workers Logs ifobservabilityis turned on. That is not turned on here; it is the owner's call.503 hub-unavailablewhen Cloudflare marks the error retryable or overloaded,500 hub-errorotherwise. Before this, the runtime answered with a bare 1101.chunkbodies may carryt, the bridge's stamp, for the web's latency readout. The doperpowers side is sminos plane: a DX4 chunk carries the bridge's stamp t (MAWS #57) (7.183.2) doperpowers#246. The fake machine now stamps its chunks the same way.machine-offline;Storage
No new table, column, or key. A subscription or an RPC that waits for the next stream is kept in its existing table (
subs,rpcs) with generation 0. That is a new value in an existing column; no stream is ever generation 0.Tests
test/reconnect.test.ts. It covers:409 replaced;n0 and failing a waiting RPC;stream-close.test.ts. The RPC still turnsuncertainat once. The machine now goes offline one grace later.Gates:
static,unit,e2e:desk-web --class1a linuxgreen at the head fc692dd: https://github.com/SSFSKIM/MAWS/actions/runs/39160629366.test/latency.test.tsprints the hub's hops on the local runtime. Over three local runs, p95 was 3–72 ms per hop. A replaced object's stream ended 415–467 ms after the replacement. The next stream took a waiting subscription 20–31 ms after the reconnect. The machine never read offline.