Skip to content

Commit 6360cf2

Browse files
committed
fix(web): retain question attachments while thread details load
1 parent acf4d82 commit 6360cf2

2 files changed

Lines changed: 50 additions & 1 deletion

File tree

‎apps/server/src/orchestration/Normalizer.attachments.test.ts‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,55 @@ describe("normalizeDispatchCommand attachments", () => {
363363
});
364364

365365
describe("question attachments", () => {
366+
it.effect("enforces the total response limit and claims duplicate filenames independently", () =>
367+
Effect.gen(function* () {
368+
const config = yield* ServerConfig.ServerConfig;
369+
const id = `pending-${attachmentUuid}-txt`;
370+
NodeFS.writeFileSync(NodePath.join(config.attachmentsDir, `${id}.txt`), "report");
371+
const attachment = {
372+
type: "file" as const,
373+
id,
374+
name: 'notes "final" ü.txt',
375+
mimeType: "text/plain",
376+
sizeBytes: 6,
377+
};
378+
const command: ClientOrchestrationCommand = {
379+
type: "thread.user-input.respond",
380+
commandId: CommandId.make("answer-cap"),
381+
threadId: ThreadId.make("thread-1"),
382+
requestId: ApprovalRequestId.make("request-cap"),
383+
answers: { first: "", second: "" },
384+
createdAt: "2026-08-01T00:00:00.000Z",
385+
attachmentsByQuestionId: {
386+
first: Array.from({ length: 4 }, () => attachment),
387+
second: Array.from({ length: 5 }, () => attachment),
388+
},
389+
};
390+
const failure = yield* normalizeDispatchCommand(command).pipe(Effect.flip);
391+
expect(failure.message).toContain("up to 8");
392+
expect(NodeFS.readdirSync(config.attachmentsDir)).toEqual([`${id}.txt`]);
393+
const accepted = {
394+
...command,
395+
attachmentsByQuestionId: {
396+
...command.attachmentsByQuestionId,
397+
second: Array.from({ length: 4 }, () => attachment),
398+
},
399+
};
400+
const normalized = yield* normalizeDispatchCommand(accepted);
401+
if (normalized.type !== "thread.user-input.respond") throw new Error("Wrong command");
402+
const attachments = Object.values(normalized.attachmentsByQuestionId!).flat();
403+
expect(attachments).toHaveLength(8);
404+
expect(new Set(attachments.map((item) => item.id)).size).toBe(8);
405+
for (const item of attachments) {
406+
expect(item.name).toBe(attachment.name);
407+
expect(
408+
NodeFS.readFileSync(NodePath.join(config.attachmentsDir, `${item.id}.txt`), "utf8"),
409+
).toBe("report");
410+
}
411+
yield* cleanupFailedUploadedAttachments(accepted, normalized);
412+
expect(NodeFS.readdirSync(config.attachmentsDir)).toEqual([`${id}.txt`]);
413+
}).pipe(Effect.provide(testLayer)),
414+
);
366415
it("requires uploaded metadata for question images, including pasted images", () => {
367416
expect(
368417
isClientCommand({

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2621,7 +2621,7 @@ export default function ChatView(props: ChatViewProps) {
26212621
Object.fromEntries(pendingQuestionDraftKeys.map((key) => [key, state.counts[key] ?? 0])),
26222622
),
26232623
);
2624-
const questionThreadReady = activeThread !== null;
2624+
const questionThreadReady = serverThread != null && !threadDetailLoading;
26252625
useEffect(() => {
26262626
if (!activeThreadId || !questionThreadReady) return;
26272627
const prefix = questionAttachmentDraftPrefix(environmentId, activeThreadId);

0 commit comments

Comments
 (0)