Skip to content

Commit 83c970b

Browse files
committed
Merge remote-tracking branch 'github/main' into pr-29576
# Conflicts: # apps/mobile/src/features/threads/ThreadFeed.tsx # apps/mobile/src/lib/threadActivity.ts
2 parents 1d84ba4 + 2756da4 commit 83c970b

277 files changed

Lines changed: 10776 additions & 1795 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/ci.yml‎

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,41 @@ jobs:
192192
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
193193
run: node apps/desktop/scripts/verify-preload-bundle.mjs
194194

195+
# Browser tests run source modules; this boots the production chunk graph. The
196+
# desktop build above already produced apps/web/dist, and the client waits about
197+
# 15s for a session that never comes, so this runs here instead of in Test Web,
198+
# which gates the whole run. Chromium comes from the cache Test Web shares.
199+
- name: Resolve Playwright version
200+
id: playwright_version
201+
if: ${{ !cancelled() && steps.build.outcome == 'success' && needs.changes.outputs.test_web != 'false' }}
202+
run: echo "version=$(node -p "require('./apps/web/node_modules/playwright/package.json').version")" >> "$GITHUB_OUTPUT"
203+
204+
- name: Cache Chromium
205+
id: chromium_cache
206+
if: ${{ !cancelled() && steps.build.outcome == 'success' && needs.changes.outputs.test_web != 'false' }}
207+
uses: actions/cache@v6
208+
with:
209+
path: ~/.cache/ms-playwright
210+
key: playwright-chromium-shell-${{ runner.os }}-${{ runner.arch }}-${{ steps.playwright_version.outputs.version }}
211+
212+
- name: Install Chromium for the built web client boot check
213+
if: ${{ !cancelled() && steps.build.outcome == 'success' && needs.changes.outputs.test_web != 'false' && steps.chromium_cache.outputs.cache-hit != 'true' }}
214+
run: node apps/web/node_modules/playwright/cli.js install --only-shell chromium
215+
216+
- name: Install missing Chromium system dependencies
217+
if: ${{ !cancelled() && steps.build.outcome == 'success' && needs.changes.outputs.test_web != 'false' }}
218+
run: |
219+
browser=$(find "$HOME/.cache/ms-playwright" -name chrome-headless-shell -type f -print -quit)
220+
test -n "$browser"
221+
if ldd "$browser" | grep '=> not found'; then
222+
node apps/web/node_modules/playwright/cli.js install-deps chromium
223+
fi
224+
225+
- name: Boot the built web client
226+
if: ${{ !cancelled() && steps.build.outcome == 'success' && needs.changes.outputs.test_web != 'false' }}
227+
timeout-minutes: 3
228+
run: node apps/web/scripts/verify-built-boot.ts
229+
195230
- name: Typecheck
196231
if: ${{ !cancelled() && steps.typecheck.outcome == 'success' }}
197232
timeout-minutes: 5
@@ -340,12 +375,6 @@ jobs:
340375
- name: Test
341376
run: vp run --filter @t3tools/web test
342377

343-
# Browser tests run source modules; this boots the production chunk graph.
344-
- name: Boot the built web client
345-
run: |
346-
vp run --filter @t3tools/web build
347-
node apps/web/scripts/verify-built-boot.ts
348-
349378
# apps/server sets `fileParallelism: false`, so its test files run strictly
350379
# one at a time. Sharding spreads them over separate runners instead of
351380
# separate workers, so no two server test files ever share a machine and the

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

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { assert, it } from "@effect/vitest";
22
import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
33
import * as Deferred from "effect/Deferred";
44
import * as Effect from "effect/Effect";
5+
import * as Exit from "effect/Exit";
56
import * as Layer from "effect/Layer";
67
import * as FileSystem from "effect/FileSystem";
78
import * as Path from "effect/Path";
@@ -69,14 +70,19 @@ import * as ElectronWindow from "../electron/ElectronWindow.ts";
6970
import * as MacPermissions from "../permissions/MacPermissions.ts";
7071
import * as PreviewManager from "../preview/Manager.ts";
7172

