Skip to content

Commit e907266

Browse files
Merge main into fix/issue-14967
2 parents c93d54e + 7d87be3 commit e907266

566 files changed

Lines changed: 20136 additions & 9480 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.

‎.devcontainer/devcontainer.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Dev container for T3 Code. Mirrors CI (ubuntu-24.04, Node 24, Rust stable)
1+
// Dev container for T3 Code. Mirrors CI (ubuntu-24.04, Node 26, Rust stable)
22
// and the canonical setup in docs/operations/development.md: global `vp`, `vp i`.
33
// Contributor doc: docs/internals/devcontainer.md
44
{
@@ -8,7 +8,7 @@
88
// nodeGypDependencies (default true) brings python3/make/g++, which Linux
99
// needs for node-pty's node-gyp fallback (its prebuilds are mac/win only).
1010
"ghcr.io/devcontainers/features/node:2": {
11-
"version": "24"
11+
"version": "26"
1212
},
1313
// native/resource-monitor (edition 2024, needs stable >= 1.85). The server
1414
// degrades gracefully without the binary, but CI checks cargo fmt + test.

‎.github/actions/setup-ci-deps/action.yml‎

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,38 @@ description: Install Vite+ and the workspace dependencies from cache.
33
runs:
44
using: composite
55
steps:
6-
# setup-vp reuses an installed exact version, so restoring its home skips the
7-
# installer download on every job.
6+
# ~/.vite-plus holds vp, the Node.js runtime, and pnpm. A cache entry never
7+
# updates, so the key names all three versions; otherwise a pnpm or Node.js
8+
# bump makes every job download them from npm again.
89
- name: Resolve Vite+ version
910
id: vp
1011
shell: bash
1112
run: |
1213
echo "version=$(sed -nE 's/^ vite-plus: ([0-9][^ ]*)$/\1/p' pnpm-workspace.yaml)" >> "$GITHUB_OUTPUT"
14+
echo "node=$(jq -r '.engines.node' package.json)" >> "$GITHUB_OUTPUT"
15+
echo "pnpm=$(jq -r '.packageManager' package.json)" >> "$GITHUB_OUTPUT"
1316
1417
- name: Cache Vite+
18+
id: vp_cache
1519
if: steps.vp.outputs.version != ''
1620
uses: actions/cache@v6
1721
with:
1822
path: ~/.vite-plus
19-
key: vite-plus-home-v1-${{ runner.os }}-${{ runner.arch }}-${{ steps.vp.outputs.version }}
23+
key: vite-plus-home-v2-${{ runner.os }}-${{ runner.arch }}-${{ steps.vp.outputs.version }}-node${{ steps.vp.outputs.node }}-${{ steps.vp.outputs.pnpm }}
24+
25+
# setup-vp always runs the installer, which fetches vp from npm even when
26+
# this exact version is installed. A cache hit already has everything, so
27+
# skip setup-vp and do its remaining work here. This keeps npm outages from
28+
# failing jobs.
29+
- name: Use cached Vite+
30+
if: steps.vp_cache.outputs.cache-hit == 'true'
31+
shell: bash
32+
run: |
33+
echo "$HOME/.vite-plus/bin" >> "$GITHUB_PATH"
34+
"$HOME/.vite-plus/bin/vp" env use "${{ steps.vp.outputs.node }}"
2035
2136
- name: Setup Vite+
37+
if: steps.vp_cache.outputs.cache-hit != 'true'
2238
uses: voidzero-dev/setup-vp@v1
2339
with:
2440
node-version-file: package.json

‎.github/workflows/mobile-showcase-screenshots.yml‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ env:
4343

4444
jobs:
4545
ios:
46-
name: iPhone 6.9, iPhone 6.5, and iPad 13
46+
name: iPhone, iPhone Duo, and iPad 13
4747
if: inputs.platform == 'all' || inputs.platform == 'ios'
4848
runs-on: blacksmith-12vcpu-macos-26
4949
# Capturing every palette multiplies the device matrix by six, and only the
@@ -87,6 +87,9 @@ jobs:
8787
brew install cameroncooke/axe/axe
8888
axe --version
8989
90+
- name: Install foldable simulator controls
91+
run: npm install --global [email protected]
92+
9093
- name: Capture iOS showcase
9194
run: pnpm screenshots:mobile --platform ios --appearance "${{ inputs.appearance }}" --theme "${{ inputs.theme }}"
9295

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Close stale "needs more info" issues
2+
3+
on:
4+
schedule:
5+
- cron: "17 6 * * *"
6+
workflow_dispatch:
7+
8+
permissions:
9+
actions: write
10+
issues: write
11+
12+
jobs:
13+
stale:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/stale@v9
17+
with:
18+
only-issue-labels: "needs more info"
19+
# The label is applied by the triage flow, so never auto-mark; close 7 days after it was added.
20+
days-before-issue-stale: -1
21+
days-before-issue-close: 7
22+
days-before-pr-stale: -1
23+
days-before-pr-close: -1
24+
remove-issue-stale-when-updated: true
25+
stale-issue-label: "needs more info"
26+
close-issue-reason: not_planned
27+
close-issue-message: >-
28+
Closing: no reply in 7 days after we asked for more information.
29+
Comment with the missing details and we will reopen.
30+
operations-per-run: 200

‎.pnpmfile.cjs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@
55
// Release scripts stage their own installs with explicit architectures.
66
module.exports = {
77
hooks: {
8+
// `typescript` is @tsc-rs/typescript (the catalog entry). Its npm version (0.8.x) is outside
9+
// vite-plus-core's typescript peer range, so pnpm gave the vite-plus that @effect/vitest
10+
// imports apps/marketing's [email protected] instead, and tests loaded a second vitest.
11+
readPackage(pkg) {
12+
if (pkg.name === "@voidzero-dev/vite-plus-core" && pkg.peerDependencies?.typescript) {
13+
pkg.peerDependencies.typescript = "*";
14+
}
15+
return pkg;
16+
},
817
updateConfig(config) {
918
// oxlint-disable-next-line t3code/no-global-process-runtime -- pnpm loads this file before any Effect runtime exists.
1019
if (process.platform !== "win32") return config;

‎AGENTS.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ An empty database is a bad test. Seed your worktree's `.t3` with a copy of real
100100

101101
- Before you push, run `vp run check:changed`. It runs CI's fast checks for changed files: format, lint, knip, typecheck of affected packages and dependents, and tests beside changes. CI still runs the full test suites.
102102
- While you iterate, run `vp test run <files>`. For big files, add `-t "<name>"`.
103-
- Do not use `npx tsc`. Use `vp run typecheck`; it uses tsc-rs, which is 3x faster.
103+
- Use `vp run typecheck`, not `npx tsc`; it caches per package. Both run tsc-rs (`typescript` is the `@tsc-rs/typescript` drop-in).
104104
- Run `node -e` snippets from `apps/server` or the owning package. `effect` does not resolve from the repo root.
105105
- Test meaningful logic or observable behavior. Do not render components to static markup to assert props or attributes, or add tests that merely assert callback wiring or mirror the implementation.
106106
- **Do not run repo-wide checks.** No `vp check`, no `vp run -r test`, no `vp run -r typecheck` unless I ask. CI owns the full suite.
@@ -139,6 +139,7 @@ For authorized mobile verification, a missing or outdated native client is a bui
139139
## Pull requests
140140

141141
- Never make a PR unless the developer explicitly asks you to do so.
142+
- If `origin` is git.cafe, follow [GitCafe mirror](docs/operations/development.md#gitcafe-mirror-optional): use `cafe` for existing PRs, issues, comments and labels, but push and open PRs on GitHub, where CI runs.
142143
- Conventional commit titles, plain language: `fix(web): new threads no longer spike CPU`.
143144
- Body: the problem in a sentence or two, then how you fixed it. End with the model and harness that did the work.
144145
- UI changes need before/after images. Motion or timing needs a short video.

‎apps/desktop/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@t3tools/desktop",
3-
"version": "0.1.1",
3+
"version": "0.1.2",
44
"private": true,
55
"type": "module",
66
"main": "dist-electron/boot.cjs",

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

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as Deferred from "effect/Deferred";
33
import * as Effect from "effect/Effect";
44
import * as Layer from "effect/Layer";
55
import * as Ref from "effect/Ref";
6+
import * as TestClock from "effect/testing/TestClock";
67

78
import type * as Electron from "electron";
89

@@ -18,6 +19,7 @@ import * as DesktopWindow from "../window/DesktopWindow.ts";
1819
function layerElectronApp(
1920
appListeners: Map<string, (...args: readonly unknown[]) => void>,
2021
quit: Effect.Effect<void> = Effect.void,
22+
exit: (code: number) => Effect.Effect<void> = () => Effect.void,
2123
) {
2224
const registerListener = (eventName: string, listener: (...args: readonly unknown[]) => void) =>
2325
Effect.acquireRelease(
@@ -37,7 +39,7 @@ function layerElectronApp(
3739
whenReady: Effect.void,
3840
requestSingleInstanceLock: Effect.succeed(true),
3941
quit,
40-
exit: () => Effect.void,
42+
exit,
4143
relaunch: () => Effect.void,
4244
setPath: () => Effect.void,
4345
setName: () => Effect.void,
@@ -221,6 +223,60 @@ describe("DesktopLifecycle", () => {
221223
}),
222224
);
223225

226+
it.effect("exits on a repeated quit only once shutdown has stalled", () =>
227+
Effect.gen(function* () {
228+
const appListeners = new Map<string, (...args: readonly unknown[]) => void>();
229+
const exitCodes: number[] = [];
230+
const exit = (code: number) =>
231+
Effect.sync(() => {
232+
exitCodes.push(code);
233+
});
234+
const layerEnvironment = Layer.succeed(DesktopEnvironment.DesktopEnvironment, {
235+
platform: "darwin",
236+
isDevelopment: false,
237+
} as DesktopEnvironment.DesktopEnvironment["Service"]);
238+
const layer = DesktopLifecycle.layer.pipe(
239+
Layer.provideMerge(layerElectronApp(appListeners, Effect.void, exit)),
240+
Layer.provideMerge(layerElectronTheme),
241+
Layer.provideMerge(layerElectronWindow()),
242+
Layer.provideMerge(layerDesktopWindow()),
243+
Layer.provideMerge(layerEnvironment),
244+
// Nothing marks this shutdown complete, so it stays pending.
245+
Layer.provideMerge(DesktopShutdown.layer),
246+
Layer.provideMerge(DesktopState.layer),
247+
);
248+
249+
yield* Effect.scoped(
250+
Effect.gen(function* () {
251+
const lifecycle = yield* DesktopLifecycle.DesktopLifecycle;
252+
yield* lifecycle.register;
253+
254+
let prevented = 0;
255+
const event = {
256+
preventDefault: () => {
257+
prevented += 1;
258+
},
259+
} as Electron.Event;
260+
appListeners.get("before-quit")?.(event);
261+
appListeners.get("before-quit")?.(event);
262+
yield* TestClock.adjust("9999 millis");
263+
appListeners.get("before-quit")?.(event);
264+
assert.deepEqual(
265+
exitCodes,
266+
[],
267+
"a repeat before the threshold must not cut shutdown short",
268+
);
269+
270+
yield* TestClock.adjust("1 millis");
271+
appListeners.get("before-quit")?.(event);
272+
273+
assert.deepEqual(exitCodes, [0]);
274+
assert.equal(prevented, 4);
275+
}),
276+
).pipe(Effect.provide(layer));
277+
}),
278+
);
279+
224280
it.effect("ignores app activation while quitting", () =>
225281
Effect.gen(function* () {
226282
const appListeners = new Map<string, (...args: readonly unknown[]) => void>();

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

Lines changed: 58 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import * as Clock from "effect/Clock";
12
import * as Context from "effect/Context";
3+
import * as Duration from "effect/Duration";
24
import * as Effect from "effect/Effect";
35
import * as Layer from "effect/Layer";
46
import * as Ref from "effect/Ref";
@@ -94,15 +96,50 @@ const requestDesktopShutdownAndWait = Effect.fn("desktop.lifecycle.requestShutdo
9496
},
9597
);
9698

99+
interface QuitState {
100+
phase: "running" | "waiting" | "allowed";
101+
waitingSinceNanos: bigint;
102+
}
103+
104+
// Longer than a backend's stop budget (SIGTERM, 5s grace, SIGKILL, 1s wait),
105+
// so a double Cmd-Q at the start of a normal quit cannot cut the backend stop
106+
// short and orphan it.
107+
const SHUTDOWN_STALL_THRESHOLD = Duration.seconds(10);
108+
109+
const startWaitingForShutdown = Effect.fn("desktop.lifecycle.startWaitingForShutdown")(function* (
110+
quit: QuitState,
111+
) {
112+
quit.phase = "waiting";
113+
quit.waitingSinceNanos = yield* Clock.monotonicTimeNanos;
114+
});
115+
116+
// While a quit waits on shutdown, `quitting` makes activation open nothing. If
117+
// that shutdown stalls, a repeated Quit or SIGTERM is the user's only way out
118+
// short of SIGKILL.
119+
const exitIfShutdownStalled = Effect.fn("desktop.lifecycle.exitIfShutdownStalled")(function* (
120+
quit: QuitState,
121+
source: string,
122+
) {
123+
const pendingMs = Number(
124+
((yield* Clock.monotonicTimeNanos) - quit.waitingSinceNanos) / 1_000_000n,
125+
);
126+
if (pendingMs < Duration.toMillis(SHUTDOWN_STALL_THRESHOLD)) {
127+
yield* logLifecycleInfo("quit already in progress", { source, pendingMs });
128+
return;
129+
}
130+
yield* logLifecycleError("desktop shutdown stalled; exiting without it", { source, pendingMs });
131+
const electronApp = yield* ElectronApp.ElectronApp;
132+
yield* electronApp.exit(0);
133+
});
134+
97135
function handleBeforeQuit(
98136
event: Electron.Event,
99137
runEffect: <A, E>(
100138
effect: Effect.Effect<A, E, DesktopLifecycleRegistrationServices>,
101139
) => Promise<A>,
102-
allowQuit: () => boolean,
103-
markQuitAllowed: () => void,
140+
quit: QuitState,
104141
): void {
105-
if (allowQuit()) {
142+
if (quit.phase === "allowed") {
106143
void runEffect(
107144
Effect.gen(function* () {
108145
const state = yield* DesktopState.DesktopState;
@@ -114,10 +151,15 @@ function handleBeforeQuit(
114151
}
115152

116153
event.preventDefault();
154+
if (quit.phase === "waiting") {
155+
void runEffect(exitIfShutdownStalled(quit, "before-quit"));
156+
return;
157+
}
117158
void runEffect(
118159
Effect.gen(function* () {
119160
const state = yield* DesktopState.DesktopState;
120161
const electronWindow = yield* ElectronWindow.ElectronWindow;
162+
yield* startWaitingForShutdown(quit);
121163
yield* Ref.set(state.quitting, true);
122164
yield* logLifecycleInfo("before-quit received");
123165
yield* requestDesktopShutdownAndWait(
@@ -129,7 +171,7 @@ function handleBeforeQuit(
129171
);
130172
}).pipe(Effect.withSpan("desktop.lifecycle.beforeQuit")),
131173
).finally(() => {
132-
markQuitAllowed();
174+
quit.phase = "allowed";
133175
void runEffect(
134176
Effect.gen(function* () {
135177
const electronApp = yield* ElectronApp.ElectronApp;
@@ -144,16 +186,23 @@ function quitFromSignal(
144186
runEffect: <A, E>(
145187
effect: Effect.Effect<A, E, DesktopLifecycleRegistrationServices>,
146188
) => Promise<A>,
189+
quit: QuitState,
147190
): void {
191+
if (quit.phase === "waiting") {
192+
void runEffect(exitIfShutdownStalled(quit, signal));
193+
return;
194+
}
148195
void runEffect(
149196
Effect.gen(function* () {
150197
yield* Effect.annotateCurrentSpan({ signal });
151198
const electronApp = yield* ElectronApp.ElectronApp;
152199
const state = yield* DesktopState.DesktopState;
153200
const wasQuitting = yield* Ref.getAndSet(state.quitting, true);
154201
if (wasQuitting) return;
202+
yield* startWaitingForShutdown(quit);
155203
yield* logLifecycleInfo("process signal received", { signal });
156204
yield* requestDesktopShutdownAndWait();
205+
quit.phase = "allowed";
157206
yield* electronApp.quit;
158207
}).pipe(Effect.withSpan("desktop.lifecycle.processSignal")),
159208
);
@@ -196,8 +245,7 @@ export const make = DesktopLifecycle.of({
196245
const environment = yield* DesktopEnvironment.DesktopEnvironment;
197246
const context = yield* Effect.context<DesktopLifecycleRegistrationServices>();
198247
const runEffect = Effect.runPromiseWith(context);
199-
let quitAllowed = false;
200-
let updaterQuitAllowed = false;
248+
const quit: QuitState = { phase: "running", waitingSinceNanos: 0n };
201249
yield* electronTheme.onUpdated(() => {
202250
void runEffect(
203251
desktopWindow.syncAppearance.pipe(Effect.withSpan("desktop.lifecycle.themeUpdated")),
@@ -207,7 +255,7 @@ export const make = DesktopLifecycle.of({
207255
// Electron's updater owns the remaining quit/install/relaunch sequence.
208256
// Cancelling the following app "before-quit" event breaks that sequence,
209257
// most visibly on macOS where the native updater performs the relaunch.
210-
updaterQuitAllowed = true;
258+
quit.phase = "allowed";
211259
// This event is synchronous and the updater's quit proceeds as soon as
212260
// the listener returns, so a forked destroyAll would race the quit
213261
// and windows could still be open when the process exits (visible on
@@ -223,14 +271,7 @@ export const make = DesktopLifecycle.of({
223271
);
224272
});
225273
yield* electronApp.on("before-quit", (event: Electron.Event) => {
226-
handleBeforeQuit(
227-
event,
228-
runEffect,
229-
() => quitAllowed || updaterQuitAllowed,
230-
() => {
231-
quitAllowed = true;
232-
},
233-
);
274+
handleBeforeQuit(event, runEffect, quit);
234275
});
235276
yield* electronApp.on("activate", () => {
236277
void runEffect(
@@ -255,10 +296,10 @@ export const make = DesktopLifecycle.of({
255296

256297
if (environment.platform !== "win32") {
257298
yield* addScopedListener(process, "SIGINT", () => {
258-
quitFromSignal("SIGINT", runEffect);
299+
quitFromSignal("SIGINT", runEffect, quit);
259300
});
260301
yield* addScopedListener(process, "SIGTERM", () => {
261-
quitFromSignal("SIGTERM", runEffect);
302+
quitFromSignal("SIGTERM", runEffect, quit);
262303
});
263304
}
264305
}).pipe(Effect.withSpan("desktop.lifecycle.register")),

0 commit comments

Comments
 (0)