Skip to content

Commit 779063d

Browse files
saphidclaude
andcommitted
fix(server): worktree thread lookups match any spelling of the path
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent e58ad1d commit 779063d

2 files changed

Lines changed: 37 additions & 4 deletions

File tree

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1699,6 +1699,14 @@ it.effect("SQL shells read a subagent family and a worktree's threads", () =>
16991699
yield* createThread({ name: "archived-child", parent: "root", root: "root", archived: true });
17001700
yield* createThread({ name: "other", worktreePath: "/repo" });
17011701
yield* createThread({ name: "other-child", parent: "other", root: "other", worktreePath });
1702+
yield* createThread({
1703+
name: "aliased-child",
1704+
parent: "other",
1705+
root: "other",
1706+
worktreePath: `${worktreePath}/`,
1707+
});
1708+
yield* createThread({ name: "cased", worktreePath: worktreePath.toUpperCase() });
1709+
yield* createThread({ name: "windows", worktreePath: "C:\\RÉPO\\wt" });
17021710

17031711
const family = (threadId: ThreadId) =>
17041712
store
@@ -1710,11 +1718,20 @@ it.effect("SQL shells read a subagent family and a worktree's threads", () =>
17101718
assert.sameMembers([...(yield* family(id("grandchild")))], tree);
17111719
assert.deepEqual([...(yield* family(id("missing")))], []);
17121720

1713-
// Includes another root's idle child on the same path, which a shell may leave out.
1721+
// Includes another root's idle child on the same path, which a shell may leave out, under any
1722+
// spelling of that path. POSIX paths keep their case.
17141723
const onWorktree = yield* store.getShellSnapshot({ location: "active", worktreePath });
17151724
assert.sameMembers(
17161725
onWorktree.threads.map((thread) => thread.id),
1717-
[id("root"), id("child"), id("other-child")],
1726+
[id("root"), id("child"), id("other-child"), id("aliased-child")],
1727+
);
1728+
const onWindowsWorktree = yield* store.getShellSnapshot({
1729+
location: "active",
1730+
worktreePath: "c:/répo/wt/",
1731+
});
1732+
assert.deepEqual(
1733+
onWindowsWorktree.threads.map((thread) => thread.id),
1734+
[id("windows")],
17181735
);
17191736
// A fork keeps its deleted source's root, so the deleted root still names the live tree.
17201737
yield* store.apply({

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ import * as SqlClient from "effect/sql/SqlClient";
9393
import type * as Statement from "effect/sql/Statement";
9494

9595
import { MCP_APP_OUTPUT_KEY } from "@t3tools/shared/mcpApp";
96+
import { normalizeProjectPathForComparison } from "@t3tools/shared/path";
9697
import { threadHtmlRenderAttachmentIds } from "../attachmentStore.ts";
9798
import {
9899
isThreadHistoryUserTurn,
@@ -973,6 +974,7 @@ type ShellThreadRow = {
973974
readonly thread_id: string;
974975
readonly payload_json: string;
975976
readonly forked_from_run_source_thread_id: string | null;
977+
readonly worktree_path: string | null;
976978
readonly latest_run_id: string | null;
977979
readonly latest_run_status: string | null;
978980
readonly latest_run_requested_at: string | null;
@@ -6001,6 +6003,7 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
60016003
THEN json_extract(t.payload_json, '$.forkedFrom.threadId')
60026004
ELSE NULL
60036005
END AS forked_from_run_source_thread_id,
6006+
json_extract(t.payload_json, '$.worktreePath') AS worktree_path,
60046007
presented.run_id AS latest_run_id,
60056008
presented.status AS latest_run_status,
60066009
presented.requested_at AS latest_run_requested_at,
@@ -6194,7 +6197,11 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
61946197
}${
61956198
worktreePath === undefined
61966199
? sql``
6197-
: sql` AND json_extract(t.payload_json, '$.worktreePath') = ${worktreePath}`
6200+
: // Loose match of any spelling of the path; readShellSnapshotRows keeps exact ones.
6201+
// SQLite's lower() folds only ASCII, so other paths always reach that check.
6202+
sql` AND (json_extract(t.payload_json, '$.worktreePath') GLOB '*[^ -~]*'
6203+
OR lower(rtrim(replace(trim(json_extract(t.payload_json, '$.worktreePath')), '\\', '/'), '/'))
6204+
= lower(rtrim(replace(trim(${worktreePath}), '\\', '/'), '/')))`
61986205
}${threadIds === undefined ? sql`` : sql` AND t.thread_id IN (SELECT value FROM json_each(${encodeIdList(threadIds)}))`}
61996206
ORDER BY t.updated_at ASC, t.thread_id ASC
62006207
`;
@@ -6734,7 +6741,16 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
67346741
const readShellSnapshotRows = Effect.fn("ProjectionStore.readShellSnapshotRows")(function* (
67356742
options: ShellSnapshotOptions | undefined,
67366743
) {
6737-
const targetThreadRows = yield* selectShellThreadRows(undefined, options);
6744+
const worktreeKey =
6745+
options?.worktreePath === undefined
6746+
? undefined
6747+
: normalizeProjectPathForComparison(options.worktreePath);
6748+
const targetThreadRows = (yield* selectShellThreadRows(undefined, options)).filter(
6749+
(row) =>
6750+
worktreeKey === undefined ||
6751+
(row.worktree_path !== null &&
6752+
normalizeProjectPathForComparison(row.worktree_path) === worktreeKey),
6753+
);
67386754
const targetThreadIds = new Set(targetThreadRows.map((row) => ThreadId.make(row.thread_id)));
67396755
const rowsByThreadId = new Map(
67406756
targetThreadRows.map((row) => [ThreadId.make(row.thread_id), row] as const),

0 commit comments

Comments
 (0)