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 <[email protected]>
This commit is contained in:
Theo BrowneandClaude Fable 5 committed 2026-07-22 14:15:56 -07:00
1 parent ac8f559445
commit bae3c9470f
5 files changed
+36 -33

No files matched your search

@@ -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;
@@ -47,10 +47,6 @@ export interface ProjectionQueuedMessageRepositoryShape {
readonly listByThreadId: (
input: ListProjectionQueuedMessagesInput,
) => Effect.Effect<ReadonlyArray<ProjectionQueuedMessage>, ProjectionRepositoryError>;
readonly listAll: () => Effect.Effect<
ReadonlyArray<ProjectionQueuedMessage>,
ProjectionRepositoryError
>;
readonly deleteByMessageId: (
input: DeleteProjectionQueuedMessageInput,
) => Effect.Effect<void, ProjectionRepositoryError>;
@@ -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,
+10 -5
View File
@@ -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;
}
+3
View File
@@ -457,6 +457,7 @@ function useLocalDispatchState(input: {
const [localDispatch, setLocalDispatch] = useState<LocalDispatchSnapshot | null>(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,
],
);