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
8 changes: 8 additions & 0 deletions apps/server/src/mcp/OrchestratorMcpService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,10 @@ function listItemFromShell(
creationSource: shell.creationSource,
status: listedThreadStatus(shell),
latestRunId: shell.latestRunId,
latestRunCompletedAt:
shell.latestRunCompletedAt === undefined || shell.latestRunCompletedAt === null
? null
: DateTime.formatIso(shell.latestRunCompletedAt),
providerInstanceId: shell.modelSelection.instanceId,
model: shell.modelSelection.model,
runtimeMode: shell.runtimeMode,
Expand All @@ -957,6 +961,10 @@ function listItemFromShell(
itemCount: shell.visibleItemCount,
createdAt: DateTime.formatIso(shell.createdAt),
updatedAt: DateTime.formatIso(shell.updatedAt),
lastVisitedAt:
shell.lastVisitedAt === undefined || shell.lastVisitedAt === null
? null
: DateTime.formatIso(shell.lastVisitedAt),
};
}

Expand Down
6 changes: 6 additions & 0 deletions apps/server/src/peer/linkedSidebar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ it.effect("reads a reachable server-only link and skips catalog and unreachable
itemCount: 4,
createdAt: "2026-11-19T12:00:00.000Z",
updatedAt: "2026-11-20T04:00:00.000Z",
lastVisitedAt: "2026-11-20T03:59:00.000Z",
latestRunCompletedAt: "2026-11-20T03:58:00.000Z",
},
],
});
Expand All @@ -103,5 +105,9 @@ it.effect("reads a reachable server-only link and skips catalog and unreachable
"10-model copy eval",
]);
expect(result.environments[0]?.threads[0]?.inbox?.owner).toBe("jeff");
expect(result.environments[0]?.threads[0]?.lastVisitedAt).toBe("2026-11-20T03:59:00.000Z");
expect(result.environments[0]?.threads[0]?.latestRunCompletedAt).toBe(
"2026-11-20T03:58:00.000Z",
);
}),
);
4 changes: 4 additions & 0 deletions apps/server/src/peer/linkedSidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ const slimThread = (
creationSource: thread.creationSource,
status: thread.status,
latestRunId: thread.latestRunId,
...(thread.latestRunCompletedAt === undefined
? {}
: { latestRunCompletedAt: thread.latestRunCompletedAt }),
providerInstanceId: thread.providerInstanceId,
model: thread.model,
runtimeMode: thread.runtimeMode,
Expand All @@ -94,6 +97,7 @@ const slimThread = (
itemCount: thread.itemCount,
createdAt: thread.createdAt,
updatedAt: thread.updatedAt,
...(thread.lastVisitedAt === undefined ? {} : { lastVisitedAt: thread.lastVisitedAt }),
});

