Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): agents stop when the server is killed #18648

Closedgustavohariel(GitHub profile, opens in a new tab)wants to merge 6 commits intomain fromrefs/pull/18648/headopened View on GitHub

Showing 3 changed files with 168 additions and 4 deletions (loading 1).

x
0 of 3 viewed, 3 left
17 additions and 2 deletionsapps/server/src/process/agentScope.tsModified
View file
@@ -177,6 +177,12 @@
// at a time, so only its latest scope can explain a failure.
const scopeByThread = new Map<string, { unit: string; oomKilled: boolean }>();
​
+ const setpriv = yield* Effect.cached(
+ resolve("setpriv", hostEnvironment).pipe(
+ Effect.map((resolved) => (resolved._tag === "Some" ? resolved.value : undefined)),
+ ),
+ );
+​
const readCgroupFile = (controlGroup: string, file: string) =>
fileSystem
.readFileString(path.join("/sys/fs/cgroup", controlGroup, file))
@@ -296,11 +302,15 @@
// Leave unresolved commands alone so the spawn reports the missing binary.
if (resolved._tag === "None") return { command, args };
const scope = yield* systemd;
- if (scope === undefined) return agentScopeCommand({ command: resolved.value, args });
+ const dieWithServer = yield* setpriv;
+ if (scope === undefined) {
+ return agentScopeCommand({ command: resolved.value, args, setpriv: dieWithServer });
+ }
const unit = `t3code-${name}-${NodeCrypto.randomUUID().slice(0, 8)}.scope`;
if (threadId !== undefined) yield* track(scope.systemctl, threadId, unit);
const systemdScope: AgentSystemdScope = {
systemdRun: scope.systemdRun,
+ systemctl: scope.systemctl,
runtimeDir: scope.runtimeDir,
slice: AGENT_SLICE,