Skip to content

fix(client-runtime): skip waiting for lower-priority linked addresses - #40989

Merged
juliusmarminge merged 5 commits into
pingdotgg:mainfrom
StiensWout:t3/1308-a-silent-fallback-address-delays-connect
Nov 22, 2026
Merged

juliusmarminge merged 5 commits into
pingdotgg:mainfrom
StiensWout:t3/1308-a-silent-fallback-address-delays-connect

Conversation

@StiensWout

Copy link
Copy Markdown
Contributor

Connecting from a linked thread waited for every address probe, so a silent fallback delayed pairing even when the preferred address had answered. The shared client runtime starts probes together and selects the first reachable address in preference order as soon as all higher-priority probes have failed, for both automatic pairing and manual pairing prefill.

Fixes #40988

Reproduction on main

Commit 6972026121 (main). The thread remains read-only until the fallback probe times out about six seconds later. The cause is at packages/client-runtime/src/linkedThread.ts:92. Ran pnpm scenarios:prove scripts/scenarios/linked-thread-connects-before-fallback-timeout.e2e.ts --base main with the repro test added: it failed in 2 of 2 runs on a clean checkout, with expect.poll(...).toBe(...) timed out after 4000 ms in the output.

Evidence

Environment: boat.dev default machine, Linux x64, a fresh checkout of each commit

Steps: Connect to interact opens the editable thread before a silent fallback times out: browser.addInitScript function; app.open ; expect.not.toHaveURL //pair(?:[?#]|$)/; app.open /linked/97ca4216-cc64-4976-96b6-69fd38413353/ed9a2ded-a7de-4736-99e7-e233d1fc933c/mcp:51372fb2-443b-4259-a838-158776e30f6a; locator.waitFor getByRole("heading", name: "Linked handoff") → visible; locator.tap getByRole("button", name: "Connect to interact"); browser.evaluate ; browser.evaluate ; app.screenshot linked-thread-after-connect.

Proven: the scenario fails on base bc13afaa3c and passes on head 5b695f4b98.

Before After
Commit bc13afaa3c 5b695f4b98
Result Fails: ASSERTION_FAILED: expect.poll(...).toBe(...) timed out after 4000 ms Passes
linked thread after connect Before: linked thread after connect After: linked thread after connect
failure Before: failure
Recording Before: Recording After: Recording
Scenario source: scripts/scenarios/linked-thread-connects-before-fallback-timeout.e2e.ts
/// <reference lib="dom" />
import { expect } from "e2e";
import * as Effect from "effect/Effect";
import * as Schema from "effect/Schema";

import { T3_HOME } from "../e2e.config.ts";
import { SECOND_HOME, startSecondServer } from "./second-server.ts";
import { environmentId, makeState, rpcClient, runPromise, test, WEB } from "./t3.ts";

const decodePairing = Schema.decodeEffect(
  Schema.fromJsonString(Schema.Struct({ credential: Schema.String })),
);

const linkEnvironments = Effect.fn("scenario.linkEnvironments")(function* (
  primaryOrigin: string,
  secondOrigin: string,
  fallback: string,
) {
  const primary = yield* rpcClient(T3_HOME, primaryOrigin);
  const second = yield* rpcClient(SECOND_HOME, secondOrigin);
  for (const client of [primary, second]) {
    yield* client["server.updateSettings"]({ patch: { linkedEnvironmentsEnabled: true } });
  }
  const pairing = yield* makeState(SECOND_HOME).cli(["auth", "pairing", "create", "--json"]);
  const { credential } = yield* decodePairing(pairing.stdout);
  yield* primary["peerLinks.link"]({
    url: secondOrigin,
    alternateUrls: [fallback],
    pairingCode: credential,
    access: "full-access",
  });
}, Effect.scoped);

