Repository navigation
fix(server): a stalled preview capture no longer times out snapshots and drops the agent's tab #24523
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
Open
Mikiyas-Meles-Assefa
wants to merge
1
commit into
pingdotgg:main
Choose a base branch
from
Mikiyas-Meles-Assefa:feat/persistent-preview-panel-sync
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+312
−46
Open
fix(server): a stalled preview capture no longer times out snapshots and drops the agent's tab #24523
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import { describe, expect, it } from "vite-plus/test"; | ||
|
|
||
| import { CaptureLock } from "./CaptureLock.ts"; | ||
|
|
||
| // oxlint-disable-next-line t3code/no-real-time-wait-in-tests -- a zero-delay macrotask boundary, not a wait for time | ||
| const settle = () => new Promise<void>((resolve) => setImmediate(resolve)); | ||
|
|
||
| describe("CaptureLock", () => { | ||
| it("keeps the capture ahead exclusive when a waiting capture gives up", async () => { | ||
| const lock = new CaptureLock(); | ||
| const ahead = Promise.withResolvers<void>(); | ||
| const events: string[] = []; | ||
| const first = lock.run(async () => { | ||
| events.push("first started"); | ||
| await ahead.promise; | ||
| events.push("first finished"); | ||
| }); | ||
| const giveUp = new AbortController(); | ||
| const expired = lock.run(async () => { | ||
| events.push("expired started"); | ||
| }, giveUp.signal); | ||
| const reason = new Error("expired"); | ||
| giveUp.abort(reason); | ||
| await expect(expired).rejects.toBe(reason); | ||
|
|
||
| const next = lock.run(async () => { | ||
| events.push("next started"); | ||
| }); | ||
| await settle(); | ||
| expect(events).toEqual(["first started"]); | ||
|
|
||
| ahead.resolve(); | ||
| await Promise.all([first, next]); | ||
| expect(events).toEqual(["first started", "first finished", "next started"]); | ||
| }); | ||
|
|
||
| it("frees the lock when a running capture that never settles gives up", async () => { | ||
| const lock = new CaptureLock(); | ||
| const giveUp = new AbortController(); | ||
| const stalled = lock.run(() => new Promise<never>(() => {}), giveUp.signal); | ||
| await settle(); | ||
| const reason = new Error("expired"); | ||
| giveUp.abort(reason); | ||
|
|
||
| await expect(stalled).rejects.toBe(reason); | ||
| await expect(lock.run(async () => "next")).resolves.toBe("next"); | ||
| }); | ||
| }); |
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,30 @@ | ||
| import { constVoid } from "effect/Function"; | ||
|
|
||
| const abandonOnAbort = <A>(promise: Promise<A>, signal: AbortSignal): Promise<A> => | ||
| new Promise<A>((resolve, reject) => { | ||
| const abort = () => reject(signal.reason); | ||
| if (signal.aborted) abort(); | ||
| signal.addEventListener("abort", abort, { once: true }); | ||
| promise.then(resolve, reject).finally(() => signal.removeEventListener("abort", abort)); | ||
| }); | ||
|
|
||
| /** | ||
| * Runs a tab's captures one at a time. A capture given a signal gives up when | ||
| * it aborts, waiting included, so one that never gets a frame cannot stall | ||
| * every capture behind it. One that gives up while still waiting keeps its | ||
| * place, so the capture ahead of it never overlaps the next. | ||
| */ | ||
| export class CaptureLock { | ||
| private tail: Promise<void> = Promise.resolve(); | ||
|
|
||
| run<A>(operation: () => Promise<A>, signal?: AbortSignal): Promise<A> { | ||
| const previous = this.tail; | ||
| const run = previous.then(() => { | ||
| signal?.throwIfAborted(); | ||
| return operation(); | ||
| }); | ||
| const result = signal ? abandonOnAbort(run, signal) : run; | ||
| this.tail = Promise.all([previous, result.then(constVoid, constVoid)]).then(constVoid); | ||
| return result; | ||
| } | ||
| } | ||
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
Oops, something went wrong.
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.
🔎 Supported by static analysis
Script executed:
Repository: pingdotgg/t3code
Length of output: 3784
Script executed:
Repository: pingdotgg/t3code
Length of output: 23550
Script executed:
Repository: pingdotgg/t3code
Length of output: 23434
Script executed:
Repository: pingdotgg/t3code
Length of output: 11227
Script executed:
Repository: pingdotgg/t3code
Length of output: 17064
Guard the recording restart during an active snapshot.
A timed-out snapshot can restart the recording screencast after the next snapshot has paused it. The recording consumer can then encode a repaint frame from that snapshot. The snapshot result itself follows a separate
ServerBrowserPage.snapshotpath.🐛 Suggested fix
The later snapshot still restarts recording after its cleanup decrements
tab.capturingto zero.