Skip to content

Commit 7d0ef87

Browse files
Merge remote-tracking branch 'origin/main' into fix/issue-24390
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2 parents 8a9d132 + 286eeea commit 7d0ef87

37 files changed

Lines changed: 1267 additions & 127 deletions

‎apps/desktop/src/app/DesktopCliShim.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const fakeAppImage = (canMount = true, app = REPORTER) => {
5656
`echo $$ >'${root}/mounter.pid'`,
5757
canMount ? `echo '${image}'` : 'echo "Cannot mount AppImage"; exit 1',
5858
// Like the FUSE runtime, any of these unmounts. fd 3 reports to the test when it is open.
59-
`trap 'echo unmounted >&3 2>/dev/null; touch "${root}/unmounted"; exit 0' TERM HUP INT`,
59+
"trap 'echo unmounted >&3 2>/dev/null; exit 0' TERM HUP INT",
6060
"trap 'echo mounted >&3 2>/dev/null' WINCH",
6161
"while :; do sleep 0.05; done",
6262
"",

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ import * as ClaudeAdapterV2 from "./ClaudeAdapterV2.ts";
109109
import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator";
110110
import * as ProviderInstallationGate from "../../provider/ProviderInstallationGate.ts";
111111
import { ClaudeOrchestratorReplayHarness } from "./ClaudeAdapterV2.testkit.ts";
112+
import { withInlineContext } from "../ContextHandoffDelivery.ts";
112113
import { provideDeterministicTestRuntime } from "../testkit/DeterministicRuntime.ts";
113114
import { runOrchestratorV2Scenario } from "../testkit/OrchestratorScenario.ts";
114115
import { layerProviderReplay } from "../testkit/ProviderReplayHarness.ts";
@@ -5483,6 +5484,55 @@ describe("ClaudeAdapterV2 background wake turns", () => {
54835484
),
54845485
);
54855486

5487+
// regression: #34393 a provider switch replayed a $skill from the handoff history
5488+
it.effect("dispatches only skills from the user's text, not from inline handoff history", () =>
5489+
Effect.gen(function* () {
5490+
const fs = yield* FileSystem.FileSystem;
5491+
const path = yield* Path.Path;
5492+
const homePath = yield* fs.makeTempDirectoryScoped({ prefix: "t3-claude-skill-handoff-" });
5493+
const directory = path.join(homePath, "skills", "review");
5494+
yield* fs.makeDirectory(directory, { recursive: true });
5495+
yield* fs.writeFileString(
5496+
path.join(directory, "SKILL.md"),
5497+
"---\nname: review\n---\nFollow the review instructions.\n",
5498+
);
5499+
const harness = yield* makeWakeHarnessWithOptions({
5500+
settings: { ...DEFAULT_CLAUDE_SETTINGS, homePath },
5501+
});
5502+
const history = "Context handoff:\n[Historical user; user_message]\n$review the diff";
5503+
const text = withInlineContext(history, "continue");
5504+
yield* harness.runtime.startTurn({
5505+
...makeClaudeTestTurnInput({
5506+
threadId: harness.threadId,
5507+
providerThread: harness.providerThread,
5508+
now: yield* DateTime.now,
5509+
attemptId: RunAttemptId.make("skill-handoff"),
5510+
text,
5511+
attachments: [],
5512+
runtimePolicy: { ...CLAUDE_TEST_RUNTIME_POLICY, cwd: homePath },
5513+
}),
5514+
inlineContextLength: text.length - "continue".length,
5515+
});
5516+
5517+
const content = harness.offeredMessages[0]?.message.content;
5518+
const blocks =
5519+
typeof content === "string"
5520+
? [content]
5521+
: (content ?? []).map((block) => (block.type === "text" ? block.text : ""));
5522+
assert.isFalse(blocks.some((text) => text.startsWith("/review")));
5523+
assert.include(blocks.join("\n"), "$review the diff");
5524+
}).pipe(
5525+
Effect.provide(
5526+
Layer.mergeAll(
5527+
IdAllocator.layer,
5528+
McpProviderSessions.layer,
5529+
NodeServices.layer,
5530+
NodeCrypto.layer,
5531+
),
5532+
),
5533+
),
5534+
);
5535+
54865536
// regression: #15475 MCP title arriving after the tool starts must survive to completion
54875537
it.effect.each([
54885538
{ isError: false, title: "Check weather" },

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

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2631,12 +2631,15 @@ export function makeClaudeUserMessage(input: {
26312631
readonly text: string;
26322632
readonly priority?: SDKUserMessage["priority"];
26332633
readonly skills?: ReadonlyMap<string, ClaudeSkillTarget>;
2634+
readonly skillMentionsFrom?: number;
26342635
readonly uuid?: SDKUserMessage["uuid"];
26352636
}): SDKUserMessage {
26362637
// Claude expands a skill only when `/name` starts the last text block.
26372638
// Keep the whole request before that block; see ClaudeSkillDispatch.
26382639
const dispatch =
2639-
input.skills === undefined ? undefined : planClaudeSkillDispatch(input.text, input.skills);
2640+
input.skills === undefined
2641+
? undefined
2642+
: planClaudeSkillDispatch(input.text, input.skills, input.skillMentionsFrom);
26402643
// Claude runs `/goal` only when it opens the prompt, so a goal stays one block.
26412644
const isGoalCommand = parseGoalCommand({ text: input.text }) !== null;
26422645
return {
@@ -2801,11 +2804,15 @@ const makeClaudeUserMessageWithAttachments = Effect.fnUntraced(function* (input:
28012804
readonly fileSystem: FileSystem.FileSystem;
28022805
readonly pdfReservation: Effect.Success<ReturnType<typeof reserveClaudePdfBudget>>;
28032806
readonly skills?: ReadonlyMap<string, ClaudeSkillTarget>;
2807+
readonly skillMentionsFrom?: number;
28042808
}) {
28052809
if (input.attachments.length === 0) {
28062810
const message = makeClaudeUserMessage({
28072811
text: input.text,
28082812
...(input.skills === undefined ? {} : { skills: input.skills }),
2813+
...(input.skillMentionsFrom === undefined
2814+
? {}
2815+
: { skillMentionsFrom: input.skillMentionsFrom }),
28092816
...(input.priority === undefined ? {} : { priority: input.priority }),
28102817
...(input.uuid === undefined ? {} : { uuid: input.uuid }),
28112818
});
@@ -2829,7 +2836,7 @@ const makeClaudeUserMessageWithAttachments = Effect.fnUntraced(function* (input:
28292836
const dispatch =
28302837
input.skills === undefined
28312838
? undefined
2832-
: planClaudeSkillDispatch(textWithAttachmentPaths, input.skills);
2839+
: planClaudeSkillDispatch(textWithAttachmentPaths, input.skills, input.skillMentionsFrom);
28332840
const content: Array<ClaudeUserContentBlock> = [];
28342841
// Base64 adds a third to the payload. Leave room below Anthropic's 32 MB
28352842
// request limit for text, instructions, and SDK framing. The SDK does not
@@ -12422,15 +12429,24 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
1242212429
pdfBudgets.get(nativeThreadId)!,
1242312430
persistAttachmentBudget(nativeThreadId),
1242412431
);
12432+
const promptText = applyClaudePromptEffortPrefix(
12433+
turnInput.message.text,
12434+
compileClaudeModelSelection(turnInput.modelSelection, modelCatalog).promptEffort,
12435+
);
1242512436
const userMessage =
1242612437
promptUuid === null
1242712438
? null
1242812439
: yield* makeClaudeUserMessageWithAttachments({
12429-
text: applyClaudePromptEffortPrefix(
12430-
turnInput.message.text,
12431-
compileClaudeModelSelection(turnInput.modelSelection, modelCatalog)
12432-
.promptEffort,
12433-
),
12440+
text: promptText,
12441+
// Mentions in inline handoff history are history, not this turn's skill.
12442+
...(turnInput.inlineContextLength === undefined
12443+
? {}
12444+
: {
12445+
skillMentionsFrom:
12446+
promptText.length -
12447+
turnInput.message.text.slice(turnInput.inlineContextLength).trimEnd()
12448+
.length,
12449+
}),
1243412450
attachments: turnInput.message.attachments,
1243512451
attachmentsDir,
1243612452
fileSystem,

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,12 +1639,11 @@ export const layer: Layer.Layer<
16391639
.filter((part) => part !== "")
16401640
.join("\n\n");
16411641
const { restartContinuationOfRunId: _resumedRunId, ...promptedInput } = turnInput;
1642+
const text = goalCommand ? userText : withInlineContext(context, userText);
16421643
yield* start({
16431644
...(noteContinuation ? promptedInput : turnInput),
1644-
message: {
1645-
...turnInput.message,
1646-
text: goalCommand ? userText : withInlineContext(context, userText),
1647-
},
1645+
message: { ...turnInput.message, text },
1646+
...(text === userText ? {} : { inlineContextLength: text.length - userText.length }),
16481647
}).pipe(
16491648
// Clear pending handoff markers for refused prompts so the next turn retains the native session.
16501649
Effect.tapError((error) =>

‎apps/server/src/preview/PreviewBrowser.ts‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,31 +25,31 @@ import { openZipArchive } from "../zipArchive.ts";
2525
// https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json
2626
// Never pin below 156.0.8078.70: the shell has no CRLSet and older SPKI blocklists trust
2727
// compromised eMudhra intermediates (crrev.com/c/8627687).
28-
const VERSION = "157.0.8103.38";
28+
const VERSION = "157.0.8103.78";
2929
const ARCHIVES = {
3030
linux64: {
31-
bytes: 128_168_542,
32-
sha256: "deafffa74660b34853a4119c361fd427ac8c9fcb62db51ddb8a797cd83a4ba2d",
31+
bytes: 127_965_683,
32+
sha256: "f90329720fb61e5a76da9b6b509b6ad12a484c9c5df0359403e935177c6d153a",
3333
},
3434
"linux-arm64": {
35-
bytes: 128_171_139,
36-
sha256: "b9b910a57b2a15eb3e55000a2339f93a973934a413ebfc6e585a50ec6c42fd6c",
35+
bytes: 128_047_138,
36+
sha256: "912fbf877e53de34d7b3cca5104f3b95607d41bd35412ccc6cd2a599ff0c0dbf",
3737
},
3838
"mac-arm64": {
39-
bytes: 104_773_711,
40-
sha256: "e6a6b13551aa12f951d0891d79282606b13742837c8fa0505e1272bae116ce82",
39+
bytes: 104_822_985,
40+
sha256: "17bf66d53c1b1104dcb641c5b331cd4ac5d200c778f5feed0934a0b92deaf8d6",
4141
},
4242
"mac-x64": {
43-
bytes: 110_442_262,
44-
sha256: "79821745d0a72d2ba752d981284ed0a9e6fa320dad133596941a17dba6186de3",
43+
bytes: 110_132_547,
44+
sha256: "f1a6a9561eaf1f409849538de663695d36d72fbf1ebca4d42e47c7b5f2a157f3",
4545
},
4646
win32: {
47-
bytes: 120_390_416,
48-
sha256: "35e0d45c0136448f7b587f6fb7195a0686127a4dfdc23ef3b0e04b5e9ffe16cd",
47+
bytes: 120_403_126,
48+
sha256: "d9829c59dcc79d9e6e920f8ab841f2a9a055dcf54229d756ac0b42dfec303910",
4949
},
5050
win64: {
51-
bytes: 126_513_060,
52-
sha256: "1ff4540855478ba0848e03f1ef8d455f77d058b38285df91bc34273788a73446",
51+
bytes: 126_047_001,
52+
sha256: "2138c1583d25d6f3abec5269943b2f430207d87a539895aa9e90cc4697ec0e1f",
5353
},
5454
} as const;
5555

‎apps/server/src/preview/ServerBrowser.test.ts‎

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -360,12 +360,10 @@ function makeEncoderPage() {
360360
document: { createElement: (tag: string) => (tag === "video" ? video : canvas) },
361361
Path2D: function Path2D() {},
362362
MediaRecorder: FakeMediaRecorder,
363-
createImageBitmap: async (blob: Blob) => ({
364-
width: 1280,
365-
height: 800,
366-
pixels: await blob.text(),
367-
close() {},
368-
}),
363+
createImageBitmap: async (blob: Blob) => {
364+
await decodeGate?.promise;
365+
return { width: 1280, height: 800, pixels: await blob.text(), close() {} };
366+
},
369367
atob,
370368
btoa,
371369
Blob,
@@ -386,6 +384,7 @@ function makeEncoderPage() {
386384
const contexts: ReturnType<typeof makeContext>[] = [];
387385
let encoderPageOverride: Page | undefined;
388386
const encoderStreams: Array<{ frameRate: number | undefined; bitsPerSecond: number }> = [];
387+
let decodeGate: PromiseWithResolvers<void> | null = null;
389388
const contextRequests: Array<{ profileId: string; isolated: boolean }> = [];
390389
let contextGate: PromiseWithResolvers<void> | null = null;
391390
let heldStill: (() => Promise<void>) | null = null;
@@ -571,6 +570,7 @@ beforeEach(() => {
571570
contexts.length = 0;
572571
encoderPageOverride = undefined;
573572
encoderStreams.length = 0;
573+
decodeGate = null;
574574
contextRequests.length = 0;
575575
contextGate = null;
576576
heldStill = null;
@@ -1077,6 +1077,32 @@ it.effect.each([
10771077
).pipe(Effect.provide(layer)),
10781078
);
10791079

1080+
// Chrome stops sending screencast frames while too many are unacked.
1081+
it.effect("recordings ack screencast frames without waiting for the encoder to decode them", () =>
1082+
Effect.scoped(
1083+
Effect.gen(function* () {
1084+
const { broker, tabId } = yield* ready;
1085+
yield* broker.invoke({ scope, tabId, operation: "recordingStart", input: {} });
1086+
const session = contexts[0]!.sessions.find((candidate) =>
1087+
candidate.send.mock.calls.some(([method]) => method === "Page.startScreencast"),
1088+
)!;
1089+
const gate = Promise.withResolvers<void>();
1090+
decodeGate = gate;
1091+
yield* Effect.addFinalizer(() => Effect.sync(() => gate.resolve()));
1092+
for (const sessionId of [1, 2, 3]) {
1093+
session.emit("Page.screencastFrame", {
1094+
data: Buffer.from(`frame ${sessionId}`).toString("base64"),
1095+
sessionId,
1096+
metadata: { deviceWidth: 1280 },
1097+
});
1098+
}
1099+
expect(
1100+
session.send.mock.calls.filter(([method]) => method === "Page.screencastFrameAck"),
1101+
).toHaveLength(3);
1102+
}),
1103+
).pipe(Effect.provide(layer)),
1104+
);
1105+
10801106
it.effect.each([{ truncated: false }, { truncated: true }])(
10811107
"saves a large recording as a binary download and removes its staged file (truncated: $truncated)",
10821108
({ truncated }) =>

‎apps/server/src/preview/ServerBrowser.ts‎

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,24 +1986,37 @@ const make = Effect.gen(function* () {
19861986
const opened = await tab.page.context().newCDPSession(tab.page);
19871987
session = opened;
19881988
const framesInFlight = new Set<Promise<void>>();
1989+
// Chrome withholds frames while acks are outstanding, so ack on arrival and let a
1990+
// slow encoder skip to the newest frame instead of throttling the capture.
1991+
let pendingFrame: readonly [string, number] | null = null;
1992+
const deliverPending = async () => {
1993+
while (pendingFrame) {
1994+
const next = pendingFrame;
1995+
pendingFrame = null;
1996+
const accepted = await encoder
1997+
.evaluate(
1998+
([data, width]) =>
1999+
(globalThis as unknown as EncoderWindow).__t3Recorder.frame(data, width),
2000+
next,
2001+
)
2002+
.catch(() => true);
2003+
if (!accepted) {
2004+
pendingFrame = null;
2005+
await opened.send("Page.stopScreencast").catch(constVoid);
2006+
}
2007+
}
2008+
};
19892009
opened.on("Page.screencastFrame", (frame) => {
2010+
void opened
2011+
.send("Page.screencastFrameAck", { sessionId: frame.sessionId })
2012+
.catch(constVoid);
19902013
const cssWidth = tab.page.viewportSize()?.width ?? frame.metadata.deviceWidth;
1991-
const delivered: Promise<void> = encoder
1992-
.evaluate(
1993-
([data, width]) =>
1994-
(globalThis as unknown as EncoderWindow).__t3Recorder.frame(data, width),
1995-
[frame.data, cssWidth] as const,
1996-
)
1997-
.then(async (accepted) => {
1998-
if (!accepted) await opened.send("Page.stopScreencast");
1999-
})
2000-
.catch(constVoid)
2001-
.finally(() => {
2002-
framesInFlight.delete(delivered);
2003-
void opened
2004-
.send("Page.screencastFrameAck", { sessionId: frame.sessionId })
2005-
.catch(constVoid);
2006-
});
2014+
const delivering = framesInFlight.size > 0;
2015+
pendingFrame = [frame.data, cssWidth];
2016+
if (delivering) return;
2017+
const delivered: Promise<void> = deliverPending().finally(() =>
2018+
framesInFlight.delete(delivered),
2019+
);
20072020
framesInFlight.add(delivered);
20082021
});
20092022
await opened.send("Page.startScreencast", RECORDING_SCREENCAST);

‎apps/server/src/preview/ServerBrowserPage.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,8 @@ export const recordingEncoderScript = (frameRate: BrowserRecordingFrameRate) =>
11031103
window.__t3Recorder = {
11041104
async frame(base64, cssWidth) {
11051105
if (tooLarge) return false;
1106-
const bytes = Uint8Array.from(atob(base64), (char) => char.charCodeAt(0));
1106+
// A per-character atob copy costs ~30 ms on a 3200x1800 frame and throttles recordings.
1107+
const bytes = Uint8Array.fromBase64(base64);
11071108
const bitmap = await createImageBitmap(new Blob([bytes], { type: "image/jpeg" }));
11081109
if (tooLarge) { bitmap.close(); return false; }
11091110
if (!recorder) {

0 commit comments

Comments
 (0)