Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): agents stop when the server that launched them dies on Linux #15450

ClosedSunkenInTime(GitHub profile, opens in a new tab)wants to merge 7 commits intomain fromrefs/pull/15450/headopened View on GitHub

Showing 4 changed files with 89 additions and 6 deletions (loading 2).

x
0 of 4 viewed, 4 left
69 additions and 4 deletionsapps/server/src/process/agentScope.test.tsModified
View file
@@ -1,4 +1,5 @@
// @effect-diagnostics nodeBuiltinImport:off -- fake systemd binaries live in a temp dir.
+import * as NodeChildProcess from "node:child_process";
import * as NodeFS from "node:fs";
import * as NodeOS from "node:os";
import * as NodePath from "node:path";
@@ -70,12 +71,31 @@
readonly calls: ReadonlyArray<ReadonlyArray<string>>;
readonly stateDir: string;
}) => Effect.Effect<A, E>,
- { oomPolicy = true }: { readonly oomPolicy?: boolean } = {},
+ {
+ systemd = true,
+ setprivExitCode = 0,
+ oomPolicy = true,
+ }: {
+ systemd?: boolean;
+ setprivExitCode?: number | null;
+ readonly oomPolicy?: boolean;
+ } = {},
) =>
Effect.gen(function* () {
const bin = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-agent-scope-"));
- for (const name of ["systemd-run", "systemctl", "agent"]) {
- NodeFS.writeFileSync(NodePath.join(bin, name), "", { mode: 0o755 });
+ for (const name of ["agent", ...(systemd ? ["systemd-run", "systemctl"] : [])]) {
+ NodeFS.writeFileSync(
+ NodePath.join(bin, name),
+ '#!/bin/sh\nwhile [ "$1" != "--" ]; do shift; done\nshift\nexec "$@"\n',
+ { mode: 0o755 },