export const collectLinkedSidebar = Effect.fn("linkedSidebar.collect")(function* (input: {
Expand Down
10 changes: 8 additions & 2 deletions apps/web/src/components/sidebar/SidebarThreadFilterMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import type { ReactNode } from "react";
import { updateClientSettings, useClientSettings } from "../../hooks/useSettings";
import { cn } from "../../lib/utils";
import { useConnectedEnvironmentIds } from "../../state/environments";
import { useSidebarEnvironmentIdentities } from "../../state/linkedSidebar";
import {
linkedSidebarEnvironmentIds,
useSidebarEnvironmentIdentities,
} from "../../state/linkedSidebar";
import {
Menu,
MenuCheckboxItem,
Expand Down Expand Up @@ -124,6 +127,7 @@ function SidebarThreadFilterOptions<T extends CountedThread>({
isChanged: boolean;
}) {
const connectedEnvironmentIds = useConnectedEnvironmentIds();
const linkedEnvironmentIds = linkedSidebarEnvironmentIds();
const inboxOrder = inboxMenuOrder(owner);
const older = olderSettled();
const counts = threadListFilterCounts(
Expand Down Expand Up @@ -201,7 +205,9 @@ function SidebarThreadFilterOptions<T extends CountedThread>({
{environments.map((environment) => {
const checked = shownEnvironmentIds.includes(environment.environmentId);
const isLast = checked && shownEnvironmentIds.length === 1;
const connected = connectedEnvironmentIds.includes(environment.environmentId);
const connected =
connectedEnvironmentIds.includes(environment.environmentId) ||
linkedEnvironmentIds.includes(environment.environmentId);
const count =
counts.environments.get(environment.environmentId) ??
EMPTY_THREAD_LIST_FILTER_BUCKETS;
Expand Down
52 changes: 51 additions & 1 deletion apps/web/src/state/linkedSidebar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import {
import { afterEach, describe, expect, it } from "vite-plus/test";

import { appAtomRegistry } from "../rpc/atomRegistry";
import { linkedSidebarByHostAtom, readLinkedSidebarThreadShell } from "./linkedSidebar";
import {
linkedSidebarByHostAtom,
linkedSidebarEnvironmentIds,
readLinkedSidebarThreadShell,
} from "./linkedSidebar";

const laptop = EnvironmentId.make("primary-mac-laptop");
const omarcy = EnvironmentId.make("omarcy-desktop");
Expand Down Expand Up @@ -67,3 +71,49 @@ describe("readLinkedSidebarThreadShell", () => {
expect(readLinkedSidebarThreadShell({ environmentId: laptop, threadId })).toBeNull();
});
});

const visited = "2026-11-20T05:01:00.000Z";

describe("linked sidebar refresh", () => {
it("picks up a visit that changes nothing else", () => {
const result = {
environments: [
{
environmentId: omarcy,
label: "omarcy-desktop",
projects: [],
threads: [{ ...linkedThread, status: "failed" as const }],
},
],
} satisfies LinkedSidebarResult;
appAtomRegistry.set(linkedSidebarByHostAtom, new Map([[laptop, result]]));
const before = readLinkedSidebarThreadShell({ environmentId: omarcy, threadId });
appAtomRegistry.set(
linkedSidebarByHostAtom,
new Map([
[
laptop,
{
environments: [
{
...result.environments[0]!,
threads: [{ ...linkedThread, status: "failed" as const, lastVisitedAt: visited }],
},
],
},
],
]),
);
const after = readLinkedSidebarThreadShell({ environmentId: omarcy, threadId });
expect(before?.lastVisitedAt ?? null).toBeNull();
expect(after?.lastVisitedAt).toBe(visited);
expect(after).not.toBe(before);
});
});

describe("linkedSidebarEnvironmentIds", () => {
it("reports a server-only link, which the filter paints connected", () => {
appAtomRegistry.set(linkedSidebarByHostAtom, new Map([[laptop, hostResult]]));
expect(linkedSidebarEnvironmentIds()).toEqual([omarcy]);
});
});
8 changes: 8 additions & 0 deletions apps/web/src/state/linkedSidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const sameThread = (left: EnvironmentThreadShell, right: EnvironmentThreadShell)
left.settledOverride === right.settledOverride &&
left.snoozedUntil === right.snoozedUntil &&
left.runtime?.status === right.runtime?.status &&
left.lastVisitedAt === right.lastVisitedAt &&
left.latestRun?.completedAt === right.latestRun?.completedAt &&
left.source.inbox?.owner === right.source.inbox?.owner &&
left.source.inbox?.audience === right.source.inbox?.audience &&
left.source.inbox?.attentionKind === right.source.inbox?.attentionKind;
Expand Down Expand Up @@ -116,6 +118,12 @@ export function readLinkedSidebarThreadShell(ref: ScopedThreadRef): EnvironmentT
);
}

export function linkedSidebarEnvironmentIds(): ReadonlyArray<EnvironmentId> {
return appAtomRegistry
.get(linkedSidebarSupplementAtom)
.identities.map((identity) => identity.environmentId);
}

export function useLinkedOnlyEnvironment(environmentId: EnvironmentId | null) {
const identities = useAtomValue(linkedSidebarSupplementAtom).identities;
return environmentId === null
Expand Down
55 changes: 55 additions & 0 deletions packages/client-runtime/src/state/linkedSidebar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import {
makeThreadInbox,
ProjectId,
ProviderInstanceId,
RunId,
ThreadId,
type LinkedSidebarThread,
} from "@t3tools/contracts";
import { describe, expect, it } from "vite-plus/test";

import { sidebarFromServerLinks } from "./linkedSidebar.ts";
import { hasUnseenRunFailure } from "./threadSettled.ts";
import { matchesThreadListFilter, threadListFilterOf } from "./threadListFilter.ts";

const laptop = EnvironmentId.make("primary-mac-laptop");
Expand Down Expand Up @@ -101,4 +103,57 @@ describe("sidebarFromServerLinks", () => {
expect(listed.threads.map((thread) => thread.id)).toEqual([threadId]);
expect(listed.projects).toHaveLength(1);
});

it("keeps a failed run unseen until the host records a later visit", () => {
const failed = {
...jeffThread,
status: "failed" as const,
latestRunId: RunId.make("run-eval"),
latestRunCompletedAt: "2026-11-20T05:00:00.000Z",
updatedAt: "2026-11-20T05:00:00.000Z",
} satisfies LinkedSidebarThread;
const listed = (thread: LinkedSidebarThread) =>
sidebarFromServerLinks({
catalogEnvironmentIds: [laptop],
environments: [
{ environmentId: omarcy, label: "omarcy-desktop", projects: [], threads: [thread] },
],
}).threads[0]!;
const unseen = listed(failed);
expect(unseen.latestRun?.status).toBe("failed");
expect(hasUnseenRunFailure(unseen)).toBe(true);
const seen = listed({ ...failed, lastVisitedAt: "2026-11-20T05:01:00.000Z" });
expect(hasUnseenRunFailure(seen)).toBe(false);
const failedAgain = listed({ ...failed, lastVisitedAt: "2026-11-20T04:59:00.000Z" });
expect(hasUnseenRunFailure(failedAgain)).toBe(true);
const renamedAfter = listed({
...failed,
lastVisitedAt: "2026-11-20T05:01:00.000Z",
updatedAt: "2026-11-20T05:02:00.000Z",
});
expect(hasUnseenRunFailure(renamedAfter)).toBe(false);
});

it("drops the failed pill once the host completes the thread", () => {
const listed = sidebarFromServerLinks({
catalogEnvironmentIds: [laptop],
environments: [
{
environmentId: omarcy,
label: "omarcy-desktop",
projects: [],
threads: [
{
...jeffThread,
status: "idle",
latestRunId: RunId.make("run-eval"),
lastVisitedAt: "2026-11-20T04:30:00.000Z",
},
],
},
],
}).threads[0]!;
expect(listed.latestRun?.status).toBe("completed");
expect(hasUnseenRunFailure(listed)).toBe(false);
});
});
6 changes: 6 additions & 0 deletions packages/client-runtime/src/state/linkedSidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ function threadShellFromLinkedThread(
forkedFrom: null,
activeProviderThreadId: null,
latestRunId: thread.latestRunId,
...(thread.latestRunCompletedAt === undefined
? {}
: { latestRunCompletedAt: utcOrNull(thread.latestRunCompletedAt) }),
activeRunId: active ? thread.latestRunId : null,
...(active ? { activityRunStatus: thread.status } : {}),
status: thread.status,
Expand All @@ -70,6 +73,9 @@ function threadShellFromLinkedThread(
visibleItemCount: thread.itemCount,
createdAt: utc(thread.createdAt),
updatedAt: utc(thread.updatedAt),
...(thread.lastVisitedAt === undefined
? {}
: { lastVisitedAt: utcOrNull(thread.lastVisitedAt) }),
archivedAt: null,
settledOverride: thread.settled ? "settled" : null,
settledAt: utcOrNull(thread.settledAt),
Expand Down
4 changes: 4 additions & 0 deletions packages/contracts/src/linkedSidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export const LinkedSidebarThread = Schema.Struct({
creationSource: OrchestrationV2CreationSource,
status: OrchestratorMcpThreadStatus,
latestRunId: Schema.NullOr(RunId),
/** Absent from linked environments that predate it. */
latestRunCompletedAt: Schema.optional(Schema.NullOr(IsoDateTime)),
providerInstanceId: ProviderInstanceId,
model: Schema.String,
runtimeMode: RuntimeMode,
Expand All @@ -43,6 +45,8 @@ export const LinkedSidebarThread = Schema.Struct({
itemCount: NonNegativeInt,
createdAt: IsoDateTime,
updatedAt: IsoDateTime,
/** Absent from linked environments that predate it. */
lastVisitedAt: Schema.optional(Schema.NullOr(IsoDateTime)),
});
export type LinkedSidebarThread = typeof LinkedSidebarThread.Type;

Expand Down
4 changes: 4 additions & 0 deletions packages/contracts/src/orchestratorMcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,8 @@ export const OrchestratorMcpThreadListItem = Schema.Struct({
creationSource: OrchestrationV2CreationSource,
status: OrchestratorMcpThreadStatus,
latestRunId: Schema.NullOr(RunId),
/** Absent from linked environments that predate it. */
latestRunCompletedAt: Schema.optional(Schema.NullOr(IsoDateTime)),
providerInstanceId: ProviderInstanceId,
model: Schema.String,
runtimeMode: RuntimeMode,
Expand All @@ -449,6 +451,8 @@ export const OrchestratorMcpThreadListItem = Schema.Struct({
itemCount: NonNegativeInt,
createdAt: IsoDateTime,
updatedAt: IsoDateTime,
/** Absent from linked environments that predate it. */
lastVisitedAt: Schema.optional(Schema.NullOr(IsoDateTime)),
});
export type OrchestratorMcpThreadListItem = typeof OrchestratorMcpThreadListItem.Type;

Expand Down
Loading