Skip to content

fix(client-runtime): retry saving repeated direct routes - #45443

Merged
juliusmarminge merged 16 commits into
pingdotgg:mainfrom
StiensWout:wf/find-3d2e2fa38c39776ef5eaca40
Nov 29, 2026
Merged

juliusmarminge merged 16 commits into
pingdotgg:mainfrom
StiensWout:wf/find-3d2e2fa38c39776ef5eaca40

Conversation

@StiensWout

Copy link
Copy Markdown
Contributor

A temporary storage outage could leave T3 Connect on the relay after the host advertised a direct Tailscale route. The client retries saving the latest endpoint report with capped backoff, even when no more snapshots arrive. Closing the session cancels retries waiting for the registry lock, while an in-flight save finishes publishing the route so the registry stays consistent with storage.

Related: #33484, #45024, #36311, #34826, #34963, #44850, #44344

Reproduction on main

Commit 0fbd32628b (main). The client discards the repeated address and keeps only the relay route. Expected: The client saves the Tailscale route so it can connect directly.

The cause is at packages/client-runtime/src/connection/supervisor.ts:374. Ran cd packages/client-runtime && pnpm exec vp test run src/connection/registry.test.ts with the repro test added: it failed in 2 of 2 runs on a clean checkout, with expected 1 to be 2 in the output.

Evidence

Environment: Linux x64, the repository's own tests.

Proven: the repro fails at the test commit 26b3d03cf2 and passes on the head 31a571d548, both on main 23aed63cec.

Before After
Commit 26b3d03cf2 31a571d548
Result failed with "expected 1 to be 2" passed

Outside view: not shown in the running app. The bug fails the rule that every step is the person's or the world's. Staying on the relay depends on connection settings failing to save at the moment the host first advertises a Tailscale address, then succeeding before a later snapshot repeats that same address, and nothing a person does in the app, nor a network change or an outside service, puts the running app into that temporary save failure.

Tests

  • 26b3d03cf2 adds the failing test, alone, before the fix.
  • pnpm exec vp run check:changed 23aed63ceccac3b5ecd3d8020986c3206a7bb4e8 passed on head.

Not in this change

  • Route eligibility and ranking keep their existing behavior.
  • The disconnect regression uses a paused catalog write at the registry’s persistence boundary.

Who did the work

  • Repro written by GPT 6.2 Sol, in Codex
  • Outside view by Grok 4.7, in Grok
  • Duplicate check judged by Claude Opus 5.5, in Claude Code
  • Written by GPT 6.2 Sol, in Codex
  • Trimmed by Claude Opus 5.5, in Claude Code
  • Reviewed by Claude Opus 5.5, in Claude Code, and by GPT 6.2 Sol, in Codex, and by Grok 4.7, in Grok
  • Reproduction, checks and proof run by a program on base and head, not by an agent

Made in T3 Code by GPT 6.2 Sol, Claude Opus 5.5 and Grok 4.7

StiensWout and others added 14 commits November 29, 2026 11:11
Co-authored-by: GPT 6.2 Sol <codex@openai.com>
Co-authored-by: GPT 6.2 Sol <codex@openai.com>
Co-authored-by: GPT 6.2 Sol <codex@openai.com>
Co-authored-by: GPT 6.2 Sol <codex@openai.com>
Co-authored-by: GPT 6.2 Sol <codex@openai.com>
Co-authored-by: GPT 6.2 Sol <codex@openai.com>
…ptible sleeping fiber

Drops the cancel Deferred and join: interrupting the retry fiber already waits for an in-flight save.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: GPT 6.2 Sol <codex@openai.com>
Co-authored-by: GPT 6.2 Sol <codex@openai.com>
Co-authored-by: GPT 6.2 Sol <codex@openai.com>
Co-authored-by: GPT 6.2 Sol <codex@openai.com>
Co-authored-by: GPT 6.2 Sol <codex@openai.com>
…y test harness