test(
  "Connect to interact opens the editable thread before a silent fallback times out",
  WEB,
  async ({ t3, app, browser, screen }) => {
    await t3.project("primary");
    const primary = app.baseUrl ?? "";
    const secondServer = startSecondServer(primary);
    try {
      const { host } = await secondServer.ready;
      const alternate = new URL(host);
      alternate.hostname = "127.0.0.2";
      await runPromise(linkEnvironments(primary, host, alternate.origin));

      const second = makeState(SECOND_HOME).state;
      const project = await second.project("linked");
      const thread = await second.thread({
        project,
        title: "Linked handoff",
        messages: ["first"],
      });
      const via = await runPromise(environmentId(primary));
      const target = await runPromise(environmentId(host));

      await browser.addInitScript((fallback) => {
        const fetchActual = globalThis.fetch;
        globalThis.fetch = (input, init) => {
          const url = new URL(input instanceof Request ? input.url : String(input), location.href);
          if (url.origin !== fallback || url.pathname !== "/.well-known/t3/environment") {
            // @effect-diagnostics-next-line globalFetch:off - This interception runs inside the browser.
            return fetchActual(input, init);
          }
          // The browser's network silently drops this route. The preferred address is still real.
          return new Promise((_, reject) => {
            const signal = init?.signal ?? (input instanceof Request ? input.signal : undefined);
            signal?.addEventListener("abort", () => reject(signal.reason), { once: true });
          });
        };
      }, alternate.origin);

      await t3.open(`/linked/${via}/${target}/${thread.threadId}`);
      await screen.getByRole("heading", "Linked handoff").waitFor();
      await screen.getByRole("button", "Connect to interact").tap();

      try {
        await expect
          .poll(() => browser.evaluate(() => location.pathname), { timeout: 4_000 })
          .toBe(`/${target}/${encodeURIComponent(thread.threadId)}`);
      } finally {
        await app.screenshot("linked-thread-after-connect");
      }
    } finally {
      await secondServer.stop();
    }
  },
);

Tests

  • bd54aaf7df adds the failing test, alone, before the fix.
  • pnpm exec vp test run packages/client-runtime/src/linkedThread.test.ts passed on head.
  • pnpm exec vp run check:changed passed on head.

Not in this change

  • An unanswered higher-priority address keeps its existing timeout to preserve the link's address preference.
  • Pending lower-priority descriptor reads keep their existing timeout once a host has been chosen.
  • Missing pairing data, empty candidate lists, and failed redemption keep the existing manual or unreachable outcomes.
  • Address normalization, duplicate URLs, and environment identity checks belong to link storage and onboarding.
  • Pairing RPC timeouts, simultaneous connection requests, and navigation during pairing belong to their existing callers.

Who did the work

  • Written by GPT 6.2 Sol, in Codex
  • Review findings fixed by GPT 6.2 Sol, in Codex
  • Reviewed by Claude Opus 5.5, in Claude Code, and by GPT 6.2 Sol, in Codex, each on its own
  • Also reviewed by cubic, run locally by a program, with no score
  • Reproduction, checks and proof run by a program on base and head, not by an agent
  • Left open after review: should, scripts/scenarios/linked-thread-connects-before-fallback-timeout.e2e.ts:14: This copies the linked-environment setup from scripts/scenarios/mention-finds-older-linked-thread.e2e.ts:36, including the settings RPC and pairing CLI decoder. Share that setup in scripts/scenarios/second-server.ts, which owns the second-server fixture. Let each scenario pass its access level and optional alternate addresses so changes to the pairing setup have one place to land.; should, scripts/scenarios/linked-thread-connects-before-fallback-timeout.e2e.ts:61: The browser shim copies the descriptor endpoint path from packages/contracts/src/environmentHttp.ts. Pass EnvironmentHttpApi.groups.metadata.endpoints.descriptor.path to the init script along with the fallback origin. If the endpoint moves, the fixture should still stall the probe the client sends.

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

StiensWout and others added 5 commits November 22, 2026 19:40
Co-authored-by: GPT 6.2 Sol <codex@openai.com>
Co-authored-by: GPT 6.2 Sol <codex@openai.com>
…p the original comment

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

Co-authored-by: GPT 6.2 Sol <codex@openai.com>
@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Nov 22, 2026
@juliusmarminge juliusmarminge added the takeover:in-progress A takeover lead is working on this PR label Nov 22, 2026
@coderabbitai

coderabbitai Bot commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The linked-thread connection flow now probes advertised addresses sequentially and stops at the first reachable address. Unit and end-to-end tests cover connection outcomes when an alternate-address probe remains pending.

Changes: Linked thread connection

Layer / File(s) Summary
Ordered probing and connection tests
packages/client-runtime/src/linkedThread.ts, packages/client-runtime/src/linkedThread.test.ts
connectLinkedEnvironment probes addresses in order and treats rejected probes as unreachable. Tests cover alternate credential redemption and preferred-address prefill while a later probe remains pending.
Browser handoff scenario
scripts/scenarios/linked-thread-connects-before-fallback-timeout.e2e.ts
The scenario links two environments, leaves requests to the alternate discovery URL pending, and checks that the browser reaches the secondary thread within four seconds.

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

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: juliusmarminge, macroscopeapp

Merge Risk: Minimal · up to 5b695

