Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions apps/mobile/src/features/threads/PendingUserInputCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ export interface PendingUserInputCardProps {
customAnswer: string,
) => void;
readonly onSubmit: () => Promise<unknown>;
/** Closes an async question without a reply. Hidden for native callback questions. */
readonly onDismiss: () => Promise<unknown>;
}

/**
Expand Down Expand Up @@ -338,6 +340,18 @@ export function PendingUserInputCard(props: PendingUserInputCardProps) {
Submit answers
</Text>
</Pressable>
{props.pendingUserInput.dismissible ? (
<Pressable
accessibilityRole="button"
className="items-center justify-center rounded-2xl px-4 py-2.5 active:opacity-70"
disabled={props.respondingUserInputId === props.pendingUserInput.requestId}
onPress={() => void props.onDismiss()}
>
<Text className="font-t3-bold text-sm text-foreground-muted">
Dismiss without answering
</Text>
</Pressable>
) : null}
</Animated.View>
) : null;
return (
Expand Down
2 changes: 2 additions & 0 deletions apps/mobile/src/features/threads/ThreadDetailScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export interface ThreadDetailScreenProps {
customAnswer: string,
) => void;
readonly onSubmitUserInput: () => Promise<unknown>;
readonly onDismissUserInput: () => Promise<unknown>;
readonly showContent?: boolean;
}

Expand Down Expand Up @@ -909,6 +910,7 @@ export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: Thread
onSelectOption={props.onSelectUserInputOption}
onChangeCustomAnswer={props.onChangeUserInputCustomAnswer}
onSubmit={props.onSubmitUserInput}
onDismiss={props.onDismissUserInput}
/>
) : null}
</Animated.View>
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/src/features/threads/ThreadRouteScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,7 @@ function ThreadRouteContent(
onSelectUserInputOption={requests.onSelectUserInputOption}
onChangeUserInputCustomAnswer={requests.onChangeUserInputCustomAnswer}
onSubmitUserInput={requests.onSubmitUserInput}
onDismissUserInput={requests.onDismissUserInput}
/>
</View>
</>
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/src/lib/threadActivity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ describe("pending user input answers", () => {
{
requestId: "interaction_1",
createdAt: requested.createdAt,
dismissible: false,
questions: [nativeQuestion, singleSelectQuestion],
},
]);
Expand Down
25 changes: 25 additions & 0 deletions apps/mobile/src/state/use-selected-thread-requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ export function useSelectedThreadRequests() {
threadEnvironment.respondToUserInput,
"thread user input response",
);
const dismissUserInput = useAtomCommand(
threadEnvironment.dismissUserInput,
"thread user input dismissal",
);
const { selectedThread: selectedThreadShell } = useThreadSelection();
const selectedThread = useSelectedThreadDetail();
const userInputDraftsByRequestKey = useAtomValue(userInputDraftsByRequestKeyAtom);
Expand Down Expand Up @@ -170,6 +174,26 @@ export function useSelectedThreadRequests() {
selectedThreadShell,
]);

// Closes an async question without messaging the agent.
const onDismissUserInput = useCallback(async () => {
if (!selectedThreadShell || !activePendingUserInput) {
return;
}

setRespondingUserInputId(activePendingUserInput.requestId);
const result = await dismissUserInput({
environmentId: selectedThreadShell.environmentId,
input: {
threadId: selectedThreadShell.id,
requestId: activePendingUserInput.requestId,
},
});
setRespondingUserInputId((current) =>
current === activePendingUserInput.requestId ? null : current,
);
return result;
}, [activePendingUserInput, dismissUserInput, selectedThreadShell]);

return {
activePendingApproval,
activePendingUserInput,
Expand All @@ -181,5 +205,6 @@ export function useSelectedThreadRequests() {
onSelectUserInputOption,
onChangeUserInputCustomAnswer,
onSubmitUserInput,
onDismissUserInput,
};
}
3 changes: 2 additions & 1 deletion apps/server/src/orchestration/Layers/OrchestrationEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ const makeOrchestrationEngine = Effect.gen(function* () {
// Command snapshots omit activities at startup and cap them while running.
// Read this request's durable state before deciding how to send the answer.
const userInputActivity =
envelope.command.type === "thread.user-input.respond"
envelope.command.type === "thread.user-input.respond" ||
envelope.command.type === "thread.user-input.dismiss"
? yield* projectionSnapshotQuery.getUserInputActivity(envelope.command)
: Option.none();
const eventBase = yield* decideOrchestrationCommand({
Expand Down
45 changes: 45 additions & 0 deletions apps/server/src/orchestration/decider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1289,6 +1289,51 @@ export const decideOrchestrationCommand = Effect.fn("decideOrchestrationCommand"
};
}

case "thread.user-input.dismiss": {
yield* requireThread({
readModel,
command,
threadId: command.threadId,
});
const request = userInputActivity;
if (request === undefined || request.kind !== "user-input.requested") {
return yield* new OrchestrationCommandInvariantError({
commandType: command.type,
detail: "This question has already been answered.",
});
}
// Only async questions can be dropped silently. A native callback
// question leaves the provider blocked until it gets a reply, so it
// still needs an answer or an interrupted turn.
if (!Predicate.isObject(request.payload) || request.payload.responseMode !== "message") {
return yield* new OrchestrationCommandInvariantError({
commandType: command.type,
detail: "This question needs an answer. Answer it or stop the turn.",
});
}
return {
...(yield* withEventBase({
aggregateKind: "thread",
aggregateId: command.threadId,
occurredAt: command.createdAt,
commandId: command.commandId,
})),
type: "thread.activity-appended",
payload: {
threadId: command.threadId,
activity: {
id: EventId.make(`async-dismiss:${command.requestId}`),
kind: "user-input.resolved",
summary: "User input dismissed",
tone: "info",
turnId: request.turnId,
createdAt: command.createdAt,
payload: { requestId: command.requestId, responseMode: "message" },
},
},
};
}

case "thread.checkpoint.revert": {
yield* requireThread({
readModel,
Expand Down
142 changes: 142 additions & 0 deletions apps/server/src/orchestration/decider.userInputDismiss.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import {
CommandId,
EventId,
ProjectId,
ProviderInstanceId,
ThreadId,
ApprovalRequestId,
type OrchestrationReadModel,
type OrchestrationThreadActivity,
} from "@t3tools/contracts";
import * as NodeServices from "@effect/platform-node/NodeServices";
import { expect, it } from "@effect/vitest";
import * as Effect from "effect/Effect";

import { decideOrchestrationCommand } from "./decider.ts";
import { projectEvent } from "./projector.ts";

const NOW = "2026-01-01T00:00:00.000Z";
const threadId = ThreadId.make("thread-1");
const requestId = ApprovalRequestId.make("question-1");

function makeRequest(responseMode: "message" | undefined): OrchestrationThreadActivity {
return {
id: EventId.make(requestId),
kind: "user-input.requested",
summary: "Question",
tone: "approval",
turnId: null,
createdAt: NOW,
payload: {
requestId,
...(responseMode === undefined ? {} : { responseMode }),
questions: [{ id: "0", header: "Q", question: "Continue?", options: [] }],
},
};
}

function makeReadModel(
activities: ReadonlyArray<OrchestrationThreadActivity>,
): OrchestrationReadModel {
return {
snapshotSequence: 0,
projects: [],
threads: [
{
id: threadId,
projectId: ProjectId.make("project-1"),
title: "Thread",
modelSelection: { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.4" },
runtimeMode: "full-access",
interactionMode: "default",
branch: null,
worktreePath: null,
latestTurn: null,
createdAt: NOW,
updatedAt: NOW,
archivedAt: null,
settledOverride: null,
settledAt: null,
snoozedUntil: null,
snoozedAt: null,
pinnedAt: null,
deletedAt: null,
messages: [],
proposedPlans: [],
activities: [...activities],
checkpoints: [],
session: null,
},
],
updatedAt: NOW,
};
}

const command = {
type: "thread.user-input.dismiss" as const,
commandId: CommandId.make("dismiss-1"),
threadId,
requestId,
createdAt: NOW,
};

it.layer(NodeServices.layer)("user input dismiss decider", (it) => {
it.effect("closes an async question without sending a message or starting a turn", () =>
Effect.gen(function* () {
const request = makeRequest("message");
const readModel = makeReadModel([request]);
const result = yield* decideOrchestrationCommand({
command,
readModel,
userInputActivity: request,
});
const events = Array.isArray(result) ? result : [result];
expect(events.map((event) => event.type)).toEqual(["thread.activity-appended"]);
expect(events[0]?.payload).toMatchObject({
threadId,
activity: {
kind: "user-input.resolved",
summary: "User input dismissed",
payload: { requestId, responseMode: "message" },
},
});
const projected = yield* projectEvent(readModel, { ...events[0]!, sequence: 1 });
expect(projected.threads[0]?.messages).toEqual([]);
expect(projected.threads[0]?.latestTurn).toBeNull();
}),
);

it.effect("rejects dismissing a native callback question", () =>
Effect.gen(function* () {
const request = makeRequest(undefined);
const result = yield* decideOrchestrationCommand({
command,
readModel: makeReadModel([request]),
userInputActivity: request,
}).pipe(Effect.flip);
expect(result).toMatchObject({
_tag: "OrchestrationCommandInvariantError",
detail: "This question needs an answer. Answer it or stop the turn.",
});
}),
);

it.effect("rejects dismissing a question that was already resolved", () =>
Effect.gen(function* () {
const resolved: OrchestrationThreadActivity = {
...makeRequest("message"),
id: EventId.make("resolved"),
kind: "user-input.resolved",
};
const result = yield* decideOrchestrationCommand({
command,
readModel: makeReadModel([makeRequest("message"), resolved]),
userInputActivity: resolved,
}).pipe(Effect.flip);
expect(result).toMatchObject({
_tag: "OrchestrationCommandInvariantError",
detail: "This question has already been answered.",
});
}),
);
});
30 changes: 30 additions & 0 deletions apps/web/src/components/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,9 @@ export default function ChatView(props: ChatViewProps) {
const respondToThreadUserInput = useAtomCommand(threadEnvironment.respondToUserInput, {
reportFailure: false,
});
const dismissThreadUserInput = useAtomCommand(threadEnvironment.dismissUserInput, {
reportFailure: false,
});
const revertThreadCheckpoint = useAtomCommand(threadEnvironment.revertCheckpoint, {
reportFailure: false,
});
Expand Down Expand Up @@ -6960,6 +6963,32 @@ export default function ChatView(props: ChatViewProps) {
[activeThreadId, environmentId, respondToThreadUserInput, setThreadError],
);

// Closes an async question without messaging the agent. The server records
// the dismissal so every client releases the composer.
const onDismissUserInput = useCallback(
async (requestId: ApprovalRequestId) => {
if (!activeThreadId) return;

setRespondingUserInputRequestIds((existing) =>
existing.includes(requestId) ? existing : [...existing, requestId],
);
const result = await dismissThreadUserInput({
environmentId,
input: { threadId: activeThreadId, requestId },
});
if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
const error = squashAtomCommandFailure(result);
setThreadError(
activeThreadId,
error instanceof Error ? error.message : "Failed to dismiss the question.",
);
}
setRespondingUserInputRequestIds((existing) => existing.filter((id) => id !== requestId));
return result;
},
[activeThreadId, dismissThreadUserInput, environmentId, setThreadError],
);

const setActivePendingUserInputQuestionIndex = useCallback(
(nextQuestionIndex: number) => {
if (!activePendingUserInput) {
Expand Down Expand Up @@ -8055,6 +8084,7 @@ export default function ChatView(props: ChatViewProps) {
onSelectActivePendingUserInputOption
}
onAdvanceActivePendingUserInput={onAdvanceActivePendingUserInput}
onDismissActivePendingUserInput={onDismissUserInput}
onPreviousActivePendingUserInputQuestion={
onPreviousActivePendingUserInputQuestion
}
Expand Down
4 changes: 4 additions & 0 deletions apps/web/src/components/chat/ChatComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1284,6 +1284,7 @@ export interface ChatComposerProps {
) => Promise<unknown>;
onSelectActivePendingUserInputOption: (questionId: string, optionValue: string) => void;
onAdvanceActivePendingUserInput: () => void;
onDismissActivePendingUserInput: (requestId: ApprovalRequestId) => void;
onPreviousActivePendingUserInputQuestion: () => void;
onChangeActivePendingUserInputCustomAnswer: (
questionId: string,
Expand Down Expand Up @@ -1384,6 +1385,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
onRespondToApproval,
onSelectActivePendingUserInputOption,
onAdvanceActivePendingUserInput,
onDismissActivePendingUserInput,
onPreviousActivePendingUserInputQuestion,
onChangeActivePendingUserInputCustomAnswer,
onProviderModelSelect,
Expand Down Expand Up @@ -4911,6 +4913,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
questionIndex={activePendingQuestionIndex}
onToggleOption={onSelectActivePendingUserInputOption}
onAdvance={onAdvanceActivePendingUserInput}
onDismiss={onDismissActivePendingUserInput}
/>
) : !isComposerCollapsedMobile && showPlanFollowUpPrompt && activeProposedPlan ? (
<ComposerPlanFollowUpBanner
Expand All @@ -4926,6 +4929,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
questionIndex={activePendingQuestionIndex}
onToggleOption={onSelectActivePendingUserInputOption}
onAdvance={onAdvanceActivePendingUserInput}
onDismiss={onDismissActivePendingUserInput}
/>
{!isChoiceOnlyPendingQuestion ||
activePendingProgress?.activeQuestion?.multiSelect ? (
Expand Down
Loading
Loading