Skip to content

Commit ab8e488

Browse files
t3dotggclaude
andauthored
feat(antigravity): runtime 1.4.5 with real turn failures and subagent work (#28629)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent c65f8d5 commit ab8e488

45 files changed

Lines changed: 3650 additions & 142 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import type {
2+
EnvironmentId,
3+
OrchestrationV2GetNativeChildWorkResult,
4+
OrchestrationV2NativeChildWork,
5+
ThreadId,
6+
} from "@t3tools/contracts";
7+
import { ScrollView, View } from "react-native";
8+
import { useSafeAreaInsets } from "react-native-safe-area-context";
9+
10+
import { AppText as Text } from "../../components/ui/AppText";
11+
import { Button } from "../../components/ui/Button";
12+
import { Sheet } from "../../components/ui/Sheet";
13+
import { orchestrationEnvironment } from "../../state/orchestration";
14+
import { useEnvironmentQuery } from "../../state/query";
15+
16+
const stepLabel = (type: string) => {
17+
const words = type.toLowerCase().replaceAll("_", " ");
18+
return words.charAt(0).toUpperCase() + words.slice(1);
19+
};
20+
21+
/** Read-only view of what a provider-native subagent's children did. Mount only while open. */
22+
export function NativeChildWorkSheet(props: {
23+
readonly environmentId: EnvironmentId;
24+
readonly threadId: ThreadId;
25+
readonly onClose: () => void;
26+
}) {
27+
const insets = useSafeAreaInsets();
28+
const query = useEnvironmentQuery<OrchestrationV2GetNativeChildWorkResult, unknown>(
29+
orchestrationEnvironment.nativeChildWork({
30+
environmentId: props.environmentId,
31+
input: { threadId: props.threadId },
32+
}),
33+
);
34+
const children = query.data?.children;
35+
return (
36+
<Sheet title="Subagent work" onClose={props.onClose}>
37+
<ScrollView
38+
contentInsetAdjustmentBehavior="automatic"
39+
contentContainerStyle={{
40+
gap: 16,
41+
paddingHorizontal: 20,
42+
paddingTop: 12,
43+
paddingBottom: Math.max(20, insets.bottom),
44+
}}
45+
>
46+
<Text className="font-sans text-xs text-foreground-secondary">
47+
Read only. These subagents cannot take messages.
48+
</Text>
49+
{query.error !== null ? (
50+
<Text selectable className="font-sans text-sm text-danger-foreground">
51+
{query.error}
52+
</Text>
53+
) : children === undefined ? (
54+
<Text className="font-sans text-sm text-foreground-secondary">Loading…</Text>
55+
) : children.length === 0 ? (
56+
<Text className="font-sans text-sm text-foreground-secondary">
57+
The provider has no record of which subagents this call started.
58+
</Text>
59+
) : (
60+
children.map((child) => <NativeChild key={child.conversationId} child={child} />)
61+
)}
62+
<View className="flex-row justify-end">
63+
<Button
64+
label="Refresh"
65+
tone="secondary"
66+
disabled={query.isPending}
67+
onPress={query.refresh}
68+
/>
69+
</View>
70+
</ScrollView>
71+
</Sheet>
72+
);
73+
}
74+
75+
function NativeChild(props: { readonly child: OrchestrationV2NativeChildWork }) {
76+
const { child } = props;
77+
return (
78+
<View className="gap-2">
79+
<Text className="font-t3-bold text-sm text-foreground">{child.role || "Subagent"}</Text>
80+
<Text selectable className="font-sans text-sm text-foreground-secondary">
81+
{child.prompt}
82+
</Text>
83+
{child.truncated ? (
84+
<Text className="font-sans text-xs text-foreground-secondary">
85+
Earlier steps are not shown.
86+
</Text>
87+
) : null}
88+
{child.steps === null ? (
89+
<Text className="font-sans text-xs text-foreground-secondary">No transcript yet.</Text>
90+
) : (
91+
<View className="gap-2 border-l border-border ps-3">
92+
{child.steps.map((step) => (
93+
<View key={step.index} className="gap-1">
94+
<Text className="font-t3-bold text-xs text-foreground-secondary">
95+
{stepLabel(step.type)}
96+
{step.status !== null && step.status !== "DONE"
97+
? ` · ${stepLabel(step.status)}`
98+
: ""}
99+
</Text>
100+
{step.toolCalls.length === 0 ? null : (
101+
<Text selectable className="font-mono text-xs text-foreground">
102+
{step.toolCalls.map((call) => `${call.name} ${call.input}`).join("\n")}
103+
</Text>
104+
)}
105+
{step.text === null ? null : (
106+
<Text selectable className="font-mono text-xs text-foreground">
107+
{step.text}
108+
</Text>
109+
)}
110+
</View>
111+
))}
112+
</View>
113+
)}
114+
</View>
115+
);
116+
}

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ import {
22
formatProviderSubagentStatus,
33
type ProviderSubagentStatus,
44
} from "@t3tools/client-runtime/state/thread-execution";
5-
import { isOrchestrationV2WorkActive } from "@t3tools/contracts";
5+
import { isOrchestrationV2WorkActive, type EnvironmentId, type ThreadId } from "@t3tools/contracts";
6+
import { useState } from "react";
67
import { View } from "react-native";
78

89
import { AppText as Text } from "../../components/ui/AppText";
910
import { ProviderIcon } from "../../components/ProviderIcon";
1011
import { Button } from "../../components/ui/Button";
12+
import { NativeChildWorkSheet } from "./NativeChildWorkSheet";
1113
import { useVisibleSecondClock } from "./use-visible-second-clock";
1214

1315
export function ProviderSubagentBar(props: {
@@ -16,7 +18,10 @@ export function ProviderSubagentBar(props: {
1618
readonly effortLabel: string | null;
1719
readonly status: ProviderSubagentStatus | null;
1820
readonly onOpenParent: (() => void) | null;
21+
/** Set for providers whose children T3 reads on demand instead of streaming. */
22+
readonly inspect: { readonly environmentId: EnvironmentId; readonly threadId: ThreadId } | null;
1923
}) {
24+
const [inspecting, setInspecting] = useState(false);
2025
const live = props.status !== null && isOrchestrationV2WorkActive(props.status.status);
2126
const nowMs = useVisibleSecondClock(live);
2227
const statusLabel = formatProviderSubagentStatus(props.status, nowMs);
@@ -59,9 +64,15 @@ export function ProviderSubagentBar(props: {
5964
{statusLabel} · Runs on its own
6065
</Text>
6166
</View>
67+
{props.inspect ? (
68+
<Button label="Work" tone="secondary" onPress={() => setInspecting(true)} />
69+
) : null}
6270
{props.onOpenParent ? (
6371
<Button label="Open parent" tone="secondary" onPress={props.onOpenParent} />
6472
) : null}
73+
{props.inspect && inspecting ? (
74+
<NativeChildWorkSheet {...props.inspect} onClose={() => setInspecting(false)} />
75+
) : null}
6576
</View>
6677
);
6778
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,6 +1722,14 @@ function ThreadDetailBody(
17221722
reportedModelSelection,
17231723
)}
17241724
status={props.providerSubagentStatus ?? null}
1725+
inspect={
1726+
providerSubagentProvider?.driver === "antigravity"
1727+
? {
1728+
environmentId: props.environmentId,
1729+
threadId: props.selectedThread.id,
1730+
}
1731+
: null
1732+
}
17251733
onOpenParent={
17261734
props.selectedThread.lineage.parentThreadId === null
17271735
? null

‎apps/server/scripts/acp-mock-agent.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ const program = Effect.gen(function* () {
512512
parameterizedModelPicker = request.capabilities?._meta?.parameterizedModelPicker === true;
513513
return {
514514
protocolVersion: 2,
515-
info: { name: "t3-acp-mock-agent", version: "0.0.0" },
515+
info: { name: "t3-acp-mock-agent", version: process.env.T3_ACP_AGENT_VERSION ?? "0.0.0" },
516516
...(omitInitializeModelState ? {} : { _meta: { modelState: modelState() } }),
517517
capabilities: {
518518
session: {

‎apps/server/src/auth/RpcAuthorization.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export const RPC_REQUIRED_SCOPES = {
4141
...CLIENT_GUARDED_RPC_SCOPES,
4242
[ORCHESTRATION_V2_WS_METHODS.dispatchCommand]: AuthOrchestrationOperateScope,
4343
[ORCHESTRATION_V2_WS_METHODS.getWorkflowScript]: AuthOrchestrationReadScope,
44+
[ORCHESTRATION_V2_WS_METHODS.getNativeChildWork]: AuthOrchestrationReadScope,
4445
[ORCHESTRATION_V2_WS_METHODS.stopWorkflow]: AuthOrchestrationOperateScope,
4546
[ORCHESTRATION_V2_WS_METHODS.forceStopThread]: AuthOrchestrationOperateScope,
4647
[ORCHESTRATION_V2_WS_METHODS.getTurnDiff]: AuthOrchestrationReadScope,

‎apps/server/src/observability/RpcInstrumentation.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type WsRpcMethod = RpcGroup.Rpcs<typeof WsRpcGroup>["_tag"];
1313
const RPC_AGGREGATES = {
1414
[ORCHESTRATION_V2_WS_METHODS.dispatchCommand]: "orchestrationV2",
1515
[ORCHESTRATION_V2_WS_METHODS.getWorkflowScript]: "orchestration",
16+
[ORCHESTRATION_V2_WS_METHODS.getNativeChildWork]: "orchestration",
1617
[ORCHESTRATION_V2_WS_METHODS.stopWorkflow]: "orchestration",
1718
[ORCHESTRATION_V2_WS_METHODS.forceStopThread]: "orchestration",
1819
[ORCHESTRATION_V2_WS_METHODS.getTurnItem]: "orchestration",

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

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ import {
8282
acpPostSettleContinuationOfferEvidence,
8383
acpPostSettleWakeEvidence,
8484
acpToolCallDiffPatch,
85+
acpToolCallSnippetEdit,
8586
makeAcpAdapterV2,
8687
type AcpAdapterV2ExtensionContext,
8788
type AcpAdapterV2Flavor,
@@ -138,6 +139,32 @@ describe("acpPerTurnPromptUsage", () => {
138139
reasoningTokens: 3,
139140
},
140141
);
142+
// Antigravity 1.4.5: its harness reports prompt tokens without the 24 cached ones.
143+
assert.deepEqual(
144+
acpPerTurnPromptUsage(
145+
{
146+
inputTokens: 42,
147+
outputTokens: 3,
148+
totalTokens: 54,
149+
cachedReadTokens: 24,
150+
cachedWriteTokens: 0,
151+
thoughtTokens: 9,
152+
},
153+
false,
154+
"completed",
155+
true,
156+
),
157+
{
158+
usageScope: "main_agent",
159+
usageStatus: "complete",
160+
hasSubagents: false,
161+
inputTokens: 66,
162+
outputTokens: 12,
163+
cachedInputTokens: 24,
164+
cacheCreationTokens: 0,
165+
reasoningTokens: 9,
166+
},
167+
);
141168
});
142169

143170
it("clamps subsets that exceed their parents and drops unset counters", () => {
@@ -231,6 +258,45 @@ describe("acpPerTurnPromptUsage", () => {
231258
});
232259

233260
describe("acpToolCallDiffPatch", () => {
261+
it("keeps an unplaced snippet as recorded text instead of numbering it from line 1", () => {
262+
const content = [
263+
{
264+
type: "diff",
265+
path: "/repo/a.ts",
266+
oldText: "const target = 10;",
267+
newText: "const target = 100;",
268+
patch: { format: "snippet", text: "@@ -1,1 +1,1 @@ snippet, line unknown\n" },
269+
},
270+
];
271+
assert.isUndefined(acpToolCallDiffPatch(content));
272+
// An omitted preview is not re-diffed from the bare snippets either.
273+
assert.isUndefined(acpToolCallDiffPatch([{ ...content[0], patch: { format: "omitted" } }]));
274+
// A status block beside the snippet must not hide it.
275+
for (const blocks of [
276+
content,
277+
[{ type: "content", content: { type: "text", text: "Edited." } }, ...content],
278+
]) {
279+
assert.isUndefined(acpToolCallDiffPatch(blocks));
280+
assert.deepEqual(acpToolCallSnippetEdit(blocks), {
281+
oldStr: "const target = 10;",
282+
newStr: "const target = 100;",
283+
});
284+
}
285+
// Beside another diff, the snippet is neither a patch nor a placed edit.
286+
const twoDiffs = [
287+
...content,
288+
{
289+
type: "diff",
290+
path: "/repo/b.ts",
291+
oldText: "b\n",
292+
newText: "B\n",
293+
patch: { text: "@@ -1 +1 @@\n-b\n+B\n" },
294+
},
295+
];
296+
assert.isUndefined(acpToolCallDiffPatch(twoDiffs));
297+
assert.isUndefined(acpToolCallSnippetEdit(twoDiffs));
298+
});
299+
234300
it("builds per-file patches from ACP hunks and recorded old/new text", () => {
235301
for (const operation of ["add", "delete"]) {
236302
const text = operation === "add" ? "@@ -0,0 +1 @@\n+content\n" : "@@ -1 +0,0 @@\n-content\n";
@@ -661,6 +727,97 @@ describe("AcpAdapterV2", () => {
661727
assert.equal(promptOrdinal, 2, "continuation turn must not dispatch session/prompt");
662728
}).pipe(Effect.provide(layerTest), Effect.scoped),
663729
);
730+
it.live("fails an end_turn the outcome check rejects and restarts before the next turn", () =>
731+
Effect.gen(function* () {
732+
const path = yield* Path.Path;
733+
const instanceId = ProviderInstanceId.make("acp-test-prompt-outcome");
734+
const threadId = ThreadId.make("thread-acp-prompt-outcome");
735+
const quota = {
736+
class: "usage_limit",
737+
message: "Quota reached.",
738+
code: "RESOURCE_EXHAUSTED",
739+
retryable: true,
740+
resetAt: "2030-01-01T00:00:00.000Z",
741+
} as const;
742+
// The runtime ordinal of each prompt, and the session each check watched.
743+
const promptRuntimes: Array<number> = [];
744+
const watchedSessions: Array<string> = [];
745+
const adapter = yield* makeAcpAdapterV2({
746+
instanceId,
747+
selfInvocation: yield* resolveSelfInvocation(),
748+
flavor: {
749+
driver: ACP_TEST_DRIVER,
750+
capabilities: AcpProviderCapabilitiesV2,
751+
watchPromptOutcome: (sessionId) =>
752+
Effect.sync(() => {
753+
watchedSessions.push(sessionId);
754+
const failed = watchedSessions.length === 1;
755+
return () => Effect.succeed(failed ? quota : undefined);
756+
}),
757+
makeRuntime: makeMockRuntime({
758+
childProcessSpawner: yield* ChildProcessSpawner.ChildProcessSpawner,
759+
mockAgentPath: yield* path.fromFileUrl(
760+
new URL("../../../scripts/acp-mock-agent.ts", import.meta.url),
761+
),
762+
wrapRuntime: (runtime, runtimeOrdinal) => ({
763+
...runtime,
764+
prompt: () =>
765+
Effect.sync(() => {
766+
promptRuntimes.push(runtimeOrdinal);
767+
return { stopReason: "end_turn" as const };
768+
}),
769+
}),
770+
}),
771+
},
772+
});
773+
const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
774+
runtimeMode: "full-access",
775+
interactionMode: "default",
776+
cwd: process.cwd(),
777+
});
778+
const modelSelection = { instanceId, model: "default" } as const;
779+
const runtime = yield* adapter.openSession({
780+
threadId,
781+
providerSessionId: ProviderSessionId.make("provider-session-acp-prompt-outcome"),
782+
modelSelection,
783+
runtimePolicy,
784+
});
785+
const providerThread = yield* runtime.ensureThread({
786+
threadId,
787+
modelSelection,
788+
runtimePolicy,
789+
});
790+
const runTurn = (ordinal: number) =>
791+
Effect.gen(function* () {
792+
yield* runtime.startTurn(
793+
makeTurnInput({
794+
threadId,
795+
providerThread,
796+
instanceId,
797+
runtimePolicy,
798+
now: yield* DateTime.now,
799+
ordinal,
800+
}),
801+
);
802+
const events = yield* runtime.events.pipe(
803+
Stream.takeUntil((event) => event.type === "turn.terminal"),
804+
Stream.runCollect,
805+
);
806+
return events.at(-1);
807+
});
808+
809+
const failed = yield* runTurn(1);
810+
if (failed?.type !== "turn.terminal" || failed.status !== "failed") {
811+
return assert.fail("expected a failed terminal");
812+
}
813+
assert.deepEqual(failed.failure, quota);
814+
const completed = yield* runTurn(2);
815+
assert.equal(completed?.type === "turn.terminal" ? completed.status : null, "completed");
816+
assert.deepEqual(promptRuntimes, [1, 2], "the next turn runs on a fresh runtime");
817+
assert.equal(watchedSessions.length, 2);
818+
assert.equal(watchedSessions[0], watchedSessions[1]);
819+
}).pipe(Effect.provide(layerTest), Effect.scoped),
820+
);
664821
it.live("retains returned usage when Stop finalizes before the prompt callback", () =>
665822
Effect.gen(function* () {
666823
const path = yield* Path.Path;

0 commit comments

Comments
 (0)