Skip to content

Commit b162fb0

Browse files
committed
Merge remote-tracking branch 'origin/main' into t3/reduce-delegated-recovery-startup-cost
2 parents d884754 + edc37c9 commit b162fb0

18 files changed

Lines changed: 260 additions & 240 deletions

‎apps/marketing/src/lib/site.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ export const ANDROID_PLAY_STORE_URL =
77
"https://play.google.com/store/apps/details?id=com.t3tools.t3code";
88

99
export const MARKETING_STATS = {
10-
githubStars: "31k+",
10+
githubStars: "40k+",
1111
users: "500,000",
1212
} as const;

‎apps/server/src/provider/Drivers/ClaudeHome.test.ts‎

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -59,29 +59,44 @@ it.layer(NodeServices.layer)("ClaudeHome", (it) => {
5959
);
6060
});
6161

62-
it.effect("labels Claude processes t3-code unless instance env or Claude settings set one", () =>
63-
Effect.gen(function* () {
64-
const fileSystem = yield* FileSystem.FileSystem;
65-
const path = yield* Path.Path;
66-
const homePath = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-claude-home-" });
67-
const host = { CLAUDE_CODE_ENTRYPOINT: "claude-desktop", KEEP: "1" };
68-
const instance = [{ name: "CLAUDE_CODE_ENTRYPOINT", value: "instance", sensitive: false }];
62+
it.effect(
63+
"drops the launching Claude session and labels processes t3-code unless overridden",
64+
() =>
65+
Effect.gen(function* () {
66+
const fileSystem = yield* FileSystem.FileSystem;
67+
const path = yield* Path.Path;
68+
const homePath = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-claude-home-" });
69+
const host = {
70+
CLAUDE_CODE_ENTRYPOINT: "claude-desktop",
71+
CLAUDECODE: "1",
72+
CLAUDE_CODE_SESSION_ID: "host-session",
73+
CLAUDE_CODE_MESSAGING_SOCKET: "/tmp/host-claude.sock",
74+
CLAUDE_EFFORT: "high",
75+
KEEP: "1",
76+
};
77+
const instance = [
78+
{ name: "CLAUDE_CODE_ENTRYPOINT", value: "instance", sensitive: false },
79+
{ name: "CLAUDE_EFFORT", value: "low", sensitive: false },
80+
];
6981

70-
expect(yield* mergeClaudeProcessEnvironment({ homePath }, undefined, host)).toMatchObject({
71-
CLAUDE_CODE_ENTRYPOINT: "t3-code",
72-
KEEP: "1",
73-
});
74-
expect(
75-
(yield* mergeClaudeProcessEnvironment({ homePath }, instance, host)).CLAUDE_CODE_ENTRYPOINT,
76-
).toBe("instance");
82+
expect(yield* mergeClaudeProcessEnvironment({ homePath }, undefined, host)).toEqual({
83+
CLAUDE_CODE_ENTRYPOINT: "t3-code",
84+
KEEP: "1",
85+
});
86+
expect(yield* mergeClaudeProcessEnvironment({ homePath }, instance, host)).toEqual({
87+
CLAUDE_CODE_ENTRYPOINT: "instance",
88+
CLAUDE_EFFORT: "low",
89+
KEEP: "1",
90+
});
7791

78-
yield* fileSystem.writeFileString(
79-
path.join(homePath, "settings.json"),
80-
JSON.stringify({ env: { CLAUDE_CODE_ENTRYPOINT: "custom" } }),
81-
);
82-
expect(
83-
(yield* mergeClaudeProcessEnvironment({ homePath }, instance, host)).CLAUDE_CODE_ENTRYPOINT,
84-
).toBe("custom");
85-
}),
92+
yield* fileSystem.writeFileString(
93+
path.join(homePath, "settings.json"),
94+
JSON.stringify({ env: { CLAUDE_CODE_ENTRYPOINT: "custom" } }),
95+
);
96+
expect(
97+
(yield* mergeClaudeProcessEnvironment({ homePath }, instance, host))
98+
.CLAUDE_CODE_ENTRYPOINT,
99+
).toBe("custom");
100+
}),
86101
);
87102
});