72-
it.effect(
73-
"starts the backend and window while Linux registration is stalled and cancels it on shutdown",
74-
() =>
73+
it.effect.each([false, true])(
74+
"stops backends together before flushing history and cancels Linux registration, stop defect=%s",
75+
(stopDefect) =>
7576
Effect.gen(function* () {
7677
const registrationStarted = yield* Deferred.make<void>();
7778
const releaseRegistration = yield* Deferred.make<void>();
7879
const registrationStopped = yield* Deferred.make<void>();
7980
const windowStarted = yield* Deferred.make<void>();
81+
const firstStopStarted = yield* Deferred.make<void>();
82+
const secondStopStarted = yield* Deferred.make<void>();
83+
const releaseStops = yield* Deferred.make<void>();
84+
const historyStarted = yield* Deferred.make<void>();
85+
const releaseHistory = yield* Deferred.make<void>();
8086
const quitting = yield* Ref.make(false);
8187
const events: string[] = [];
8288
const record = (event: string) =>
@@ -169,7 +175,21 @@ it.effect(
169175
start: record("backend"),
170176
currentConfig: Effect.succeedSome({ preflightFailure: Option.none() }),
171177
}),
172-
list: Effect.succeed([]),
178+
list: Effect.succeed([
179+
{
180+
stop: () =>
181+
Deferred.succeed(firstStopStarted, undefined).pipe(
182+
Effect.andThen(Deferred.await(releaseStops)),
183+
Effect.andThen(stopDefect ? Effect.die("stop defect") : Effect.void),
184+
),
185+
},
186+
{
187+
stop: () =>
188+
Deferred.succeed(secondStopStarted, undefined).pipe(
189+
Effect.andThen(Deferred.await(releaseStops)),
190+
),
191+
},
192+
]),
173193
} as unknown as DesktopBackendPool.DesktopBackendPool["Service"]),
174194
Effect.provideService(DesktopServerExposure.DesktopServerExposure, {
175195
configureFromSettings: () => Effect.succeed({ mode: "local-only" }),
@@ -182,7 +202,10 @@ it.effect(
182202
start: Effect.void,
183203
} as unknown as DesktopAppActivation.DesktopAppActivation["Service"]),
184204
Effect.provideService(DesktopRendererHistory.DesktopRendererHistory, {
185-
shutdown: Effect.void,
205+
shutdown: Deferred.succeed(historyStarted, undefined).pipe(
206+
Effect.andThen(Deferred.await(releaseHistory)),
207+
Effect.asVoid,
208+
),
186209
} as DesktopRendererHistory.DesktopRendererHistory["Service"]),
187210
);
188211
const app = yield* runApp.pipe(
@@ -226,8 +249,19 @@ it.effect(
226249
yield* Deferred.await(windowStarted);
227250
assert.deepEqual(events, ["identity", "ready", "identity", "backend", "window"]);
228251
assert.isFalse(yield* Deferred.isDone(registrationStopped));
229-
yield* (yield* DesktopShutdown.DesktopShutdown).request;
230-
yield* Fiber.join(app);
252+
const shutdown = yield* DesktopShutdown.DesktopShutdown;
253+
yield* shutdown.request;
254+
yield* Deferred.await(firstStopStarted);
255+
yield* Deferred.await(secondStopStarted);
256+
assert.isFalse(yield* Deferred.isDone(historyStarted));
257+
assert.isFalse(yield* shutdown.isComplete);
258+
yield* Deferred.succeed(releaseStops, undefined);
259+
yield* Deferred.await(historyStarted);
260+
assert.isFalse(yield* shutdown.isComplete);
261+
yield* Deferred.succeed(releaseHistory, undefined);
262+
const result = yield* Fiber.await(app);
263+
assert.equal(Exit.isFailure(result), stopDefect);
264+
assert.isTrue(yield* shutdown.isComplete);
231265
assert.isTrue(yield* Deferred.isDone(registrationStopped));
232266
}).pipe(Effect.provide(DesktopShutdown.layer)),
233267
);

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as Cause from "effect/Cause";
22
import * as Config from "effect/Config";
3-
import * as Duration from "effect/Duration";
43
import * as Effect from "effect/Effect";
54
import * as Option from "effect/Option";
65
import * as Ref from "effect/Ref";
@@ -19,6 +18,7 @@ import * as DesktopClerk from "./DesktopClerk.ts";
1918
import * as DesktopApplicationMenu from "../window/DesktopApplicationMenu.ts";
2019
import * as DesktopWindow from "../window/DesktopWindow.ts";
2120
import * as PreviewPasskeys from "../preview/Passkeys.ts";
21+
import * as DesktopBackendManager from "../backend/DesktopBackendManager.ts";
2222
import * as DesktopBackendPool from "../backend/DesktopBackendPool.ts";
2323
import * as DesktopEnvironment from "./DesktopEnvironment.ts";
2424
import * as DesktopLegacyLocalStorage from "./DesktopLegacyLocalStorage.ts";
@@ -160,7 +160,7 @@ const stopAllPoolInstances = Effect.fn("desktop.app.stopAllPoolInstances")(
160160
const instances = yield* pool.list;
161161
yield* Effect.forEach(
162162
instances,
163-
(instance) => instance.stop({ timeout: Duration.seconds(5) }),
163+
(instance) => instance.stop({ timeout: DesktopBackendManager.BACKEND_QUIT_STOP_TIMEOUT }),
164164
{ concurrency: "unbounded" },
165165
);
166166
},
@@ -363,6 +363,7 @@ const scopedProgram = Effect.scoped(
363363
stopAllPoolInstances().pipe(
364364
Effect.ensuring(rendererHistory.shutdown),
365365
Effect.ensuring(shutdown.markComplete),
366+
Effect.withSpan("desktop.app.shutdown"),
366367
),
367368
);
368369

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

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,4 +720,58 @@ describe("DesktopBackendManager", () => {
720720
}).pipe(Effect.provide(TestClock.layer())),
721721
),
722722
);
723+
724+
it.effect("the quit stop deadline waits for a backend that only exits at the force kill", () =>
725+
Effect.scoped(
726+
Effect.gen(function* () {
727+
const spawned = yield* Deferred.make<void>();
728+
const teardownStarted = yield* Deferred.make<void>();
729+
const teardownFinished = yield* Deferred.make<void>();
730+
// The real spawner sends SIGTERM, waits the grace, then SIGKILLs. A backend that
731+
// ignores SIGTERM therefore finishes tearing down just after the grace.
732+
const instance = yield* makeTestInstance({
733+
spawnerLayer: Layer.succeed(
734+
ChildProcessSpawner.ChildProcessSpawner,
735+
ChildProcessSpawner.make(() =>
736+
Effect.gen(function* () {
737+
const scope = yield* Scope.Scope;
738+
yield* Deferred.succeed(spawned, undefined);
739+
yield* Scope.addFinalizer(
740+
scope,
741+
Deferred.succeed(teardownStarted, undefined).pipe(
742+
Effect.andThen(Effect.sleep(Duration.seconds(6))),
743+
Effect.andThen(Deferred.succeed(teardownFinished, undefined)),
744+
Effect.asVoid,
745+
),
746+
);
747+
return makeProcess({
748+
exitCode: Deferred.await(teardownFinished).pipe(
749+
Effect.as(ChildProcessSpawner.ExitCode(0)),
750+
),
751+
});
752+
}),
753+
),
754+
),
755+
httpClientLayer: layerHttpClient(() => Effect.never),
756+
});
757+
yield* instance.start;
758+
yield* Deferred.await(spawned);
759+
760+
// App quit and the updater stop every backend with this deadline.
761+
const quitDone = yield* Deferred.make<void>();
762+
const quitFiber = yield* instance
763+
.stop({ timeout: DesktopBackendManager.BACKEND_QUIT_STOP_TIMEOUT })
764+
.pipe(Effect.andThen(Deferred.succeed(quitDone, undefined)), Effect.forkChild);
765+
766+
yield* Deferred.await(teardownStarted);
767+
// Past the SIGTERM grace but before the force kill lands: quit must still be waiting.
768+
yield* TestClock.adjust(Duration.millis(5_500));
769+
assert.isFalse(yield* Deferred.isDone(quitDone));
770+
771+
yield* TestClock.adjust(Duration.millis(500));
772+
yield* Fiber.join(quitFiber);
773+
assert.isTrue(yield* Deferred.isDone(teardownFinished));
774+
}).pipe(Effect.provide(TestClock.layer())),
775+
),
776+
);
723777
});

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ const DEFAULT_BACKEND_READINESS_INTERVAL = Duration.millis(100);
4141
const DEFAULT_BACKEND_READINESS_REQUEST_TIMEOUT = Duration.seconds(1);
4242
// Match the service launcher's grace period so backends can stop provider sessions.
4343
const DEFAULT_BACKEND_TERMINATE_GRACE = Duration.seconds(5);
44+
// Allow SIGKILL and the spawner exit wait after the SIGTERM grace so quit cannot
45+
// orphan a backend whose shutdown hangs.
46+
export const BACKEND_QUIT_STOP_TIMEOUT = Duration.sum(
47+
DEFAULT_BACKEND_TERMINATE_GRACE,
48+
Duration.seconds(2),
49+
);
4450
const DEFAULT_BACKEND_OUTPUT_DRAIN_TIMEOUT = Duration.seconds(5);
4551
const BACKEND_READINESS_PATH = "/.well-known/t3/environment";
4652
// Three restarts without readiness is about 2 s of backoff: past a blip, early enough to help.
@@ -306,7 +312,10 @@ const closeRun = (
306312
onNone: () => Effect.void,
307313
onSome: (fiber) => Fiber.await(fiber).pipe(Effect.asVoid),
308314
});
309-
const close = Scope.close(run.scope, Exit.void).pipe(Effect.andThen(waitForFiber));
315+
const close = Scope.close(run.scope, Exit.void).pipe(
316+
Effect.withSpan("desktop.backendInstance.closeScope"),
317+
Effect.andThen(waitForFiber.pipe(Effect.withSpan("desktop.backendInstance.awaitRun"))),
318+
);
310319
const timeout = options?.timeout;
311320

