Skip to content
TypeScript

fix(clients): open a delegated child's approval on the environment it runs in (#28592)

Rob Homewood95d4da5a932a
diff --git a/apps/mobile/src/features/threads/ThreadDetailScreen.tsx b/apps/mobile/src/features/threads/ThreadDetailScreen.tsx
index f101bb469d0..0cc08fdb3fe 100644
--- a/apps/mobile/src/features/threads/ThreadDetailScreen.tsx
+++ b/apps/mobile/src/features/threads/ThreadDetailScreen.tsx
@@ -772,7 +772,7 @@ function ThreadDetailBody(
accessibilityLabel: `Open ${childInput.hasPendingApprovals ? "approval" : "question"} from ${childInput.title}`,
onPress: () => {
Keyboard.dismiss();
- openLinkedThread({ environmentId: props.environmentId, threadId: childInput.id });
+ openLinkedThread({ environmentId: childInput.environmentId, threadId: childInput.id });
},
};
}
diff --git a/apps/web/src/components/chat/ThreadActivityBanners.tsx b/apps/web/src/components/chat/ThreadActivityBanners.tsx
index 5342bd09b3c..217d0b6ea92 100644
--- a/apps/web/src/components/chat/ThreadActivityBanners.tsx
+++ b/apps/web/src/components/chat/ThreadActivityBanners.tsx
@@ -1,4 +1,5 @@
import type {
+ EnvironmentId,
OrchestrationV2PendingBackgroundTask,
OrchestrationV2ProviderGoal,
ThreadId,
@@ -34,7 +35,8 @@ import type { ThreadNowItem } from "./ThreadNow";
export function childInputNowItem(input: {
readonly childThreadInputs: ReadonlyArray<EnvironmentThreadShell>;
readonly parentAwaitingUser: boolean;
- readonly onOpenThread: (threadId: ThreadId) => void;
+ // A task delegated to a linked environment lives there, not where the parent runs.
+ readonly onOpenThread: (threadId: ThreadId, environmentId: EnvironmentId) => void;
}): (ThreadNowItem & { readonly waitingLabel: string }) | null {
const { childThreadInputs, onOpenThread } = input;
const first = childThreadInputs[0];
@@ -55,7 +57,7 @@ export function childInputNowItem(input: {
<Fragment key={child.id}>
{index > 0 ? " " : null}
<span className="whitespace-nowrap">
- <InlineButton tone="muted" onClick={() => onOpenThread(child.id)}>
+ <InlineButton tone="muted" onClick={() => onOpenThread(child.id, child.environmentId)}>
{child.title}
</InlineButton>
{index < childThreadInputs.length - 1 ? "," : null}
@@ -63,7 +65,7 @@ export function childInputNowItem(input: {
</Fragment>
)),
actions: (
- <InlineButton onClick={() => onOpenThread(first.id)}>
+ <InlineButton onClick={() => onOpenThread(first.id, first.environmentId)}>
{first.hasPendingApprovals ? "Open approval" : "Open question"}
</InlineButton>
),
diff --git a/apps/web/src/components/chat/useThreadLifecycle.tsx b/apps/web/src/components/chat/useThreadLifecycle.tsx
index 6d71e3f59f0..b9f8a42d289 100644
--- a/apps/web/src/components/chat/useThreadLifecycle.tsx
+++ b/apps/web/src/components/chat/useThreadLifecycle.tsx
@@ -56,6 +56,7 @@ import { useEnvironmentScope } from "~/state/session";
import { threadEnvironment } from "../../state/threads";
import { vcsEnvironment } from "../../state/vcs";
import { useChildThreadInputs, readThreadShell, waitForThreadShell } from "../../state/entities";
+import { serverEnvironment } from "../../state/server";
import { environmentShell } from "../../state/shell";
import { ThreadStatusLine } from "./ThreadStatusLine";
import { formatRelativeTimeLabel } from "../../timestampFormat";
@@ -455,14 +456,20 @@ export function useThreadLifecycle(input: ThreadLifecycleInput) {
};
const handleStopBackgroundWorkStable = useStableCallback(handleStopBackgroundWork);
const openRelatedThreadGenerationRef = useRef(0);
- const onOpenRelatedThread = async (threadId: ThreadId) => {
+ // A task delegated to a linked environment opens there; the default is this thread's own.
+ const onOpenRelatedThread = async (
+ threadId: ThreadId,
+ threadEnvironmentId: EnvironmentId = environmentId,
+ ) => {
const generation = ++openRelatedThreadGenerationRef.current;
- const threadRef = scopeThreadRef(environmentId, threadId);
+ const threadRef = scopeThreadRef(threadEnvironmentId, threadId);
const isEnvironmentLive = () =>
- appAtomRegistry.get(environmentShell.stateValueAtom(environmentId)).status === "live";
+ appAtomRegistry.get(environmentShell.stateValueAtom(threadEnvironmentId)).status === "live";
// The shell can leave idle subagent children out, so absence is not deletion there: the
// route decides from the thread's own detail.
- const shellOmitsChildren = serverConfig?.shellThreadFamilies === true;
+ const shellOmitsChildren =
+ appAtomRegistry.get(serverEnvironment.configValueAtom(threadEnvironmentId))
+ ?.shellThreadFamilies === true;
// A just-launched child can reach this timeline before its shell syncs.
if (!shellOmitsChildren && isEnvironmentLive() && readThreadShell(threadRef) === null) {
const location = router.latestLocation;