Skip to content

Commit d4d2539

Browse files
Merge origin/main into fix/delegated-pr-watch-follow-up
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2 parents 980d989 + 95cb068 commit d4d2539

296 files changed

Lines changed: 8062 additions & 2606 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.

‎.gitignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,5 @@ node_modules/
4949

5050
# pnpm content-addressable store; never belongs in the repo.
5151
.pnpm-store/
52+
53+
/packages/ssh/.ssh-launcher-test-*/

‎AGENTS.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ The most common defect in this repo is a change that works on the path you teste
8383
- Ports derive from the worktree path and are stable across restarts, but read the real ones from the `[dev-runner]` line since occupied ports shift.
8484
- Sharing over the tailnet is three steps: run `vp run dev --share` in the background, wait for the `pairingUrl:` line in its output, then give that full URL to an unpaired browser. Do not wire up `tailscale serve` by hand, open the URL yourself, or consume the user's pairing link. A browser with the reusable dev cookie can use the bare origin. If a normal one-time token was consumed, mint a fresh one with `node apps/server/src/bin.ts pair`. It carries standard scopes, while the startup URL carries admin scopes needed for Connections settings.
8585
- To reuse web dev auth across worktrees, configure one fixed `T3CODE_DEV_AUTH_TOKEN` in the main checkout's gitignored `.env`. The `t3.json` setup links that file into worktrees. Never commit or publish the token or a startup URL. See [Reusable dev credential](docs/operations/development.md#reusable-dev-credential).
86-
- Stop what you started, by the PID you tracked. See rule 1.
86+
- Stop what you started, by the PID you tracked. See rule 1. `vp` does not pass SIGTERM on, so signalling the `vp run dev` PID alone leaves Vite and the server running. Stop the background task with your harness's own stop, which ends the whole tree.
87+
- Run dev servers, Metro, and builds from your own shell so they end with your session. Do not detach them with `systemd-run`, `nohup`, `setsid`, or `tmux` unless the user asks for one that outlives the session. Detached servers ran for weeks and filled RAM and swap. The dev runner stops itself above `--memory-limit-gb` (half of RAM, at most 16 GiB) on Linux.
8788
- Need a second checkout? `git worktree add` it next to this worktree, not in `/tmp`. Remove it when done.
8889

8990
## Test data
@@ -149,7 +150,7 @@ For mobile verification, a missing or outdated native client is an install step,
149150
## Pull requests
150151

