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
Closed
Mikiyas-Meles-Assefa
wants to merge
8
commits into
pingdotgg:main
from
Mikiyas-Meles-Assefa:feat/persistent-preview-panel-sync
+310
−52
Closed
fix(server): a stalled preview capture no longer times out snapshots and drops the agent's tab #24523
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1115032
fix(server): a stalled preview capture no longer times out snapshots …
Mikiyas-Meles-Assefa 0412fae
fix(server): merge main and isolate stalled capture timeout state
maria-rcks f78780b
test(server): create capture abort signals outside effect generators
maria-rcks 9db80ac
fix(server): share capture deadline with snapshot ref generation
maria-rcks def550b
fix(server): merge main preserving preview capture deadlines
maria-rcks 3055073
Merge branch 'main' into feat/persistent-preview-panel-sync
Mikiyas-Meles-Assefa 992147c
Merge remote-tracking branch 'origin/main' into feat/persistent-previ…
juliusmarminge 77c1747
Merge remote-tracking branch 'origin/main' into feat/persistent-previ…
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
| 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; | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.