Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/mobile/src/features/threads/thread-list-v2-items.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1594,7 +1594,7 @@ export const ThreadListV2Row = memo(function ThreadListV2Row(props: {
strokeWidth={2}
fill="none"
strokeDasharray={2 * Math.PI * 4.5}
strokeDashoffset={2 * Math.PI * 4.5 * (1 - (lifeRing.fill ?? 0) / 100)}
strokeDashoffset={2 * Math.PI * 4.5 * (1 - lifeRing.fill / 100)}
rotation={-90}
origin="6, 6"
/>
Expand Down
6 changes: 3 additions & 3 deletions apps/web/src/components/sidebar/SidebarThreadRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,9 @@ function SidebarThreadTooltip({
{lifeRing ? (
<div className="flex flex-col items-start gap-1">
<span>
{lifeRing.fill === undefined
{lifeRing.context === undefined
? gt("Context usage unavailable")
: gt("{percent}% of context used", { percent: lifeRing.fill })}
: gt("{percent}% of context used", { percent: lifeRing.context })}
</span>
<span>
{gt("{count, plural, one {{count} compaction} other {{count} compactions}}", {
Expand Down Expand Up @@ -1434,7 +1434,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
<span
className="size-3 rounded-full"
style={{
background: `conic-gradient(currentColor ${lifeRing.fill ?? 0}%, color-mix(in srgb, currentColor 25%, transparent) 0)`,
background: `conic-gradient(currentColor ${lifeRing.fill}%, color-mix(in srgb, currentColor 25%, transparent) 0)`,
maskImage: "radial-gradient(transparent 43%, black 50%)",
}}
/>
Expand Down
27 changes: 26 additions & 1 deletion packages/client-runtime/src/sidebarRowModel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import {
ProviderDriverKind,
ProviderInstanceId,
type ModelSelection,
type OrchestrationV2ThreadShell,
type ServerProviderModel,
} from "@t3tools/contracts";
import { describe, expect, it } from "vite-plus/test";
import { sidebarRowModel } from "./sidebarRowModel.ts";
import { sidebarRowModel, threadLifeRing } from "./sidebarRowModel.ts";

const selection = {
instanceId: ProviderInstanceId.make("codex"),
Expand Down Expand Up @@ -54,3 +55,27 @@ describe("sidebar row speed", () => {
expect(sidebarRowModel({ ...selection, options }, undefined, undefined).speed).toBe("fast");
});
});

describe("thread life ring", () => {
const shell = (compactionCount: number, contextFillPercent?: number) =>
({
lineage: { parentThreadId: null },
compactionCount,
...(contextFillPercent === undefined ? {} : { contextFillPercent }),
}) as unknown as OrchestrationV2ThreadShell;

it("fills with lifetime toward the compaction limit, not the context window", () => {
expect(threadLifeRing(shell(2, 90), 4)).toEqual({
count: 2,
context: 90,
fill: 73,
warning: false,
});
expect(threadLifeRing(shell(0, 50), 4)?.fill).toBe(13);
});

it("is full and warns once the compaction limit is reached", () => {
expect(threadLifeRing(shell(4, 10), 4)).toMatchObject({ fill: 100, warning: true });
expect(threadLifeRing(shell(1), 4)?.fill).toBe(25);
});
});
8 changes: 7 additions & 1 deletion packages/client-runtime/src/sidebarRowModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,15 @@ export function shouldRecedeSidebarThread(input: {
export function threadLifeRing(thread: OrchestrationV2ThreadShell, threshold: number) {
if (thread.lineage.parentThreadId !== null || thread.delegatedFrom !== undefined) return null;
const count = thread.compactionCount ?? 0;
const context = thread.contextFillPercent;
return {
count,
fill: thread.contextFillPercent,
context,
// Lifetime toward Start fresh: full when the compaction limit is reached.
fill: Math.min(
100,
Math.round(((count + Math.min(context ?? 0, 100) / 100) / threshold) * 100),
),
warning: count >= threshold,
};
}
Expand Down
Loading