Co-Authored-By: Claude Opus 4.6 <[email protected]>
This commit is contained in:
Tim SmartandClaude Opus 4.6 authored and Julius Marminge committed 2026-03-09 12:18:33 -07:00
1 parent c6dc7c6524
commit fd98835834
2 files changed
+26 -66

No files matched your search

@@ -13,7 +13,7 @@ import type {
ServerProviderStatus,
ServerProviderStatusState,
} from "@t3tools/contracts";
import { Effect, Layer, Option, Result, Stream } from "effect";
import { Array, Effect, Fiber, Layer, Option, Result, Stream } from "effect";
import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process";
import {
@@ -312,56 +312,13 @@ export const checkCodexProviderStatus: Effect.Effect<
export const ProviderHealthLive = Layer.effect(
ProviderHealth,
Effect.gen(function* () {
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
let cachedStatuses: ReadonlyArray<ServerProviderStatus> = [
{
provider: CODEX_PROVIDER,
status: "warning",
available: false,
authStatus: "unknown",
checkedAt: new Date().toISOString(),
message: "Checking Codex CLI availability...",
},
];
let readyListeners: Array<(statuses: ReadonlyArray<ServerProviderStatus>) => void> = [];
let resolved = false;
const notifyReady = (statuses: ReadonlyArray<ServerProviderStatus>) => {
resolved = true;
cachedStatuses = statuses;
for (const cb of readyListeners) cb(statuses);
readyListeners = [];
};
// Run health checks in the background so they don't block server startup.
checkCodexProviderStatus.pipe(
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
Effect.runPromise,
).then((status) => {
notifyReady([status]);
}).catch(() => {
notifyReady([
{
provider: CODEX_PROVIDER,
status: "error",
available: false,
authStatus: "unknown",
checkedAt: new Date().toISOString(),
message: "Failed to check Codex CLI status.",
},
]);
});
const codexStatusFiber = yield* checkCodexProviderStatus.pipe(
Effect.map(Array.of),
Effect.forkScoped,
);
return {
getStatuses: Effect.sync(() => cachedStatuses),
onReady: (cb) => {
if (resolved) {
cb(cachedStatuses);
} else {
readyListeners.push(cb);
}
},
getStatuses: Fiber.join(codexStatusFiber),
} satisfies ProviderHealthShape;
}),
);
+20 -17
View File
@@ -26,6 +26,7 @@ import {
WebSocketRequest,
WsPush,
WsResponse,
ServerProviderStatus,
} from "@t3tools/contracts";
import * as NodeHttpServer from "@effect/platform-node/NodeHttpServer";
import {
@@ -268,9 +269,6 @@ export const createServer = Effect.fn(function* (): Effect.fn.Return<
),
);
// Read provider statuses lazily so background health checks are reflected.
const getProviderStatuses = () => Effect.runSync(providerHealth.getStatuses);
const clients = yield* Ref.make(new Set<WebSocket>());
const logger = createLogger("ws");
@@ -618,6 +616,23 @@ export const createServer = Effect.fn(function* (): Effect.fn.Return<
const subscriptionsScope = yield* Scope.make("sequential");
yield* Effect.addFinalizer(() => Scope.close(subscriptionsScope, Exit.void));
// Push updated provider statuses to connected clients once background health checks finish.
let providers: ReadonlyArray<ServerProviderStatus> = [];
yield* providerHealth.getStatuses.pipe(
Effect.flatMap((statuses) => {
providers = statuses;
return broadcastPush({
type: "push",
channel: WS_CHANNELS.serverConfigUpdated,
data: {
issues: [],
providers: statuses,
},
});
}),
Effect.forkIn(subscriptionsScope),
);
yield* Stream.runForEach(orchestrationEngine.streamDomainEvents, (event) =>
broadcastPush({
type: "push",
@@ -632,23 +647,11 @@ export const createServer = Effect.fn(function* (): Effect.fn.Return<
channel: WS_CHANNELS.serverConfigUpdated,
data: {
issues: event.issues,
providers: getProviderStatuses(),
providers,
},
}),
).pipe(Effect.forkIn(subscriptionsScope));
// Push updated provider statuses to connected clients once background health checks finish.
providerHealth.onReady((statuses) => {
broadcastPush({
type: "push",
channel: WS_CHANNELS.serverConfigUpdated,
data: {
issues: [],
providers: statuses,
},
}).pipe(Effect.runPromise).catch(() => {});
});
yield* Scope.provide(orchestrationReactor.start, subscriptionsScope);
let welcomeBootstrapProjectId: ProjectId | undefined;
@@ -896,7 +899,7 @@ export const createServer = Effect.fn(function* (): Effect.fn.Return<
keybindingsConfigPath,
keybindings: keybindingsConfig.keybindings,
issues: keybindingsConfig.issues,
providers: getProviderStatuses(),
providers,
availableEditors,
};