@devries-cameron20 / t3code Mirror · read-only / commits / c38777968b
Fork 0

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 23, 03:00 UTC

fix(server): explain root browser launch failures instead of pointing to setup (#19846)

Madhav Gautam committed Oct 19, 2026 at 04:11 UTC c38777968b8decb2de86d7bd2e94b245a7135224
5 files changed +78 -6
apps/server/src/cli/browser.test.ts new
+30
@@ -0,0 +1,30 @@
1 +import * as NodeServices from "@effect/platform-node/NodeServices";
2 +import { expect, it } from "@effect/vitest";
3 +import * as HostProcess from "@t3tools/shared/HostProcess";
4 +import * as Effect from "effect/Effect";
5 +import * as FileSystem from "effect/FileSystem";
6 +import * as Layer from "effect/Layer";
7 +import * as TestConsole from "effect/testing/TestConsole";
8 +import { Command } from "effect/cli";
9 +
10 +import { browserCommand } from "./browser.ts";
11 +
12 +it.effect("setup in a root shell warns that the server cannot run as root", () =>
13 + Effect.gen(function* () {
14 + // Every file read fails, so setup finds nothing to install and changes nothing.
15 + yield* Command.runWith(browserCommand, { version: "0.0.0" })([
16 + "setup",
17 + "--base-dir",
18 + "/nonexistent",
19 + ]).pipe(
20 + Effect.provide(FileSystem.layerNoop({})),
21 + Effect.provideService(HostProcess.Platform, "linux"),
22 + Effect.provideService(HostProcess.UserId, 0),
23 + // A root user who follows the old advice runs setup through sudo.
24 + Effect.provideService(HostProcess.Environment, { SUDO_USER: "root" }),
25 + );
26 + const output = (yield* TestConsole.logLines).join("\n");
27 + expect(output).toContain("Chrome will not start its sandbox as root");
28 + expect(output).not.toContain("ready");
29 + }).pipe(Effect.provide(Layer.mergeAll(NodeServices.layer, TestConsole.layer))),
30 +);
apps/server/src/cli/browser.ts
+11 -4
@@ -96,6 +96,12 @@ const browserSetupCommand = Command.make("setup", { baseDir: baseDirFlag }).pipe
96 const fs = yield* FileSystem.FileSystem;
97 const isRoot = (yield* HostProcess.UserId) === 0;
98 const setupCommand = yield* resolveRootCliCommand(PreviewBrowserHost.SETUP_SUBCOMMAND);
99 + // Root, unless sudo came from another user, is likely the server's own account.
100 + const env = yield* HostProcess.Environment;
101 + const rootWarning =
102 + isRoot && (env.SUDO_USER ?? "root") === "root" && !PreviewBrowserHost.sandboxDisabled(env)
103 + ? new PreviewBrowserHost.PreviewBrowserRootError().message
104 + : undefined;
105
106 const needsProfile = yield* PreviewBrowserHost.sandboxBlocked;
107 const browser = yield* installedBrowser(yield* setupBaseDir(baseDir));
@@ -106,9 +112,10 @@ const browserSetupCommand = Command.make("setup", { baseDir: baseDirFlag }).pipe
112
113 if (!needsProfile && missing.length === 0) {
114 return yield* Console.log(
109 - Option.isSome(browser)
110 - ? "This host is ready for T3's browser."
111 - : "Chrome's sandbox is allowed here. T3's browser installs on first use; if it then reports missing libraries, run this again.",
115 + rootWarning ??
116 + (Option.isSome(browser)
117 + ? "This host is ready for T3's browser."
118 + : "Chrome's sandbox is allowed here. T3's browser installs on first use; if it then reports missing libraries, run this again."),
119 );
120 }
121
@@ -165,7 +172,7 @@ const browserSetupCommand = Command.make("setup", { baseDir: baseDirFlag }).pipe
172 yield* Console.log("Installed the browser's libraries.");
173 }
174
168 - yield* Console.log("This host is ready for T3's browser.");
175 + yield* Console.log(rootWarning ?? "This host is ready for T3's browser.");
176 }),
177 ),
178 );
apps/server/src/preview/PreviewBrowserHost.test.ts
+18
@@ -56,6 +56,7 @@ const diagnose = (input: {
56 output: string;
57 ldd: string;
58 version?: string;
59 + uid?: number;
60 }) => {
61 const { spawner, commands } = hostReporting({
62 ldd: input.ldd,
@@ -68,6 +69,7 @@ const diagnose = (input: {
69 }).pipe(
70 Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
71 Effect.provideService(HostProcess.Platform, input.platform),
72 + Effect.provideService(HostProcess.UserId, input.uid ?? 1000),
73 Effect.map((error) => ({ error, commands })),
74 );
75 };
@@ -86,6 +88,22 @@ describe("diagnoseLaunchFailure", () => {
88 }),
89 );
90
91 + it.effect("tells a root server to drop root, not to run setup", () =>
92 + Effect.gen(function* () {
93 + const { error, commands } = yield* diagnose({
94 + platform: "linux",
95 + output: PreviewBrowserHost.NO_SANDBOX_SIGNATURE,
96 + ldd: "",
97 + uid: 0,
98 + });
99 + expect(error?._tag).toBe("PreviewBrowserRootError");
100 + expect(error?.message).toContain("`User=`");
101 + expect(error?.message).toContain("`T3CODE_SERVER_BROWSER_SANDBOX=0`");
102 + expect(error?.message).not.toMatch(/AppArmor|browser setup/);
103 + expect(commands).toEqual([]);
104 + }),
105 + );
106 +
107 it.effect("names every library the loader cannot find", () =>
108 Effect.gen(function* () {
109 const { error } = yield* diagnose({
apps/server/src/preview/PreviewBrowserHost.ts
+18 -2
@@ -73,7 +73,20 @@ export class PreviewBrowserLibrariesError extends Schema.TaggedError<PreviewBrow
73 }
74 }
75
76 -export type PreviewBrowserHostError = PreviewBrowserSandboxError | PreviewBrowserLibrariesError;
76 +/** Chrome will not start its sandbox as root (crbug.com/638180), which no host setup fixes. */
77 +export class PreviewBrowserRootError extends Schema.TaggedError<PreviewBrowserRootError>()(
78 + "PreviewBrowserRootError",
79 + {},
80 +) {
81 + override get message(): string {
82 + return "Chrome will not start its sandbox as root, so T3's browser cannot run while the T3 server runs as root. Run the server as a nonroot user (for example `User=` in its systemd service), or set `T3CODE_SERVER_BROWSER_SANDBOX=0` to run the browser unsandboxed as root.";
83 + }
84 +}
85 +
86 +export type PreviewBrowserHostError =
87 + | PreviewBrowserSandboxError
88 + | PreviewBrowserLibrariesError
89 + | PreviewBrowserRootError;
90
91 const MISSING_LIBRARY = /^\s*(\S+) => not found$/gm;
92 const LOADER_ERROR = /error while loading shared libraries: ([^:\s]+)/;
@@ -86,7 +99,10 @@ export const diagnoseLaunchFailure = Effect.fn("PreviewBrowserHost.diagnoseLaunc
99 }) {
100 const { setupCommand } = input;
101 if (input.output.includes(NO_SANDBOX_SIGNATURE)) {
89 - return new PreviewBrowserSandboxError({ setupCommand });
102 + // Playwright reports Chrome's refusal to sandbox as root as a sandbox failure too.
103 + return (yield* HostProcess.UserId) === 0
104 + ? new PreviewBrowserRootError()
105 + : new PreviewBrowserSandboxError({ setupCommand });
106 }
107 if ((yield* HostProcess.Platform) !== "linux") return undefined;
108 const libraries = yield* missingLibraries(input.executable);
apps/server/src/preview/ServerBrowser.ts
+1
@@ -137,6 +137,7 @@ const isHostSetupError = Schema.is(
137 Schema.Union([
138 PreviewBrowserHost.PreviewBrowserSandboxError,
139 PreviewBrowserHost.PreviewBrowserLibrariesError,
140 + PreviewBrowserHost.PreviewBrowserRootError,
141 ]),
142 );
143