Repository navigation
fix(app): order the inbox Working shelf by when each run started #60147
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
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,26 @@ | ||
| import { expect, test } from "bun:test" | ||
| import { compareWorking, workingSince } from "./inbox-working" | ||
|
|
||
| test("uses the current run's start", () => { | ||
| expect(workingSince({ time: { busy: 20 } })).toBe(20) | ||
| expect(workingSince({ time: { busy: 20, idle: 10 } })).toBe(20) | ||
| }) | ||
|
|
||
| test("has no start while only an earlier run's start is known", () => { | ||
| expect(workingSince({ time: { busy: 10, idle: 20 } })).toBeUndefined() | ||
| expect(workingSince({ time: { idle: 20 } })).toBeUndefined() | ||
| expect(workingSince({ time: {} })).toBeUndefined() | ||
| }) | ||
|
|
||
| test("orders by run start, then puts runs with no known start last", () => { | ||
| const entry = (key: string, time: { busy?: number; idle?: number }) => ({ key, session: { time } }) | ||
|
|
||
| const sorted = [ | ||
| entry("d", {}), | ||
| entry("b", { busy: 30 }), | ||
| entry("c", { busy: 5, idle: 10 }), | ||
| entry("a", { busy: 20, idle: 10 }), | ||
| ].toSorted(compareWorking) | ||
|
|
||
| expect(sorted.map((item) => item.key)).toEqual(["a", "b", "c", "d"]) | ||
| }) |
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,22 @@ | ||
| type SessionTime = { time: { busy?: number; idle?: number } } | ||
|
|
||
| /** | ||
| * When the session's current run started. Undefined while the client still holds an earlier run's start (it ended at | ||
| * `time.idle`, after `time.busy`) or the server does not record `time.busy`. | ||
| */ | ||
| export function workingSince(session: SessionTime) { | ||
| const { busy, idle } = session.time | ||
|
|
||
| if (busy === undefined || (idle !== undefined && idle > busy)) return undefined | ||
|
|
||
| return busy | ||
| } | ||
|
|
||
| /** Earliest run start first, so a session that starts working joins the end. Runs with no known start go last. */ | ||
| export function compareWorking(a: { key: string; session: SessionTime }, b: { key: string; session: SessionTime }) { | ||
| const start = (workingSince(a.session) ?? Infinity) - (workingSince(b.session) ?? Infinity) | ||
|
|
||
| if (start) return start | ||
|
|
||
| return a.key < b.key ? -1 : a.key > b.key ? 1 : 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
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.
The data store only refetches on
session.execution.startedwhen the session is already instore.session.infoor being synced (packages/client/src/solid/data.ts). Some inbox rows come only from theinbox-sessionslist query (staleTime: 30_000, refetched on mount/reconnect), for example an older session rerun from the TUI or another window. For those,time.busystays at the previous run's value for the whole new run, so the row shows plain "Working" and sorts last until it ends. That's no worse than the old staletime.updatedtimer. If you want those rows to get a timer too, one option is to refresh the inbox entry (or invalidate the inbox query) when such a session starts executing.