Skip to content

fix(computers): keep links dialled before the listener opens - #1349

Merged
nixuuu merged 2 commits into
devfrom
test/computers-fix-move-flakiness
Nov 27, 2026
Merged

nixuuu merged 2 commits into
devfrom
test/computers-fix-move-flakiness

Conversation

@nixuuu

@nixuuu nixuuu commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Changes

Root cause. A gateway starts its linked-computer runtime before network access opens its listener. The runtime's first tick already dials every partner. When the listener opened, the first address advertisement treated the listener's addresses as a network change and rotated every link (computersReconnect with the 100 ms flush). A link that had finished its handshake in that window was marked retiring and closed 100 ms later. The partner then stayed "unreachable" until the next dial, after a backoff of about a second.

In tests/integration/computer-moves.test.ts, the restarted source (A) settled the committed move over such a short-lived link, so finalState(id1) returned done and the test continued. The next StartMove failed with Laptop C is unreachable since …. The two tests after it ran inside the same backoff window and failed the same way (CI run 46031074683, shard 8/12). Delaying the fixture's network.start() by 300 ms reproduced the same three failures, plus the earlier "interrupted before the decision" test.

  • runtime-lan.ts: opening the listener (gateway start, or network access turned on) is not treated as a network change. No partner can hold a link to an earlier address, and links this computer dialled keep working. Partners still get the new routes in a routes frame. Closing the listener and interface or address changes still rotate links.
  • computer-moves.test.ts: waits for the link after restarting the source. An afterEach clears crash hooks and restarts link runtimes a test left stopped, so a failure cannot carry over to later tests.
  • lan-routes.test.ts + support/computers.ts: a fixture hook (beforeListening) runs between runtime start and listener start, the same order as a gateway. A new test checks that a link dialled before the listener opens is not retired. It fails on the old code (2/2 runs) and passes with the fix.
  • docs/linked-computers.md: documents the behaviour and adds a status line.

Fixes: #348

Verification

Ran locally:

  • computer-moves.test.ts via check:tmp: 15/15 passes in a row, 5/5 under 18 busy-loop CPU hogs (load average about 20), and passing with a 300 ms delay before the listener opens (this delay made 4 tests fail before the fix).
  • lan-routes, linked-routes-status, linked-computers, computer-relay, network-access, linked-relocation, tailscale-network: all pass.
  • tsc --noEmit for tests/integration and apps/gateway; oxfmt and oxlint on the edited files.

Left to CI: the full gate (all test shards, repo-wide typecheck/lint/format, gen:check, builds).

Copy audit: no UI text changed.

Follow-up: thread mirror regression

The first version made thread-mirrors.test.ts fail in every run (3/3 locally, CI run 46036520107): opening the listener no longer called computersReconnect, which was also what cleared dial retries and read circuits. A partner that failed while this computer was unreachable stayed blocked for the 30 s circuit backoff. Opening the listener now calls computersRedial (clear retries, reset read circuits) without aborting dials: a dial controller owns its live link, so aborting it would drop the link this PR keeps.

Verified locally: thread-mirrors 3/3 (was 0/3), computer-moves + lan-routes 3/3, and linked-computers, linked-routes-status, network-access, computer-relay, linked-relocation, linked-thread-liveness 58/58 through check:tmp. Gateway typecheck, oxlint, oxfmt.

🤖 Generated with Claude Code

A gateway starts its linked-computer runtime, whose first tick dials
every partner, before network access opens its listener. The first
advertisement then saw the listener's addresses as a network change and
rotated every link: links that had just completed their handshake were
marked retiring and closed 100 ms later, and the partner stayed
"unreachable" until the next dial after a backoff of about a second.

In computer-moves.test.ts a restarted computer settled a committed move
over such a short-lived link, the test went on, and the next StartMove
failed with "Laptop C is unreachable"; the following tests in the file
ran inside the same backoff window and failed the same way.

The listener opening is no network change: no partner can hold a link
to an earlier address, and the links this computer dialled keep working.
Partners still get the new routes in a routes frame. Closing the
listener and interface or address changes still rotate the links.

The moves test now waits for the link after restarting the source, and
clears crash hooks and restarts stopped runtimes after each test so a
failure cannot carry over. lan-routes covers a restart whose link is up
before its listener opens.

Fixes: #348

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@nixuuu
nixuuu enabled auto-merge (squash) November 27, 2026 16:47
@nixuuu
nixuuu disabled auto-merge November 27, 2026 16:58
Opening the listener no longer retired links, but it also stopped
clearing dial retries and read circuits. A partner that failed while
this computer was unreachable stayed blocked for the 30 s circuit
backoff, so thread mirror tests that toggle network access timed out
waiting for the link.

Opening the listener now clears retries and read circuits without
aborting dials: a dial controller owns its live link, so aborting it
would drop a link made before the listener opened.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@nixuuu
nixuuu enabled auto-merge (squash) November 27, 2026 17:21
@nixuuu
nixuuu merged commit 7fc5e1b into dev Nov 27, 2026
25 checks passed
@nixuuu
nixuuu deleted the test/computers-fix-move-flakiness branch November 27, 2026 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant