Compare commits

..
Author SHA1 Message Date
Cursor AgentandJulius Marminge ebbd80dee7 Normalize readiness duration inputs
Co-authored-by: Julius Marminge <[email protected]>
2026-05-27 16:10:08 +00:00
Cursor AgentandJulius Marminge 21a1242530 Use idiomatic Effect readiness policies
Co-authored-by: Julius Marminge <[email protected]>
2026-05-27 16:08:52 +00:00
6 changed files with 87 additions and 152 deletions

No files matched your search

+8 -19
View File
@@ -2,6 +2,7 @@ import * as Context from "effect/Context";
import * as Effect from "effect/Effect";
import * as FileSystem from "effect/FileSystem";
import * as Layer from "effect/Layer";
import * as Option from "effect/Option";
import * as Path from "effect/Path";
import * as Schema from "effect/Schema";
@@ -15,16 +16,9 @@ const ProjectVcsConfig = Schema.Struct({
),
vcsKind: Schema.optional(VcsDriverKind),
});
const isProjectVcsConfig = Schema.is(ProjectVcsConfig);
interface ProjectVcsConfigFile {
readonly vcs?:
| {
readonly kind?: VcsDriverKindType | undefined;
}
| undefined;
readonly vcsKind?: VcsDriverKindType | undefined;
}
const ProjectVcsConfigJson = Schema.fromJsonString(ProjectVcsConfig);
const decodeProjectVcsConfigJson = Schema.decodeUnknownOption(ProjectVcsConfigJson);
type ProjectVcsConfigFile = typeof ProjectVcsConfig.Type;
export interface VcsProjectConfigResolveInput {
readonly cwd: string;
@@ -45,13 +39,8 @@ function configuredKind(config: ProjectVcsConfigFile): VcsDriverKindType | "auto
return config.vcs?.kind ?? config.vcsKind ?? "auto";
}
function parseConfig(raw: string): ProjectVcsConfigFile | null {
try {
const parsed = JSON.parse(raw) as unknown;
return isProjectVcsConfig(parsed) ? parsed : null;
} catch {
return null;
}
function parseConfig(raw: string): Option.Option<ProjectVcsConfigFile> {
return decodeProjectVcsConfigJson(raw);
}
export const make = Effect.fn("makeVcsProjectConfig")(function* () {
@@ -90,14 +79,14 @@ export const make = Effect.fn("makeVcsProjectConfig")(function* () {
}
const parsed = parseConfig(raw);
if (parsed === null) {
if (Option.isNone(parsed)) {
yield* Effect.logWarning("invalid VCS project config", {
configPath,
});
return "auto" as const;
}
return configuredKind(parsed);
return configuredKind(parsed.value);
});
const resolveKind: VcsProjectConfigShape["resolveKind"] = Effect.fn(
@@ -1,16 +1,7 @@
import { useNavigate } from "@tanstack/react-router";
import type { ServerProvider } from "@t3tools/contracts";
import { CircleCheckIcon, DownloadIcon, LoaderIcon, TriangleAlertIcon, XIcon } from "lucide-react";
import {
useCallback,
useEffect,
useRef,
useState,
type CSSProperties,
type Dispatch,
type SetStateAction,
type TransitionEvent,
} from "react";
import { useCallback, useEffect, useState, type CSSProperties } from "react";
import { useServerProviders } from "../../rpc/serverState";
import {
@@ -46,36 +37,48 @@ function latestProviderCheckedAt(
);
}
function useProviderUpdateVisibleAfterIso(
providers: ReadonlyArray<Pick<ServerProvider, "checkedAt">>,
): string | undefined {
const visibleAfterIsoRef = useRef<string | undefined>(undefined);
if (visibleAfterIsoRef.current === undefined) {
visibleAfterIsoRef.current = latestProviderCheckedAt(providers);
}
return visibleAfterIsoRef.current;
}
function useDisplayedProviderUpdatePill(input: {
view: ProviderUpdateSidebarPillView | null;
setDismissedKeys: Dispatch<SetStateAction<ReadonlySet<string>>>;
}) {
const { view, setDismissedKeys } = input;
const [renderedView, setRenderedView] = useState<ProviderUpdateSidebarPillView | null>(view);
export function SidebarProviderUpdatePill() {
const navigate = useNavigate();
const providers = useServerProviders();
const [dismissedKeys, setDismissedKeys] = useState<ReadonlySet<string>>(() => new Set());
const [renderedView, setRenderedView] = useState<ProviderUpdateSidebarPillView | null>(null);
const [pendingView, setPendingView] = useState<ProviderUpdateSidebarPillView | null>(null);
const [exitingKey, setExitingKey] = useState<string | null>(null);
const pendingViewRef = useRef<ProviderUpdateSidebarPillView | null>(null);
const dismissAfterExitKeyRef = useRef<string | null>(null);
const [dismissAfterExitKey, setDismissAfterExitKey] = useState<string | null>(null);
const [visibleAfterIso, setVisibleAfterIso] = useState<string | undefined>();
const effectiveVisibleAfterIso = visibleAfterIso ?? latestProviderCheckedAt(providers);
const view = getProviderUpdateSidebarPillView(providers, {
...(effectiveVisibleAfterIso !== undefined
? { visibleAfterIso: effectiveVisibleAfterIso }
: {}),
dismissedKeys,
});
useEffect(() => {
if (visibleAfterIso === undefined && effectiveVisibleAfterIso !== undefined) {
setVisibleAfterIso(effectiveVisibleAfterIso);
}
}, [effectiveVisibleAfterIso, visibleAfterIso]);
const openProviderSettings = useCallback(() => {
void navigate({ to: "/settings/providers" });
}, [navigate]);
const displayedView = renderedView ?? view;
const dismissAfterVisibleMs = displayedView?.dismissAfterVisibleMs;
const viewKey = displayedView?.key ?? null;
const showDismissProgress =
dismissAfterVisibleMs !== undefined &&
displayedView?.tone !== "loading" &&
exitingKey !== viewKey;
const startExit = useCallback(
(key: string, nextView: ProviderUpdateSidebarPillView | null, dismissKey?: string) => {
if (exitingKey === key) {
return;
}
pendingViewRef.current = nextView;
dismissAfterExitKeyRef.current = dismissKey ?? null;
setPendingView(nextView);
setExitingKey(key);
setDismissAfterExitKey(dismissKey ?? null);
},
[exitingKey],
);
@@ -100,46 +103,6 @@ function useDisplayedProviderUpdatePill(input: {
}
}, [exitingKey, renderedView, startExit, view]);
const displayedView = renderedView ?? view;
const onTransitionEnd = useCallback(
(event: TransitionEvent<HTMLDivElement>) => {
if (event.target !== event.currentTarget) {
return;
}
if (!displayedView || exitingKey !== displayedView.key) {
return;
}
if (dismissAfterExitKeyRef.current === displayedView.key) {
setDismissedKeys((previous) => new Set(previous).add(displayedView.key));
}
setRenderedView(pendingViewRef.current);
pendingViewRef.current = null;
dismissAfterExitKeyRef.current = null;
setExitingKey(null);
},
[displayedView, exitingKey, setDismissedKeys],
);
return {
displayedView,
exitingKey,
onTransitionEnd,
startExit,
};
}
function useProviderUpdateAutoDismiss(input: {
dismissAfterVisibleMs: number | undefined;
exitingKey: string | null;
startExit: (
key: string,
nextView: ProviderUpdateSidebarPillView | null,
dismissKey?: string,
) => void;
viewKey: string | null;
}) {
const { dismissAfterVisibleMs, exitingKey, startExit, viewKey } = input;
useEffect(() => {
if (!dismissAfterVisibleMs || !viewKey) {
return;
@@ -153,40 +116,6 @@ function useProviderUpdateAutoDismiss(input: {
return () => window.clearTimeout(timeoutId);
}, [dismissAfterVisibleMs, exitingKey, startExit, viewKey]);
}
export function SidebarProviderUpdatePill() {
const navigate = useNavigate();
const providers = useServerProviders();
const [dismissedKeys, setDismissedKeys] = useState<ReadonlySet<string>>(() => new Set());
const effectiveVisibleAfterIso = useProviderUpdateVisibleAfterIso(providers);
const view = getProviderUpdateSidebarPillView(providers, {
...(effectiveVisibleAfterIso !== undefined
? { visibleAfterIso: effectiveVisibleAfterIso }
: {}),
dismissedKeys,
});
const openProviderSettings = useCallback(() => {
void navigate({ to: "/settings/providers" });
}, [navigate]);
const { displayedView, exitingKey, onTransitionEnd, startExit } = useDisplayedProviderUpdatePill({
view,
setDismissedKeys,
});
const dismissAfterVisibleMs = displayedView?.dismissAfterVisibleMs;
const viewKey = displayedView?.key ?? null;
const showDismissProgress =
dismissAfterVisibleMs !== undefined &&
displayedView?.tone !== "loading" &&
exitingKey !== viewKey;
useProviderUpdateAutoDismiss({
dismissAfterVisibleMs,
exitingKey,
startExit,
viewKey,
});
if (!displayedView) {
return null;
@@ -201,7 +130,21 @@ export function SidebarProviderUpdatePill() {
? "pointer-events-none translate-y-1.5 opacity-0"
: "translate-y-0 opacity-100"
}`}
onTransitionEnd={onTransitionEnd}
onTransitionEnd={(event) => {
if (event.target !== event.currentTarget) {
return;
}
if (!displayedView || exitingKey !== displayedView.key) {
return;
}
if (dismissAfterExitKey === displayedView.key) {
setDismissedKeys((previous) => new Set(previous).add(displayedView.key));
}
setRenderedView(pendingView);
setPendingView(null);
setExitingKey(null);
setDismissAfterExitKey(null);
}}
>
{showDismissProgress ? (
<div
+3 -3
View File
@@ -242,9 +242,9 @@ describe("ssh tunnel scripts", () => {
Effect.result(
waitForHttpReady({
baseUrl: "http://127.0.0.1:41773/",
timeoutMs: 1_000,
intervalMs: 100,
probeTimeoutMs: 250,
timeout: Duration.seconds(1),
interval: Duration.millis(100),
probeTimeout: Duration.millis(250),
}),
),
);
+26 -23
View File
@@ -50,11 +50,13 @@ import {
export const DEFAULT_REMOTE_PORT = 3773;
const REMOTE_PORT_SCAN_WINDOW = 200;
const SSH_READY_TIMEOUT_MS = 20_000;
const SSH_READY_PROBE_TIMEOUT_MS = 1_000;
const TUNNEL_SHUTDOWN_TIMEOUT_MS = 2_000;
const REMOTE_READY_TIMEOUT_MS = 15_000;
const REMOTE_REUSE_READY_TIMEOUT_MS = 2_000;
const SSH_READY_TIMEOUT = Duration.seconds(20);
const SSH_READY_PROBE_TIMEOUT = Duration.seconds(1);
const TUNNEL_SHUTDOWN_TIMEOUT = Duration.seconds(2);
const REMOTE_READY_TIMEOUT = Duration.seconds(15);
const REMOTE_REUSE_READY_TIMEOUT = Duration.seconds(2);
const DEFAULT_HTTP_READY_TIMEOUT = Duration.seconds(30);
const HTTP_READY_RETRY_INTERVAL = Duration.millis(100);
export interface RemoteT3RunnerOptions {
readonly packageSpec?: string;
@@ -686,9 +688,9 @@ export function buildRemoteLaunchScript(input?: RemoteT3RunnerOptions): string {
T3_WAIT_READY_SCRIPT: stripTrailingNewlines(REMOTE_WAIT_READY_SCRIPT),
T3_DEFAULT_REMOTE_PORT: String(DEFAULT_REMOTE_PORT),
T3_REMOTE_PORT_SCAN_WINDOW: String(REMOTE_PORT_SCAN_WINDOW),
T3_READY_TIMEOUT_MS: String(REMOTE_READY_TIMEOUT_MS),
T3_REUSE_READY_TIMEOUT_MS: String(REMOTE_REUSE_READY_TIMEOUT_MS),
T3_READY_PROBE_TIMEOUT_MS: String(SSH_READY_PROBE_TIMEOUT_MS),
T3_READY_TIMEOUT_MS: String(Duration.toMillis(REMOTE_READY_TIMEOUT)),
T3_REUSE_READY_TIMEOUT_MS: String(Duration.toMillis(REMOTE_REUSE_READY_TIMEOUT)),
T3_READY_PROBE_TIMEOUT_MS: String(Duration.toMillis(SSH_READY_PROBE_TIMEOUT)),
});
}
@@ -870,17 +872,18 @@ const readRemoteServerLogTail = Effect.fn("ssh/tunnel.readRemoteServerLogTail")(
export const waitForHttpReady = Effect.fn("ssh/tunnel.waitForHttpReady")(function* (input: {
readonly baseUrl: string;
readonly timeoutMs?: number;
readonly intervalMs?: number;
readonly probeTimeoutMs?: number;
readonly timeout?: Duration.Input;
readonly interval?: Duration.Input;
readonly probeTimeout?: Duration.Input;
readonly path?: string;
}): Effect.fn.Return<void, SshReadinessError, HttpClient.HttpClient> {
const timeoutMs = input.timeoutMs ?? 30_000;
const intervalMs = input.intervalMs ?? 100;
const probeTimeoutMs = input.probeTimeoutMs ?? SSH_READY_PROBE_TIMEOUT_MS;
const retryPolicy = Schedule.spaced(Duration.millis(intervalMs)).pipe(
Schedule.take(Math.max(0, Math.ceil(timeoutMs / intervalMs))),
);
const timeout = Duration.fromInputUnsafe(input.timeout ?? DEFAULT_HTTP_READY_TIMEOUT);
const interval = Duration.fromInputUnsafe(input.interval ?? HTTP_READY_RETRY_INTERVAL);
const probeTimeout = Duration.fromInputUnsafe(input.probeTimeout ?? SSH_READY_PROBE_TIMEOUT);
const timeoutMs = Duration.toMillis(timeout);
const intervalMs = Duration.toMillis(interval);
const probeTimeoutMs = Duration.toMillis(probeTimeout);
const retryPolicy = Schedule.spaced(interval);
const requestUrl = new URL(input.path ?? "/", input.baseUrl).toString();
const client = yield* HttpClient.HttpClient;
const lastProbeFailure = yield* Ref.make<unknown>(null);
@@ -900,7 +903,7 @@ export const waitForHttpReady = Effect.fn("ssh/tunnel.waitForHttpReady")(functio
Effect.gen(function* () {
attempt += 1;
const responseOption = yield* effect.pipe(
Effect.timeoutOption(Duration.millis(probeTimeoutMs)),
Effect.timeoutOption(probeTimeout),
Effect.mapError(
(cause) =>
new SshReadinessError({
@@ -953,7 +956,7 @@ export const waitForHttpReady = Effect.fn("ssh/tunnel.waitForHttpReady")(functio
cause,
}),
),
Effect.timeoutOption(Duration.millis(timeoutMs)),
Effect.timeoutOption(timeout),
);
return yield* Option.match(result, {
@@ -1236,7 +1239,7 @@ const startSshTunnel = Effect.fn("ssh/tunnel.startSshTunnel")(function* (input:
yield* Effect.raceFirst(
waitForHttpReady({
baseUrl: input.httpBaseUrl,
timeoutMs: SSH_READY_TIMEOUT_MS,
timeout: SSH_READY_TIMEOUT,
}),
exitFailure,
).pipe(
@@ -1296,7 +1299,7 @@ const startSshTunnel = Effect.fn("ssh/tunnel.startSshTunnel")(function* (input:
: child
.kill({
killSignal: "SIGTERM",
forceKillAfter: TUNNEL_SHUTDOWN_TIMEOUT_MS,
forceKillAfter: TUNNEL_SHUTDOWN_TIMEOUT,
})
.pipe(Effect.ignore),
),
@@ -1540,7 +1543,7 @@ const makeSshEnvironmentManager = Effect.fn("ssh/tunnel.SshEnvironmentManager.ma
[
tunnelEntry.process.kill({
killSignal: "SIGTERM",
forceKillAfter: TUNNEL_SHUTDOWN_TIMEOUT_MS,
forceKillAfter: TUNNEL_SHUTDOWN_TIMEOUT,
}),
stopRemoteServer(
tunnelEntry.target,
@@ -1594,7 +1597,7 @@ const makeSshEnvironmentManager = Effect.fn("ssh/tunnel.SshEnvironmentManager.ma
remotePort: entry.remotePort,
});
const readinessExit = yield* Effect.exit(
waitForHttpReady({ baseUrl: entry.httpBaseUrl, timeoutMs: 2_000 }),
waitForHttpReady({ baseUrl: entry.httpBaseUrl, timeout: REMOTE_REUSE_READY_TIMEOUT }),
);
if (Exit.isSuccess(readinessExit)) {
yield* Effect.logDebug("ssh.environment.tunnel.reused", {