Compare commits
1
Commits
main
...
t3code/09efeb7d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
32ebbe1a4c |
No files matched your search
@@ -42,6 +42,7 @@ const BENIGN_ERROR_LOG_SNIPPETS = [
|
|||||||
"state db missing rollout path for thread",
|
"state db missing rollout path for thread",
|
||||||
"state db record_discrepancy: find_thread_path_by_id_str_in_subdir, falling_back",
|
"state db record_discrepancy: find_thread_path_by_id_str_in_subdir, falling_back",
|
||||||
];
|
];
|
||||||
|
const CODEX_APP_SERVER_FORCE_KILL_AFTER = "2 seconds" as const;
|
||||||
const RECOVERABLE_THREAD_RESUME_ERROR_SNIPPETS = [
|
const RECOVERABLE_THREAD_RESUME_ERROR_SNIPPETS = [
|
||||||
"not found",
|
"not found",
|
||||||
"missing thread",
|
"missing thread",
|
||||||
@@ -702,6 +703,7 @@ export const makeCodexSessionRuntime = (
|
|||||||
ChildProcess.make(options.binaryPath, ["app-server"], {
|
ChildProcess.make(options.binaryPath, ["app-server"], {
|
||||||
cwd: options.cwd,
|
cwd: options.cwd,
|
||||||
env,
|
env,
|
||||||
|
forceKillAfter: CODEX_APP_SERVER_FORCE_KILL_AFTER,
|
||||||
shell: process.platform === "win32",
|
shell: process.platform === "win32",
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { it } from "@effect/vitest";
|
import { it } from "@effect/vitest";
|
||||||
import { Cause, Effect, Exit } from "effect";
|
import { Cause, Deferred, Effect, Exit, Fiber } from "effect";
|
||||||
import { describe, expect } from "vitest";
|
import { describe, expect } from "vitest";
|
||||||
|
|
||||||
import { scopedSafeTeardown } from "./scopedSafeTeardown.ts";
|
import { scopedSafeTeardown } from "./scopedSafeTeardown.ts";
|
||||||
@@ -91,4 +91,23 @@ describe("scopedSafeTeardown", () => {
|
|||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
it.effect("runs finalizers when the body is interrupted", () =>
|
||||||
|
Effect.gen(function* () {
|
||||||
|
const started = yield* Deferred.make<void>();
|
||||||
|
const finalized = yield* Deferred.make<void>();
|
||||||
|
const wrapped = Effect.gen(function* () {
|
||||||
|
yield* Effect.addFinalizer(() =>
|
||||||
|
Deferred.succeed(finalized, undefined).pipe(Effect.asVoid),
|
||||||
|
);
|
||||||
|
yield* Deferred.succeed(started, undefined);
|
||||||
|
return yield* Effect.never;
|
||||||
|
}).pipe(scopedSafeTeardown("test"));
|
||||||
|
|
||||||
|
const fiber = yield* wrapped.pipe(Effect.forkChild);
|
||||||
|
yield* Deferred.await(started);
|
||||||
|
yield* Fiber.interrupt(fiber);
|
||||||
|
yield* Deferred.await(finalized);
|
||||||
|
}),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
@@ -23,9 +23,11 @@
|
|||||||
* 1. Make a fresh scope manually.
|
* 1. Make a fresh scope manually.
|
||||||
* 2. Run the body against that scope, capturing its Exit via
|
* 2. Run the body against that scope, capturing its Exit via
|
||||||
* `Effect.exit`.
|
* `Effect.exit`.
|
||||||
* 3. Close the scope, catching any cause (typed failure *or* defect)
|
* 3. Run the body inside an interruptible region, but capture the Exit from
|
||||||
|
* success, failure, defect, or interruption.
|
||||||
|
* 4. Close the scope, catching any cause (typed failure *or* defect)
|
||||||
* with a log.
|
* with a log.
|
||||||
* 4. Replay the captured Exit so typed body failures still surface and
|
* 5. Replay the captured Exit so typed body failures still surface and
|
||||||
* successes still return their value.
|
* successes still return their value.
|
||||||
*
|
*
|
||||||
* The helper deliberately logs teardown causes at `Warning` level —
|
* The helper deliberately logs teardown causes at `Warning` level —
|
||||||
@@ -34,7 +36,7 @@
|
|||||||
*
|
*
|
||||||
* @module provider/Layers/scopedSafeTeardown
|
* @module provider/Layers/scopedSafeTeardown
|
||||||
*/
|
*/
|
||||||
import { Effect, Exit, Scope } from "effect";
|
import { Effect, Scope } from "effect";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run `effect` with a freshly made `Scope.Scope`, guaranteeing that
|
* Run `effect` with a freshly made `Scope.Scope`, guaranteeing that
|
||||||
@@ -49,13 +51,17 @@ import { Effect, Exit, Scope } from "effect";
|
|||||||
export const scopedSafeTeardown =
|
export const scopedSafeTeardown =
|
||||||
(label: string) =>
|
(label: string) =>
|
||||||
<A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, Exclude<R, Scope.Scope>> =>
|
<A, E, R>(effect: Effect.Effect<A, E, R>): Effect.Effect<A, E, Exclude<R, Scope.Scope>> =>
|
||||||
Effect.gen(function* () {
|
Effect.uninterruptibleMask((restore) =>
|
||||||
const scope = yield* Scope.make();
|
Effect.gen(function* () {
|
||||||
const bodyExit = yield* effect.pipe(Effect.provideService(Scope.Scope, scope), Effect.exit);
|
const scope = yield* Scope.make();
|
||||||
yield* Scope.close(scope, Exit.void).pipe(
|
const bodyExit = yield* restore(
|
||||||
Effect.catchCause((cause) =>
|
effect.pipe(Effect.provideService(Scope.Scope, scope)),
|
||||||
Effect.logWarning(`${label} teardown errored; preserving body result`, cause),
|
).pipe(Effect.exit);
|
||||||
),
|
yield* Scope.close(scope, bodyExit).pipe(
|
||||||
);
|
Effect.catchCause((cause) =>
|
||||||
return yield* bodyExit;
|
Effect.logWarning(`${label} teardown errored; preserving body result`, cause),
|
||||||
}) as Effect.Effect<A, E, Exclude<R, Scope.Scope>>;
|
),
|
||||||
|
);
|
||||||
|
return yield* bodyExit;
|
||||||
|
}),
|
||||||
|
) as Effect.Effect<A, E, Exclude<R, Scope.Scope>>;
|
||||||
@@ -17,6 +17,8 @@ import {
|
|||||||
} from "./_internal/shared.ts";
|
} from "./_internal/shared.ts";
|
||||||
import { makeChildStdio, makeTerminationError } from "./_internal/stdio.ts";
|
import { makeChildStdio, makeTerminationError } from "./_internal/stdio.ts";
|
||||||
|
|
||||||
|
const DEFAULT_APP_SERVER_FORCE_KILL_AFTER = "2 seconds" as const;
|
||||||
|
|
||||||
export interface CodexAppServerClientOptions {
|
export interface CodexAppServerClientOptions {
|
||||||
readonly logIncoming?: boolean;
|
readonly logIncoming?: boolean;
|
||||||
readonly logOutgoing?: boolean;
|
readonly logOutgoing?: boolean;
|
||||||
@@ -279,6 +281,7 @@ export const layerCommand = (
|
|||||||
const command = ChildProcess.make(options.command, [...(options.args ?? [])], {
|
const command = ChildProcess.make(options.command, [...(options.args ?? [])], {
|
||||||
...(options.cwd ? { cwd: options.cwd } : {}),
|
...(options.cwd ? { cwd: options.cwd } : {}),
|
||||||
...(options.env ? { env: { ...process.env, ...options.env } } : {}),
|
...(options.env ? { env: { ...process.env, ...options.env } } : {}),
|
||||||
|
forceKillAfter: DEFAULT_APP_SERVER_FORCE_KILL_AFTER,
|
||||||
shell: process.platform === "win32",
|
shell: process.platform === "win32",
|
||||||
});
|
});
|
||||||
return yield* spawner.spawn(command).pipe(
|
return yield* spawner.spawn(command).pipe(
|
||||||
@@ -291,7 +294,8 @@ export const layerCommand = (
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
(handle) => handle.kill().pipe(Effect.orDie),
|
(handle) =>
|
||||||
|
handle.kill({ forceKillAfter: DEFAULT_APP_SERVER_FORCE_KILL_AFTER }).pipe(Effect.orDie),
|
||||||
).pipe(
|
).pipe(
|
||||||
Effect.flatMap((handle) =>
|
Effect.flatMap((handle) =>
|
||||||
make(makeChildStdio(handle), options, makeTerminationError(handle)),
|
make(makeChildStdio(handle), options, makeTerminationError(handle)),
|
||||||
|
|||||||
Reference in new issue
Block a user