-
Notifications
You must be signed in to change notification settings - Fork 28
Give log-viewer rows a stable unique key, so messages stop stacking on top of each other #587
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
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| // @vitest-environment node | ||
| import { describe, it, expect } from "vitest"; | ||
| import { buildEntryKeys } from "@/lib/entry-keys"; | ||
| import type { LogEntry } from "@/lib/log-entries"; | ||
|
|
||
| /** | ||
| * Regression coverage for the virtualized log viewer's row identity. | ||
| * | ||
| * Duplicate React keys strand orphaned DOM nodes on top of live rows in the | ||
| * virtualized list (a Codex session with 93 colliding timestamps rendered | ||
| * three overlapping copies of index 3). Every entry must get a unique key, | ||
| * and that key must be stable across rebuilds. | ||
| */ | ||
|
|
||
| const entry = (over: Partial<LogEntry> = {}): LogEntry => | ||
| ({ | ||
| type: "user", | ||
| _source: "session", | ||
| uuid: "", | ||
| parentUuid: null, | ||
| timestamp: "2026-05-15T11:57:43.872Z", | ||
| timestampMs: 1778846263872, | ||
| timestampFormatted: "May 15, 2026, 5:27:43 PM.872", | ||
| message: { role: "user", content: "hi" }, | ||
| ...over, | ||
| }) as LogEntry; | ||
|
|
||
| describe("lib/log-entries: buildEntryKeys", () => { | ||
| it("gives uuid-less entries sharing a timestamp distinct keys", () => { | ||
| // The exact Codex shape: no uuid, identical timestamps. | ||
| const entries = [entry(), entry(), entry()]; | ||
|
|
||
| const keys = buildEntryKeys(entries); | ||
| const values = entries.map((e) => keys.get(e)); | ||
|
|
||
| expect(new Set(values).size).toBe(3); | ||
| expect(values.every((v) => typeof v === "string" && v.length > 0)).toBe(true); | ||
| }); | ||
|
|
||
| it("keeps every key unique across a run of colliding timestamps", () => { | ||
| const entries = Array.from({ length: 50 }, (_, i) => | ||
| entry({ timestamp: i % 2 === 0 ? "2026-05-15T11:57:43.872Z" : "2026-05-15T11:57:52.077Z" }), | ||
| ); | ||
|
|
||
| const keys = buildEntryKeys(entries); | ||
|
|
||
| expect(new Set(entries.map((e) => keys.get(e))).size).toBe(50); | ||
| }); | ||
|
|
||
| it("prefers a real uuid when the transcript supplies one", () => { | ||
| const a = entry({ uuid: "uuid-a" }); | ||
| const b = entry({ uuid: "uuid-b" }); | ||
|
|
||
| const keys = buildEntryKeys([a, b]); | ||
|
|
||
| expect(keys.get(a)).toBe("uuid-a"); | ||
| expect(keys.get(b)).toBe("uuid-b"); | ||
| }); | ||
|
|
||
| it("still disambiguates if a transcript repeats a uuid", () => { | ||
| const a = entry({ uuid: "dupe" }); | ||
| const b = entry({ uuid: "dupe" }); | ||
|
|
||
| const keys = buildEntryKeys([a, b]); | ||
|
|
||
| expect(keys.get(a)).not.toBe(keys.get(b)); | ||
| }); | ||
|
|
||
| it("does not collide across sources that share a timestamp", () => { | ||
| const a = entry({ _source: "session" }); | ||
| const b = entry({ _source: "agent-1" }); | ||
|
|
||
| const keys = buildEntryKeys([a, b]); | ||
|
|
||
| expect(keys.get(a)).not.toBe(keys.get(b)); | ||
| }); | ||
|
|
||
| it("assigns stable keys across rebuilds of the same list", () => { | ||
| // The virtualizer caches measured heights by key, so an unstable key would | ||
| // replay one entry's height onto another after a collapse/expand. | ||
| const entries = [entry(), entry(), entry({ uuid: "x" })]; | ||
|
|
||
| const first = buildEntryKeys(entries); | ||
| const second = buildEntryKeys(entries); | ||
|
|
||
| for (const e of entries) { | ||
| expect(second.get(e)).toBe(first.get(e)); | ||
| } | ||
| }); | ||
|
|
||
| it("handles an empty list", () => { | ||
| expect(buildEntryKeys([]).size).toBe(0); | ||
| }); | ||
| }); |
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
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.