@devries-cameron20 / t3code Mirror · read-only / commits / d8b12ae801
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 24, 20:15 UTC

Fix sending messages during active turns (#3919)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Jake Leventhal committed Jul 18, 2026 at 07:19 UTC d8b12ae801f2123e9be73d2f4139f8994e4d1d19
3 files changed +73 -1
apps/web/src/components/ChatView.logic.test.ts
+56 -1
@@ -1,4 +1,11 @@
1 -import { EnvironmentId, ProjectId, ProviderInstanceId, ThreadId, TurnId } from "@t3tools/contracts";
1 +import {
2 + EnvironmentId,
3 + MessageId,
4 + ProjectId,
5 + ProviderInstanceId,
6 + ThreadId,
7 + TurnId,
8 +} from "@t3tools/contracts";
9 import { describe, expect, it } from "vite-plus/test";
10
11 import type { Thread } from "../types";
@@ -359,6 +366,7 @@ describe("hasServerAcknowledgedLocalDispatch", () => {
366 localDispatch,
367 phase: "ready",
368 latestTurn: completedTurn,
369 + latestUserMessageId: localDispatch.latestUserMessageId,
370 session: readySession,
371 hasPendingApproval: false,
372 hasPendingUserInput: false,
@@ -384,6 +392,7 @@ describe("hasServerAcknowledgedLocalDispatch", () => {
392 localDispatch,
393 phase: "ready",
394 latestTurn: newerTurn,
395 + latestUserMessageId: localDispatch.latestUserMessageId,
396 session: { ...readySession, updatedAt: newerTurn.completedAt },
397 hasPendingApproval: false,
398 hasPendingUserInput: false,
@@ -410,6 +419,7 @@ describe("hasServerAcknowledgedLocalDispatch", () => {
419 localDispatch,
420 phase: "running",
421 latestTurn: runningTurn,
422 + latestUserMessageId: localDispatch.latestUserMessageId,
423 session: {
424 ...readySession,
425 status: "running",
@@ -425,6 +435,7 @@ describe("hasServerAcknowledgedLocalDispatch", () => {
435 localDispatch,
436 phase: "running",
437 latestTurn: runningTurn,
438 + latestUserMessageId: localDispatch.latestUserMessageId,
439 session: {
440 ...readySession,
441 status: "running",
@@ -437,12 +448,56 @@ describe("hasServerAcknowledgedLocalDispatch", () => {
448 ).toBe(true);
449 });
450
451 + it("acknowledges a steering message projected onto the current running turn", () => {
452 + const runningTurn = {
453 + ...completedTurn,
454 + state: "running" as const,
455 + completedAt: null,
456 + };
457 + const runningSession = {
458 + ...readySession,
459 + status: "running" as const,
460 + activeTurnId: runningTurn.turnId,
461 + };
462 + const localDispatch = createLocalDispatchSnapshot(
463 + makeThread({
464 + latestTurn: runningTurn,
465 + session: runningSession,
466 + messages: [
467 + {
468 + id: MessageId.make("message-before-steer"),
469 + role: "user",
470 + text: "Initial prompt",
471 + turnId: runningTurn.turnId,
472 + createdAt: runningTurn.requestedAt,
473 + updatedAt: runningTurn.requestedAt,
474 + streaming: false,
475 + },
476 + ],
477 + }),
478 + );
479 +
480 + expect(
481 + hasServerAcknowledgedLocalDispatch({
482 + localDispatch,
483 + phase: "running",
484 + latestTurn: runningTurn,
485 + latestUserMessageId: MessageId.make("message-steer"),
486 + session: runningSession,
487 + hasPendingApproval: false,
488 + hasPendingUserInput: false,
489 + threadError: null,
490 + }),
491 + ).toBe(true);
492 + });
493 +
494 it("acknowledges pending user interaction and errors immediately", () => {
495 const localDispatch = createLocalDispatchSnapshot(makeThread());
496 const common = {
497 localDispatch,
498 phase: "ready" as const,
499 latestTurn: null,
500 + latestUserMessageId: localDispatch.latestUserMessageId,
501 session: null,
502 hasPendingApproval: false,
503 hasPendingUserInput: false,
apps/web/src/components/ChatView.logic.ts
+13
@@ -387,6 +387,7 @@ export async function waitForStartedServerThread(
387 export interface LocalDispatchSnapshot {
388 startedAt: string;
389 preparingWorktree: boolean;
390 + latestUserMessageId: ChatMessage["id"] | null;
391 latestTurnTurnId: TurnId | null;
392 latestTurnRequestedAt: string | null;
393 latestTurnStartedAt: string | null;
@@ -401,9 +402,11 @@ export function createLocalDispatchSnapshot(
402 ): LocalDispatchSnapshot {
403 const latestTurn = activeThread?.latestTurn ?? null;
404 const session = activeThread?.session ?? null;
405 + const latestUserMessage = activeThread?.messages.findLast((message) => message.role === "user");
406 return {
407 startedAt: new Date().toISOString(),
408 preparingWorktree: Boolean(options?.preparingWorktree),
409 + latestUserMessageId: latestUserMessage?.id ?? null,
410 latestTurnTurnId: latestTurn?.turnId ?? null,
411 latestTurnRequestedAt: latestTurn?.requestedAt ?? null,
412 latestTurnStartedAt: latestTurn?.startedAt ?? null,
@@ -417,6 +420,7 @@ export function hasServerAcknowledgedLocalDispatch(input: {
420 localDispatch: LocalDispatchSnapshot | null;
421 phase: SessionPhase;
422 latestTurn: Thread["latestTurn"] | null;
423 + latestUserMessageId: ChatMessage["id"] | null;
424 session: Thread["session"] | null;
425 hasPendingApproval: boolean;
426 hasPendingUserInput: boolean;
@@ -431,6 +435,8 @@ export function hasServerAcknowledgedLocalDispatch(input: {
435
436 const latestTurn = input.latestTurn ?? null;
437 const session = input.session ?? null;
438 + const latestUserMessageChanged =
439 + input.localDispatch.latestUserMessageId !== input.latestUserMessageId;
440 const latestTurnChanged =
441 input.localDispatch.latestTurnTurnId !== (latestTurn?.turnId ?? null) ||
442 input.localDispatch.latestTurnRequestedAt !== (latestTurn?.requestedAt ?? null) ||
@@ -438,6 +444,13 @@ export function hasServerAcknowledgedLocalDispatch(input: {
444 input.localDispatch.latestTurnCompletedAt !== (latestTurn?.completedAt ?? null);
445
446 if (input.phase === "running") {
447 + // Steering adds a user message to the current running turn without
448 + // necessarily changing any of the turn timestamps. Treat that projected
449 + // message as the server acknowledgment so the composer does not remain
450 + // stuck in its local "Sending" state until the turn settles.
451 + if (latestUserMessageChanged) {
452 + return true;
453 + }
454 if (!latestTurnChanged) {
455 return false;
456 }
apps/web/src/components/ChatView.tsx
+4
@@ -452,6 +452,8 @@ function useLocalDispatchState(input: {
452 threadError: string | null | undefined;
453 }) {
454 const [localDispatch, setLocalDispatch] = useState<LocalDispatchSnapshot | null>(null);
455 + const latestUserMessageId =
456 + input.activeThread?.messages.findLast((message) => message.role === "user")?.id ?? null;
457
458 const resetLocalDispatch = useCallback(() => {
459 setLocalDispatch(null);
@@ -463,6 +465,7 @@ function useLocalDispatchState(input: {
465 localDispatch,
466 phase: input.phase,
467 latestTurn: input.activeLatestTurn,
468 + latestUserMessageId,
469 session: input.activeThread?.session ?? null,
470 hasPendingApproval: input.activePendingApproval !== null,
471 hasPendingUserInput: input.activePendingUserInput !== null,
@@ -475,6 +478,7 @@ function useLocalDispatchState(input: {
478 input.activeThread?.session,
479 input.phase,
480 input.threadError,
481 + latestUserMessageId,
482 localDispatch,
483 ],
484 );