Repository navigation
fix(terminal): recover Kitty Unicode images after eviction and renderer reload #33120
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
JhaceLam
wants to merge
18
commits into
stablyai:main
Choose a base branch
from
JhaceLam:codex/terminal-image-recovery
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.
Open
Changes from 5 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
a499261
fix(terminal): recover Kitty Unicode images after eviction and render…
12f8089
fix(terminal): permit replay after repeated image eviction
6ae1825
fix(terminal): retry failed Kitty replay lookups
fcb934a
test: make full-suite fixtures reliable on developer hosts
0b02d77
test: isolate Git reflog identity in workflow fixtures
4029abb
test: scope Git author and committer variables to fixtures
8f44f3b
fix: recover reused Kitty IDs and tolerate bridge-only imports
26c5583
fix: invalidate stale image lookups without rewriting replay records
c0da25d
test: isolate PTY failure injection and bound census type checking
8eb9c1d
fix: restore image recovery after placement deletion and reuse
6bd44d2
test: separate repository fixtures from image recovery
18b4c1d
Merge commit 'db8fc6d0cc9bf7e7f945d54d7387fc2539ee0e3a' into codex/te…
aee9f55
fix: retain named physical Kitty placement deletion
334bf87
Merge main and preserve terminal image replay scope
dad8de5
Merge upstream main typecheck repair for image
d25a9de
Merge upstream main to retain updated terminal patch lock hashes
514431f
Merge upstream main to retain updated terminal patch lock hashes
146f572
fix: retain Kitty invalidations after failed image writes
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
289 changes: 229 additions & 60 deletions
289
config/patches/@xterm__addon-image@0.10.0-beta.301.patch
Large diffs are not rendered by default.
Oops, something went wrong.
269 changes: 219 additions & 50 deletions
269
config/patches/xterm-src/@xterm__addon-image@0.10.0-beta.301.src.patch
Large diffs are not rendered by default.
Oops, something went wrong.
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,264 @@ | ||
| import { afterEach, expect, it, vi } from 'vitest' | ||
| import { | ||
| createPlaceholderTerminal, | ||
| placeholderCells, | ||
| PNG, | ||
| render, | ||
| TrackedBitmap, | ||
| write, | ||
| writeKitty | ||
| } from './xterm-kitty-placeholder-test-terminal.mjs' | ||
| afterEach(() => vi.unstubAllGlobals()) | ||
|
|
||
| it('lazily decodes a pixel-evicted prototype without a new transmission', async () => { | ||
| const h = createPlaceholderTerminal() | ||
| try { | ||
| await writeKitty(h.terminal, 'a=T,f=100,i=7,U=1,c=2,r=2', PNG) | ||
| await write(h.terminal, placeholderCells(7)) | ||
| h.storage._pixelLimit = 200 | ||
| await writeKitty(h.terminal, 'a=T,f=100,i=8,U=1,c=2,r=2', PNG) | ||
| expect(h.bitmaps[0].close).toHaveBeenCalledOnce() | ||
| render(h) | ||
| await vi.waitFor(() => expect(h.bitmaps).toHaveLength(3)) | ||
| await vi.waitFor(() => expect(render(h)).toHaveLength(2)) | ||
| expect(h.storage.getUsage()).toBeLessThanOrEqual(0.0008) | ||
| } finally { | ||
| h.terminal.dispose() | ||
| } | ||
| }) | ||
|
|
||
| it('recovers after an alternate-buffer round trip empties the entire pixel store', async () => { | ||
| const h = createPlaceholderTerminal() | ||
| try { | ||
| await write(h.terminal, '\x1b[?1049h') | ||
| await writeKitty(h.terminal, 'a=T,f=100,i=7,U=1,c=2,r=2', PNG) | ||
| await write(h.terminal, `\x1b[?1049l\x1b[?1049h${placeholderCells(7)}`) | ||
| expect(h.storage._images.size).toBe(0) | ||
| render(h) | ||
| await vi.waitFor(() => expect(h.storage._images.size).toBe(1)) | ||
| h.renderer._layers.set('top', { | ||
| drawImage: h.drawImage, | ||
| clearRect() {}, | ||
| canvas: { remove() {} } | ||
| }) | ||
| expect(render(h)).toHaveLength(2) | ||
| } finally { | ||
| h.terminal.dispose() | ||
| } | ||
| }) | ||
|
|
||
| it('does not resurrect a deleted prototype while its recovery decode is in flight', async () => { | ||
| const h = createPlaceholderTerminal() | ||
| try { | ||
| await writeKitty(h.terminal, 'a=T,f=100,i=7,U=1,c=2,r=2', PNG) | ||
| await write(h.terminal, placeholderCells(7)) | ||
| h.storage._evictOldest(32_000_000) | ||
| let complete | ||
| h.decode.mockImplementationOnce( | ||
| () => | ||
| new Promise((resolve) => { | ||
| complete = resolve | ||
| }) | ||
| ) | ||
| render(h) | ||
| await vi.waitFor(() => expect(complete).toBeTypeOf('function')) | ||
| await writeKitty(h.terminal, 'a=d,d=I,i=7,q=2') | ||
| const bitmap = new TrackedBitmap() | ||
| complete(bitmap) | ||
| await vi.waitFor(() => expect(bitmap.close).toHaveBeenCalledOnce()) | ||
| expect(h.storage._images.size).toBe(0) | ||
| expect(h.kitty._virtualPlacements.size).toBe(0) | ||
| } finally { | ||
| h.terminal.dispose() | ||
| } | ||
| }) | ||
|
|
||
| it('restores only referenced images after a new renderer replays placeholder text', async () => { | ||
| const saved = new Map() | ||
| const first = createPlaceholderTerminal({ | ||
| onKittyImageChanged: (id, image) => { | ||
| if (image) { | ||
| saved.set(id, image) | ||
| } else { | ||
| saved.delete(id) | ||
| } | ||
| } | ||
| }) | ||
| await writeKitty(first.terminal, 'a=T,f=100,i=7,U=1,c=2,r=2', PNG) | ||
| first.terminal.dispose() | ||
| const read = vi.fn(async (id) => saved.get(id)) | ||
| const second = createPlaceholderTerminal({ readKittyImage: read }) | ||
| try { | ||
| expect(second.decode).not.toHaveBeenCalled() | ||
| await write(second.terminal, placeholderCells(7)) | ||
| render(second) | ||
| await vi.waitFor(() => expect(second.kitty.getImage(7)).toBeDefined()) | ||
| render(second) | ||
| await vi.waitFor(() => expect(second.storage._images.size).toBe(1)) | ||
| second.renderer._layers.set('top', { | ||
| drawImage: second.drawImage, | ||
| clearRect() {}, | ||
| canvas: { remove() {} } | ||
| }) | ||
| expect(render(second)).toHaveLength(2) | ||
| expect(read).toHaveBeenCalledTimes(1) | ||
| } finally { | ||
| second.terminal.dispose() | ||
| } | ||
| }) | ||
|
|
||
| it('lets new uploads win over an old asynchronous replay lookup', async () => { | ||
| let finish | ||
| const h = createPlaceholderTerminal({ | ||
| readKittyImage: () => | ||
| new Promise((resolve) => { | ||
| finish = resolve | ||
| }) | ||
| }) | ||
| try { | ||
| await write(h.terminal, placeholderCells(7)) | ||
| render(h) | ||
| await writeKitty(h.terminal, 'a=T,f=100,i=7,U=1,c=3,r=1', PNG) | ||
| const current = h.kitty.getImage(7) | ||
| finish({ | ||
| image: current, | ||
| placements: [{ placementId: 0, cols: 99, rows: 99, command: { unicodePlaceholder: 1 } }] | ||
| }) | ||
| await Promise.resolve() | ||
| await Promise.resolve() | ||
| expect(h.kitty.getImage(7)).toBe(current) | ||
| expect(h.kitty._virtualPlacementFor(7, 0).cols).toBe(3) | ||
| } finally { | ||
| h.terminal.dispose() | ||
| } | ||
| }) | ||
|
|
||
| it('recovers again after a restored encoded payload is evicted by the byte budget', async () => { | ||
| let snapshot | ||
| const first = createPlaceholderTerminal({ | ||
| onKittyImageChanged: (_id, image) => { | ||
| if (image) { | ||
| snapshot = image | ||
| } | ||
| } | ||
| }) | ||
| await writeKitty(first.terminal, 'a=T,f=100,i=7,U=1,c=2,r=2', PNG) | ||
| first.terminal.dispose() | ||
| const read = vi.fn(async () => snapshot) | ||
| const second = createPlaceholderTerminal({ readKittyImage: read }) | ||
| try { | ||
| vi.spyOn(second.storage, 'getLimit').mockReturnValue(snapshot.image.data.size / 1000000) | ||
| await write(second.terminal, placeholderCells(7)) | ||
| for (let attempt = 0; attempt < 3; attempt++) { | ||
| render(second) | ||
| await vi.waitFor(() => expect(second.kitty.getImage(7)).toBeDefined()) | ||
| expect(read).toHaveBeenCalledTimes(attempt + 1) | ||
| await writeKitty(second.terminal, `a=T,f=100,i=${8 + attempt},U=1,c=2,r=2`, PNG) | ||
| expect(second.kitty.getImage(7)).toBeUndefined() | ||
| } | ||
| } finally { | ||
| second.terminal.dispose() | ||
| } | ||
| }) | ||
|
|
||
| it.each(['absent', 'rejected', 'wrong id', 'oversized'])( | ||
| 'retries a %s replay lookup after a viewport change without polling the same viewport', | ||
| async (failure) => { | ||
| let snapshot | ||
| const first = createPlaceholderTerminal({ | ||
| onKittyImageChanged: (_id, image) => { | ||
| if (image) { | ||
| snapshot = image | ||
| } | ||
| } | ||
| }) | ||
| await writeKitty(first.terminal, 'a=T,f=100,i=7,U=1,c=2,r=2', PNG) | ||
| first.terminal.dispose() | ||
| const read = vi | ||
| .fn(async () => snapshot) | ||
| .mockImplementationOnce(async () => { | ||
| if (failure === 'rejected') { | ||
| throw new Error('temporary cache failure') | ||
| } | ||
| if (failure === 'absent') { | ||
| return undefined | ||
| } | ||
| return { | ||
| ...snapshot, | ||
| image: { | ||
| ...snapshot.image, | ||
| ...(failure === 'wrong id' | ||
| ? { id: 8 } | ||
| : { data: new Blob([new Uint8Array(9 * 1024 * 1024)]) }) | ||
| } | ||
| } | ||
| }) | ||
| const h = createPlaceholderTerminal({ readKittyImage: read }) | ||
| try { | ||
| await write(h.terminal, placeholderCells(7)) | ||
| for (let frame = 0; frame < 5; frame++) { | ||
| render(h) | ||
| await new Promise((resolve) => setTimeout(resolve, 0)) | ||
| } | ||
| expect(read).toHaveBeenCalledTimes(1) | ||
| expect(h.kitty.getImage(7)).toBeUndefined() | ||
| await write(h.terminal, '\r') | ||
| render(h) | ||
| await vi.waitFor(() => expect(h.kitty.getImage(7)).toBeDefined()) | ||
| expect(read).toHaveBeenCalledTimes(2) | ||
| } finally { | ||
| h.terminal.dispose() | ||
| } | ||
| } | ||
| ) | ||
|
|
||
| it('bounds recovery when visible prototypes exceed the decoded-pixel budget', async () => { | ||
| const h = createPlaceholderTerminal() | ||
| try { | ||
| h.storage._pixelLimit = 200 | ||
| for (const id of [7, 8, 9]) { | ||
| await writeKitty(h.terminal, `a=T,f=100,i=${id},U=1,c=2,r=2`, PNG) | ||
| } | ||
| await write( | ||
| h.terminal, | ||
| `${placeholderCells(7)}\r\n${placeholderCells(8)}\r\n${placeholderCells(9)}` | ||
| ) | ||
| for (let frame = 0; frame < 20; frame++) { | ||
| render(h) | ||
| await new Promise((resolve) => setTimeout(resolve, 0)) | ||
| } | ||
| expect(h.bitmaps.length).toBeLessThanOrEqual(6) | ||
| expect(h.storage.getUsage()).toBeLessThanOrEqual(0.0008) | ||
| } finally { | ||
| h.terminal.dispose() | ||
| } | ||
| }) | ||
|
|
||
| it('bounds replay reads when visible payloads exceed the encoded-byte budget', async () => { | ||
| const saved = new Map() | ||
| const first = createPlaceholderTerminal({ | ||
| onKittyImageChanged: (id, image) => { | ||
| if (image) { | ||
| saved.set(id, image) | ||
| } | ||
| } | ||
| }) | ||
| for (const id of [7, 8]) { | ||
| await writeKitty(first.terminal, `a=T,f=100,i=${id},U=1,c=2,r=2`, PNG) | ||
| } | ||
| first.terminal.dispose() | ||
| const read = vi.fn(async (id) => saved.get(id)) | ||
| const second = createPlaceholderTerminal({ readKittyImage: read }) | ||
| try { | ||
| vi.spyOn(second.storage, 'getLimit').mockReturnValue(saved.get(7).image.data.size / 1000000) | ||
| await write(second.terminal, `${placeholderCells(7)}\r\n${placeholderCells(8)}`) | ||
| for (let frame = 0; frame < 20; frame++) { | ||
| render(second) | ||
| await new Promise((resolve) => setTimeout(resolve, 0)) | ||
| } | ||
| expect(read).toHaveBeenCalledTimes(2) | ||
| expect(second.kitty.images.size).toBeLessThanOrEqual(1) | ||
| } finally { | ||
| second.terminal.dispose() | ||
| } | ||
| }) |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.