Connecting from a linked thread should no longer wait for a silent lower-priority address to time out. No remaining merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the fix scope: lower-priority linked addresses no longer block connecting. It matches the linkedThread.ts change, where probes run in order and the first reachable address is selected,…
Description check Passed The description follows the template sections: Problem, Change, Scope, Verification. It states the bug and its cause, names the linked issue #40988, and gives reproduction and proof on base and head. …
Linked Issues check Passed Issue #40988 requires that, when the preferred address answers and a fallback address stays silent, Connect to interact opens the editable linked thread without waiting for the fallback timeout. At he…
Out of Scope Changes check Passed The changes fall into three groups. (1) packages/client-runtime/src/linkedThread.ts changes host selection in connectLinkedEnvironment. This is the fix for #40988. (2) packages/client-runtime/src/link…
Full details: Title check

Explanation

The title names the fix scope: lower-priority linked addresses no longer block connecting. It matches the linkedThread.ts change, where probes run in order and the first reachable address is selected, and the PR objectives. It uses a conventional commit format with a clear, specific subject.

Full details: Description check

Explanation

The description follows the template sections: Problem, Change, Scope, Verification. It states the bug and its cause, names the linked issue #40988, and gives reproduction and proof on base and head. It also lists the test commands run and notes what remains unchanged. The author notes that the Scope section should state a reason for no issue, but an issue is linked, so it is satisfied. The Problem section is present but embedded in the opening paragraph rather than under a heading, which is a minor formatting deviation. The template's Verification guidance is met with specific observed results. Two open review items are left unresolved in the description, which is acceptable because they are disclosed.

Full details: Linked Issues check

Explanation

Issue #40988 requires that, when the preferred address answers and a fallback address stays silent, Connect to interact opens the editable linked thread without waiting for the fallback timeout. At head, connectLinkedEnvironment in packages/client-runtime/src/linkedThread.ts starts every reaches(url) probe in one map call, so all probes run together. It then awaits the probes in preference order and breaks at the first non-null result. A reachable preferred address therefore returns at once, and the pending fallback probe is never awaited. Pairing then runs at that host. The same host selection feeds the unsupported (manual prefill) branch, which the PR also covers. Retained behavior matches the issue scope: an unanswered higher-priority probe still waits on its own, empty candidates and failed pairing keep their existing outcomes, and a probe rejection counts as unreachable. The e2e scenario reproduces the reported steps. Limit: the base-to-head diff was unavailable, so the before-state is taken from the PR evidence, not from a diff. The raw summary says probes run sequentially. The head code does not match that wording, and this assessment relies on the code. The unit test diff was not read directly; the pass verdict rests on the head implementation.

Full details: Out of Scope Changes check

Explanation

The changes fall into three groups. (1) packages/client-runtime/src/linkedThread.ts changes host selection in connectLinkedEnvironment. This is the fix for #40988. (2) packages/client-runtime/src/linkedThread.test.ts adds unit tests for the new selection behavior, which is supporting test coverage. (3) scripts/scenarios/linked-thread-connects-before-fallback-timeout.e2e.ts adds the end-to-end reproduction for the issue. The PR description lists no unrelated work, and the reviewed code does not show changes to address normalization, identity checks, or pairing RPC behavior, which the PR states are excluded. The base-to-head diff was unavailable, so the absence of other changed files rests on the PR summary and the described scope, not on a full file list diff.

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 bc13afa and 5b695f4.

Files selected for processing: 3

  • packages/client-runtime/src/linkedThread.test.ts
  • packages/client-runtime/src/linkedThread.ts
  • scripts/scenarios/linked-thread-connects-before-fallback-timeout.e2e.ts

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

@juliusmarminge

Copy link
Copy Markdown
Member

Evidence

Linux x64, Chromium, 1280×800. Link a second environment with full access and its reachable address first; hold fallback discovery pending until client abort. Open its read-only thread, click Connect to interact, measure until the editable composer appears, then enter the same unsent draft. Five fresh runs per commit; all ten opened the expected thread and accepted input.

Before After
bc13afaa3c 5b695f4b98
7.090 s median, 6.994–7.114 s 1.000 s median, 0.878–1.203 s
Before recording After recording

Median improvement: 6.090 s (85.9%), exceeding the combined run spreads of 0.445 s. Recordings show comparison 3 at normal speed, with setup trimmed.

All five measurements on base and head

Scenario · Repeat driver · Raw measurements · Image renderer

Not shown:

  • Preference between two simultaneously reachable addresses was not exercised; this proof covers the reported preferred-reachable, silent-fallback ordering.

@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 22, 2026
@juliusmarminge
juliusmarminge merged commit 3806763 into pingdotgg:main Nov 22, 2026
73 checks passed
@juliusmarminge juliusmarminge removed the takeover:ready Takeover done; auto-lands when gates pass label Nov 22, 2026
github-actions Bot added a commit to omarcresp/t3code-flake that referenced this pull request Nov 22, 2026
**v0.1.12-nightly.20261122.5111** · 30 changes from 10 contributors