151152
- Never make a PR unless the developer explicitly asks you to do so.
152-
- If `origin` is git.cafe, follow [GitCafe mirror](docs/operations/development.md#gitcafe-mirror-optional): push to `origin`, open and track PRs with `cafe` and their git.cafe URLs, and keep `gh` for merging.
153+
- `origin` is not always GitHub. Check `git remote get-url origin` before your first forge command and use that forge's CLI and skill. See [Forge mirror](docs/operations/development.md#forge-mirror-optional).
153154
- Conventional commit titles, plain language: `fix(web): new threads no longer spike CPU`.
154155
- Body: the problem in a sentence or two, then how you fixed it. End with the model and harness that did the work.
155156
- UI changes need before/after images. Motion or timing needs a short video.

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

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ import {
55
type DesktopBackendBootstrap as DesktopBackendBootstrapValue,
66
DesktopTelemetryControlMessage,
77
} from "@t3tools/contracts";
8+
import {
9+
DATABASE_MIGRATION_PROGRESS_MESSAGE,
10+
DATABASE_MIGRATIONS_FINISHED_MESSAGE,
11+
DATABASE_MIGRATIONS_STARTED_MESSAGE,
12+
} from "@t3tools/shared/databaseMigrationLog";
813
import { assert, describe, it } from "@effect/vitest";
914
import * as Deferred from "effect/Deferred";
1015
import * as Duration from "effect/Duration";
@@ -688,12 +693,21 @@ describe("DesktopBackendManager", () => {
688693
Effect.scoped(
689694
Effect.gen(function* () {
690695
const reports = yield* Queue.unbounded<DesktopBackendManager.BackendStartupFailure>();
691-
const startInstance = (status: Ref.Ref<number>, onReady?: Effect.Effect<void>) =>
696+
const startInstance = (
697+
status: Ref.Ref<number>,
698+
onReady?: Effect.Effect<void>,
699+
stdout = "",
700+
) =>
692701
makeTestInstance({
693702
spawnerLayer: Layer.succeed(
694703
ChildProcessSpawner.ChildProcessSpawner,
695704
ChildProcessSpawner.make(() =>
696-
Effect.succeed(makeProcess({ exitCode: Effect.never })),
705+
Effect.succeed(
706+
makeProcess({
707+
exitCode: Effect.never,
708+
stdout: Stream.make(new TextEncoder().encode(stdout)),
709+
}),
710+
),
697711
),
698712
),
699713
httpClientLayer: layerHttpClient((request) =>
@@ -712,7 +726,30 @@ describe("DesktopBackendManager", () => {
712726
yield* Deferred.await(ready);
713727
assert.isTrue(Option.isNone(yield* Queue.poll(reports)));
714728

715-
yield* startInstance(yield* Ref.make(503));
729+
const migratingStatus = yield* Ref.make(503);
730+
const migrated = yield* Deferred.make<void>();
731+
yield* startInstance(
732+
migratingStatus,
733+
Deferred.succeed(migrated, undefined).pipe(Effect.asVoid),
734+
// Enough progress lines that the start line scrolls out of the output tail.
735+
`INFO ${DATABASE_MIGRATIONS_STARTED_MESSAGE}\n` +
736+
Array.from(
737+
{ length: 80 },
738+
(_, index) =>
739+
`INFO ${DATABASE_MIGRATION_PROGRESS_MESSAGE} migration=${index}_Migration progress="${index + 1} of 80"\n`,
740+
).join(""),
741+
);
742+
yield* TestClock.adjust(Duration.minutes(10));
743+
assert.isTrue(Option.isNone(yield* Queue.poll(reports)));
744+
yield* Ref.set(migratingStatus, 200);
745+
yield* TestClock.adjust(Duration.millis(100));
746+
yield* Deferred.await(migrated);
747+
748+
yield* startInstance(
749+
yield* Ref.make(503),
750+
undefined,
751+
`${DATABASE_MIGRATIONS_STARTED_MESSAGE}\n${DATABASE_MIGRATIONS_FINISHED_MESSAGE}\n`,
752+
);
716753
yield* TestClock.adjust(Duration.seconds(179));
717754
assert.isTrue(Option.isNone(yield* Queue.poll(reports)));
718755
yield* TestClock.adjust(Duration.seconds(1));

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
DesktopTelemetryControlMessage,
2626
type DesktopTelemetryControlMessage as DesktopTelemetryControlMessageValue,
2727
} from "@t3tools/contracts";
28+
import { isRunningDatabaseMigrations } from "@t3tools/shared/databaseMigrationLog";
2829
import { waitForHttpReady as waitForHttpReadyShared } from "@t3tools/shared/httpReadiness";
2930

3031
import * as DesktopObservability from "../app/DesktopObservability.ts";
@@ -204,7 +205,7 @@ interface RunBackendProcessOptions extends DesktopBackendStartConfig {
204205
readonly outputDrainTimeout?: Duration.Duration;
205206
readonly onStarted?: (pid: number) => Effect.Effect<void>;
206207
readonly onExitObserved?: () => Effect.Effect<void>;
207-
readonly onReady?: () => Effect.Effect<void>;
208+
readonly onReady?: (pid: number) => Effect.Effect<void>;
208209
readonly onReadinessFailure?: (error: BackendReadinessTimeoutError) => Effect.Effect<void>;
209210
readonly onOutput?: (
210211
streamName: BackendProcessOutputStream,
@@ -251,8 +252,8 @@ export interface BackendInstanceSpec {
251252
readonly id: BackendInstanceId;
252253
readonly label: Effect.Effect<string>;
253254
readonly configResolve: Effect.Effect<DesktopBackendStartConfig, PlatformError.PlatformError>;
254-
/** Receives the ready run's resolved URL; reading current config could race a subsequent restart. */
255-
readonly onReady?: (httpBaseUrl: URL) => Effect.Effect<void>;
255+
/** Receives the ready run's URL and pid; reading current config could race a subsequent restart. */
256+
readonly onReady?: (httpBaseUrl: URL, pid: number) => Effect.Effect<void>;
256257
readonly onShutdown?: () => Effect.Effect<void>;
257258
readonly onPreflightFailed?: (failure: PreflightFailure) => Effect.Effect<boolean>;
258259
readonly onStateDirOwned?: () => Effect.Effect<void>;
@@ -577,7 +578,7 @@ export const runBackendProcess = Effect.fn("runBackendProcess")(function* (
577578
httpBaseUrl: options.httpBaseUrl,
578579
timeout: options.readinessTimeout ?? DEFAULT_BACKEND_READINESS_TIMEOUT,
579580
}).pipe(
580-
Effect.flatMap(() => options.onReady?.() ?? Effect.void),
581+
Effect.flatMap(() => options.onReady?.(handle.pid) ?? Effect.void),
581582
Effect.as(true),
582583
Effect.catchTags({
583584
BackendReadinessTimeoutError: (error) =>
@@ -938,7 +939,7 @@ export const makeBackendInstance = Effect.fn("makeBackendInstance")(function* (
938939
...run,
939940
exitObserved: true,
940941
})),
941-
onReady: Effect.fn("desktop.backendInstance.onReady")(function* () {
942+
onReady: Effect.fn("desktop.backendInstance.onReady")(function* (pid) {
942943
const isCurrentRun = yield* SubscriptionRef.modify(state, (latest) => {
943944
const activeRun = Option.getOrUndefined(latest.active);
944945
if (activeRun?.id !== runId) {
@@ -958,7 +959,7 @@ export const makeBackendInstance = Effect.fn("makeBackendInstance")(function* (
958959
return;
959960
}
960961

961-
yield* spec.onReady?.(config.value.httpBaseUrl) ?? Effect.void;
962+
yield* spec.onReady?.(config.value.httpBaseUrl, pid) ?? Effect.void;
962963
if (
963964
config.value.runningDistro !== undefined &&
964965
config.value.wslRuntimeId !== undefined
@@ -971,6 +972,12 @@ export const makeBackendInstance = Effect.fn("makeBackendInstance")(function* (
971972
}),
972973
onReadinessFailure: Effect.fn("desktop.backendInstance.onReadinessFailure")(
973974
function* (error) {
975+
if (isRunningDatabaseMigrations(yield* Ref.get(outputTail))) {
976+
yield* logInstanceWarning("backend is still migrating its database; waiting", {
977+
error: error.message,
978+
});
979+
return;
980+
}
974981
yield* logInstanceWarning("backend readiness check failed during bootstrap", {
975982
error: error.message,
976983
});

0 commit comments

Comments
 (0)