Repository navigation
fix: restart linked thread reads when trying again #41020
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
juliusmarminge
merged 5 commits into
pingdotgg:main
from
StiensWout:t3/1316-try-again-leaves-a-linked-thread-waiting
Nov 22, 2026
+153
−19
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b349da9
test: cover retrying a linked thread read
StiensWout 97e7bf3
fix: restart linked thread reads when trying again
StiensWout b2b40a3
test: mark the linked thread scenario timer as browser-side
StiensWout 17944a4
chore: credit the models that worked on this change
StiensWout 8c3a39e
Merge origin/main into t3/1316-try-again-leaves-a-linked-thread-waiting
juliusmarminge File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
105 changes: 105 additions & 0 deletions
105
scripts/scenarios/linked-thread-retry-reads-again.e2e.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| /// <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 })), | ||
| ); | ||
|
|
||
| test( | ||
| "Try again immediately reads a linked thread once it is reachable", | ||
| WEB, | ||
| async ({ t3, app, browser, screen }) => { | ||
| await t3.project("primary"); | ||
| const origin = app.baseUrl ?? ""; | ||
| const server = startSecondServer(origin); | ||
| try { | ||
| const { host } = await server.ready; | ||
| await runPromise( | ||
| Effect.gen(function* () { | ||
| const primary = yield* rpcClient(T3_HOME, origin); | ||
| const remote = yield* rpcClient(SECOND_HOME, host); | ||
| for (const client of [primary, remote]) { | ||
| 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: host, | ||
| pairingCode: credential, | ||
| access: "approval-required", | ||
| }); | ||
| }).pipe(Effect.scoped), | ||
| ); | ||
|
|
||
| const remote = makeState(SECOND_HOME).state; | ||
| const project = await remote.project("linked"); | ||
| const prompt = "Read the linked design notes"; | ||
| const thread = await remote.thread({ project, title: "Design notes", messages: [prompt] }); | ||
| const via = await runPromise(environmentId(origin)); | ||
| const linked = await runPromise(environmentId(host)); | ||
|
|
||
| // Drop only the first subscription, as if the linked machine were briefly unreachable. | ||
| // Every later request goes to the real server and reads the seeded thread. | ||
| await browser.addInitScript(() => { | ||
| let failed = false; | ||
| const send = WebSocket.prototype.send; | ||
| WebSocket.prototype.send = function (data) { | ||
| if (failed || typeof data !== "string") return send.call(this, data); | ||
| const parsed = JSON.parse(data); | ||
| const messages = Array.isArray(parsed) ? parsed : [parsed]; | ||
| const request = messages.find( | ||
| (message) => message?._tag === "Request" && message.tag === "peerLinks.subscribeThread", | ||
| ); | ||
| if (!request) return send.call(this, data); | ||
| failed = true; | ||
| const others = messages.filter((message) => message !== request); | ||
| if (others.length > 0) send.call(this, JSON.stringify(others)); | ||
| // @effect-diagnostics-next-line globalTimers:off - This callback is injected into the browser. | ||
| setTimeout(() => { | ||
| this.dispatchEvent( | ||
| new MessageEvent("message", { | ||
| data: JSON.stringify({ | ||
| _tag: "Exit", | ||
| requestId: request.id, | ||
| exit: { | ||
| _tag: "Failure", | ||
| cause: [ | ||
| { | ||
| _tag: "Fail", | ||
| error: { | ||
| _tag: "PeerLinkThreadReadError", | ||
| reason: "unreachable", | ||
| label: "Scenario", | ||
| message: "The linked machine is temporarily unreachable.", | ||
| }, | ||
| }, | ||
| ], | ||
| }, | ||
| }), | ||
| }), | ||
| ); | ||
| }, 0); | ||
| }; | ||
| }); | ||
|
|
||
| await t3.open(`/linked/${via}/${linked}/${thread.threadId}`); | ||
| await screen.getByRole("button", "Try again", { exact: true }).tap(); | ||
| await app.screenshot("after-trying-again"); | ||
| // The automatic retry waits 15 seconds. This checks the user's explicit retry. | ||
| await expect(screen.getByText(prompt, { exact: true })).toBeVisible({ timeout: 4_000 }); | ||
| } finally { | ||
| await server.stop(); | ||
| } | ||
| }, | ||
| ); | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Start the recovery assertion before taking the screenshot.
If
app.screenshottakes 12 seconds, the four-second assertion can include the automatic retry at 15 seconds. The scenario can then pass even when “Try again” does not restart the read. The automatic retry delay is 15 seconds in the reviewed revision. (raw.githubusercontent.com)Move the screenshot after the assertion. This keeps the labeled capture without delaying the recovery check.