312321
if (!timeout) {
@@ -567,6 +576,7 @@ export const runBackendProcess = Effect.fn("runBackendProcess")(function* (
567576
yield* probeReadiness().pipe(Effect.repeat({ while: (ready) => !ready }), Effect.forkScoped);
568577

569578
const exit = yield* handle.exitCode.pipe(
579+
Effect.withSpan("desktop.backendProcess.awaitExit"),
570580
Effect.map((exitCode) => ({
571581
code: Option.some(exitCode),
572582
reason: `code=${exitCode}`,
@@ -602,6 +612,7 @@ export const runBackendProcess = Effect.fn("runBackendProcess")(function* (
602612
}).pipe(
603613
Effect.timeout(options.outputDrainTimeout ?? DEFAULT_BACKEND_OUTPUT_DRAIN_TIMEOUT),
604614
Effect.ignore,
615+
Effect.withSpan("desktop.backendProcess.drainOutput"),
605616
);
606617
if (Exit.isFailure(exit)) {
607618
return yield* Effect.failCause(exit.cause);

‎apps/desktop/src/settings/DesktopAppSettings.test.ts‎

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -200,16 +200,22 @@ describe("DesktopSettings", () => {
200200
withSettings(
201201
Effect.gen(function* () {
202202
const settings = yield* DesktopAppSettings.DesktopAppSettings;
203-
yield* writeSettingsPatch({
204-
mainWindowBounds: { x: 10.5, y: 20, width: 839, height: 620 },
205-
mainWindowMaximized: true,
206-
serverExposureMode: "network-accessible",
207-
});
208-
209-
const loaded = yield* settings.load;
210-
assert.isNull(loaded.mainWindowBounds);
211-
assert.isFalse(loaded.mainWindowMaximized);
212-
assert.equal(loaded.serverExposureMode, "network-accessible");
203+
for (const bounds of [
204+
{ x: 10.5, y: 20, width: 400, height: 360 },
205+
{ x: 10, y: 20, width: 399, height: 360 },
206+
{ x: 10, y: 20, width: 400, height: 359 },
207+
]) {
208+
yield* writeSettingsPatch({
209+
mainWindowBounds: bounds,
210+
mainWindowMaximized: true,
211+
serverExposureMode: "network-accessible",
212+
});
213+
214+
const loaded = yield* settings.load;
215+
assert.isNull(loaded.mainWindowBounds);
216+
assert.isFalse(loaded.mainWindowMaximized);
217+
assert.equal(loaded.serverExposureMode, "network-accessible");
218+
}
213219
}),
214220
),
215221
);
@@ -221,17 +227,24 @@ describe("DesktopSettings", () => {
221227
const fileSystem = yield* FileSystem.FileSystem;
222228
const settings = yield* DesktopAppSettings.DesktopAppSettings;
223229

224-
yield* settings.setMainWindowBounds({ x: -1200, y: 40, width: 1440, height: 960 }, true);
230+
yield* settings.setMainWindowBounds({ x: -1200, y: 40, width: 400, height: 360 }, true);
225231
yield* settings.setServerExposureMode("network-accessible");
226232

227233
const persisted = yield* decodeDesktopSettingsPatch(
228234
yield* fileSystem.readFileString(environment.desktopSettingsPath),
229235
);
230236
assert.deepEqual(persisted, {
231-
mainWindowBounds: { x: -1200, y: 40, width: 1440, height: 960 },
237+
mainWindowBounds: { x: -1200, y: 40, width: 400, height: 360 },
232238
mainWindowMaximized: true,
233239
serverExposureMode: "network-accessible",
234240
} satisfies typeof DesktopSettingsPatch.Type);
241+
242+
const restored = yield* Effect.gen(function* () {
243+
const freshSettings = yield* DesktopAppSettings.DesktopAppSettings;
244+
return yield* freshSettings.load;
245+
}).pipe(Effect.provide(DesktopAppSettings.layer));
246+
assert.deepEqual(restored.mainWindowBounds, persisted.mainWindowBounds);
247+
assert.isTrue(restored.mainWindowMaximized);
235248
}),
236249
),
237250
);

‎apps/desktop/src/settings/DesktopAppSettings.ts‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,12 @@ export interface DesktopSettingsChange {
4747
}
4848

4949
const DEFAULT_TAILSCALE_SERVE_PORT = 443;
50-
const MIN_MAIN_WINDOW_SIZE = {
51-
width: 840,
52-
height: 620,
50+
// Fits half and third tiles of common scaled displays (down to 480x432 DIP) on
51+
// Wayland, where Electron's client-side frame adds 32x42 DIP to the enforced
52+
// minimum. The web layout already handles phone widths.
53+
export const MIN_MAIN_WINDOW_SIZE = {
54+
width: 400,
55+
height: 360,
5356
} as const;
5457
export const DesktopWindowBoundsSchema = Schema.Struct({
5558
x: Schema.Int,

‎apps/desktop/src/telemetry/DesktopRendererHistory.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,11 @@ const make = Effect.fn("DesktopRendererHistory.make")(function* () {
273273
accepting = false;
274274
for (const renderer of active.values()) renderer.removeListeners();
275275
active.clear();
276-
}).pipe(Effect.andThen(Fiber.interrupt(writerFiber)), Effect.asVoid);
276+
}).pipe(
277+
Effect.andThen(Fiber.interrupt(writerFiber)),
278+
Effect.asVoid,
279+
Effect.withSpan("desktop.rendererHistory.shutdown"),
280+
);
277281
yield* Effect.addFinalizer(() => shutdown);
278282

279283
return DesktopRendererHistory.of({ register, recordMetrics, shutdown });

‎apps/desktop/src/updates/DesktopUpdates.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import * as Scope from "effect/Scope";
2525
import * as Semaphore from "effect/Semaphore";
2626
import * as Stream from "effect/Stream";
2727

28+
import * as DesktopBackendManager from "../backend/DesktopBackendManager.ts";
2829
import * as DesktopBackendPool from "../backend/DesktopBackendPool.ts";
2930
import * as DesktopConfig from "../app/DesktopConfig.ts";
3031
import * as DesktopEnvironment from "../app/DesktopEnvironment.ts";
@@ -819,7 +820,8 @@ export const make = Effect.gen(function* () {
819820
yield* Ref.set(installRunningBackendsRef, runningInstances);
820821
yield* Effect.forEach(
821822
instances,
822-
(instance) => instance.stop({ timeout: Duration.seconds(5) }),
823+
(instance) =>
824+
instance.stop({ timeout: DesktopBackendManager.BACKEND_QUIT_STOP_TIMEOUT }),
823825
{ concurrency: "unbounded" },
824826
);
825827
yield* electronUpdater.quitAndInstall({

‎apps/desktop/src/window/DesktopWindow.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,8 @@ export const make = Effect.gen(function* () {
399399
if (yield* Ref.get(desktopState.quitting)) return Option.none();
400400
const window = yield* electronWindow.create({
401401
...initialBounds,
402-
minWidth: 840,
403-
minHeight: 620,
402+
minWidth: DesktopAppSettings.MIN_MAIN_WINDOW_SIZE.width,
403+
minHeight: DesktopAppSettings.MIN_MAIN_WINDOW_SIZE.height,
404404
show: false,
405405
autoHideMenuBar: true,
406406
...(environment.platform === "darwin" ? { disableAutoHideCursor: true } : {}),

0 commit comments

Comments
 (0)