Skip to content

Commit 32ebb8d

Browse files
Merge remote-tracking branch 'origin/main' into pr-33038
2 parents ddd1015 + fa2f4ff commit 32ebb8d

18 files changed

Lines changed: 542 additions & 63 deletions

‎apps/mobile/src/features/files/FileTreeBrowser.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ export function FileTreeBrowser(props: {
215215
return (
216216
<LegendList
217217
renderScrollComponent={NativeScrollView}
218+
nestedScrollEnabled={false}
218219
contentInset={{ top: headerInset, bottom: bottomInset }}
219220
alwaysBounceVertical
220221
className="flex-1"

‎apps/mobile/src/features/files/thread-file-navigator-pane.tsx‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ export function ThreadFileNavigatorPane(props: {
7878
);
7979

8080
return (
81-
<View className="flex-1 ios:bg-sheet android:bg-header">
81+
// Material drags target the first scroll view, so place content before the header.
82+
<View className="flex-1 ios:bg-sheet android:bg-header android:flex-col-reverse">
83+
<ScreenContent insetHorizontal>{fileTree}</ScreenContent>
8284
<AppBar
8385
title="Files"
8486
subtitle={props.projectName}
@@ -89,7 +91,6 @@ export function ThreadFileNavigatorPane(props: {
8991
}}
9092
refresh={{ accessibilityLabel: "Refresh files", onPress: entriesQuery.refresh }}
9193
/>
92-
<ScreenContent insetHorizontal>{fileTree}</ScreenContent>
9394
</View>
9495
);
9596
}

‎apps/mobile/src/features/layout/inspector-host.android.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ export function InspectorPanes(props: {
5353
position: "absolute",
5454
inset: 0,
5555
opacity: visible ? 1 : 0,
56-
zIndex: visible ? 1 : 0,
56+
// A lower zIndex puts the visible pane first in native order, where Material finds its scroll view.
57+
zIndex: visible ? 0 : 1,
5758
}}
5859
>
5960
<PaneContent pane={pane} resetKeys={props.content?.resetKeys} />

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

Lines changed: 131 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import {
5656
} from "@t3tools/contracts";
5757
import { mcpAppFromToolItem } from "@t3tools/shared/toolOutput";
5858
import { assert, describe, it } from "@effect/vitest";
59+
import * as Cause from "effect/Cause";
5960
import * as Context from "effect/Context";
6061
import * as DateTime from "effect/DateTime";
6162
import * as Deferred from "effect/Deferred";
@@ -2466,7 +2467,7 @@ describe("ClaudeAdapterV2 native fork", () => {
24662467
Effect.sync(() => {
24672468
openedQueries.push(input);
24682469
return {
2469-
messages: Stream.empty,
2470+
messages: Stream.never,
24702471
offer: () => Effect.void,
24712472
setModel: () => Effect.void,
24722473
applyFlagSettings: () => Effect.void,
@@ -2808,7 +2809,7 @@ describe("ClaudeAdapterV2 native session identity", () => {
28082809
Effect.sync(() => {
28092810
openedQueries.push(input);
28102811
return {
2811-
messages: Stream.empty,
2812+
messages: Stream.never,
28122813
offer: () => Effect.void,
28132814
setModel: () => Effect.void,
28142815
applyFlagSettings: () => Effect.void,
@@ -10979,6 +10980,134 @@ describe("ClaudeAdapterV2 background wake turns", () => {
1097910980
),
1098010981
);
1098110982

10983+
const openAdapterWhoseFirstQueryEndsBeforeItsFirstFrame = Effect.fnUntraced(function* (
10984+
name: string,
10985+
) {
10986+
const fileSystem = yield* FileSystem.FileSystem;
10987+
const idAllocator = yield* IdAllocator.IdAllocatorV2;
10988+
const attachmentsDir = yield* fileSystem.makeTempDirectoryScoped({
10989+
prefix: `t3-claude-v2-${name}-`,
10990+
});
10991+
const deadStreamEnded = yield* Deferred.make<void>();
10992+
let opened = 0;
10993+
const adapter = yield* ClaudeAdapterV2.makeClaudeAdapterV2({
10994+
instanceId: ClaudeAdapterV2.CLAUDE_DEFAULT_INSTANCE_ID,
10995+
settings: DEFAULT_CLAUDE_SETTINGS,
10996+
environment: {},
10997+
attachmentsDir,
10998+
// startTurn reads the auto-compact window from settings between opening the query and
10999+
// attaching the turn; holding that read until the CLI's stream has ended pins the race.
11000+
fileSystem: {
11001+
...fileSystem,
11002+
readFileString: (filePath, encoding) =>
11003+
opened === 1 && filePath.endsWith("settings.json")
11004+
? Deferred.await(deadStreamEnded).pipe(
11005+
Effect.andThen(fileSystem.readFileString(filePath, encoding)),
11006+
)
11007+
: fileSystem.readFileString(filePath, encoding),
11008+
},
11009+
path: yield* Path.Path,
11010+
random: yield* SecureRandom.SecureRandom,
11011+
idAllocator,
11012+
continuationRequests: { offer: () => Effect.void },
11013+
queryRunner: {
11014+
allocateSessionId: Effect.succeed(`native-${name}`),
11015+
open: () =>
11016+
Effect.gen(function* () {
11017+
opened += 1;
11018+
const sdkMessages = yield* Queue.unbounded<SDKMessage>();
11019+
return {
11020+
// The first CLI exits without writing a frame.
11021+
messages:
11022+
opened === 1
11023+
? Stream.empty.pipe(Stream.ensuring(Deferred.succeed(deadStreamEnded, undefined)))
11024+
: Stream.fromQueue(sdkMessages),
11025+
offer: () => Effect.void,
11026+
setModel: () => Effect.void,
11027+
applyFlagSettings: () => Effect.void,
11028+
setPermissionMode: () => Effect.void,
11029+
backgroundTasks: () => Effect.succeed(false),
11030+
mcpServerStatus: Effect.succeed([]),
11031+
readMcpResource: () => Effect.die("unexpected MCP resource read"),
11032+
callMcpTool: () => Effect.die("unexpected MCP tool call"),
11033+
listPermissionRules: Effect.die("unexpected permission rules read"),
11034+
stopTask: () => Effect.void,
11035+
interrupt: Effect.void,
11036+
close: Queue.shutdown(sdkMessages),
11037+
};
11038+
}),
11039+
forkSession: () => Effect.die("unused forkSession"),
11040+
subagentLaunchToolUseId: () => Effect.succeed(null),
11041+
assertComplete: Effect.void,
11042+
},
11043+
});
11044+
const threadId = ThreadId.make(`thread-${name}`);
11045+
const runtime = yield* adapter.openSession({
11046+
threadId,
11047+
providerSessionId: ProviderSessionId.make(`provider-session-${name}`),
11048+
modelSelection: CLAUDE_TEST_MODEL_SELECTION,
11049+
runtimePolicy: CLAUDE_TEST_RUNTIME_POLICY,
11050+
});
11051+
const providerThread = yield* runtime.ensureThread({
11052+
threadId,
11053+
modelSelection: CLAUDE_TEST_MODEL_SELECTION,
11054+
runtimePolicy: CLAUDE_TEST_RUNTIME_POLICY,
11055+
});
11056+
const now = yield* DateTime.now;
11057+
const turnInput = (attempt: string, providerTurnOrdinal: number) =>
11058+
makeClaudeTestTurnInput({
11059+
threadId,
11060+
providerThread,
11061+
now,
11062+
attemptId: RunAttemptId.make(`attempt-${name}-${attempt}`),
11063+
text: "Continue with the plan.",
11064+
attachments: [],
11065+
providerTurnOrdinal,
11066+
});
11067+
return { runtime, turnInput };
11068+
});
11069+
11070+
it.effect("fails a turn whose Claude query ends before its first frame", () =>
11071+
Effect.scoped(
11072+
Effect.gen(function* () {
11073+
const harness = yield* openAdapterWhoseFirstQueryEndsBeforeItsFirstFrame(
11074+
"claude-query-dies-before-frame",
11075+
);
11076+
const started = yield* harness.runtime
11077+
.startTurn(harness.turnInput("a", 1))
11078+
.pipe(Effect.exit);
11079+
assert.isTrue(
11080+
Exit.isFailure(started),
11081+
"a turn whose Claude query ended before its first frame started running on the dead query",
11082+
);
11083+
if (Exit.isFailure(started)) {
11084+
assert.include(
11085+
Cause.pretty(started.cause),
11086+
"Claude provider query ended before the turn could start.",
11087+
);
11088+
}
11089+
const followUp = yield* harness.runtime
11090+
.startTurn(harness.turnInput("b", 2))
11091+
.pipe(Effect.exit);
11092+
assert.isTrue(
11093+
Exit.isSuccess(followUp),
11094+
`the turn whose query ended before its first frame is still active: ${
11095+
Exit.isFailure(followUp) ? Cause.pretty(followUp.cause) : ""
11096+
}`,
11097+
);
11098+
}).pipe(
11099+
Effect.provide(
11100+
Layer.mergeAll(
11101+
IdAllocator.layer,
11102+
McpProviderSessions.layer,
11103+
NodeServices.layer,
11104+
NodeCrypto.layer,
11105+
),
11106+
),
11107+
),
11108+
),
11109+
);
11110+
1098211111
it.effect(
1098311112
"clears the replaced sibling native thread roster when openQuery switches processes",
1098411113
() =>

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

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11311,8 +11311,22 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
1131111311
executedModel: undefined,
1131211312
};
1131311313
const attachTurn = Effect.gen(function* () {
11314-
querySession.lastTurn = context;
11314+
// Set before claiming: a query that exits after the claim finalizes this turn; one that exits before it fails the start.
1131511315
yield* Ref.set(activeTurn, context);
11316+
const attached = yield* Ref.modify(queryContext, (current) => {
11317+
if (current?.query !== querySession.query || querySession.stopping) {
11318+
return [false, current];
11319+
}
11320+
querySession.lastTurn = context;
11321+
return [true, current];
11322+
});
11323+
if (!attached) {
11324+
yield* Ref.update(activeTurn, (current) => (current === context ? null : current));
11325+
return yield* new ProviderAdapter.ProviderAdapterProtocolError({
11326+
driver: CLAUDE_PROVIDER,
11327+
detail: "Claude provider query ended before the turn could start.",
11328+
});
11329+
}
1131611330
if (
1131711331
!isClaudeProviderContinuationTurn(turnInput) &&
1131811332
permissionModeForClaudeRuntimePolicy(turnInput.runtimePolicy) ===
@@ -11389,15 +11403,6 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
1138911403
// Transcript reads suspend replay; hold SDK frames until the buffer is applied to preserve order.
1139011404
yield* sdkMessageLock.withPermits(1)(
1139111405
Effect.gen(function* () {
11392-
if (
11393-
(yield* Ref.get(queryContext))?.query !== querySession.query ||
11394-
querySession.stopping
11395-
) {
11396-
return yield* new ProviderAdapter.ProviderAdapterProtocolError({
11397-
driver: CLAUDE_PROVIDER,
11398-
detail: "Claude provider query ended before the continuation could start.",
11399-
});
11400-
}
1140111406
yield* attachTurn;
1140211407
const drained = (yield* Ref.get(wakeBuffers)).get(nativeThreadId)?.messages ?? [];
1140311408
yield* Ref.update(requestedContinuations, (current) => {

‎apps/server/src/orchestration-v2/ProjectionStore.test.ts‎

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3517,7 +3517,7 @@ it.layer(layerTest)("ProjectionStoreV2", (it) => {
35173517
activeAttemptId: null,
35183518
status: "cancelled",
35193519
requestedAt: nowIso,
3520-
startedAt: nowIso,
3520+
startedAt: null,
35213521
completedAt: nowIso,
35223522
checkpointId: null,
35233523
contextHandoffId: null,
@@ -3646,6 +3646,48 @@ it.layer(layerTest)("ProjectionStoreV2", (it) => {
36463646
),
36473647
);
36483648

3649+
// A steer cancels the queued run before it starts while the steered run keeps writing, so
3650+
// the queued message leaves the window but its run is still the shell's latest run.
3651+
const steeredItemId = "turn-item:bounded-sql-history:steered-output";
3652+
const steeredRunId = RunId.make("run:bounded-sql-history:1000");
3653+
yield* sql`
3654+
INSERT INTO orchestration_v2_projection_turn_items (
3655+
turn_item_id, thread_id, run_id, node_id, provider_thread_id, provider_turn_id,
3656+
parent_item_id, ordinal, type, status, updated_at, payload_json
3657+
) VALUES (
3658+
${steeredItemId}, ${threadId}, ${steeredRunId}, NULL, NULL, NULL, NULL, 1203,
3659+
'command_execution', 'completed', ${nowIso},
3660+
${encodeUnknownJsonString({
3661+
id: steeredItemId,
3662+
threadId,
3663+
runId: steeredRunId,
3664+
nodeId: null,
3665+
providerThreadId: null,
3666+
providerTurnId: null,
3667+
nativeItemRef: null,
3668+
parentItemId: null,
3669+
ordinal: 1203,
3670+
status: "completed",
3671+
title: "steered output",
3672+
input: "echo steered",
3673+
output: "steered",
3674+
exitCode: 0,
3675+
startedAt: nowIso,
3676+
completedAt: nowIso,
3677+
updatedAt: nowIso,
3678+
type: "command_execution",
3679+
})}
3680+
)
3681+
`;
3682+
const steeredSnapshot = yield* projectionStore.getThreadSnapshotWindow(threadId, {
3683+
rowLimit: sqlPageLimit,
3684+
});
3685+
assert.isFalse(
3686+
steeredSnapshot.projection.turnItems.some((item) => item.runId === cancelledRunId),
3687+
);
3688+
assert.isTrue(steeredSnapshot.projection.runs.some((run) => run.id === cancelledRunId));
3689+
yield* sql`DELETE FROM orchestration_v2_projection_turn_items WHERE turn_item_id = ${steeredItemId}`;
3690+
36493691
const interruptRunId = RunId.make("run:bounded-sql-history:interrupt");
36503692
const interruptNodeId = NodeId.make("node:bounded-sql-history:interrupt");
36513693
const interruptRequestId = TurnItemId.make("turn-item:bounded-sql-history:interrupt-request");

‎apps/server/src/orchestration-v2/ProjectionStore.ts‎

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3378,6 +3378,12 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
33783378
AND (status IN ('queued','preparing','starting','running','waiting')
33793379
OR run_id IN (SELECT value FROM json_each(${cohortRunIds}))
33803380
OR run_id = ${window.requiredRunId ?? null}
3381+
${
3382+
// The shell's latest run, even a steer-cancelled one outside the newest window.
3383+
window.anchorItemId === undefined && window.requiredRunId === undefined
3384+
? sql`OR run_id = ${presentedShellRunId(sql`${threadId}`)}`
3385+
: sql``
3386+
}
33813387
-- Queued or cancelled turns must not hide the latest actual session.
33823388
OR run_id = ${latestTodoList?.run_id ?? null}
33833389
OR run_id = (
@@ -6192,6 +6198,19 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
61926198
)
61936199
)`;
61946200
};
6201+
// The newest run not waiting in a held queue, matching latestUnheldRun.
6202+
const presentedShellRunId = (threadId: Statement.Fragment) => sql`(
6203+
SELECT candidate.run_id
6204+
FROM orchestration_v2_projection_runs candidate
6205+
WHERE candidate.thread_id = ${threadId}
6206+
AND NOT (
6207+
candidate.status = 'queued'
6208+
AND json_extract(candidate.payload_json, '$.queueHeld') IS 1
6209+
)
6210+
AND NOT ${isSilentShellRun("candidate")}
6211+
ORDER BY candidate.ordinal DESC, candidate.run_id DESC
6212+
LIMIT 1
6213+
)`;
61956214

61966215
const selectShellThreadRows = (
61976216
threadId?: ThreadId,
@@ -6359,19 +6378,8 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
63596378
ORDER BY r.ordinal DESC, r.run_id DESC
63606379
LIMIT 1
63616380
)
6362-
-- The newest run not waiting in a held queue, matching latestUnheldRun.
6363-
LEFT JOIN orchestration_v2_projection_runs presented ON presented.run_id = (
6364-
SELECT candidate.run_id
6365-
FROM orchestration_v2_projection_runs candidate
6366-
WHERE candidate.thread_id = t.thread_id
6367-
AND NOT (
6368-
candidate.status = 'queued'
6369-
AND json_extract(candidate.payload_json, '$.queueHeld') IS 1
6370-
)
6371-
AND NOT ${isSilentShellRun("candidate")}
6372-
ORDER BY candidate.ordinal DESC, candidate.run_id DESC
6373-
LIMIT 1
6374-
)
6381+
LEFT JOIN orchestration_v2_projection_runs presented
6382+
ON presented.run_id = ${presentedShellRunId(sql.literal("t.thread_id"))}
63756383
LEFT JOIN orchestration_v2_projection_runs blocked ON blocked.run_id = (
63766384
SELECT candidate.run_id
63776385
FROM orchestration_v2_projection_runs candidate

0 commit comments

Comments
 (0)