Skip to content

Commit e381e70

Browse files
committed
fix: keep delegated approvals reachable and honor Claude mode fallback
1 parent e480bdf commit e381e70

4 files changed

Lines changed: 58 additions & 16 deletions

File tree

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

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { AuthOrchestrationOperateScope, type ScopedThreadRef } from "@t3tools/co
33
import type { ChildThreadApproval } from "@t3tools/client-runtime/state/thread-requests";
44
import { useState } from "react";
55
import { useEnvironmentScope } from "../../state/session";
6-
import { View } from "react-native";
6+
import { ScrollView, View } from "react-native";
7+
import Animated, { useAnimatedStyle, type DerivedValue } from "react-native-reanimated";
78
import { AppText } from "../../components/ui/AppText";
89
import { childThreadApprovalsAtom, threadEnvironment } from "../../state/threads";
910
import { useAtomCommand } from "../../state/use-atom-command";
@@ -37,20 +38,30 @@ function ChildApproval({ entry }: { entry: ChildThreadApproval }) {
3738
);
3839
}
3940

40-
export function ChildThreadApprovals({ threadRef }: { threadRef: ScopedThreadRef | null }) {
41+
export function ChildThreadApprovals({
42+
threadRef,
43+
maxHeight,
44+
}: {
45+
threadRef: ScopedThreadRef | null;
46+
maxHeight: DerivedValue<number>;
47+
}) {
4148
const approvals = useAtomValue(childThreadApprovalsAtom(threadRef));
49+
const heightStyle = useAnimatedStyle(() => ({ maxHeight: Math.min(320, maxHeight.value / 2) }));
50+
if (approvals.length === 0) return null;
4251
return (
43-
<>
44-
{approvals.map((entry) => (
45-
<ChildApproval
46-
key={JSON.stringify([
47-
entry.thread.environmentId,
48-
entry.thread.threadId,
49-
entry.approval.requestId,
50-
])}
51-
entry={entry}
52-
/>
53-
))}
54-
</>
52+
<Animated.View style={heightStyle} className="overflow-hidden">
53+
<ScrollView keyboardShouldPersistTaps="handled" nestedScrollEnabled style={{ flexShrink: 1 }}>
54+
{approvals.map((entry) => (
55+
<ChildApproval
56+
key={JSON.stringify([
57+
entry.thread.environmentId,
58+
entry.thread.threadId,
59+
entry.approval.requestId,
60+
])}
61+
entry={entry}
62+
/>
63+
))}
64+
</ScrollView>
65+
</Animated.View>
5566
);
5667
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1529,7 +1529,10 @@ function ThreadDetailBody(props: ThreadDetailScreenProps) {
15291529
key={`chatgpt-limit:${props.selectedThread.latestRun?.runId}`}
15301530
thread={props.selectedThread}
15311531
/>
1532-
<ChildThreadApprovals threadRef={props.selectedThreadDetailRef} />
1532+
<ChildThreadApprovals
1533+
threadRef={props.selectedThreadDetailRef}
1534+
maxHeight={pendingUserInputMaxHeight}
1535+
/>
15331536
<ThreadGuestShareBar
15341537
threadRef={props.selectedThreadDetailRef}
15351538
canOperateThread={props.canOperateThread}

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3945,6 +3945,32 @@ describe("ClaudeAdapterV2 background wake turns", () => {
39453945
assert.equal((yield* Fiber.join(forwardedDecision))?.behavior, "deny");
39463946
yield* harness.offerAndWait(frame);
39473947
}
3948+
const fallbackDecision = yield* Effect.promise(() =>
3949+
harness.getOpenedOptions()!.canUseTool!(
3950+
"Bash",
3951+
{ command: "echo checked" },
3952+
{
3953+
signal: new AbortController().signal,
3954+
toolUseID: "safety-check-after-downgrade",
3955+
requestId: "request-safety-check-after-downgrade",
3956+
decisionReason:
3957+
"Dangerous rm operation not ruled out — the shell may read this command differently than it was parsed",
3958+
},
3959+
),
3960+
).pipe(Effect.forkScoped);
3961+
const fallbackFirst = yield* Effect.raceFirst(
3962+
Queue.take(harness.runtimeRequestReceipts).pipe(
3963+
Effect.map((event) => ({ type: "request", event }) as const),
3964+
),
3965+
Fiber.join(fallbackDecision).pipe(Effect.map(() => ({ type: "decision" }) as const)),
3966+
);
3967+
assert.equal(fallbackFirst.type, "request");
3968+
if (fallbackFirst.type !== "request") return;
3969+
yield* harness.runtime.respondToRuntimeRequest({
3970+
requestId: fallbackFirst.event.runtimeRequest.id,
3971+
decision: "decline",
3972+
});
3973+
assert.equal((yield* Fiber.join(fallbackDecision))?.behavior, "deny");
39483974
yield* finish;
39493975
const unrestrictedOptions = harness.getOpenedOptions();
39503976
yield* start("/unrestricted");

‎apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9763,13 +9763,15 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
97639763
} satisfies PermissionResult;
97649764
}
97659765

9766+
const activePermissionMode =
9767+
(yield* Ref.get(queryContext))?.permissionMode ?? context.queryPolicy.permissionMode;
97669768
const safetyReason = NodeUtil.stripVTControlCharacters(
97679769
callbackOptions.decisionReason ?? "",
97689770
).trim();
97699771
// The SDK omits the CLI's dangerousRemoval discriminator, so match its removal warnings.
97709772
if (
97719773
toolName === "Bash" &&
9772-
context.queryPolicy.permissionMode === "bypassPermissions" &&
9774+
activePermissionMode === "bypassPermissions" &&
97739775
callbackOptions.matchedAskRule === undefined &&
97749776
(/^Dangerous rm(?:dir)?\b/i.test(safetyReason) ||
97759777
safetyReason === "This shell -c script runs rm and could not be checked" ||

0 commit comments

Comments
 (0)