‎apps/server/src/provider/Drivers/ClaudeHome.ts‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,23 @@ export const makeClaudeEnvironment = Effect.fn("makeClaudeEnvironment")(function
4545
};
4646
});
4747

48+
// A Claude Code session that launched T3 exports these. A claude spawned with them acts as part of
49+
// that session: its session id, messaging socket and token, and effort.
50+
const CLAUDE_HOST_SESSION_VARIABLES = [
51+
"CLAUDECODE",
52+
"CLAUDE_CODE_SESSION_ID",
53+
"CLAUDE_CODE_HOST_SESSION_ID",
54+
"CLAUDE_CODE_CHILD_SESSION",
55+
"CLAUDE_CODE_SESSION_ATTENDED",
56+
"CLAUDE_CODE_MESSAGING_SOCKET",
57+
"CLAUDE_CODE_MESSAGING_TOKEN",
58+
"CLAUDE_CODE_EXECPATH",
59+
"CLAUDE_CODE_DESKTOP_APP_VERSION",
60+
"CLAUDE_EFFORT",
61+
"CLAUDE_PID",
62+
"CLAUDE_AGENT_SDK_VERSION",
63+
];
64+
4865
/**
4966
* Base env for the Claude processes T3 Code runs, before `makeClaudeEnvironment`.
5067
* Claude Code reads its entrypoint from the process env, not its settings `env`, so T3 Code applies that override itself.
@@ -54,10 +71,12 @@ export const mergeClaudeProcessEnvironment = Effect.fn("mergeClaudeProcessEnviro
5471
instanceEnvironment: ProviderInstanceEnvironment | undefined,
5572
hostEnvironment: NodeJS.ProcessEnv,
5673
) {
57-
const environment = yield* mergeProviderInstanceEnvironment(instanceEnvironment, {
74+
const baseEnvironment: NodeJS.ProcessEnv = {
5875
...hostEnvironment,
5976
CLAUDE_CODE_ENTRYPOINT: "t3-code",
60-
});
77+
};
78+
for (const name of CLAUDE_HOST_SESSION_VARIABLES) delete baseEnvironment[name];
79+
const environment = yield* mergeProviderInstanceEnvironment(instanceEnvironment, baseEnvironment);
6180
const settingsEntrypoint = (yield* readClaudeSettingsEnv(config, undefined, environment))
6281
.CLAUDE_CODE_ENTRYPOINT;
6382
return settingsEntrypoint

‎apps/server/src/telemetry/ProviderUsageAnalytics.test.ts‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@ const context = (
7777
modelSelection: {
7878
instanceId: ProviderInstanceId.make("codex"),
7979
model,
80-
options: [{ id: "reasoningEffort", value: "xhigh" }],
80+
options: [
81+
{ id: "reasoningEffort", value: "xhigh" },
82+
{ id: "serviceTier", value: "priority" },
83+
],
8184
},
8285
runtimeMode: "full-access",
8386
interactionMode: "default",
@@ -154,6 +157,7 @@ describe("provider usage reporting", () => {
154157
lifecycleObserved: true,
155158
model: "gpt-6-sol",
156159
effort: "xhigh",
160+
serviceTier: "fast",
157161
runtimeMode: "full-access",
158162
interactionMode: "default",
159163
createdBy: "user",
@@ -320,4 +324,27 @@ describe("provider usage reporting", () => {
320324
}
321325
expect(routed("ollama/acme-internal", "secret-variant")).not.toHaveProperty("effort");
322326
});
327+
328+
it("reports closed service tiers from a tier option or a fast mode toggle", () => {
329+
const tier = (option: { id: string; value: string | boolean }) =>
330+
providerTurnProperties(
331+
{
332+
driver: "codex",
333+
context: {
334+
modelSelection: {
335+
instanceId: ProviderInstanceId.make("codex"),
336+
model: "gpt-6-sol",
337+
options: [option],
338+
},
339+
},
340+
providerTurn: turn("t", complete(1, 1)),
341+
},
342+
label,
343+
).serviceTier;
344+
expect(tier({ id: "serviceTier", value: "ultrafast" })).toBe("ultrafast");
345+
expect(tier({ id: "serviceTier", value: "default" })).toBe("standard");
346+
expect(tier({ id: "serviceTier", value: "/home/me/secret" })).toBeUndefined();
347+
expect(tier({ id: "fastMode", value: true })).toBe("fast");
348+
expect(tier({ id: "fastMode", value: false })).toBe("standard");
349+
});
323350
});

‎apps/server/src/telemetry/ProviderUsageAnalytics.ts‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ import * as DateTime from "effect/DateTime";
2020
import * as Effect from "effect/Effect";
2121
import * as Layer from "effect/Layer";
2222

23-
import { getModelSelectionStringOptionValue } from "@t3tools/shared/model";
23+
import {
24+
getModelSelectionBooleanOptionValue,
25+
getModelSelectionStringOptionValue,
26+
} from "@t3tools/shared/model";
2427
import * as ProviderRegistry from "../provider/ProviderRegistry.ts";
2528
import * as AnalyticsService from "./AnalyticsService.ts";
2629
import { catalogModelLabel } from "./ProviderDimensions.ts";
@@ -106,6 +109,22 @@ function selectedEffort(selection: ModelSelection): string | undefined {
106109
return effort !== undefined && REPORTED_EFFORTS.has(effort) ? effort : undefined;
107110
}
108111

112+
// Codex sends a tier id (its "fast" config shows up as "priority"); Claude has a fastMode toggle.
113+
const REPORTED_SERVICE_TIERS: ReadonlyMap<string, string> = new Map([
114+
["default", "standard"],
115+
["flex", "flex"],
116+
["fast", "fast"],
117+
["priority", "fast"],
118+
["ultrafast", "ultrafast"],
119+
]);
120+
121+
function selectedServiceTier(selection: ModelSelection): string | undefined {
122+
const tier = getModelSelectionStringOptionValue(selection, "serviceTier");
123+
if (tier !== undefined) return REPORTED_SERVICE_TIERS.get(tier);
124+
const fastMode = getModelSelectionBooleanOptionValue(selection, "fastMode");
125+
return fastMode === undefined ? undefined : fastMode ? "fast" : "standard";
126+
}
127+
109128
/**
110129
* Confirmed models across counted work. Unknown when any piece of work has no
111130
* reported model, unless two distinct models were already seen.
@@ -130,6 +149,7 @@ function selectionProperties(
130149
return defined({
131150
model: selection === undefined ? undefined : label(selection.model),
132151
effort: selection === undefined ? undefined : selectedEffort(selection),
152+
serviceTier: selection === undefined ? undefined : selectedServiceTier(selection),
133153
runtimeMode: context?.runtimeMode,
134154
interactionMode: context?.interactionMode,
135155
...context?.origin,

‎apps/web/src/components/ThreadNotificationCoordinator.badge.browser.test.ts‎

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import { WORKING_EXIT_GRACE_MS } from "@t3tools/client-runtime/state/thread-inbox";
21
import type { AnyRouter } from "@tanstack/react-router";
32
import { EnvironmentId } from "@t3tools/contracts";
43
import * as DateTime from "effect/DateTime";
54
import * as Option from "effect/Option";
65
import { Atom, AtomRegistry } from "effect/reactivity";
76
import { expect, it, vi } from "vite-plus/test";
87

9-
import { fakeTimers, stubGlobal } from "../../test/render";
8+
import { stubGlobal } from "../../test/render";
109

1110
const state = vi.hoisted(() => ({
1211
mode: "notifications",
@@ -241,24 +240,18 @@ it.each(["hasPendingApprovals", "hasPendingUserInput"] as const)(
241240
},
242241
);
243242

244-
it("holds a completion through a continuation gap and notifies once it settles", async () => {
243+
it("presents completion notifications and sound as soon as the shell completes", async () => {
245244
await using app = setup();
245+
state.mode = "notifications-and-sound";
246246
app.start();
247-
using _timers = fakeTimers();
248-
const finished = (turnId: string, completedAt: string) => ({
249-
latestTurn: { turnId, state: "completed", completedAt },
250-
});
251-
state.shells.set("one", shell(finished("turn-1", "2026-09-13T07:00:01.000Z")));
252247
state.shells.set(
253248
"one",
254-
shell({ latestTurn: { turnId: "turn-2", state: "running", completedAt: null } }),
249+
shell({
250+
latestTurn: { turnId: "turn", state: "completed", completedAt: "2026-09-13T07:00:01.000Z" },
251+
}),
255252
);
256-
state.shells.set("one", shell(finished("turn-2", "2026-09-13T07:00:02.000Z")));
257-
expect(TestNotification.sent).toEqual([]);
258-
await vi.advanceTimersByTimeAsync(WORKING_EXIT_GRACE_MS - 1);
259-
expect(TestNotification.sent).toEqual([]);
260-
await vi.advanceTimersByTimeAsync(1);
261253
expect(TestNotification.sent.map((sent) => sent.title)).toEqual(["Thread completed"]);
254+
expect(state.sound).toHaveBeenCalledWith("completion", expect.any(Function));
262255
});
263256

264257
it.each(["hasPendingApprovals", "hasPendingUserInput"] as const)(
@@ -277,7 +270,6 @@ it.each(["hasPendingApprovals", "hasPendingUserInput"] as const)(
277270
};
278271
state.shells.set("one", shell({ id: "working" }, { id: "asking" }, { id: "offline" }, done));
279272
app.start();
280-
using _timers = fakeTimers();
281273
state.shells.set("one", shell({ id: "working" }, asking, { id: "offline" }, done));
282274
state.shells.set("one", {
283275
...shell({ id: "working" }, asking, { id: "offline" }, done),
@@ -296,37 +288,31 @@ it.each(["hasPendingApprovals", "hasPendingUserInput"] as const)(
296288

297289
expect(TestNotification.sent.map(({ title }) => title)).toEqual([
298290
"Approval needed",
291+
"Thread completed",
299292
flag === "hasPendingApprovals" ? "Approval needed" : "Input needed",
300293
]);
301-
await vi.advanceTimersByTimeAsync(WORKING_EXIT_GRACE_MS);
302294
state.shells.set("one", { ...shell(completed, asking, offline, done), status: "cached" });
303295
state.shells.set("one", shell(completed, asking, offline, done));
304-
await vi.advanceTimersByTimeAsync(WORKING_EXIT_GRACE_MS);
305296
expect(TestNotification.sent.map(({ title }) => title)).toEqual([
306297
"Approval needed",
307-
flag === "hasPendingApprovals" ? "Approval needed" : "Input needed",
308298
"Thread completed",
299+
flag === "hasPendingApprovals" ? "Approval needed" : "Input needed",
309300
]);
310301
},
311302
);
312303

313304
it.each([false, true])(
314-
"rechecks a pending completion after reconnect (continued: %s)",
305+
"does not replay a notified completion after reconnect (continued: %s)",
315306
async (continued) => {
316307
await using app = setup();
317308
app.start();
318-
using _timers = fakeTimers();
319309
const completed = shell({
320310
latestTurn: { turnId: "turn", state: "completed", completedAt: "2026-09-13T07:05:00.000Z" },
321311
});
322312
state.shells.set("one", completed);
323313
state.shells.set("one", { ...completed, status: "cached" });
324-
await vi.advanceTimersByTimeAsync(WORKING_EXIT_GRACE_MS);
325-
expect(TestNotification.sent).toEqual([]);
314+
expect(TestNotification.sent.map(({ title }) => title)).toEqual(["Thread completed"]);
326315
state.shells.set("one", continued ? shell() : completed);
327-
await vi.advanceTimersByTimeAsync(WORKING_EXIT_GRACE_MS);
328-
expect(TestNotification.sent.map(({ title }) => title)).toEqual(
329-
continued ? [] : ["Thread completed"],
330-
);
316+
expect(TestNotification.sent.map(({ title }) => title)).toEqual(["Thread completed"]);
331317
},
332318
);

0 commit comments

Comments
 (0)