From 4f2fbe18afaa25d6afcf7ca89fc5455250fddde9 Mon Sep 17 00:00:00 2001 From: Okan YILDIRIM <63511519+ragokan@users.noreply.github.com> Date: Wed, 18 Nov 2026 06:10:41 +0000 Subject: [PATCH] fix(archive): bound worktree teardown and stream its output (#9852) Give worktree teardown commands a shared one-minute deadline. Projects can override it with `worktree.teardownTimeoutMs` in `paseo.json`. Drain output so successful teardowns can exceed the old 1 MiB buffer. Bound the output retained for diagnostics. At the deadline, try to terminate the command, close its output streams, and keep the worktree on disk. An exit status of zero in response to the stop signal still counts as a timeout. Closes #9857. Co-authored-by: Okan YILDIRIM <63511519+ragokan@users.noreply.github.com> --- packages/protocol/src/paseo-config-schema.ts | 14 ++ ...orkspace-archive-record-scoped.e2e.test.ts | 175 ++++++++++++++---- .../server/workspace-archive-undo.e2e.test.ts | 59 +++++- .../src/utils/paseo-config-file.test.ts | 29 +++ .../utils/worktree-shell-selection.test.ts | 32 +--- packages/server/src/utils/worktree.test.ts | 24 +++ packages/server/src/utils/worktree.ts | 55 ++++-- public-docs/worktrees/index.md | 13 ++ public-docs/worktrees/index.zh-CN.md | 13 ++ 9 files changed, 343 insertions(+), 71 deletions(-) diff --git a/packages/protocol/src/paseo-config-schema.ts b/packages/protocol/src/paseo-config-schema.ts index 31935bd796..541f876229 100644 --- a/packages/protocol/src/paseo-config-schema.ts +++ b/packages/protocol/src/paseo-config-schema.ts @@ -47,6 +47,9 @@ export const PaseoWorktreeConfigRawSchema = z .object({ setup: PaseoLifecycleCommandRawSchema.optional(), teardown: PaseoLifecycleCommandRawSchema.optional(), + // Checked by WorktreeConfigSchema, where an invalid value falls back to the default, so it + // never stops paseo.json from being edited or sent to the app. + teardownTimeoutMs: z.unknown().optional(), terminals: z.unknown().optional(), servicePorts: PaseoServicePortAllocationSchema.optional(), }) @@ -79,9 +82,20 @@ export const PaseoConfigRawSchema = z }) .passthrough(); +// Node timers can't wait longer than this; a longer delay fires at once. +const MAX_TIMER_DELAY_MS = 2_147_483_647; + export const WorktreeConfigSchema = PaseoWorktreeConfigRawSchema.extend({ setup: z.unknown().optional().transform(normalizeLifecycleCommands), teardown: z.unknown().optional().transform(normalizeLifecycleCommands), + // Its own catch, so an invalid limit doesn't drop the commands with the rest of the worktree. + teardownTimeoutMs: z + .number() + .int() + .positive() + .max(MAX_TIMER_DELAY_MS) + .optional() + .catch(undefined), }) .passthrough() .catch({ setup: [], teardown: [] }); diff --git a/packages/server/src/server/workspace-archive-record-scoped.e2e.test.ts b/packages/server/src/server/workspace-archive-record-scoped.e2e.test.ts index d10a098d79..bd243ced8e 100644 --- a/packages/server/src/server/workspace-archive-record-scoped.e2e.test.ts +++ b/packages/server/src/server/workspace-archive-record-scoped.e2e.test.ts @@ -1,5 +1,13 @@ -import { execFile, execFileSync, spawn } from "node:child_process"; -import { existsSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; +import { execFile, execFileSync } from "node:child_process"; +import { + chmodSync, + existsSync, + mkdtempSync, + readFileSync, + rmSync, + statSync, + writeFileSync, +} from "node:fs"; import { tmpdir } from "node:os"; import path from "node:path"; import { fileURLToPath } from "node:url"; @@ -569,7 +577,130 @@ test.skipIf(process.platform === "win32")( 60000, ); +async function createWorktreeWithTeardown( + slug: string, + worktreeConfig: { teardown: string; teardownTimeoutMs?: number }, +): Promise<{ workspaceId: string; worktreePath: string }> { + const repoDir = createGitRepo(); + writeFileSync(path.join(repoDir, "paseo.json"), JSON.stringify({ worktree: worktreeConfig })); + execFileSync("git", ["add", "paseo.json"], { cwd: repoDir, stdio: "pipe" }); + execFileSync("git", ["-c", "commit.gpgsign=false", "commit", "-m", "add teardown"], { + cwd: repoDir, + stdio: "pipe", + }); + const result = await ctx.client.createWorkspace({ + source: { kind: "worktree", cwd: repoDir, worktreeSlug: slug, baseBranch: "main" }, + }); + const workspace = result.workspace; + if (!workspace?.workspaceDirectory) { + throw new Error(result.error ?? "Failed to create worktree workspace"); + } + return { workspaceId: workspace.id, worktreePath: workspace.workspaceDirectory }; +} + +function isProcessRunning(pid: number): boolean { + try { + process.kill(pid, 0); + return true; + } catch { + return false; + } +} + test.skipIf(process.platform === "win32")( + "a paseo.json teardown that never exits is stopped and the archive answers", + async () => { + const pidFile = path.join(makeTempDir("hanging-teardown-"), "sleep.pid"); + const { workspaceId, worktreePath } = await createWorktreeWithTeardown("hanging-teardown", { + teardown: `sleep 600 & echo $! > ${JSON.stringify(pidFile)}; wait`, + teardownTimeoutMs: 2000, + }); + + try { + const archive = await ctx.client.archiveWorkspace(workspaceId); + + expect({ + error: archive.error, + workspaceActive: (await activeWorkspaceIds()).has(workspaceId), + worktreeOnDisk: existsSync(worktreePath), + }).toEqual({ error: null, workspaceActive: false, worktreeOnDisk: true }); + const sleepPid = Number(readFileSync(pidFile, "utf8").trim()); + await expect.poll(() => isProcessRunning(sleepPid), { timeout: 5000 }).toBe(false); + } finally { + if (existsSync(pidFile)) { + const sleepPid = Number(readFileSync(pidFile, "utf8").trim()); + if (isProcessRunning(sleepPid)) process.kill(sleepPid, "SIGKILL"); + } + } + }, + 30000, +); + +test.skipIf(process.platform === "win32")( + "a paseo.json teardown that prints more than 1 MiB still removes the worktree", + async () => { + const { workspaceId, worktreePath } = await createWorktreeWithTeardown("chatty-teardown", { + teardown: `node -e "process.stdout.write('x'.repeat(2 * 1024 * 1024))"`, + }); + + const archive = await ctx.client.archiveWorkspace(workspaceId); + + expect({ + error: archive.error, + workspaceActive: (await activeWorkspaceIds()).has(workspaceId), + worktreeOnDisk: existsSync(worktreePath), + }).toEqual({ error: null, workspaceActive: false, worktreeOnDisk: false }); + }, + 60000, +); + +test.skipIf(process.platform === "win32")( + "a teardown that handles SIGTERM and exits zero still leaves the worktree", + async () => { + const { workspaceId, worktreePath } = await createWorktreeWithTeardown("teardown-trap", { + teardown: `trap 'exit 0' TERM; sleep 5 & wait`, + teardownTimeoutMs: 2000, + }); + + const archive = await ctx.client.archiveWorkspace(workspaceId); + + expect({ + error: archive.error, + workspaceActive: (await activeWorkspaceIds()).has(workspaceId), + worktreeOnDisk: existsSync(worktreePath), + }).toEqual({ error: null, workspaceActive: false, worktreeOnDisk: true }); + }, + 15000, +); + +test.skipIf(process.platform === "win32")( + "the archive answers when an exited teardown shell's child holds its output open", + async () => { + const pidFile = path.join(makeTempDir("teardown-open-output-"), "sleep.pid"); + const { workspaceId, worktreePath } = await createWorktreeWithTeardown("teardown-open-output", { + teardown: `sleep 12 & echo $! > ${JSON.stringify(pidFile)}`, + teardownTimeoutMs: 2000, + }); + + try { + const archive = await ctx.client.archiveWorkspace(workspaceId); + + expect({ + error: archive.error, + workspaceActive: (await activeWorkspaceIds()).has(workspaceId), + worktreeOnDisk: existsSync(worktreePath), + }).toEqual({ error: null, workspaceActive: false, worktreeOnDisk: true }); + } finally { + if (existsSync(pidFile)) { + const sleepPid = Number(readFileSync(pidFile, "utf8").trim()); + if (isProcessRunning(sleepPid)) process.kill(sleepPid, "SIGKILL"); + } + } + }, + 10000, +); + +test.skipIf(process.platform === "win32" || process.getuid?.() === 0)( "repeating archive removes a residual worktree for an already-archived workspace", async () => { const repoDir = createGitRepo(); @@ -586,42 +717,24 @@ test.skipIf(process.platform === "win32")( throw new Error(result.error ?? "Failed to create worktree workspace"); } - const writerStartedPath = path.join(repoDir, "writer-started"); - const stopWriterPath = path.join(repoDir, "stop-writer"); - const target = path.join( - workspace.workspaceDirectory, - "node_modules/react-native-svg/lib/typescript", - ); - const writer = spawn( - process.execPath, - [ - "-e", - `const fs=require('fs'),path=require('path');const target=${JSON.stringify(target)};const started=${JSON.stringify(writerStartedPath)};const stop=${JSON.stringify(stopWriterPath)};fs.writeFileSync(started,'started');while(!fs.existsSync(stop)){try{fs.mkdirSync(target,{recursive:true});fs.writeFileSync(path.join(target,'active'),String(Date.now()))}catch{}}`, - ], - { stdio: "ignore" }, - ); - const writerExit = new Promise((resolve) => writer.once("exit", () => resolve())); - + const directory = workspace.workspaceDirectory; + const originalMode = statSync(directory).mode & 0o777; + // Deny removal of entries such as .git until the second archive request. + chmodSync(directory, originalMode & ~0o222); try { - await expect.poll(() => existsSync(writerStartedPath), { timeout: 10000 }).toBe(true); - const firstArchive = await ctx.client.archiveWorkspace(workspace.id); expect(firstArchive.error).toBeNull(); expect((await activeWorkspaceIds()).has(workspace.id)).toBe(false); - expect(existsSync(workspace.workspaceDirectory)).toBe(true); - - writeFileSync(stopWriterPath, "stop\n"); - await writerExit; - - const retry = await ctx.client.archiveWorkspace(workspace.id); - - expect(retry.error).toBeNull(); - expect(existsSync(workspace.workspaceDirectory)).toBe(false); + expect(existsSync(directory)).toBe(true); } finally { - writeFileSync(stopWriterPath, "stop\n"); - await writerExit; + if (existsSync(directory)) chmodSync(directory, originalMode); } + + const retry = await ctx.client.archiveWorkspace(workspace.id); + + expect(retry.error).toBeNull(); + expect(existsSync(directory)).toBe(false); }, 60000, ); diff --git a/packages/server/src/server/workspace-archive-undo.e2e.test.ts b/packages/server/src/server/workspace-archive-undo.e2e.test.ts index f68dbc5dd1..1d65afc307 100644 --- a/packages/server/src/server/workspace-archive-undo.e2e.test.ts +++ b/packages/server/src/server/workspace-archive-undo.e2e.test.ts @@ -1,6 +1,14 @@ import { DaemonClient } from "./test-utils/daemon-client.js"; import { execFileSync } from "node:child_process"; -import { existsSync, mkdtempSync, rmSync, writeFileSync, renameSync, mkdirSync } from "node:fs"; +import { + existsSync, + mkdtempSync, + readFileSync, + rmSync, + writeFileSync, + renameSync, + mkdirSync, +} from "node:fs"; import { tmpdir } from "node:os"; import path from "node:path"; import { afterEach, beforeEach, expect, test } from "vitest"; @@ -125,6 +133,55 @@ test.skipIf(process.platform === "win32")( 60000, ); +test.skipIf(process.platform === "win32")( + "an undo during a teardown that never exits returns once the deadline stops it", + async () => { + const tempRoot = mkdtempSync(path.join(tmpdir(), "workspace-archive-undo-hang-")); + tempRoots.push(tempRoot); + const repoDir = path.join(tempRoot, "repo"); + const pidFile = path.join(tempRoot, "sleep.pid"); + execFileSync("git", ["init", "-b", "main", repoDir], { stdio: "pipe" }); + git(repoDir, ["config", "user.email", "test@getpaseo.local"]); + git(repoDir, ["config", "user.name", "Paseo Test"]); + writeFileSync( + path.join(repoDir, "paseo.json"), + JSON.stringify({ + worktree: { + teardown: `sleep 600 & echo $! > ${JSON.stringify(pidFile)}; wait`, + teardownTimeoutMs: 2000, + }, + }), + ); + git(repoDir, ["add", "paseo.json"]); + git(repoDir, ["-c", "commit.gpgsign=false", "commit", "-m", "hanging teardown"]); + const { workspaceId, directory, agentId } = await createWorktreeWorkspaceWithAgent( + repoDir, + "undo-during-hanging-teardown", + ); + try { + const archive = ctx.client.archiveWorkspace(workspaceId); + await expect.poll(() => existsSync(pidFile), { timeout: 15000 }).toBe(true); + await Promise.all([archive, ctx.client.undoWorkspaceArchive(workspaceId)]); + + expect({ + workspaceActive: await isWorkspaceActive(workspaceId), + directoryExists: existsSync(directory), + agentArchived: await isAgentArchived(agentId), + }).toEqual({ workspaceActive: true, directoryExists: true, agentArchived: false }); + } finally { + if (existsSync(pidFile)) { + const sleepPid = Number(readFileSync(pidFile, "utf8").trim()); + try { + process.kill(sleepPid, "SIGKILL"); + } catch { + // Already stopped by the teardown deadline. + } + } + } + }, + 30000, +); + test.skipIf(process.platform === "win32")( "an undo after the archive finished recreates the worktree and its agents", async () => { diff --git a/packages/server/src/utils/paseo-config-file.test.ts b/packages/server/src/utils/paseo-config-file.test.ts index 6a7e43c757..ff77f44bce 100644 --- a/packages/server/src/utils/paseo-config-file.test.ts +++ b/packages/server/src/utils/paseo-config-file.test.ts @@ -14,6 +14,7 @@ import { PaseoConfigRawSchema, getWorktreeSetupCommands, getWorktreeTeardownCommands, + getWorktreeTeardownTimeoutMs, } from "./worktree.js"; import { readPaseoConfigForEdit, @@ -295,6 +296,34 @@ describe("paseo config file substrate", () => { expect(await getWorktreeTeardownCommands(tempDir)).toEqual(["npm run clean", "npm run reset"]); }); + it("reads the teardown time limit and defaults to one minute", async () => { + expect(await getWorktreeTeardownTimeoutMs(tempDir)).toBe(60_000); + + for (const teardownTimeoutMs of [1, 300_000, 2_147_483_647]) { + writeFileSync( + join(tempDir, "paseo.json"), + JSON.stringify({ worktree: { teardownTimeoutMs } }), + ); + expect(await getWorktreeTeardownTimeoutMs(tempDir)).toBe(teardownTimeoutMs); + } + }); + + it.each([0, -1000, 1500.5, 2_147_483_648, "90000", null, true, { ms: 90_000 }])( + "falls back to the default teardown time limit for %j and keeps the commands", + async (teardownTimeoutMs) => { + const config = { worktree: { teardown: "npm run clean", teardownTimeoutMs } }; + writeFileSync(join(tempDir, "paseo.json"), JSON.stringify(config)); + + expect(await getWorktreeTeardownTimeoutMs(tempDir)).toBe(60_000); + expect(await getWorktreeTeardownCommands(tempDir)).toEqual(["npm run clean"]); + expect(await readPaseoConfigForEdit(tempDir)).toEqual({ + ok: true, + config, + revision: await statPaseoConfigPath(tempDir), + }); + }, + ); + it("writes pretty JSON with a trailing newline when revision matches", async () => { writeFileSync(join(tempDir, "paseo.json"), JSON.stringify({ worktree: { setup: "old" } })); const expectedRevision = await statPaseoConfigPath(tempDir); diff --git a/packages/server/src/utils/worktree-shell-selection.test.ts b/packages/server/src/utils/worktree-shell-selection.test.ts index a17d6cd498..62f34174e4 100644 --- a/packages/server/src/utils/worktree-shell-selection.test.ts +++ b/packages/server/src/utils/worktree-shell-selection.test.ts @@ -5,17 +5,8 @@ import { tmpdir } from "node:os"; import { join } from "node:path"; import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; -const execFileMock = vi.hoisted(() => vi.fn()); const spawnProcessMock = vi.hoisted(() => vi.fn()); -vi.mock("child_process", async () => { - const actual = await vi.importActual("child_process"); - return { - ...actual, - execFile: execFileMock, - }; -}); - vi.mock("./spawn.js", async () => { const actual = await vi.importActual("./spawn.js"); return { @@ -42,19 +33,7 @@ describe("worktree shell selection", () => { const originalPlatform = process.platform; beforeEach(() => { - execFileMock.mockReset(); spawnProcessMock.mockReset(); - execFileMock.mockImplementation( - ( - _file: string, - _args: string[], - _options: unknown, - callback?: (error: Error | null, stdout: string, stderr: string) => void, - ) => { - callback?.(null, "", ""); - return {}; - }, - ); spawnProcessMock.mockImplementation(createSpawnChildStub); }); @@ -94,8 +73,8 @@ describe("worktree shell selection", () => { branchName: "main", }); - expect(execFileMock).toHaveBeenCalledTimes(1); - expect(execFileMock).toHaveBeenCalledWith( + expect(spawnProcessMock).toHaveBeenCalledTimes(1); + expect(spawnProcessMock).toHaveBeenCalledWith( "powershell", [ "-NoProfile", @@ -105,11 +84,10 @@ describe("worktree shell selection", () => { "-Command", "Write-Output 'teardown'", ], - expect.objectContaining({ cwd: worktreePath }), - expect.any(Function), + expect.objectContaining({ cwd: worktreePath, shell: false }), ); - const execOptions = execFileMock.mock.calls[0]?.[2] as { env?: NodeJS.ProcessEnv }; - expect(execOptions.env?.BASH_ENV).toBeUndefined(); + const spawnOptions = spawnProcessMock.mock.calls[0]?.[2] as { env?: NodeJS.ProcessEnv }; + expect(spawnOptions.env?.BASH_ENV).toBeUndefined(); } finally { if (originalBashEnv === undefined) { delete process.env.BASH_ENV; diff --git a/packages/server/src/utils/worktree.test.ts b/packages/server/src/utils/worktree.test.ts index 39f2af09c0..4f0a1d5ef3 100644 --- a/packages/server/src/utils/worktree.test.ts +++ b/packages/server/src/utils/worktree.test.ts @@ -190,6 +190,30 @@ describe("paseo worktree manager", () => { }); }); + it("retains bounded diagnostic text per teardown output stream", async () => { + const limit = 1024 * 1024; + writeFileSync( + join(repoDir, "paseo.json"), + JSON.stringify({ + worktree: { + teardown: `node -e "process.stdout.write('x'.repeat(${2 * limit})); process.stderr.write('y'.repeat(${2 * limit}))"`, + }, + }), + ); + + const [result] = await runWorktreeTeardownCommands({ + worktreePath: repoDir, + repoRootPath: repoDir, + branchName: "main", + }); + + expect({ + exitCode: result.exitCode, + stdoutLength: result.stdout.length, + stderrLength: result.stderr.length, + }).toEqual({ exitCode: 0, stdoutLength: limit, stderrLength: limit }); + }); + it("rejects paths that are not under the paseo worktrees root", async () => { const outsidePath = join(tempDir, "outside-paseo-home"); mkdirSync(outsidePath, { recursive: true }); diff --git a/packages/server/src/utils/worktree.ts b/packages/server/src/utils/worktree.ts index 92e70c9e87..98c48e460c 100644 --- a/packages/server/src/utils/worktree.ts +++ b/packages/server/src/utils/worktree.ts @@ -146,6 +146,13 @@ export class WorktreeSetupError extends Error { export type WorktreeTeardownCommandResult = WorktreeSetupCommandResult; +// paseo.json can change this with worktree.teardownTimeoutMs. Archive waits for teardown before it +// answers, and the app stops waiting for an archive answer after 60 seconds +// (DEFAULT_SESSION_RPC_TIMEOUT_MS in the client). A teardown that runs to this limit, or to a longer +// one, answers after the app has reported the archive as failed. +const DEFAULT_WORKTREE_TEARDOWN_TIMEOUT_MS = 60_000; +const MAX_WORKTREE_TEARDOWN_OUTPUT_CHARS_PER_STREAM = 1024 * 1024; + export class WorktreeTeardownError extends Error { readonly results: WorktreeTeardownCommandResult[]; @@ -281,6 +288,13 @@ export async function getWorktreeTeardownCommands(repoRoot: string): Promise { + return ( + (await readPaseoConfigOrThrow(repoRoot))?.worktree?.teardownTimeoutMs ?? + DEFAULT_WORKTREE_TEARDOWN_TIMEOUT_MS + ); +} + export async function getWorktreeTerminalSpecs( repoRoot: string, ): Promise { @@ -449,12 +463,14 @@ async function execSetupCommandStreamed(options: { index: number; total: number; signal?: AbortSignal; + maxOutputCharsPerStream?: number; onEvent?: (event: WorktreeSetupCommandProgressEvent) => void; }): Promise { return new Promise((resolvePromise) => { const startedAt = Date.now(); - const stdoutChunks: string[] = []; - const stderrChunks: string[] = []; + const outputChunks: Record<"stdout" | "stderr", string[]> = { stdout: [], stderr: [] }; + const outputLimit = options.maxOutputCharsPerStream ?? Infinity; + const remainingOutputChars = { stdout: outputLimit, stderr: outputLimit }; let settled = false; let termination: Promise | null = null; @@ -463,10 +479,10 @@ async function execSetupCommandStreamed(options: { if (!text) { return; } - if (stream === "stdout") { - stdoutChunks.push(text); - } else { - stderrChunks.push(text); + const retainedText = text.slice(0, remainingOutputChars[stream]); + if (retainedText) { + outputChunks[stream].push(retainedText); + remainingOutputChars[stream] -= retainedText.length; } options.onEvent?.({ type: "output", @@ -485,12 +501,17 @@ async function execSetupCommandStreamed(options: { } settled = true; options.signal?.removeEventListener("abort", abort); - await termination; + if (termination) { + await termination; + // A descendant can keep these pipes open after the shell exits. + child.stdout?.destroy(); + child.stderr?.destroy(); + } const result: WorktreeSetupCommandResult = { command: options.command, cwd: options.cwd, - stdout: stdoutChunks.join(""), - stderr: stderrChunks.join(""), + stdout: outputChunks.stdout.join(""), + stderr: outputChunks.stderr.join(""), exitCode, durationMs: Date.now() - startedAt, }; @@ -529,6 +550,7 @@ async function execSetupCommandStreamed(options: { gracefulTimeoutMs: 1000, forceTimeoutMs: 1000, }); + void finish(null); }; if (options.signal?.aborted) { abort(); @@ -768,17 +790,26 @@ export async function runWorktreeTeardownCommands(options: { }), ); + // One deadline covers every command. Reaching it counts as failure and keeps the worktree. + const timeoutMs = await getWorktreeTeardownTimeoutMs(teardownCwd); + const deadline = AbortSignal.timeout(timeoutMs); const results: WorktreeTeardownCommandResult[] = []; - for (const cmd of teardownCommands) { - const result = await execSetupCommand(cmd, { + for (const [index, cmd] of teardownCommands.entries()) { + const result = await execSetupCommandStreamed({ + command: cmd, cwd: teardownCwd, env: teardownEnv, + index: index + 1, + total: teardownCommands.length, + signal: deadline, + maxOutputCharsPerStream: MAX_WORKTREE_TEARDOWN_OUTPUT_CHARS_PER_STREAM, }); results.push(result); if (result.exitCode !== 0) { + const reason = deadline.aborted ? `Timed out after ${timeoutMs / 1000}s` : result.stderr; throw new WorktreeTeardownError( - `Worktree teardown command failed: ${cmd}\n${result.stderr}`.trim(), + `Worktree teardown command failed: ${cmd}\n${reason}`.trim(), results, ); } diff --git a/public-docs/worktrees/index.md b/public-docs/worktrees/index.md index faabb2d81f..55eb4de01b 100644 --- a/public-docs/worktrees/index.md +++ b/public-docs/worktrees/index.md @@ -122,6 +122,19 @@ Both fields accept a multiline shell script or an array of commands; commands ru Commands run with the worktree as `cwd`. Use `$PASEO_SOURCE_CHECKOUT_PATH` to reach files in the original checkout (untracked config, local caches, etc). +Teardown commands share a one minute limit. Set `teardownTimeoutMs` to change it, in milliseconds: + +```json +{ + "worktree": { + "teardown": "docker compose down", + "teardownTimeoutMs": 300000 + } +} +``` + +At the limit, Paseo tries to stop the command and its child processes and stops waiting for output. If teardown fails or reaches the limit, the workspace still archives and the worktree stays on disk. `teardownTimeoutMs` accepts whole numbers from 1 to 2147483647. Other values use the default. + ## Scripts and services `scripts` are named commands you can run inside a worktree on demand. Mark one as a _service_ and Paseo supervises it as a long-running process, assigns it a port, and routes HTTP traffic to it through the daemon's reverse proxy. diff --git a/public-docs/worktrees/index.zh-CN.md b/public-docs/worktrees/index.zh-CN.md index cce65fc090..59f4342627 100644 --- a/public-docs/worktrees/index.zh-CN.md +++ b/public-docs/worktrees/index.zh-CN.md @@ -120,6 +120,19 @@ paseo workspace create \ 命令以 worktree 作为 `cwd` 运行。使用 `$PASEO_SOURCE_CHECKOUT_PATH` 访问原始检出中的文件(未跟踪的配置、本地缓存等)。 +teardown 的所有命令共用一分钟的时限。用 `teardownTimeoutMs` 修改它,单位为毫秒: + +```json +{ + "worktree": { + "teardown": "docker compose down", + "teardownTimeoutMs": 300000 + } +} +``` + +达到时限后,Paseo 会尝试停止命令及其子进程,并停止等待输出。如果 teardown 失败或达到时限,工作区仍会归档,worktree 会保留在磁盘上。`teardownTimeoutMs` 接受 1 到 2147483647 之间的整数。其他值使用默认时限。 + ## 脚本与服务 {#scripts-and-services} `scripts` 是可以在 worktree 中按需运行的具名命令。把其中一个标记为 _service_,Paseo 就会把它作为长时间运行的进程进行监管,为它分配端口,并通过 daemon 的反向代理把 HTTP 流量路由给它。