Skip to content

Commit 3923e94

Browse files
committed
fix: tag changes skip transcript import, and mobile drops tags on old servers
- `thread.tag.set` no longer waits for a migrated thread's v1 transcript, so a bulk rename or delete doesn't stop at a thread whose import fails. - On mobile, a saved tag filter stops filtering while no server supports tags, instead of hiding every thread from older servers. The saved tag comes back when a server with tags connects.
1 parent 4d69578 commit 3923e94

6 files changed

Lines changed: 54 additions & 20 deletions

File tree

‎apps/mobile/src/features/home/HomeRouteScreen.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { pickableProjectGroups } from "@t3tools/client-runtime/state/project-gro
1414

1515
import { useProjects, useQuietThreadShells } from "../../state/entities";
1616
import { steadyNavigationThreadShellsAtom, steadyThreadShellsAtom } from "../../state/threads";
17+
import { threadListEnvironmentsAtom } from "../../state/presentation";
1718
import { useLaunchingThreads, usePendingNewTasks } from "../../state/use-pending-new-tasks";
1819
import { useWorkspaceState } from "../../state/workspace";
1920
import { useSavedRemoteConnections } from "../../state/use-remote-environment-registry";
@@ -129,7 +130,10 @@ export function HomeRouteScreen() {
129130
setSelectedEnvironmentId,
130131
setSelectedProjectKey,
131132
setSelectedTag,
132-
} = useHomeListOptions(availableEnvironmentIds);
133+
} = useHomeListOptions(
134+
availableEnvironmentIds,
135+
useAtomValueWhileVisible(threadListEnvironmentsAtom, visible).tagEnvironmentIds,
136+
);
133137
const selectedEnvironmentId = listOptions.selectedEnvironmentId;
134138
const selectedTag = listOptions.selectedTag;
135139
const fullShells = useAtomValueWhileVisible(

‎apps/mobile/src/features/home/home-list-options.test.tsx‎

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,24 @@ const AVAILABLE = new Set([ENVIRONMENT]);
1919
it("saves the scope from every update made in one event", async () => {
2020
harness.saved = [];
2121
let controls: ReturnType<typeof useHomeListOptions> | undefined;
22-
function Probe() {
23-
const result = useHomeListOptions(AVAILABLE);
22+
function Probe(props: { readonly tagEnvironmentIds: ReadonlySet<EnvironmentId> }) {
23+
const result = useHomeListOptions(AVAILABLE, props.tagEnvironmentIds);
2424
useLayoutEffect(() => {
2525
controls = result;
2626
});
2727
return null;
2828
}
2929

3030
const root = createRoot(document.createElement("div"));
31-
await act(async () =>
32-
root.render(
33-
<HomeListOptionsProvider projectGroupingMode="repository">
34-
<Probe />
35-
</HomeListOptionsProvider>,
36-
),
37-
);
31+
const renderWith = (tagEnvironmentIds: ReadonlySet<EnvironmentId>) =>
32+
act(async () =>
33+
root.render(
34+
<HomeListOptionsProvider projectGroupingMode="repository">
35+
<Probe tagEnvironmentIds={tagEnvironmentIds} />
36+
</HomeListOptionsProvider>,
37+
),
38+
);
39+
await renderWith(AVAILABLE);
3840
act(() => {
3941
controls!.setSelectedEnvironmentId(ENVIRONMENT);
4042
controls!.setSelectedProjectKey("env-1:project-1");
@@ -45,5 +47,13 @@ it("saves the scope from every update made in one event", async () => {
4547
});
4648
expect(controls!.options.selectedEnvironmentId).toBe(ENVIRONMENT);
4749
expect(controls!.options.selectedProjectKey).toBe("env-1:project-1");
50+
51+
// With no server that supports tags, the saved tag stops filtering but is kept.
52+
act(() => controls!.setSelectedTag("bug"));
53+
await renderWith(new Set());
54+
expect(controls!.options.selectedTag).toBeNull();
55+
expect(harness.saved.at(-1)).toMatchObject({ threadListFilters: { tag: "bug" } });
56+
await renderWith(AVAILABLE);
57+
expect(controls!.options.selectedTag).toBe("bug");
4858
act(() => root.unmount());
4959
});

‎apps/mobile/src/features/home/home-list-options.ts‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ export function HomeListOptionsProvider({
7575
return createElement(HomeListOptionsContext, { value }, children);
7676
}
7777

78-
export function useHomeListOptions(availableEnvironmentIds: ReadonlySet<EnvironmentId>) {
78+
export function useHomeListOptions(
79+
availableEnvironmentIds: ReadonlySet<EnvironmentId>,
80+
tagEnvironmentIds: ReadonlySet<EnvironmentId>,
81+
) {
7982
const shared = useContext(HomeListOptionsContext);
8083
const [localOptions, setLocalOptions] = useState<HomeListOptions>(defaultHomeListOptions);
8184
const options = shared?.options ?? localOptions;
@@ -87,10 +90,14 @@ export function useHomeListOptions(availableEnvironmentIds: ReadonlySet<Environm
8790
availableEnvironmentIds.has(options.selectedEnvironmentId)
8891
? options.selectedEnvironmentId
8992
: null;
93+
// The saved tag waits, unchanged, for a server that supports tags.
94+
const selectedTag = [...availableEnvironmentIds].some((id) => tagEnvironmentIds.has(id))
95+
? options.selectedTag
96+
: null;
9097
const availableOptions =
91-
selectedEnvironmentId === options.selectedEnvironmentId
98+
selectedEnvironmentId === options.selectedEnvironmentId && selectedTag === options.selectedTag
9299
? options
93-
: { ...options, selectedEnvironmentId };
100+
: { ...options, selectedEnvironmentId, selectedTag };
94101
const resolvedOptions: ResolvedHomeListOptions = {
95102
...availableOptions,
96103
projectGroupingMode: shared?.projectGroupingMode ?? "repository",

‎apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,9 @@ function ThreadNavigationSidebarPane(props: ThreadNavigationSidebarProps) {
159159
const availableEnvironmentIds = new Set(
160160
environments.map((environment) => environment.environmentId),
161161
);
162+
const listEnvironments = useAtomValue(threadListEnvironmentsAtom);
162163
const { options, setSelectedEnvironmentId, setSelectedProjectKey, setSelectedTag } =
163-
useHomeListOptions(availableEnvironmentIds);
164+
useHomeListOptions(availableEnvironmentIds, listEnvironments.tagEnvironmentIds);
164165
const selectedTag = options.selectedTag;
165166
const fullShells = useAtomValueWhileVisible(steadyThreadShellsAtom, selectedTag !== null);
166167
const launchingThreads = useMemo(
@@ -258,7 +259,6 @@ function ThreadNavigationSidebarPane(props: ThreadNavigationSidebarProps) {
258259
toggleWorkingShelf,
259260
} = useThreadListV2ShelfPreferences();
260261
const now = useThreadListNow(threads);
261-
const listEnvironments = useAtomValue(threadListEnvironmentsAtom);
262262
const {
263263
providersByEnvironmentId,
264264
machineByEnvironmentId,

‎apps/server/src/orchestration-v2/ThreadManagementService.test.ts‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import * as ProviderSessionManager from "./ProviderSessionManager.ts";
3838
import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter";
3939
import * as ThreadManagementService from "./ThreadManagementService.ts";
4040
import * as ThreadCommandExecutor from "./ThreadCommandExecutor.ts";
41+
import * as LegacyV1ThreadImporter from "./legacy/LegacyV1ThreadImporter.ts";
4142

4243
it("stamps authoritative provenance on commands that create threads or messages", () => {
4344
const command: OrchestrationV2Command = {
@@ -974,7 +975,19 @@ it.effect.each([
974975
])(
975976
"a failed tag change reports how many threads already changed ($name)",
976977
({ to, failAt, threadsChanged }) => {
977-
const layerTest = ThreadManagementService.layer.pipe(
978+
const layerTest = ThreadManagementService.layerWithLegacyImporter.pipe(
979+
// Tags never need a migrated transcript, so one that cannot import does not stop the loop.
980+
Layer.provide(
981+
Layer.mock(LegacyV1ThreadImporter.LegacyV1ThreadImporter)({
982+
ensureTranscript: (threadId) =>
983+
Effect.fail(
984+
new LegacyV1ThreadImporter.LegacyV1ThreadImportError({
985+
operation: "ensureTranscript",
986+
threadId,
987+
}),
988+
),
989+
}),
990+
),
978991
Layer.provide(Layer.mock(ProviderSessionManager.ProviderSessionManagerV2)({})),
979992
Layer.provide(
980993
Layer.mock(Orchestrator.OrchestratorV2)({

‎apps/server/src/orchestration-v2/ThreadManagementService.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,12 @@ function existingThreadIdsForCommand(
111111
switch (command.type) {
112112
case "thread.create":
113113
return [];
114-
// Read-state commands only rewrite the thread payload's visited/unread
115-
// watermark and open stats; they never touch messages, so they do not need the imported
116-
// v1 transcript hydrated first. Visits fire on every thread-activity bump
117-
// while a thread is open, so keeping them off the import path matters.
114+
// Read-state and tag commands only rewrite the thread payload; they never touch messages,
115+
// so they do not need the imported v1 transcript first. Visits fire on every activity bump
116+
// while a thread is open, and a bulk tag rename must not stop at one unimported thread.
118117
case "thread.visit":
119118
case "thread.mark-unread":
119+
case "thread.tag.set":
120120
return [];
121121
case "thread.fork":
122122
return [command.sourceThreadId];

0 commit comments

Comments
 (0)