- **Multi-file diffs.** Open diff now shows every file in a multi-file Codex patch.
- **Mixed-content paste.** Pasting a message with text and a picture now keeps both.
- **Queued attachments.** Edit a queued message without losing its image or file attachment chips.
- **Pull request checks.** Agents watching a pull request can recognize checks that already passed instead of waiting indefinitely.
- **Notebook outputs.** Saved HTML outputs now appear when you scroll them into view.

### Plus 24 more bug fixes and performance improvements.

<details>
<summary>Full changelog</summary>

## What's Changed
* perf(mobile): keep image bytes outside draft JSON by @t3dotgg in pingdotgg/t3code#9727
* fix(server): watch_pull_request says when checks already passed by @juliusmarminge in pingdotgg/t3code#40866
* fix(codex): Open diff shows every file of a multi-file patch by @Abhiram-745 in pingdotgg/t3code#40874
* fix(server): ACP startup gives up when the agent never answers the handshake by @juliusmarminge in pingdotgg/t3code#40864
* fix(server): a branch prefixed with another remote's name publishes under its full name by @Abhiram-745 in pingdotgg/t3code#40877
* fix(server): list open delegated tasks when task_status or task_cancel finds no match by @Project516 in pingdotgg/t3code#40886
* fix(gitlab): find merge requests opened from a fork by @Abhiram-745 in pingdotgg/t3code#40894
* fix(web): pasting a chat message with text and a picture keeps both by @juliusmarminge in pingdotgg/t3code#40909
* fix(antigravity): bound silent post-settle background command holds by @Lokkuchakreshkumar in pingdotgg/t3code#40858
* fix(desktop): WSL is not offered or started when only the Windows install stub exists by @juliusmarminge in pingdotgg/t3code#40918
* fix(server): idle /ws connections behind a reverse proxy no longer drop every 60s by @juliusmarminge in pingdotgg/t3code#40932
* fix(server): thread reads no longer attribute T3 Code's compact-before-send /compact to the user by @juliusmarminge in pingdotgg/t3code#40934
* fix(web,mobile): @-file mentions show by name in message previews, not as raw links by @tiliakoos in pingdotgg/t3code#40924
* fix(web): tool calls stay grouped after a usage-limit pause again by @matthew-waters in pingdotgg/t3code#40905
* fix(server): t3 doctor no longer reports a database just under 1 GiB as "1024.0 MiB" by @tiliakoos in pingdotgg/t3code#40952
* fix(web): show clone failure after progress is dismissed by @StiensWout in pingdotgg/t3code#40951
* Invalidate pending theme imports when a replacement is too large by @StiensWout in pingdotgg/t3code#40965
* fix(mobile): show linked thread history page errors by @StiensWout in pingdotgg/t3code#40973
* fix(client-runtime): skip waiting for lower-priority linked addresses by @StiensWout in pingdotgg/t3code#40989
* fix(web): navigate Excel sheets from the focused tab by @StiensWout in pingdotgg/t3code#41008
* fix(mobile): bound app-owned composer attachment filenames by @StiensWout in pingdotgg/t3code#40991
* fix(web): prioritize visible saved notebook outputs by @StiensWout in pingdotgg/t3code#40998
* fix(web): editing a queued message keeps its attachment chips resolved by @smirea in pingdotgg/t3code#40945
* fix(server): unlinking an environment ends its session on the other machine by @juliusmarminge in pingdotgg/t3code#41005
* fix(mobile): scope Git result banners to their originating thread by @StiensWout in pingdotgg/t3code#41015
* fix(web): keep the conversation when a pairing tab closes by @StiensWout in pingdotgg/t3code#41025
* fix: restart linked thread reads when trying again by @StiensWout in pingdotgg/t3code#41020
* fix(client-runtime): count ambiguous projects in chat file links by @StiensWout in pingdotgg/t3code#40986
* fix(mobile): keep media actions on each sent image page by @StiensWout in pingdotgg/t3code#41018
* perf(server): a run's provider turn lookup is linear, not quadratic by @navidnadali in pingdotgg/t3code#38791

## New Contributors
* @Lokkuchakreshkumar made their first contribution in pingdotgg/t3code#40858
* @matthew-waters made their first contribution in pingdotgg/t3code#40905

**Full Changelog**: pingdotgg/t3code@v0.1.12-nightly.20261122.5098...v0.1.12-nightly.20261122.5111

</details>


Upstream release: https://github.com/pingdotgg/t3code/releases/tag/v0.1.12-nightly.20261122.5111
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 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.

[Bug]: A silent fallback address delays connecting from a linked thread

2 participants