Skip to content

Commit 5643a3e

Browse files
committed
fix(clients): show child approval errors and bound Android controls
1 parent e381e70 commit 5643a3e

4 files changed

Lines changed: 108 additions & 4 deletions

File tree

‎apps/mobile/src/features/threads/ChildThreadApprovals.tsx‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { useAtomValue } from "@effect/atom-react";
22
import { AuthOrchestrationOperateScope, type ScopedThreadRef } from "@t3tools/contracts";
33
import type { ChildThreadApproval } from "@t3tools/client-runtime/state/thread-requests";
4+
import {
5+
isAtomCommandInterrupted,
6+
squashAtomCommandFailure,
7+
} from "@t3tools/client-runtime/state/runtime";
48
import { useState } from "react";
59
import { useEnvironmentScope } from "../../state/session";
610
import { ScrollView, View } from "react-native";
@@ -12,8 +16,9 @@ import { PendingApprovalCard } from "./PendingApprovalCard";
1216

1317
function ChildApproval({ entry }: { entry: ChildThreadApproval }) {
1418
const canRespond = useEnvironmentScope(entry.thread.environmentId, AuthOrchestrationOperateScope);
15-
const respond = useAtomCommand(threadEnvironment.respondToApproval);
19+
const respond = useAtomCommand(threadEnvironment.respondToApproval, { reportFailure: false });
1620
const [responding, setResponding] = useState(false);
21+
const [error, setError] = useState<string | null>(null);
1722
return (
1823
<View className="mx-3.5 my-2 gap-2">
1924
<AppText className="font-t3-bold text-sm text-foreground">
@@ -26,14 +31,30 @@ function ChildApproval({ entry }: { entry: ChildThreadApproval }) {
2631
onRespond={async (requestId, decision) => {
2732
if (!canRespond || responding) return;
2833
setResponding(true);
34+
setError(null);
2935
const result = await respond({
3036
environmentId: entry.thread.environmentId,
3137
input: { threadId: entry.thread.threadId, requestId, decision },
3238
});
39+
if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
40+
const failure = squashAtomCommandFailure(result);
41+
setError(
42+
failure instanceof Error ? failure.message : "Failed to submit approval decision.",
43+
);
44+
}
3345
setResponding(false);
3446
return result;
3547
}}
3648
/>
49+
{error !== null ? (
50+
<AppText
51+
accessibilityRole="alert"
52+
accessibilityLiveRegion="polite"
53+
className="font-sans text-sm text-danger-foreground"
54+
>
55+
{error}
56+
</AppText>
57+
) : null}
3758
</View>
3859
);
3960
}

‎apps/mobile/src/features/threads/ThreadDetailScreen.tsx‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,8 @@ export interface ThreadDetailScreenProps {
307307
readonly showContent?: boolean;
308308
}
309309

310+
// iOS questions overlay the controls; Android questions stack with child approvals.
311+
const ComposerPanels = Platform.OS === "android" ? Animated.ScrollView : Animated.View;
310312
const USAGE_LIMITS_PANEL_GAP = 12;
311313
const USAGE_LIMITS_PANEL_MIN_HEIGHT = 44;
312314

@@ -961,6 +963,10 @@ function ThreadDetailBody(props: ThreadDetailScreenProps) {
961963
composerOverlapHeight: composerBottomInset,
962964
}),
963965
);
966+
const composerPanelsHeightStyle = useAnimatedStyle(() => ({
967+
maxHeight: pendingUserInputMaxHeight.value,
968+
flexGrow: 0,
969+
}));
964970
// The usage panel stacks with the composer and any approval card, so it gets
965971
// whatever room they leave below the header. Measured only while it is open
966972
// so typing in the composer does not re-render the screen.
@@ -1471,7 +1477,15 @@ function ThreadDetailBody(props: ThreadDetailScreenProps) {
14711477
onLayout={handleComposerOverlayLayout}
14721478
className="w-full"
14731479
>
1474-
<View className="w-full self-center" style={{ maxWidth: contentMaxWidth }}>
1480+
<ComposerPanels
1481+
className="w-full self-center"
1482+
style={[
1483+
{ maxWidth: contentMaxWidth },
1484+
Platform.OS === "android" ? composerPanelsHeightStyle : undefined,
1485+
]}
1486+
keyboardShouldPersistTaps="handled"
1487+
nestedScrollEnabled
1488+
>
14751489
<FloatingWorkingControl
14761490
colorScheme={isDarkMode ? "dark" : "light"}
14771491
status={floatingStatus}
@@ -1633,7 +1647,7 @@ function ThreadDetailBody(props: ThreadDetailScreenProps) {
16331647
) : null}
16341648
</Animated.View>
16351649
) : null}
1636-
</View>
1650+
</ComposerPanels>
16371651

