Repository navigation
perf(mobile): chats left mid-turn reopen from the phone's cache #13900
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
AKolenda
wants to merge
4
commits into
pingdotgg:main
from
AKolenda:perf/mobile-reopen-running-threads
+300
−39
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1d6b485
perf(mobile): chats left mid-turn reopen from the phone's cache
AKolenda 0d9000e
fix(mobile): skip the delayed close-time write once the environment i…
AKolenda ea86a9d
fix(mobile): run state follows the newer copy; serialize thread cache…
AKolenda 2de23f1
fix(mobile): the delayed close-time write checks the registration, no…
AKolenda 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import { describe, expect, it } from "vite-plus/test"; | ||
|
|
||
| import { selectThreadRunStateSource } from "./thread-run-state"; | ||
|
|
||
| const at = (updatedAt: string, source: string) => ({ updatedAt, source }); | ||
|
|
||
| describe("selectThreadRunStateSource", () => { | ||
| it("reads run state from whichever copy holds the newer event", () => { | ||
| const retained = at("2026-09-26T10:00:00.000Z", "detail"); | ||
| const settledShell = at("2026-09-26T10:05:00.000Z", "shell"); | ||
| // A detail kept in memory (or on disk) while the turn finished elsewhere. | ||
| expect( | ||
| selectThreadRunStateSource({ detail: retained, detailIsLive: true, shell: settledShell }), | ||
| ).toBe(settledShell); | ||
| // The open view's stream is ahead of the coalesced thread list. | ||
| const streamed = at("2026-09-26T10:06:00.000Z", "detail"); | ||
| expect( | ||
| selectThreadRunStateSource({ detail: streamed, detailIsLive: true, shell: settledShell }), | ||
| ).toBe(streamed); | ||
| }); | ||
|
|
||
| it("prefers the detail on a tie", () => { | ||
| const detail = at("2026-09-26T10:00:00.000Z", "detail"); | ||
| const shell = at("2026-09-26T10:00:00.000Z", "shell"); | ||
| expect(selectThreadRunStateSource({ detail, detailIsLive: false, shell })).toBe(detail); | ||
| }); | ||
|
|
||
| it("trusts only a live detail before the thread list has loaded", () => { | ||
| const detail = at("2026-09-26T10:00:00.000Z", "detail"); | ||
| expect(selectThreadRunStateSource({ detail, detailIsLive: true, shell: null })).toBe(detail); | ||
| expect(selectThreadRunStateSource({ detail, detailIsLive: false, shell: null })).toBeNull(); | ||
| }); | ||
|
|
||
| it("uses the shell when there is no detail", () => { | ||
| const shell = at("2026-09-26T10:00:00.000Z", "shell"); | ||
| expect(selectThreadRunStateSource({ detail: null, detailIsLive: false, shell })).toBe(shell); | ||
| }); | ||
| }); |
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,25 @@ | ||
| /** | ||
| * Which copy of a thread decides whether it is working: its detail or its | ||
| * thread-list shell. | ||
| * | ||
| * A detail can be a copy retained in memory or written to disk when a view | ||
| * closed, even mid-turn, so it can say a turn is running long after it ended. | ||
| * Both copies stamp `updatedAt` with the time of the latest event they hold, | ||
| * so the newer one wins; on a tie the detail, which the open view streams. | ||
| * Before the thread list has loaded there is no shell, and only a live | ||
| * detail is trusted. | ||
| */ | ||
| export function selectThreadRunStateSource< | ||
| Detail extends { readonly updatedAt: string }, | ||
| Shell extends { readonly updatedAt: string }, | ||
| >(input: { | ||
| readonly detail: Detail | null; | ||
| readonly detailIsLive: boolean; | ||
| /** The thread-list shell only, never one derived from the detail. */ | ||
| readonly shell: Shell | null; | ||
| }): Detail | Shell | null { | ||
| const { detail, shell } = input; | ||
| if (shell === null) return input.detailIsLive ? detail : null; | ||
| if (detail === null) return shell; | ||
| return Date.parse(detail.updatedAt) >= Date.parse(shell.updatedAt) ? detail : shell; | ||
| } |
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.
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.