Skip to content

Commit a8eff87

Browse files
committed
fix(server): probe the chats folder once per connection
Restore the cached probe so a negative VCS detection, which the registry never caches, does not spawn git on every config load. Cover the gating in the server tests. The draft headline uses the same environment fallback as the hero so the hosted web app can offer Just chat.
1 parent 3b9c074 commit a8eff87

3 files changed

Lines changed: 43 additions & 12 deletions

File tree

‎apps/server/src/server.test.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4935,6 +4935,32 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
49354935
}).pipe(Effect.provide(NodeHttpServer.layerTest)),
49364936
);
49374937

4938+
it.effect("offers a chats folder only when the data dir is outside a work tree", () =>
4939+
Effect.gen(function* () {
4940+
yield* buildAppUnderTest();
4941+
const outside = yield* Effect.scoped(
4942+
withWsRpcClient(yield* getWsServerUrl("/ws"), (client) =>
4943+
client[WS_METHODS.serverGetConfig]({}),
4944+
),
4945+
);
4946+
assert.isTrue(outside.chatWorkspaceRoot?.endsWith("chats"));
4947+
}).pipe(Effect.provide(NodeHttpServer.layerTest)),
4948+
);
4949+
4950+
it.effect("withholds the chats folder when the data dir sits inside a work tree", () =>
4951+
Effect.gen(function* () {
4952+
yield* buildAppUnderTest({
4953+
layers: { vcsDriver: { isInsideWorkTree: () => Effect.succeed(true) } },
4954+
});
4955+
const inside = yield* Effect.scoped(
4956+
withWsRpcClient(yield* getWsServerUrl("/ws"), (client) =>
4957+
client[WS_METHODS.serverGetConfig]({}),
4958+
),
4959+
);
4960+
assert.isUndefined(inside.chatWorkspaceRoot);
4961+
}).pipe(Effect.provide(NodeHttpServer.layerTest)),
4962+
);
4963+
49384964
it.effect("advertises the usable file manager and its reveal label", () =>
49394965
Effect.gen(function* () {
49404966
yield* buildAppUnderTest({

‎apps/server/src/ws.ts‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1765,11 +1765,14 @@ const makeWsRpcLayer = (
17651765
// home) would inherit that repo's git status and checkpoints, so the
17661766
// folder is only offered when the data dir is outside any work tree.
17671767
// Detection failures fail closed and hide the folder, never the config.
1768-
const resolveChatWorkspaceRoot = gitWorkflow.isRepository(config.baseDir).pipe(
1769-
Effect.map((isRepository) =>
1770-
isRepository ? undefined : path.join(config.baseDir, "chats"),
1768+
// Probed once per connection: a negative VCS detection is not cached.
1769+
const resolveChatWorkspaceRoot = yield* Effect.cached(
1770+
gitWorkflow.isRepository(config.baseDir).pipe(
1771+
Effect.map((isRepository) =>
1772+
isRepository ? undefined : path.join(config.baseDir, "chats"),
1773+
),
1774+
Effect.catchCause(() => Effect.succeed(undefined)),
17711775
),
1772-
Effect.catchCause(() => Effect.succeed(undefined)),
17731776
);
17741777

17751778
// Only clients that answer /usage-limits themselves see it in the catalogs;

‎apps/web/src/components/chat/DraftHeroHeadline.tsx‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ export function DraftHeroHeadline({
6060
const applyStickyState = useComposerDraftStore((store) => store.applyStickyState);
6161
const setModelSelection = useComposerDraftStore((store) => store.setModelSelection);
6262
const openAddProject = useCallback(() => openCommandPalette({ open: "add-project" }), []);
63-
const { canStartChatIn, chatWorkspaceRootFor, ensureChatProject } = useChatProject();
63+
const { canStartChatIn, chatEnvironmentId, chatWorkspaceRootFor, ensureChatProject } =
64+
useChatProject();
6465

6566
const environmentLabelById = useMemo(
6667
() =>
@@ -144,14 +145,15 @@ export function DraftHeroHeadline({
144145
project.environmentId === activeProjectRef.environmentId &&
145146
project.id === activeProjectRef.projectId,
146147
) ?? null);
147-
const chatEnvironmentId = activeProjectRef?.environmentId ?? primaryEnvironmentId;
148-
const chatWorkspaceRoot = chatWorkspaceRootFor(chatEnvironmentId);
148+
const chatTargetEnvironmentId =
149+
activeProjectRef?.environmentId ?? chatEnvironmentId(primaryEnvironmentId);
150+
const chatWorkspaceRoot = chatWorkspaceRootFor(chatTargetEnvironmentId);
149151
const chatProject =
150-
chatEnvironmentId !== null && chatWorkspaceRoot !== null
151-
? findChatProject({ projects, environmentId: chatEnvironmentId, chatWorkspaceRoot })
152+
chatTargetEnvironmentId !== null && chatWorkspaceRoot !== null
153+
? findChatProject({ projects, environmentId: chatTargetEnvironmentId, chatWorkspaceRoot })
152154
: null;
153155
const isChatDraft = activeProject !== null && chatProject?.id === activeProject.id;
154-
const canJustChat = canStartChatIn(chatEnvironmentId) && !isChatDraft;
156+
const canJustChat = canStartChatIn(chatTargetEnvironmentId) && !isChatDraft;
155157

156158
// The picker can change the draft's target while "Just chat" is still
157159
// creating its project; a stale continuation must not retarget it again.
@@ -190,11 +192,11 @@ export function DraftHeroHeadline({
190192
}
191193
};
192194
const startChat = async () => {
193-
if (chatEnvironmentId === null || isChatDraft) {
195+
if (chatTargetEnvironmentId === null || isChatDraft) {
194196
return;
195197
}
196198
const requested = { draftId, activeProjectKey };
197-
const project = await ensureChatProject(chatEnvironmentId);
199+
const project = await ensureChatProject(chatTargetEnvironmentId);
198200
const latest = latestTargetRef.current;
199201
if (
200202
!project ||

0 commit comments

Comments
 (0)