The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 17:15 UTC
fix(server): systemd service starts again after its start limit tripped (#36359)
Julius Marminge committed
Nov 13, 2026 at 12:25 UTC
0c28045abbee9eb0f50d182480251a5bf23618c9
2 files changed
+48
-3
apps/server/src/cloud/bootService.test.ts
+39
-3
@@ -217,6 +217,8 @@ const makeHarness = Effect.fn("test.make_boot_service_harness")(function* (
217
lingerStartsManager: boolean;
218
enabled: boolean;
219
active: boolean;
220
+ /** systemd refuses starts until `reset-failed`, as after `StartLimitBurst` trips. */
221
+ startLimitHit: boolean;
222
/** A Windows launcher: it holds its lock until its task ends. */
223
launcher?: { readonly close: () => void };
224
/** Task Scheduler's own copy of the task. */
@@ -229,6 +231,7 @@ const makeHarness = Effect.fn("test.make_boot_service_harness")(function* (
231
lingerStartsManager: true,
232
enabled: true,
233
active: true,
234
+ startLimitHit: false,
235
};
236
const runner = ProcessRunner.ProcessRunner.of({
237
run: Effect.fn("test.run_boot_service_command")(function* (
@@ -238,7 +241,12 @@ const makeHarness = Effect.fn("test.make_boot_service_harness")(function* (
241
commands.push(command);
242
invocations.push(input);
243
timeouts.set(command, input.timeout);
241
- const failed = command === control.failCommand;
244
+ if (command === "systemctl --user reset-failed t3code.service") control.startLimitHit = false;
245
+ const refusedStart = control.startLimitHit && command.startsWith("systemctl --user restart ");
246
+ // `--no-block` only queues the job, so systemd reports success even when it refuses it.
247
+ const failed =
248
+ command === control.failCommand ||
249
+ (refusedStart && command === "systemctl --user restart t3code.service");
250
if (!failed && command.startsWith("loginctl enable-linger --no-ask-password ")) {
251
control.linger = "yes";
252
control.managerReachable ||= control.lingerStartsManager;
@@ -257,7 +265,8 @@ const makeHarness = Effect.fn("test.make_boot_service_harness")(function* (
265
if (input.args[0] === "/Delete") delete control.task;
266
if (input.args[0] === "/End") control.launcher?.close();
267
}
260
- if (!failed && command === "systemctl --user restart t3code.service") control.active = true;
268
+ if (!refusedStart && !failed && command.startsWith("systemctl --user restart "))
269
+ control.active = true;
270
// The manager loads units only from its own unit directory.
271
const unitOutsideManager =
272
command === "systemctl --user enable t3code.service" &&
@@ -848,7 +857,11 @@ it.layer(NodeServices.layer)("boot service install", (it) => {
857
),
858
).toEqual(
859
platform === "linux"
851
- ? ["systemctl --user stop t3code.service", "systemctl --user restart t3code.service"]
860
+ ? [
861
+ "systemctl --user stop t3code.service",
862
+ "systemctl --user reset-failed t3code.service",
863
+ "systemctl --user restart t3code.service",
864
+ ]
865
: [
866
"launchctl bootout --wait gui/501/com.t3tools.t3code.service",
867
`launchctl bootstrap gui/501 ${plan.unitPath}`,
@@ -1177,6 +1190,7 @@ process.disconnect();
1190
"systemctl --user is-active t3code.service",
1191
"systemctl --user stop t3code.service",
1192
"repair",
1193
+ "systemctl --user reset-failed t3code.service",
1194
"systemctl --user restart t3code.service",
1195
]);
1196
expect(control.active).toBe(true);
@@ -1304,6 +1318,7 @@ process.disconnect();
1318
expect(commands).toEqual([
1319
"systemctl --user daemon-reload",
1320
"systemctl --user enable t3code.service",
1321
+ "systemctl --user reset-failed t3code.service",
1322
"systemctl --user restart --no-block t3code.service",
1323
]);
1324
expect(outcome).toBe("queued");
@@ -1312,6 +1327,25 @@ process.disconnect();
1327
}),
1328
);
1329
1330
+ // regression: #36319
1331
+ it.effect("starts a service whose systemd start limit tripped after repairing it", () =>
1332
+ Effect.gen(function* () {
1333
+ const { service, control, makeService } = yield* makeHarness();
1334
+ yield* service.install();
1335
+ control.active = false;
1336
+ control.startLimitHit = true;
1337
+
1338
+ yield* service.install();
1339
+ expect(control.active).toBe(true);
1340
+
1341
+ control.active = false;
1342
+ control.startLimitHit = true;
1343
+ const inside = yield* makeService(undefined, "1.2.3", undefined, true);
1344
+ expect(yield* inside.restart).toBe("queued");
1345
+ expect(control.active).toBe(true);
1346
+ }),
1347
+ );
1348
+
1349
it.effect("restarts an installed service when repair fails", () =>
1350
Effect.gen(function* () {
1351
const { service, commands, control } = yield* makeHarness();
@@ -1328,6 +1362,7 @@ process.disconnect();
1362
).toEqual([
1363
"systemctl --user stop t3code.service",
1364
"systemctl --user daemon-reload",
1365
+ "systemctl --user reset-failed t3code.service",
1366
"systemctl --user restart t3code.service",
1367
]);
1368
}),
@@ -1361,6 +1396,7 @@ process.disconnect();
1396
),
1397
).toEqual([
1398
"systemctl --user stop t3code.service",
1399
+ "systemctl --user reset-failed t3code.service",
1400
"systemctl --user restart t3code.service",
1401
]);
1402
}
apps/server/src/cloud/bootService.ts
+9
@@ -314,6 +314,13 @@ function systemdManager(input: {
314
readonly unitDir: string;
315
}): BootServiceManager {
316
const unitPath = input.path.join(input.unitDir, BOOT_SERVICE_UNIT_FILE);
317
+ // Once StartLimitBurst trips, systemd refuses every start until the failed state is cleared.
318
+ const resetFailed = {
319
+ step: "clearing the service's failed state",
320
+ optional: true,
321
+ command: "systemctl",
322
+ args: ["--user", "reset-failed", BOOT_SERVICE_UNIT_FILE],
323
+ };
324
const prepareActivation = [
325
{
326
step: "reloading systemd user units",
@@ -325,6 +332,7 @@ function systemdManager(input: {
332
command: "systemctl",
333
args: ["--user", "enable", BOOT_SERVICE_UNIT_FILE],
334
},
335
+ resetFailed,
336
];
337
return {
338
kind: "systemd",
@@ -347,6 +355,7 @@ function systemdManager(input: {
355
},
356
],
357
restart: [
358
+ resetFailed,
359
{
360
step: "restarting the service after a failed update",
361
command: "systemctl",