16381652
<View style={composerSlotHidden ? { display: "none" } : undefined}>
16391653
{isProviderSubagent ? (
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import type { ChildThreadApproval } from "@t3tools/client-runtime/state/thread-requests";
2+
import { EnvironmentId, RuntimeRequestId, ThreadId } from "@t3tools/contracts";
3+
import * as Cause from "effect/Cause";
4+
import { AsyncResult, Atom } from "effect/reactivity";
5+
import { expect, it, vi } from "vite-plus/test";
6+
7+
import { render } from "../../../test/render";
8+
9+
const state = vi.hoisted(() => ({ respond: vi.fn(), approvalsAtom: null as unknown }));
10+
11+
vi.mock("../../state/session", () => ({ useEnvironmentScope: () => true }));
12+
vi.mock("../../state/use-atom-command", () => ({ useAtomCommand: () => state.respond }));
13+
vi.mock("../../state/threads", () => ({
14+
childThreadApprovalsAtom: () => state.approvalsAtom,
15+
threadEnvironment: { respondToApproval: {} },
16+
}));
17+
18+
import { ChildThreadApprovals } from "./ChildThreadApprovals";
19+
20+
function setup() {
21+
state.respond.mockReset();
22+
state.respond
23+
.mockResolvedValueOnce(AsyncResult.failure(Cause.fail(new Error("Child environment offline"))))
24+
.mockResolvedValueOnce(AsyncResult.success(undefined));
25+
const thread = {
26+
environmentId: EnvironmentId.make("child-env"),
27+
threadId: ThreadId.make("child"),
28+
};
29+
state.approvalsAtom = Atom.make<ReadonlyArray<ChildThreadApproval>>([
30+
{
31+
thread,
32+
title: "Compile task",
33+
approval: {
34+
requestId: RuntimeRequestId.make("approval"),
35+
requestKind: "command",
36+
detail: "Run compiler",
37+
createdAt: "2026-11-01T00:00:00.000Z",
38+
responseCapability: "live",
39+
},
40+
},
41+
]);
42+
return thread;
43+
}
44+
45+
it("shows a failed decision and clears the error when the user retries", async () => {
46+
const thread = setup();
47+
await using screen = await render(<ChildThreadApprovals threadRef={thread} />);
48+
await screen.getByRole("button", { name: "Approve", exact: true }).click();
49+
await expect.element(screen.getByRole("alert")).toHaveTextContent("Child environment offline");
50+
await screen.getByRole("button", { name: "Approve", exact: true }).click();
51+
await expect.element(screen.getByRole("alert")).not.toBeInTheDocument();
52+
});

‎apps/web/src/components/chat/ChildThreadApprovals.tsx‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import { useAtomValue } from "@effect/atom-react";
22
import { AuthOrchestrationOperateScope, type ScopedThreadRef } from "@t3tools/contracts";
33
import type { ChildThreadApproval } from "@t3tools/client-runtime/state/thread-requests";
44
import { fullAccessOverrideExplanation } from "@t3tools/client-runtime/state/thread-requests";
5+
import {
6+
isAtomCommandInterrupted,
7+
squashAtomCommandFailure,
8+
} from "@t3tools/client-runtime/state/runtime";
59
import { useState } from "react";
610
import { useEnvironmentScope } from "../../state/session";
711
import { childThreadApprovalsAtom, threadEnvironment } from "../../state/threads";
@@ -10,8 +14,9 @@ import { ComposerPendingApprovalActions } from "./ComposerPendingApprovalActions
1014

1115
function ChildApproval({ entry }: { entry: ChildThreadApproval }) {
1216
const canRespond = useEnvironmentScope(entry.thread.environmentId, AuthOrchestrationOperateScope);
13-
const respond = useAtomCommand(threadEnvironment.respondToApproval);
17+
const respond = useAtomCommand(threadEnvironment.respondToApproval, { reportFailure: false });
1418
const [responding, setResponding] = useState(false);
19+
const [error, setError] = useState<string | null>(null);
1520
const { approval } = entry;
1621
return (
1722
<section
@@ -45,15 +50,27 @@ function ChildApproval({ entry }: { entry: ChildThreadApproval }) {
4550
onRespondToApproval={async (requestId, decision) => {
4651
if (!canRespond || responding) return;
4752
setResponding(true);
53+
setError(null);
4854
const result = await respond({
4955
environmentId: entry.thread.environmentId,
5056
input: { threadId: entry.thread.threadId, requestId, decision },
5157
});
58+
if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
59+
const failure = squashAtomCommandFailure(result);
60+
setError(
61+
failure instanceof Error ? failure.message : "Failed to submit approval decision.",
62+
);
63+
}
5264
setResponding(false);
5365
return result;
5466
}}
5567
/>
5668
</div>
69+
{error !== null ? (
70+
<p role="alert" className="mt-2 text-destructive">
71+
{error}
72+
</p>
73+
) : null}
5774
</section>
5875
);
5976
}

0 commit comments

Comments
 (0)