Skip to content

[Bug]: Chat link to a thread on a newly linked environment stays unresolved until reload #41707

Done

Description

@ash663

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/web

Steps to reproduce

A client connected to server A keeps a cached list of A's linked environments. If A gets linked to server B outside this client (for example from the CLI), the list is never refreshed. A t3-thread://v2/<B>/<thread> link in an A thread then renders as an unresolved chip until the page is reloaded or the client reconnects to A.

The repro uses two servers on one machine and one web client. The same happens with A on a workstation and B on a VPS.

  1. Turn on Linked environments on both servers before starting them, and clone a repository that has a GitHub remote. delegate_task picks B's project by matching the repository, so both servers need a project for it.
    for d in /tmp/t3-a /tmp/t3-b; do
      mkdir -p "$d/userdata"
      echo '{"linkedEnvironmentsEnabled": true}' > "$d/userdata/settings.json"
    done
    git clone --depth 1 https://github.com/octocat/Hello-World /tmp/hello
  2. Start both servers (in separate terminals), then add the project to each:
    t3 serve --base-dir /tmp/t3-a --port 4101
    t3 serve --base-dir /tmp/t3-b --port 4102
    t3 project add /tmp/hello --base-dir /tmp/t3-a
    t3 project add /tmp/hello --base-dir /tmp/t3-b
  3. Open the web client and pair it with A only, using the pairing URL that A's t3 serve prints. Open a thread in the project on A and leave it open. Do not add B to this client: a client that has B saved opens B's threads directly, which hides the bug.
  4. From a terminal, link A to B. t3 pair prints B's pairing code on its Token: line, and t3 environment link prints B's environment id.
    t3 pair --base-dir /tmp/t3-b
    t3 environment link http://127.0.0.1:4102 --pairing-code <token> --base-dir /tmp/t3-a
  5. Without reloading the page, ask the agent in A's thread to call delegate_task with a small task that needs no tools (for example "reply OK") and target.environmentId=<B's id>, and to put the returned link in its reply.
  6. Look at the thread chip in the reply.
  7. Reload the page and look at the chip again.

Expected behavior

In step 6 the chip can be clicked and its tooltip reads "Read the thread on ", the same as after the reload in step 7.

Actual behavior

In step 6 the chip renders as unavailable: a dashed icon, the link text as its label, and the tooltip "Thread on another machine". It does not open. After the reload in step 7 the same chip can be clicked. In both steps, the delegated task's row opens B's thread read-only through A.

Cause: nothing refreshes the client's peerLinks.names cache when a link changes outside this client.

  • names is a plain RPC query with a 10 s stale time. It has no refreshTrigger, no refreshIntervalMs and no subscription: peerLinks.ts#L47-L52.
  • The stale time is checked only when the query's node builds, which happens when its first reader mounts: runtime.ts#L612-L649. The composer always calls useLinkedEnvironments(environmentId) (ChatComposer.tsx#L1212). The query therefore stays mounted while an A thread is open, and the stale check never runs again.
  • refreshLinks runs only after this client's own link, unlink or answerRequest succeeds: peerLinks.ts#L53-L151.
  • The server sends no event when a link changes. It answers peerLinks.names from the store on each call (ws.ts#L2765-L2766), and PeerLinks has no stream or PubSub (PeerLinks.ts#L99-L138). t3 environment link writes the store directly, without going through the running server (environment.ts#L39-L80).
  • MarkdownThreadLink looks B up in the cached names. With B missing, resolveLinkedThreadOpen returns "unavailable" and the chip falls through to UnresolvedChip: MarkdownThreadLink.tsx#L48-L58, #L87-L133, linkedThread.ts#L49-L61. The delegated row goes through useLinkedThreadOpener, which treats "unavailable" as "linked", so the row still opens: linkedThreadView.ts#L55.

Settings → Connections → "Link several…" leaves A's names stale even within one client. The batch links through linkInBatch, which has no onSuccess, and when it ends it refreshes only list: peerLinks.ts#L109-L113, LinkSeveralEnvironments.tsx#L109, #L187.

Suggested fix:

  1. Have the server push link changes. Add a link-change subscription that PeerLinks publishes to on link and unlink, and pass it to names and list as refreshTrigger, the way pullRequests.ts uses pullRequestsSubscribeRefreshes (pullRequests.ts#L694-L701, #L735). This also covers links made from a second client. The CLI links in its own process, so t3 environment link and unlink would also need to go through the running server with RunningServer.changeState, as t3 project does (runningServer.ts#L87-L91, project.ts#L325).
  2. Client-only fix: refetch names on window focus, and whenever a message or delegated row references an environment id that names does not contain. Also refresh names when a batch ends.

Related: #39406 added peerLinks.names and the linked-chip path. #26434 fixed a similar gap for links made through the client's own link card.

Impact

Minor bug or occasional failure

Version or commit

v0.1.12-nightly.20261121.5051 (dd941b9); the code path is unchanged on main @ 2621031

Environment

Servers on Linux. Seen in the macOS desktop app; the code path is in apps/web, so the browser client behaves the same. Any provider.

Logs or stack traces

No error is logged. A's server traces show no peerLinks.names request between the moment the link was made and the reload. The reload sends one, and the chip resolves.

Workaround

Reload the page or reconnect to A. Opening the delegated task's row instead of the chip also works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions