Skip to content

Commit 050e288

Browse files
authored
fix(ci): stop leftover Git processes before checkout retries (#132105)
* fix(ci): stop leftover Git processes before checkout retries * fix(ci): consolidate checkout process ownership across platforms
1 parent a79e651 commit 050e288

8 files changed

Lines changed: 914 additions & 135 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 295 additions & 101 deletions
Large diffs are not rendered by default.

‎docs/ci.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ reviewers inspect the code, tests, and CI to assess correctness.
117117

118118
When the check fails, update the PR body instead of pushing another code commit.
119119

120+
## Checkout ownership
121+
122+
The shared Linux Node checkout (`linux_node_checkout_step`) and shared Windows/macOS/iOS checkout (`platform_checkout_step`) use one process owner for every Git command within those anchors. Linux allows five whole-checkout attempts, clearing the workspace before each attempt, with 120-second candidate and trusted workflow-harness fetch deadlines and an increasing five-second backoff. Windows, macOS, and iOS retain 90-second fetch deadlines, three candidate fetch attempts on timeout only, five-second backoff, and one harness fetch attempt. Candidate and harness revisions remain separately pinned; Linux also fetches the optional ratchet base at depth one.
123+
124+
Timeout, cancellation, and leader exit drain the owned POSIX process group or Windows Job Object before workspace deletion, another Git command, or step completion. Cleanup has a ten-second allowance. If ownership inspection or cleanup fails, checkout exits with code 125 without retrying. The bootstrap uses the runner's Python standard library because repository helpers are unavailable before checkout. A fetch timeout alone does not explain why transport stalled.
125+
126+
Separate bootstrap and checkout flows in preflight, security, skills-python, ClawHub, and Android still use GNU timeout and are outside these shared anchors' ownership guarantees.
127+
120128
## Scope and routing
121129

122130
Scope logic lives in `scripts/ci-changed-scope.mjs` and is covered by unit tests in `src/scripts/ci-changed-scope.test.ts`. Ordinary manual dispatch skips changed-scope detection and makes the preflight manifest act as if every scoped area changed. The exact-head `release_gate` exception evaluates the fetched pull request merge tree and retains its macOS, iOS-build, screenshot-risk, and generated-native-locale decisions while still verifying native sources.

‎package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1937,7 +1937,7 @@
19371937
"test:live:media:music": "node --import ./scripts/tsx.mjs test/e2e/qa-lab/media/hosted-media-provider-live.ts music",
19381938
"test:live:media:video": "node --import ./scripts/tsx.mjs test/e2e/qa-lab/media/hosted-media-provider-live.ts video",
19391939
"test:live:models-profiles": "node --import ./scripts/tsx.mjs scripts/test-live.mts -- src/agents/models.profiles.live.test.ts",
1940-
"test:macos:ci": "node --import ./scripts/tsx.mjs scripts/test-projects.mts src/daemon/launchd.test.ts src/daemon/runtime-paths.test.ts src/daemon/runtime-binary.test.ts src/gateway/worker-environments/workspace-rsync-path.test.ts src/infra/brew.test.ts src/infra/stable-node-path.test.ts src/process/supervisor/adapters/child.service-lifecycle.test.ts test/scripts/vitest-process-group.test.ts test/scripts/package-mac-app.test.ts test/scripts/package-mac-dist.test.ts test/scripts/create-dmg.test.ts test/scripts/codesign-mac-app.test.ts test/scripts/notarize-mac-artifact.test.ts test/scripts/mac-elevation-host.test.ts",
1940+
"test:macos:ci": "node --import ./scripts/tsx.mjs scripts/test-projects.mts test/scripts/ci-platform-checkout.test.ts src/daemon/launchd.test.ts src/daemon/runtime-paths.test.ts src/daemon/runtime-binary.test.ts src/gateway/worker-environments/workspace-rsync-path.test.ts src/infra/brew.test.ts src/infra/stable-node-path.test.ts src/process/supervisor/adapters/child.service-lifecycle.test.ts test/scripts/vitest-process-group.test.ts test/scripts/package-mac-app.test.ts test/scripts/package-mac-dist.test.ts test/scripts/create-dmg.test.ts test/scripts/codesign-mac-app.test.ts test/scripts/notarize-mac-artifact.test.ts test/scripts/mac-elevation-host.test.ts",
19411941
"test:max": "node --import ./scripts/tsx.mjs scripts/test-projects-max.mts",
19421942
"test:parallels:linux": "bash scripts/e2e/parallels-linux-smoke.sh",
19431943
"test:parallels:macos": "bash scripts/e2e/parallels-macos-smoke.sh",
@@ -1983,7 +1983,7 @@
19831983
"test:voicecall:closedloop": "node --import ./scripts/tsx.mjs scripts/test-voicecall-closedloop.mts",
19841984
"test:watch": "node --import ./scripts/tsx.mjs scripts/test-projects.mts --watch",
19851985
"test:windows:ci": "pnpm test:windows:ci:1 && pnpm test:windows:ci:2",
1986-
"test:windows:ci:1": "node --import ./scripts/tsx.mjs scripts/test-projects.mts src/state/openclaw-state-ownership.test.ts src/snapshot/local-repository.windows.test.ts src/state/openclaw-database-paths.windows.test.ts src/node-host/invoke-system-run-allowlist.test.ts src/node-host/node-worker-transfer-client.test.ts packages/terminal-core/src/display-string.test.ts src/config/sessions/session-accessor.sqlite-archive.worker.test.ts src/commands/doctor-gateway-auth-token.windows.test.ts src/infra/state-migrations.audit-logs.windows.test.ts src/commands/backup-verify.test.ts src/commands/agents.commands.list.test.ts src/shared/runtime-import.test.ts src/shared/worker-bundle-archive.test.ts src/node-host/node-worker-bundle-installer.test.ts test/scripts/direct-run-entrypoints.test.ts test/scripts/format-generated-module.test.ts test/scripts/openclaw-cross-os-installer.windows.test.ts test/scripts/openclaw-cross-os-release-workflow.test.ts test/scripts/pnpm-runner.test.ts test/scripts/run-with-env.test.ts test/scripts/ui.test.ts test/scripts/vitest-process-group.test.ts src/agents/tools/media-tool-file-url.windows.test.ts extensions/memory-core/src/memory-extra-file-path.windows.test.ts src/daemon/schtasks.startup-fallback.test.ts src/plugin-sdk/node-host.test.ts test/e2e/qa-lab/runtime/package-openclaw-for-docker.e2e.test.ts extensions/lobster/src/lobster-runner.test.ts src/gateway/worker-environments/workspace-quiescence.windows.test.ts",
1986+
"test:windows:ci:1": "node --import ./scripts/tsx.mjs scripts/test-projects.mts test/scripts/ci-platform-checkout.test.ts src/state/openclaw-state-ownership.test.ts src/snapshot/local-repository.windows.test.ts src/state/openclaw-database-paths.windows.test.ts src/node-host/invoke-system-run-allowlist.test.ts src/node-host/node-worker-transfer-client.test.ts packages/terminal-core/src/display-string.test.ts src/config/sessions/session-accessor.sqlite-archive.worker.test.ts src/commands/doctor-gateway-auth-token.windows.test.ts src/infra/state-migrations.audit-logs.windows.test.ts src/commands/backup-verify.test.ts src/commands/agents.commands.list.test.ts src/shared/runtime-import.test.ts src/shared/worker-bundle-archive.test.ts src/node-host/node-worker-bundle-installer.test.ts test/scripts/direct-run-entrypoints.test.ts test/scripts/format-generated-module.test.ts test/scripts/openclaw-cross-os-installer.windows.test.ts test/scripts/openclaw-cross-os-release-workflow.test.ts test/scripts/pnpm-runner.test.ts test/scripts/run-with-env.test.ts test/scripts/ui.test.ts test/scripts/vitest-process-group.test.ts src/agents/tools/media-tool-file-url.windows.test.ts extensions/memory-core/src/memory-extra-file-path.windows.test.ts src/daemon/schtasks.startup-fallback.test.ts src/plugin-sdk/node-host.test.ts test/e2e/qa-lab/runtime/package-openclaw-for-docker.e2e.test.ts extensions/lobster/src/lobster-runner.test.ts src/gateway/worker-environments/workspace-quiescence.windows.test.ts",
19871987
"test:windows:ci:2": "node --import ./scripts/tsx.mjs scripts/test-projects.mts src/infra/sqlite-snapshot.test.ts src/infra/ports.test.ts src/infra/advertised-lan-host.windows.test.ts src/infra/update-managed-service-handoff-command.test.ts src/infra/update-managed-service-handoff-lifecycle.test.ts src/infra/executable-path.test.ts src/infra/fs-safe-remove.test.ts src/infra/state-migrations.legacy-session-store.test.ts src/infra/windows-install-roots.test.ts src/infra/ssh-client.windows.test.ts src/infra/exec-allowlist-pattern.test.ts src/infra/process-env.test.ts src/infra/openclaw-cli-shim.windows.test.ts src/agents/sessions/windows-git-bash-path.test.ts test/scripts/npm-runner.test.ts test/scripts/ts-topology.test.ts src/test-utils/openclaw-test-state.test.ts src/utils.test.ts src/media/local-media-path.windows.test.ts src/media/web-media.file-url.windows.test.ts src/process/exec.windows.test.ts src/process/exec.windows.integration.test.ts src/agents/sessions/exec.real.test.ts src/process/windows-command.test.ts src/process/terminal-pty.test.ts src/process/supervisor/supervisor.anchored-shell.real.test.ts src/tui/tui.resolve-codex-bin.test.ts src/media-understanding/attachments.file-url.windows.test.ts src/cli/daemon-cli/status.print.test.ts src/cli/mcp-cli.path-case.windows.test.ts src/auto-reply/usage-bar/template.windows.test.ts src/auto-reply/reply.triggers.trigger-handling.stages-inbound-media-into-sandbox-workspace.test.ts src/agents/provider-local-service.env-case.test.ts src/agents/bash-tools.exec.script-preflight.test.ts src/agents/agent-tools.read.windows.test.ts src/agents/agent-tools.read.host-operations.test.ts src/agents/sandbox/fs-paths.test.ts src/agents/sessions/tools/render-utils.test.ts src/agents/sessions/tools/path-utils.test.ts extensions/msteams/src/media-helpers.test.ts extensions/msteams/src/messenger.test.ts extensions/mxc/test/mxc-backend.test.ts extensions/mxc/test/sandbox-policy-loader.test.ts",
19881988
"test:windows:schtasks:integration": "node --import ./scripts/tsx.mjs scripts/run-with-env.mts CI_WINDOWS_SCHTASKS_INTEGRATION=1 OPENCLAW_E2E_SKIP_BUILD=1 OPENCLAW_E2E_VERBOSE=1 OPENCLAW_VITEST_MAX_WORKERS=1 -- node scripts/run-vitest.mjs src/daemon/schtasks.integration.e2e.test.ts",
19891989
"tool-display:check": "node --import ./scripts/tsx.mjs scripts/tool-display.ts --check",

‎scripts/test-projects.test-support.mts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2110,6 +2110,8 @@ const pluginSdkEntryOwners = [
21102110
// Keep only genuinely ambiguous paths explicit; conventional discovery owns
21112111
// unambiguous scripts and direct imports without a second inventory.
21122112
const EXACT_TOOLING_TARGETS = new Map<string, string[]>([
2113+
[".github/workflows/ci.yml", ["ci-platform-checkout"]],
2114+
["test/scripts/fixtures/ci-platform-checkout.mjs", ["ci-platform-checkout"]],
21132115
[
21142116
".github/workflows/mantis-telegram-live.yml",
21152117
["mantis-telegram-desktop-proof-workflow", packageAcceptance, workflowGuards],
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
import { fork } from "node:child_process";
2+
import { mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs";
3+
import { tmpdir } from "node:os";
4+
import path from "node:path";
5+
import { fileURLToPath } from "node:url";
6+
import { expectDefined } from "@openclaw/normalization-core";
7+
import { expect, it } from "vitest";
8+
import { parse } from "yaml";
9+
import { waitForChildClose } from "../helpers/process-wait.js";
10+
11+
type ProcessRecord = { pid: number; role: string; attempt: number };
12+
type Boundary = { name: string; alive: ProcessRecord[]; sentinelAlive: boolean };
13+
type Report = {
14+
code: number | null;
15+
error?: string;
16+
boundaries: Boundary[];
17+
readyAttempts: number[];
18+
cleanupRemaining: ProcessRecord[];
19+
commands: { cwd: string; args: string[] }[];
20+
output: string;
21+
};
22+
23+
const fixture = fileURLToPath(new URL("./fixtures/ci-platform-checkout.mjs", import.meta.url));
24+
25+
// Execute both workflow policies against the same owned tree fixture. A leader's
26+
// exit must not authorize workspace deletion, Git reuse, or final success.
27+
const platformCases = [
28+
{ scenario: "timeouts-exhausted", attempts: 3, code: 124, checkout: false },
29+
{ scenario: "recovery", attempts: 4, code: 0, checkout: true },
30+
{ scenario: "early-leader-exit", attempts: 2, code: 0, checkout: true },
31+
{ scenario: "harness-timeout", attempts: 2, code: 124, checkout: true },
32+
{ scenario: "git-failure", attempts: 1, code: 23, checkout: false },
33+
{ scenario: "git-exit-124", attempts: 1, code: 124, checkout: false },
34+
// Windows has no POSIX signals/ps boundary; native Job cancellation proof is separate.
35+
...(process.platform === "win32" ? [] : ["SIGTERM", "SIGINT", "SIGHUP"]).map((signal, index) => ({
36+
scenario: `cancel-${signal}`,
37+
attempts: 1,
38+
code: [143, 130, 129][index],
39+
checkout: false,
40+
})),
41+
...(process.platform === "win32"
42+
? []
43+
: [{ scenario: "cleanup-failure", attempts: 1, code: 125, checkout: false }]),
44+
];
45+
const linuxCases =
46+
process.platform === "win32"
47+
? []
48+
: [
49+
{ scenario: "timeouts-exhausted", attempts: 5, code: 1, checkout: false, deletions: 5 },
50+
{ scenario: "recovery", attempts: 4, code: 0, checkout: true, deletions: 3 },
51+
{ scenario: "early-leader-exit", attempts: 2, code: 0, checkout: true, deletions: 1 },
52+
{ scenario: "git-failure", attempts: 5, code: 1, checkout: false, deletions: 5 },
53+
{ scenario: "checkout-failure", attempts: 5, code: 1, checkout: true, deletions: 5 },
54+
{ scenario: "harness-recovery", attempts: 4, code: 0, checkout: true, deletions: 2 },
55+
{ scenario: "cancel-SIGTERM", attempts: 1, code: 143, checkout: false, deletions: 1 },
56+
{ scenario: "cleanup-failure", attempts: 1, code: 125, checkout: false, deletions: 1 },
57+
{ scenario: "non-executable-git", attempts: 0, code: null, checkout: false, deletions: 0 },
58+
{ scenario: "non-executable-find", attempts: 0, code: null, checkout: false, deletions: 0 },
59+
];
60+
61+
it.each([
62+
...platformCases.map((entry) => Object.assign(entry, { linux: false, deletions: 0 })),
63+
...linuxCases.map((entry) => Object.assign(entry, { linux: true })),
64+
])(
65+
"preserves checkout ownership and fixture isolation (Linux=$linux, $scenario)",
66+
async ({ scenario, attempts, code, checkout, linux, deletions }) => {
67+
const setupFailure = scenario.startsWith("non-executable-");
68+
const workflow = parse(readFileSync(".github/workflows/ci.yml", "utf8")) as {
69+
jobs: Record<string, { steps: { name?: string; run?: string }[] }>;
70+
};
71+
const run = workflow.jobs[linux ? "checks-fast-core" : "checks-windows"]?.steps.find(
72+
(step) => step.name === "Checkout",
73+
)?.run;
74+
expect(run).toBeTypeOf("string");
75+
if (!run) {
76+
throw new Error("Missing shared platform checkout shell");
77+
}
78+
79+
const root = realpathSync(mkdtempSync(path.join(tmpdir(), "ci platform checkout ")));
80+
const workspace = path.join(root, "workspace");
81+
mkdirSync(workspace);
82+
if (linux) {
83+
writeFileSync(path.join(workspace, ".previous-checkout"), "stale\n");
84+
}
85+
// Advance the test clock, not the real OS teardown budget: a subsecond
86+
// cleanup deadline races process scheduling instead of testing ownership.
87+
const accelerated = run
88+
.replace(/fetch_timeout_seconds = [^\n]+/u, "fetch_timeout_seconds = 2")
89+
.replace("kill_at = deadline - cleanup_seconds / 2", "kill_at = time.monotonic()")
90+
.replace(/retry_at = time\.monotonic\(\) \+ [^\n]+/u, "retry_at = time.monotonic() + 0.05")
91+
// Keep the original GNU timeout path executable for the pre-fix regression.
92+
.replace("120s git", "2s git")
93+
.replace("sleep $((attempt * 5))", "sleep 0.05");
94+
expect(accelerated).not.toBe(run);
95+
// A broken preflight must never let these negative fixture tests run real Git.
96+
writeFileSync(
97+
path.join(root, "checkout.sh"),
98+
setupFailure ? "printf 'unexpected workflow invocation\\n' >&2\nexit 99\n" : accelerated,
99+
);
100+
101+
const supervisor = fork(fixture, ["supervise", root, `${linux ? "linux:" : ""}${scenario}`], {
102+
detached: true,
103+
execArgv: [],
104+
stdio: ["ignore", "ignore", "pipe", "ipc"],
105+
});
106+
let stderr = "";
107+
supervisor.stderr?.on("data", (data) => (stderr += String(data)));
108+
const closed = waitForChildClose(supervisor, 50_000);
109+
try {
110+
const result = await closed;
111+
const report = JSON.parse(readFileSync(path.join(root, "report.json"), "utf8")) as Report;
112+
// Emit evidence before assertions; it remains available even for this deliberately red test.
113+
console.log(`${scenario}: ${JSON.stringify(report)}`);
114+
expect(report.cleanupRemaining, "fixture cleanup left owned processes").toEqual([]);
115+
if (setupFailure) {
116+
expect(report.error, report.output).toContain(
117+
"Fixture setup: mock command resolution failed",
118+
);
119+
expect(report.error).toContain(scenario.slice("non-executable-".length));
120+
expect(result, stderr).toEqual({ code: 1, signal: null });
121+
expect(report.code).toBeNull();
122+
expect(report.output).toBe("");
123+
expect(report.commands).toEqual([]);
124+
expect(report.boundaries).toEqual([]);
125+
return;
126+
}
127+
expect(result, stderr).toEqual({ code: 0, signal: null });
128+
expect(report.error, stderr).toBeUndefined();
129+
const leaks = report.boundaries
130+
.filter((entry) => entry.alive.length > 0)
131+
.map(({ name, alive }) => ({ boundary: name, survivors: alive }));
132+
expect(
133+
leaks,
134+
"Git descendants must be dead BEFORE workspace deletion, reuse or exit",
135+
).toEqual([]);
136+
expect(report.code).toBe(code);
137+
expect(report.readyAttempts).toEqual(Array.from({ length: attempts }, (_, i) => i + 1));
138+
expect(report.boundaries.filter((entry) => entry.name.startsWith("fetch:"))).toHaveLength(
139+
attempts,
140+
);
141+
expect(report.boundaries.some((entry) => entry.name === "checkout")).toBe(checkout);
142+
expect(report.boundaries.filter((entry) => entry.name === "delete")).toHaveLength(deletions);
143+
expect(report.boundaries.at(-1)?.name).toBe("exit");
144+
expect(report.output.includes("refusing reuse or retry")).toBe(
145+
scenario === "cleanup-failure",
146+
);
147+
if (code === 0) {
148+
const fetches = report.commands.filter(({ args }) => args.includes("fetch"));
149+
const candidateFetch = expectDefined(fetches[0], "candidate fetch");
150+
expect(candidateFetch.args).toContain(
151+
`+${"a".repeat(40)}:refs/remotes/origin/${linux ? "ci-target" : "checkout"}`,
152+
);
153+
expect(
154+
candidateFetch.args.includes(`+${"c".repeat(40)}:refs/remotes/origin/ci-ratchet-base`),
155+
).toBe(linux && scenario === "early-leader-exit");
156+
if (linux) {
157+
expect(
158+
report.commands.filter(
159+
({ args }) => args.join(" ") === `config --global --add safe.directory ${workspace}`,
160+
),
161+
).toHaveLength(deletions);
162+
expect(
163+
report.commands
164+
.filter(({ cwd, args }) => cwd === workspace && args[0] === "checkout")
165+
.every(
166+
({ args }) => args.join(" ") === `checkout --force --detach ${"a".repeat(40)}`,
167+
),
168+
).toBe(true);
169+
}
170+
expect(candidateFetch.cwd).toBe(workspace);
171+
expect(fetches.at(-1)?.cwd).toBe(path.join(workspace, ".ci-harness"));
172+
for (const { args } of fetches) {
173+
expect(args).toEqual(
174+
expect.arrayContaining(["--no-tags", "--no-recurse-submodules", "--depth=1"]),
175+
);
176+
}
177+
expect(fetches.at(-1)?.args).toContain(`+${"b".repeat(40)}:refs/remotes/origin/ci-harness`);
178+
expect(
179+
report.commands.some(
180+
({ args }) => args.join(" ") === "sparse-checkout set .github/actions",
181+
),
182+
).toBe(true);
183+
expect(report.commands.at(-1)?.args).toEqual([
184+
"checkout",
185+
"--force",
186+
"--detach",
187+
"b".repeat(40),
188+
]);
189+
}
190+
expect(
191+
report.boundaries.every((entry) => entry.sentinelAlive),
192+
"unrelated sentinel killed",
193+
).toBe(true);
194+
} finally {
195+
// IPC loss also triggers cleanup if Vitest is canceled or its worker is killed.
196+
if (supervisor.connected) {
197+
supervisor.disconnect();
198+
}
199+
await closed;
200+
rmSync(root, { recursive: true, force: true });
201+
}
202+
},
203+
55_000,
204+
);

0 commit comments

Comments
 (0)