Repository navigation
remote link: the direct bucket spends a token only on a socket that opened - #457
Merged
Merged
Conversation
…pened (TokenBucket.holds gates the dial, take follows the open, the catch-up re-dial too), as the listener charges only an accepted upgrade; an outage's refused dials no longer empty it, so a returning network resumes direct at once instead of 7–12 s later; remote-latency's header says the drop restores only the case's own way Sminos-Session: GUI AI agent workspace charter#37052769 (MAWS on macbook)
Sminos-Session: GUI AI agent workspace charter#37052769 (MAWS on macbook)
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
SSFSKIM
added a commit
that referenced
this pull request
Nov 3, 2026
…g 208; the hosted row's signature (22) tallied Sminos-Session: GUI AI agent workspace charter#37052769 (MAWS on macbook)
This was referenced Nov 4, 2026
SSFSKIM
added a commit
that referenced
this pull request
Nov 4, 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 bug
The direct carrier's token bucket was spent on dials that never reached the listener.
viaDirect(src/main/machines/remote/link.ts) ranbucket.take()before the direct dial. Every reconnect attempt during an outage spent a token, even when the dial was refused or timed out.src/endpoint/direct-listener.ts#upgrade; a 503 takes nothing). The two counts drifted apart in one direction: the link counted dials the listener never saw.timing.ts, mirroringHANDSHAKE_LIMITS.perSource).Measured
e2e:remote-latencyon the Mac mini, on master:The arithmetic
The first
uptakes one token (2 left). After a loss, attempts come at 0, 1, 3, 7 and 12 s (BACKOFF_MS), each taking a token before it dials. The attempts at 0 and 1 s leave about 0.08 tokens, and later attempts skip direct until the bucket refills. When the network returns after a 6.9 s outage, the probe's attempt sees about 0.57 tokens. It skips direct, the hub is unreachable in this scene, and the link waits on the backoff (+1, +3, +7 s). Direct resumes at +7 s, when the bucket reaches 1.16 tokens: 7000 ms.A unit reproduction gave 7000 ms after a 6.9 s outage, and 12000 ms after a 3.5 s or a 15 s outage (in the 15 s case, the 12 s attempt took the token that had just refilled).
Real-world cost: when the hub can't be reached (a LAN with no internet, or a hub outage), a returning network stalls for 0 to 12 s. When the hub can be reached, the session falls to the relay for up to 60 s (
DIRECT_RECHECK_MS).The fix
TokenBucket.holds()(timing.ts) refills the bucket and reports whether a whole token is there, without taking it.take()now runs through it.viaDirectdials only whenholds()is true, and callstake()only afterraceDirectresolves with an opened socket. A refused dial, a timeout or a 503 spends nothing. A socket that opens and then fails its handshake (protocol, …) still spends a token, as the listener charged its upgrade.holds()before it dials,take()once its socket opens.attemptingguards bothstartAttemptandrecheckDirect), so the tokenholds()saw is still there when the socket opens.e2e/remote-latency.spec.ts's header said the forced drop restores both of A's ways to B. It restores only the case's own way, and the other only after the gap's turn has arrived. The header now says so.Tests
All were written before the fix. The new resume and catch-up cases failed on master at
expect(h.link.state()).toBe('up'), and theholds()case failed withbucket.holds is not a function.link.test.ts› grace and backoff:networkprobe follows. The link isupoverdirectin the probe's own attempt, and every attempt during the outage dialed direct first.protocolinside a minute spend the burst. The fourth attempt, at 7 s, makes no direct dial and comes up over the hub. This case also passes on master; it guards against the fix overcorrecting.behindtriggers a catch-up whose next connection is refused. The next probe still finds the remaining token and goes up over direct. The harness's fake handshake now dials again onbehind, asconnectChanneldoes.timing.test.ts: says whether a whole token is there, refilled, without taking it.Run locally, one file at a time:
link.test.ts49/49 andtiming.test.ts3/3, plus eslint on each changed file.Gates
--gates all --class1a pool --runner macos; the mini had no hold): run 41561328996.e2e/dashboard.spec.ts:548(the chart comment test), which this change doesn't reach.gh run rerun --failed): packaged 1/2 98 passed, e2e:discover 9, e2e:render-host 2, with 0 flaky lines. The run's conclusion is success.link.tsandlink.test.tsin other functions. It merged cleanly as 530abe8. Locally,link.test.tspassed 56/56 andtiming.test.ts3/3.Review
doperpowers:reviewer-mediumon01d4488cf..c50d7274a, through the lens "the direct carrier's rate limit stays bound to the listener's own count, and no path dials direct without holding a token": correct, with no material findings.Sminos-Session: GUI AI agent workspace charter#37052769 (MAWS on macbook)