From bae3c9470fa952f99d630a0449507b9faca9dac1 Mon Sep 17 00:00:00 2001 From: Theo Browne Date: Tue, 21 Jul 2026 19:52:25 -0700 Subject: [PATCH] polish: acknowledge queued sends in the composer; drop dead listAll A mid-turn send now projects as a queued message rather than a steered timeline message, so the composer's local-dispatch acknowledgment also watches the queued-message tail. Remove the unused listAll repository method. Co-Authored-By: Claude Fable 5 --- .../Layers/ProjectionQueuedMessages.ts | 24 ------------------- .../Services/ProjectionQueuedMessages.ts | 4 ---- .../web/src/components/ChatView.logic.test.ts | 23 ++++++++++++++++++ apps/web/src/components/ChatView.logic.ts | 15 ++++++++---- apps/web/src/components/ChatView.tsx | 3 +++ 5 files changed, 36 insertions(+), 33 deletions(-) diff --git a/apps/server/src/persistence/Layers/ProjectionQueuedMessages.ts b/apps/server/src/persistence/Layers/ProjectionQueuedMessages.ts index b332a578f8..cd34c2652e 100644 --- a/apps/server/src/persistence/Layers/ProjectionQueuedMessages.ts +++ b/apps/server/src/persistence/Layers/ProjectionQueuedMessages.ts @@ -80,24 +80,6 @@ const makeProjectionQueuedMessageRepository = Effect.gen(function* () { `, }); - const listAllProjectionQueuedMessageRows = SqlSchema.findAll({ - Request: Schema.Void, - Result: ProjectionQueuedMessageDbRowSchema, - execute: () => sql` - SELECT - message_id AS "messageId", - thread_id AS "threadId", - text, - attachments_json AS "attachments", - model_selection_json AS "modelSelection", - source_proposed_plan_thread_id AS "sourceProposedPlanThreadId", - source_proposed_plan_id AS "sourceProposedPlanId", - queued_at AS "queuedAt" - FROM projection_queued_messages - ORDER BY queued_at ASC, message_id ASC - `, - }); - const deleteProjectionQueuedMessageRow = SqlSchema.void({ Request: DeleteProjectionQueuedMessageInput, execute: ({ threadId, messageId }) => sql` @@ -126,11 +108,6 @@ const makeProjectionQueuedMessageRepository = Effect.gen(function* () { ), ); - const listAll: ProjectionQueuedMessageRepositoryShape["listAll"] = () => - listAllProjectionQueuedMessageRows(undefined).pipe( - Effect.mapError(toPersistenceSqlError("ProjectionQueuedMessageRepository.listAll:query")), - ); - const deleteByMessageId: ProjectionQueuedMessageRepositoryShape["deleteByMessageId"] = (input) => deleteProjectionQueuedMessageRow(input).pipe( Effect.mapError( @@ -148,7 +125,6 @@ const makeProjectionQueuedMessageRepository = Effect.gen(function* () { return { upsert, listByThreadId, - listAll, deleteByMessageId, deleteByThreadId, } satisfies ProjectionQueuedMessageRepositoryShape; diff --git a/apps/server/src/persistence/Services/ProjectionQueuedMessages.ts b/apps/server/src/persistence/Services/ProjectionQueuedMessages.ts index 739b4a491e..6a884dd7b5 100644 --- a/apps/server/src/persistence/Services/ProjectionQueuedMessages.ts +++ b/apps/server/src/persistence/Services/ProjectionQueuedMessages.ts @@ -47,10 +47,6 @@ export interface ProjectionQueuedMessageRepositoryShape { readonly listByThreadId: ( input: ListProjectionQueuedMessagesInput, ) => Effect.Effect, ProjectionRepositoryError>; - readonly listAll: () => Effect.Effect< - ReadonlyArray, - ProjectionRepositoryError - >; readonly deleteByMessageId: ( input: DeleteProjectionQueuedMessageInput, ) => Effect.Effect; diff --git a/apps/web/src/components/ChatView.logic.test.ts b/apps/web/src/components/ChatView.logic.test.ts index d67b6b4c63..928dfd51a7 100644 --- a/apps/web/src/components/ChatView.logic.test.ts +++ b/apps/web/src/components/ChatView.logic.test.ts @@ -370,6 +370,7 @@ describe("hasServerAcknowledgedLocalDispatch", () => { phase: "ready", latestTurn: completedTurn, latestUserMessageId: localDispatch.latestUserMessageId, + latestQueuedMessageId: localDispatch.latestQueuedMessageId, session: readySession, hasPendingApproval: false, hasPendingUserInput: false, @@ -396,6 +397,7 @@ describe("hasServerAcknowledgedLocalDispatch", () => { phase: "ready", latestTurn: newerTurn, latestUserMessageId: localDispatch.latestUserMessageId, + latestQueuedMessageId: localDispatch.latestQueuedMessageId, session: { ...readySession, updatedAt: newerTurn.completedAt }, hasPendingApproval: false, hasPendingUserInput: false, @@ -423,6 +425,7 @@ describe("hasServerAcknowledgedLocalDispatch", () => { phase: "running", latestTurn: runningTurn, latestUserMessageId: localDispatch.latestUserMessageId, + latestQueuedMessageId: localDispatch.latestQueuedMessageId, session: { ...readySession, status: "running", @@ -439,6 +442,7 @@ describe("hasServerAcknowledgedLocalDispatch", () => { phase: "running", latestTurn: runningTurn, latestUserMessageId: localDispatch.latestUserMessageId, + latestQueuedMessageId: localDispatch.latestQueuedMessageId, session: { ...readySession, status: "running", @@ -486,6 +490,24 @@ describe("hasServerAcknowledgedLocalDispatch", () => { phase: "running", latestTurn: runningTurn, latestUserMessageId: MessageId.make("message-steer"), + latestQueuedMessageId: localDispatch.latestQueuedMessageId, + session: runningSession, + hasPendingApproval: false, + hasPendingUserInput: false, + threadError: null, + }), + ).toBe(true); + + // A send during a running turn can also land as a queued message + // instead of a steered timeline message; that projection must clear + // the composer's local "Sending" state too. + expect( + hasServerAcknowledgedLocalDispatch({ + localDispatch, + phase: "running", + latestTurn: runningTurn, + latestUserMessageId: localDispatch.latestUserMessageId, + latestQueuedMessageId: MessageId.make("message-queued"), session: runningSession, hasPendingApproval: false, hasPendingUserInput: false, @@ -501,6 +523,7 @@ describe("hasServerAcknowledgedLocalDispatch", () => { phase: "ready" as const, latestTurn: null, latestUserMessageId: localDispatch.latestUserMessageId, + latestQueuedMessageId: localDispatch.latestQueuedMessageId, session: null, hasPendingApproval: false, hasPendingUserInput: false, diff --git a/apps/web/src/components/ChatView.logic.ts b/apps/web/src/components/ChatView.logic.ts index 62056a8e8d..d6b35ca462 100644 --- a/apps/web/src/components/ChatView.logic.ts +++ b/apps/web/src/components/ChatView.logic.ts @@ -391,6 +391,7 @@ export interface LocalDispatchSnapshot { startedAt: string; preparingWorktree: boolean; latestUserMessageId: ChatMessage["id"] | null; + latestQueuedMessageId: ChatMessage["id"] | null; latestTurnTurnId: TurnId | null; latestTurnRequestedAt: string | null; latestTurnStartedAt: string | null; @@ -410,6 +411,7 @@ export function createLocalDispatchSnapshot( startedAt: new Date().toISOString(), preparingWorktree: Boolean(options?.preparingWorktree), latestUserMessageId: latestUserMessage?.id ?? null, + latestQueuedMessageId: activeThread?.queuedMessages.at(-1)?.messageId ?? null, latestTurnTurnId: latestTurn?.turnId ?? null, latestTurnRequestedAt: latestTurn?.requestedAt ?? null, latestTurnStartedAt: latestTurn?.startedAt ?? null, @@ -424,6 +426,7 @@ export function hasServerAcknowledgedLocalDispatch(input: { phase: SessionPhase; latestTurn: Thread["latestTurn"] | null; latestUserMessageId: ChatMessage["id"] | null; + latestQueuedMessageId: ChatMessage["id"] | null; session: Thread["session"] | null; hasPendingApproval: boolean; hasPendingUserInput: boolean; @@ -439,7 +442,8 @@ export function hasServerAcknowledgedLocalDispatch(input: { const latestTurn = input.latestTurn ?? null; const session = input.session ?? null; const latestUserMessageChanged = - input.localDispatch.latestUserMessageId !== input.latestUserMessageId; + input.localDispatch.latestUserMessageId !== input.latestUserMessageId || + input.localDispatch.latestQueuedMessageId !== input.latestQueuedMessageId; const latestTurnChanged = input.localDispatch.latestTurnTurnId !== (latestTurn?.turnId ?? null) || input.localDispatch.latestTurnRequestedAt !== (latestTurn?.requestedAt ?? null) || @@ -447,10 +451,11 @@ export function hasServerAcknowledgedLocalDispatch(input: { input.localDispatch.latestTurnCompletedAt !== (latestTurn?.completedAt ?? null); if (input.phase === "running") { - // Steering adds a user message to the current running turn without - // necessarily changing any of the turn timestamps. Treat that projected - // message as the server acknowledgment so the composer does not remain - // stuck in its local "Sending" state until the turn settles. + // A send during a running turn lands as either a steered user message or + // a queued message, without necessarily changing any turn timestamps. + // Treat either projection as the server acknowledgment so the composer + // does not remain stuck in its local "Sending" state until the turn + // settles. if (latestUserMessageChanged) { return true; } diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index 68cb4f4f6c..a6566f5a0c 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -457,6 +457,7 @@ function useLocalDispatchState(input: { const [localDispatch, setLocalDispatch] = useState(null); const latestUserMessageId = input.activeThread?.messages.findLast((message) => message.role === "user")?.id ?? null; + const latestQueuedMessageId = input.activeThread?.queuedMessages.at(-1)?.messageId ?? null; const resetLocalDispatch = useCallback(() => { setLocalDispatch(null); @@ -469,6 +470,7 @@ function useLocalDispatchState(input: { phase: input.phase, latestTurn: input.activeLatestTurn, latestUserMessageId, + latestQueuedMessageId, session: input.activeThread?.session ?? null, hasPendingApproval: input.activePendingApproval !== null, hasPendingUserInput: input.activePendingUserInput !== null, @@ -482,6 +484,7 @@ function useLocalDispatchState(input: { input.phase, input.threadError, latestUserMessageId, + latestQueuedMessageId, localDispatch, ], );