Drops the separate file's hand-built layer, driver and session for the existing makeHarness, which gains one beforeSetRoutes hook.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
The gate folds registry.test.ts edits into the repro commit, which allows only small lint and type edits.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:M 30-99 changed lines (additions + deletions). labels Nov 29, 2026
macroscopeapp[bot]
macroscopeapp Bot previously approved these changes Nov 29, 2026
@macroscopeapp

macroscopeapp Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Needs Human Approval

Macroscope's review found this PR requires human approval — Failed learned-route saves now retry, and catalog writes finish despite session closure. An unresolved review concern identifies a gap where the supervisor can retain stale routes after publication, affecting subsequent reconnects; that synchronization question needs resolution.

Notes:

  • All code in this push has already been reviewed. Approvability was decided on eligibility alone.

You can add or adjust custom eligibility rules. Learn more.

@coderabbitai

coderabbitai Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The registry now propagates learned-route persistence errors after acquiring the lease lock. The supervisor retries failed saves with increasing delays, handles newer reports during retries, and supports disconnect or removal while a save is pending.

Changes: Learned-route saves

Layer / File(s) Summary
Registry route persistence
packages/client-runtime/src/connection/registry.ts, packages/client-runtime/src/connection/registry.test.ts
The registry keeps route-learning work uninterruptible after acquiring the lease lock and propagates operation errors. Tests cover repeated configuration reports and disconnect or removal during persistence.
Supervisor retry handling
packages/client-runtime/src/connection/supervisor.ts, packages/client-runtime/src/connection/supervisor.test.ts
The supervisor fingerprints reports, retries failed saves with increasing delays, and handles newer reports by canceling a delay or joining an in-flight save. Tests cover successful retries and disconnect during a blocked save.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant ServerConfigStream
  participant EnvironmentSupervisor
  participant EnvironmentRegistry
  participant ProfileStore
  ServerConfigStream->>EnvironmentSupervisor: directEndpoints report
  EnvironmentSupervisor->>EnvironmentRegistry: learnRoutes
  EnvironmentRegistry->>ProfileStore: persist learned route
  ProfileStore-->>EnvironmentRegistry: persistence error
  EnvironmentRegistry-->>EnvironmentSupervisor: error
  EnvironmentSupervisor->>EnvironmentSupervisor: wait, then retry report
Loading

Possibly related PRs

  • pingdotgg/t3code#15468: Adds learned routes from ServerConfig.directEndpoints, which this change retries when saving fails.

Suggested labels: bugfix

Suggested reviewers: juliusmarminge

Merge Risk: Low · up to e65e5

The change makes the client keep retrying to save a newly advertised direct route instead of staying on the relay route after a temporary save failure. One open edge case remains. If a session closes just as a route save completes, reconnect attempts may keep using the older relay-only routes until a new report arrives or the app restarts. This is narrow and recoverable, so the change is mergeable with owner awareness.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "fix(client-runtime): retry saving repeated direct routes" matches the main change: the supervisor now retries failed saves of the latest endpoint report, and the registry lock and session c…
Description check Passed The description follows the template's main sections: Problem, Change, Scope, and Verification. The Problem and Change sections explain the storage-outage retry behavior and the session-close handling…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "fix(client-runtime): retry saving repeated direct routes" matches the main change: the supervisor now retries failed saves of the latest endpoint report, and the registry lock and session close handling are adjusted. It uses a conventional commit prefix and names the affected package. It is specific and accurate to the changeset.

Full details: Description check

Explanation

The description follows the template's main sections: Problem, Change, Scope, and Verification. The Problem and Change sections explain the storage-outage retry behavior and the session-close handling. Verification gives a focused test command, observed failing and passing results, and a check run. Scope links related issues but does not clearly say whether a maintainer requested the PR or why it is a bug fix rather than a feature. The description also includes a long provenance and model attribution list, and an 'Outside view' section that argues the bug is not reachable in the running app, which does not match the template's expected content. These points are weaknesses but the required information is mostly present.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 31a571d and e65e5d3.

