Skip to content

Commit 74d4bdb

Browse files
authored
Merge branch 'main' into fix/mobile-mermaid-rendering-1
2 parents 5a5fe7d + a960f56 commit 74d4bdb

36 files changed

Lines changed: 841 additions & 45 deletions

‎.github/workflows/web-preview.yml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ jobs:
8282
--archive=tgz \
8383
--yes \
8484
--token "$VERCEL_TOKEN" \
85-
--scope "$vercel_scope"
85+
--scope "$vercel_scope" \
86+
--build-env "VITE_RELEASE_CHANNEL=preview"
8687
)"
8788
printf '%s\n' "$deployment_output"
8889
# Vercel can print lockfile warnings to stdout before the deployment URL.

‎apps/desktop/src/app/DesktopObservability.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
import * as HostProcess from "@t3tools/shared/HostProcess";
88
import * as SharedObservability from "@t3tools/shared/observability";
99
import * as OtelEnvironment from "@t3tools/shared/otelEnvironment";
10+
import { releaseChannelOf, releaseResourceAttributes } from "@t3tools/shared/releaseResource";
1011
import {
1112
parsePersistedServerObservabilitySettings,
1213
type PersistedServerObservabilitySettings,
@@ -595,14 +596,21 @@ const layerTelemetry = Layer.unwrap(
595596
Effect.gen(function* () {
596597
const environment = yield* DesktopEnvironment.DesktopEnvironment;
597598
const endpoints = yield* resolveOtlpEndpoints;
599+
// Unpackaged runs launch a script, so Electron reports its own version.
600+
const serviceVersion = environment.isPackaged
601+
? environment.appVersion
602+
: desktopPackageJson.version;
598603
const resource = {
599604
serviceName: "t3code-desktop",
600-
// Unpackaged runs launch a script, so Electron reports its own version.
601-
serviceVersion: environment.isPackaged ? environment.appVersion : desktopPackageJson.version,
605+
serviceVersion,
602606
attributes: {
603607
"service.namespace": "t3code",
604608
"service.runtime": "desktop",
605609
"service.mode": environment.isDevelopment ? "development" : "packaged",
610+
...releaseResourceAttributes(
611+
environment.isDevelopment ? "dev" : releaseChannelOf(serviceVersion),
612+
endpoints.resourceAttributes,
613+
),
606614
"host.name": endpoints.resourceAttributes["host.name"] || (yield* HostProcess.Hostname),
607615
},
608616
};

‎apps/desktop/src/backend/DesktopBackendConfiguration.test.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ describe("DesktopBackendConfiguration", () => {
678678
),
679679
);
680680

681-
it.effect("resolveWsl carries the kill switch into the distro", () =>
681+
it.effect("resolveWsl carries the kill switch and resource attributes into the distro", () =>
682682
Effect.gen(function* () {
683683
const fileSystem = yield* FileSystem.FileSystem;
684684
const baseDir = yield* fileSystem.makeTempDirectoryScoped({
@@ -688,10 +688,12 @@ describe("DesktopBackendConfiguration", () => {
688688
const previousWslEnv = process.env.WSLENV;
689689
const previousDisabled = process.env.OTEL_SDK_DISABLED;
690690
const previousTelemetry = process.env.T3CODE_TELEMETRY_ENABLED;
691+
const previousResourceAttributes = process.env.OTEL_RESOURCE_ATTRIBUTES;
691692
try {
692693
delete process.env.WSLENV;
693694
process.env.OTEL_SDK_DISABLED = "true";
694695
process.env.T3CODE_TELEMETRY_ENABLED = "false";
696+
process.env.OTEL_RESOURCE_ATTRIBUTES = "deployment.environment.name=staging";
695697

696698
yield* Effect.gen(function* () {
697699
const configuration = yield* DesktopBackendConfiguration.DesktopBackendConfiguration;
@@ -701,6 +703,8 @@ describe("DesktopBackendConfiguration", () => {
701703
assert.include((config.env.WSLENV ?? "").split(":"), "OTEL_SDK_DISABLED");
702704
assert.equal(config.env.T3CODE_TELEMETRY_ENABLED, "false");
703705
assert.include((config.env.WSLENV ?? "").split(":"), "T3CODE_TELEMETRY_ENABLED");
706+
assert.equal(config.env.OTEL_RESOURCE_ATTRIBUTES, "deployment.environment.name=staging");
707+
assert.include((config.env.WSLENV ?? "").split(":"), "OTEL_RESOURCE_ATTRIBUTES");
704708
}).pipe(
705709
Effect.provide(
706710
layerBackendConfiguration().pipe(
@@ -722,6 +726,7 @@ describe("DesktopBackendConfiguration", () => {
722726
restoreEnv("WSLENV", previousWslEnv);
723727
restoreEnv("OTEL_SDK_DISABLED", previousDisabled);
724728
restoreEnv("T3CODE_TELEMETRY_ENABLED", previousTelemetry);
729+
restoreEnv("OTEL_RESOURCE_ATTRIBUTES", previousResourceAttributes);
725730
}
726731
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
727732
);

‎apps/desktop/src/backend/DesktopBackendConfiguration.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ const WSL_FORWARDED_ENV_NAMES = [
110110
"OTEL_TRACES_EXPORTER",
111111
"OTEL_METRICS_EXPORTER",
112112
"OTEL_LOGS_EXPORTER",
113+
"OTEL_RESOURCE_ATTRIBUTES",
113114
] as const;
114115

115116
const WSL_SERVER_SYSTEM_PATH = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin";

‎apps/mobile/src/features/observability/tracing.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Constants from "expo-constants";
2+
import { type ReleaseChannel, releaseResourceAttributes } from "@t3tools/shared/releaseResource";
23
import * as RelayTracing from "@t3tools/shared/relayTracing";
34

45
import { hasTracingPublicConfig, resolveCloudPublicConfig } from "../cloud/publicConfig";
@@ -14,6 +15,12 @@ export interface TracingResource {
1415
readonly appVariant: string;
1516
}
1617

18+
const RELEASE_CHANNEL_BY_VARIANT: Readonly<Record<string, ReleaseChannel | undefined>> = {
19+
development: "dev",
20+
preview: "preview",
21+
production: "stable",
22+
};
23+
1724
export function resolveTracingConfig(): TracingConfig | null {
1825
const config = resolveCloudPublicConfig();
1926
if (!hasTracingPublicConfig(config)) {
@@ -24,11 +31,16 @@ export function resolveTracingConfig(): TracingConfig | null {
2431
}
2532

2633
export function layerFromConfig(config: TracingConfig | null, resource: TracingResource) {
34+
const channel =
35+
typeof __DEV__ !== "undefined" && __DEV__
36+
? "dev"
37+
: RELEASE_CHANNEL_BY_VARIANT[resource.appVariant];
2738
return RelayTracing.layer(config, {
2839
serviceName: "t3code-mobile",
2940
serviceVersion: resource.serviceVersion,
3041
runtime: "react-native",
3142
client: `mobile-${resource.appVariant}`,
43+
attributes: channel && releaseResourceAttributes(channel),
3244
});
3345
}
3446

‎apps/mobile/src/features/threads/use-composer-command-menu.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ import type { ComposerCommandItem } from "./ComposerCommandPopover";
5959
import { matchesSlashSkillQuery } from "./composerSlashSkillSearch";
6060

6161
const WORKSPACE_SNAPSHOT_RETRY_COOLDOWN_MS = 10_000;
62+
// A cwd that never scans, such as a deleted worktree, would otherwise retry forever.
63+
const WORKSPACE_SNAPSHOT_MAX_ATTEMPTS = 3;
6264

6365
function composerSelectionAtEnd(draftMessage: string): ComposerEditorSelection {
6466
return { start: draftMessage.length, end: draftMessage.length };
@@ -252,6 +254,7 @@ export function useComposerCommandMenu({
252254
);
253255
// Record client request time to enforce TTL even when the client clock runs ahead of the server.
254256
const workspaceRefreshKeyRef = useRef<{ key: string; requestedAt: number } | null>(null);
257+
const failedRefreshesRef = useRef<{ key: string; count: number } | null>(null);
255258
const [workspaceRefreshRetry, setWorkspaceRefreshRetry] = useState<{
256259
key: string;
257260
notBefore: number;
@@ -307,6 +310,11 @@ export function useComposerCommandMenu({
307310
workspaceRefreshKeyRef.current = request;
308311
const retryLater = () => {
309312
if (workspaceRefreshKeyRef.current !== request) return;
313+
const failed = failedRefreshesRef.current;
314+
const count = failed?.key === key ? failed.count + 1 : 1;
315+
failedRefreshesRef.current = { key, count };
316+
// Keeping the request marker lets the TTL hold off the next scan.
317+
if (count >= WORKSPACE_SNAPSHOT_MAX_ATTEMPTS) return;
310318
workspaceRefreshKeyRef.current = null;
311319
setWorkspaceRefreshRetry({
312320
key,
@@ -326,6 +334,7 @@ export function useComposerCommandMenu({
326334
projectCwd,
327335
);
328336
if (!refreshed) retryLater();
337+
else failedRefreshesRef.current = null;
329338
}, retryLater);
330339
}, [
331340
draftMessage,

‎apps/server/src/config.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,15 @@ import type { OtlpEndpointSource } from "@t3tools/contracts";
1212
import { sweepStalePendingAttachments } from "./attachmentStore.ts";
1313
import { DEFAULT_SIGNAL_EXPORT, type SignalExport } from "@t3tools/shared/observability";
1414
import * as OtelEnvironment from "@t3tools/shared/otelEnvironment";
15+
import { type ReleaseChannel, releaseResourceAttributes } from "@t3tools/shared/releaseResource";
1516
import packageJson from "../package.json" with { type: "json" };
1617

18+
// Official release workflows set this telemetry channel; other builds report dev.
19+
// Unlike __T3CODE_BUILD_CHANNEL__, this is not the sign-in page's latest/nightly channel.
20+
declare const __T3CODE_TELEMETRY_CHANNEL__: ReleaseChannel | undefined;
21+
export const telemetryChannel: ReleaseChannel =
22+
typeof __T3CODE_TELEMETRY_CHANNEL__ === "undefined" ? "dev" : __T3CODE_TELEMETRY_CHANNEL__;
23+
1724
export const DEFAULT_PORT = 3773;
1825

1926
export const RuntimeMode = Schema.Literals(["web", "desktop"]);
@@ -114,6 +121,7 @@ export const otlpResource = (
114121
"service.namespace": "t3code",
115122
"service.runtime": "t3-server",
116123
"t3code.server.managed_by": config.mode === "desktop" ? "desktop" : "standalone",
124+
...releaseResourceAttributes(telemetryChannel, config.otelEnvironment.resourceAttributes),
117125
"host.name": config.otelEnvironment.resourceAttributes["host.name"] || hostName,
118126
},
119127
});

‎apps/server/src/environment/ServerEnvironment.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ export const make = Effect.gen(function* () {
239239
threadSnooze: true,
240240
environmentThemes: true,
241241
usageLimitSources: true,
242+
providerWorkspaceSnapshotsOnDemand: true,
242243
usagePriceOverrides: true,
243244
usageModelAliases: true,
244245
threadPinning: true,

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ export const rpcRequestDuration = Metric.timer("t3_rpc_request_duration", {
1515
description: "RPC request handling duration.",
1616
});
1717

18+
export const orchestrationCommandsTotal = Metric.counter("t3_orchestration_commands_total", {
19+
description: "Total orchestration commands dispatched, by outcome.",
20+
});
21+
22+
export const orchestrationCommandDuration = Metric.timer("t3_orchestration_command_duration", {
23+
description: "Orchestration command handling duration, excluding thread dispatch lock wait.",
24+
});
25+
1826
export const orchestrationEffectClaimsTotal = Metric.counter(
1927
"t3_orchestration_effect_claims_total",
2028
{
@@ -186,3 +194,14 @@ export const withMetrics: {
186194
): <A, E, R>(effect: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
187195
<A, E, R>(effect: Effect.Effect<A, E, R>, options: WithMetricsOptions): Effect.Effect<A, E, R>;
188196
} = dual(2, withMetricsImpl);
197+
198+
// Shaped as an `Effect.fn` combinator: the command is the instrumented function's argument.
199+
export const withCommandMetrics = <A, E, R>(
200+
effect: Effect.Effect<A, E, R>,
201+
command: { readonly type: string },
202+
): Effect.Effect<A, E, R> =>
203+
withMetrics(effect, {
204+
counter: orchestrationCommandsTotal,
205+
timer: orchestrationCommandDuration,
206+
attributes: { commandType: command.type },
207+
});

‎apps/server/src/orchestration-v2/Orchestrator.control-reads.test.ts‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,15 @@ import {
2121
import * as DateTime from "effect/DateTime";
2222
import * as Effect from "effect/Effect";
2323
import * as Layer from "effect/Layer";
24+
import * as Metric from "effect/Metric";
2425
import * as Result from "effect/Result";
2526
import * as Stream from "effect/Stream";
2627
import * as TestClock from "effect/testing/TestClock";
2728
import * as SqlClient from "effect/sql/SqlClient";
29+
import {
30+
orchestrationCommandDuration,
31+
orchestrationCommandsTotal,
32+
} from "../observability/Metrics.ts";
2833
import * as SqlitePersistence from "../persistence/Sqlite.ts";
2934
import { CodexProviderCapabilitiesV2 } from "./Adapters/CodexAdapterV2.ts";
3035
import * as DelegatedTaskQuestionReactor from "./DelegatedTaskQuestionReactor.ts";
@@ -1368,3 +1373,38 @@ it.effect("explicit settle clears snooze atomically and stays idempotent after r
13681373
assert.deepInclude((yield* projections.getThreadProjection(threadId)).thread, active);
13691374
}).pipe(Effect.provide(layerTest)),
13701375
);
1376+
1377+
it.effect("dispatch records the command outcome and its duration", () =>
1378+
Effect.gen(function* () {
1379+
const orchestrator = yield* Orchestrator.OrchestratorV2;
1380+
const successes = Metric.value(
1381+
Metric.withAttributes(orchestrationCommandsTotal, {
1382+
commandType: "thread.create",
1383+
outcome: "success",
1384+
}),
1385+
);
1386+
const durations = Metric.value(
1387+
Metric.withAttributes(orchestrationCommandDuration, { commandType: "thread.create" }),
1388+
);
1389+
const successesBefore = (yield* successes).count;
1390+
const durationsBefore = (yield* durations).count;
1391+
1392+
yield* orchestrator.dispatch({
1393+
type: "thread.create",
1394+
commandId: CommandId.make("create-dispatch-metrics"),
1395+
threadId: ThreadId.make("thread:dispatch-metrics"),
1396+
projectId: ProjectId.make("project:dispatch-metrics"),
1397+
title: "Dispatch metrics",
1398+
modelSelection,
1399+
runtimeMode: "full-access",
1400+
interactionMode: "default",
1401+
branch: null,
1402+
worktreePath: null,
1403+
createdBy: "user",
1404+
creationSource: "web",
1405+
});
1406+
1407+
assert.strictEqual((yield* successes).count - successesBefore, 1);
1408+
assert.strictEqual((yield* durations).count - durationsBefore, 1);
1409+
}).pipe(Effect.provide(layerTest)),
1410+
);

0 commit comments

Comments
 (0)