Files selected for processing: 1

  • packages/client-runtime/src/connection/registry.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 23aed63 and 31a571d.

Files selected for processing: 5

  • packages/client-runtime/src/connection/registry.test.ts
  • packages/client-runtime/src/connection/registry.ts
  • packages/client-runtime/src/connection/registryRouteSave.test.ts
  • packages/client-runtime/src/connection/supervisor.test.ts
  • packages/client-runtime/src/connection/supervisor.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.

Comment on lines +382 to +384
const updated = yield* learn({ activeRoute, reported }).pipe(
Effect.orElseSucceed(() => undefined),
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor · Data Integrity & Integration · Heavy lift

Keep the supervisor's route state in step with the published catalog entry.

The registry publishes the learned route in an uninterruptible region. The supervisor applies that same result to currentEntry only after learn returns, at supervisor.ts:388. If the session closes during that gap, Effect can deliver the pending interruption before Ref.set runs. The registry then holds the direct route, and the supervisor keeps the older routes.

The later reconnect attempts read currentEntry. Until a changed report or a restart, they can use the relay-only routes. A repeated identical report does not repair this state because handled is not recorded on interruption, and the re-run learn may return no update.

The fix must keep lock acquisition interruptible, as the registry comment requires. It must also ensure the supervisor's route state matches the published entry even when the save is interrupted. Do not wrap the whole learn call in Effect.uninterruptible.

@juliusmarminge juliusmarminge added the takeover:in-progress A takeover lead is working on this PR label Nov 29, 2026
juliusmarminge and others added 2 commits November 29, 2026 10:39
…76ef5eaca40

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…est harness

Drops the separate file's hand-built layer for the existing makeHarness, per
the testing guide's extend-before-add rule, and keeps main's expect import.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@macroscopeapp
macroscopeapp Bot dismissed their stale review November 29, 2026 10:43

Dismissing prior approval to re-evaluate e65e5d3

@juliusmarminge

Copy link
Copy Markdown
Member

Evidence

Real web app, Chromium on Linux, light theme, 1440×1000 viewport, fresh synthetic client state, and the real T3 Connect test stage. Images use identical map crops; unrelated test-account labels are hidden.

  1. Add the loopback-only host through T3 Connect; confirm relay-only routing.
  2. Override the origin quota to 1 byte, wait 35 seconds for Chromium's cached allowance, and confirm a genuine IndexedDB QuotaExceededError.
  3. Restart the host with --lan; observe the app's route-save warning with QuotaExceededError.
  4. Clear the quota, confirm writes succeed, and observe the same session for 150 seconds without navigation or reload.
Before — 0303e60311 After — e65e5d3358
Still only T3 Connect after 150 seconds. One failed save, with no further attempt observed. Four routes saved automatically: LAN, LAN, Tailscale, and T3 Connect. LAN is in use. Three failed saves while quota was active, followed by recovery.
Before: relay only after storage recovers After: direct routes recovered and LAN in use
Recording, 8× playback · Real-time recording Recording, 8× playback · Real-time recording

Recordings show the matched interaction with driver phase captions. Stills were captured after two identical frames 500 ms apart.

Base control, performed after its 150-second capture: a fresh connection immediately learned the direct routes and used LAN.

Base control: LAN works after a fresh connection

Reproduction driver · Quota probes and timestamped observations

Not shown:

  • Native desktop and mobile clients were not exercised; this proof covers the reported web flow.
  • Replacing a pending retry with newer endpoint reports, the maximum backoff, and retry cancellation on environment removal or lease teardown were not exercised.

@juliusmarminge juliusmarminge added takeover:ready Takeover done; auto-lands when gates pass and removed takeover:in-progress A takeover lead is working on this PR labels Nov 29, 2026
@juliusmarminge
juliusmarminge merged commit 44fd41b into pingdotgg:main Nov 29, 2026
60 checks passed
@juliusmarminge juliusmarminge removed the takeover:ready Takeover done; auto-lands when gates pass label Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 changed lines (additions + deletions). vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants