Skip to content

Commit 1737e5c

Browse files
authored
fix(ci): stop downloading a second repository copy for the CI harness (#132638)
The Checkout step fetched .ci-harness as a full --depth=1 snapshot and only applied sparse-checkout afterwards, so the narrowing never reached the network transfer: every job downloaded a complete second copy of the tree and discarded all but .github/actions. Set sparse-checkout before the fetch and add --filter=blob:none. The harness checkout now materializes blobs over the network, so it carries the fetch deadline instead of running unbounded. Measured against the live remote: harness fetch 18.59s -> 0.98s, .ci-harness/.git 117 MB -> 7.0 MB. The workspace fetch stays unfiltered because jobs need real file contents.
1 parent d510996 commit 1737e5c

3 files changed

Lines changed: 58 additions & 4 deletions

File tree

‎.github/actions/git-owner/owner.py‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,17 @@ def checkout():
350350
os.makedirs(harness, exist_ok=True)
351351
run_git(harness, "init", harness)
352352
run_git(harness, "remote", "add", "origin", remote)
353-
fetch(harness, f"+{os.environ['WORKFLOW_SHA']}:refs/remotes/origin/ci-harness", max_attempts=1)
353+
# The harness only supplies .github/actions, so narrow the fetch before it runs:
354+
# sparse first, then blob-less. A full snapshot here downloads a second copy of
355+
# the repository that the checkout below immediately discards, and every extra
356+
# byte is amplified by the shared runner egress.
354357
run_git(harness, "sparse-checkout", "set", ".github/actions")
355-
run_git(harness, "checkout", "--force", "--detach", os.environ["WORKFLOW_SHA"])
358+
fetch(harness, f"+{os.environ['WORKFLOW_SHA']}:refs/remotes/origin/ci-harness",
359+
max_attempts=1, blobless=True)
360+
# Checkout now materializes the sparse blobs over the network, so it carries the
361+
# fetch deadline instead of running unbounded like a local checkout.
362+
run_git(harness, "checkout", "--force", "--detach", os.environ["WORKFLOW_SHA"],
363+
timeout=fetch_timeout_seconds)
356364
if not os.path.isfile(os.path.join(harness, action)):
357365
raise GitFailure(1)
358366
check_cancelled()

‎.github/workflows/ci.yml‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,9 +559,17 @@ jobs:
559559
os.makedirs(harness, exist_ok=True)
560560
run_git(harness, "init", harness)
561561
run_git(harness, "remote", "add", "origin", remote)
562-
fetch(harness, f"+{os.environ['WORKFLOW_SHA']}:refs/remotes/origin/ci-harness", max_attempts=1)
562+
# The harness only supplies .github/actions, so narrow the fetch before it runs:
563+
# sparse first, then blob-less. A full snapshot here downloads a second copy of
564+
# the repository that the checkout below immediately discards, and every extra
565+
# byte is amplified by the shared runner egress.
563566
run_git(harness, "sparse-checkout", "set", ".github/actions")
564-
run_git(harness, "checkout", "--force", "--detach", os.environ["WORKFLOW_SHA"])
567+
fetch(harness, f"+{os.environ['WORKFLOW_SHA']}:refs/remotes/origin/ci-harness",
568+
max_attempts=1, blobless=True)
569+
# Checkout now materializes the sparse blobs over the network, so it carries the
570+
# fetch deadline instead of running unbounded like a local checkout.
571+
run_git(harness, "checkout", "--force", "--detach", os.environ["WORKFLOW_SHA"],
572+
timeout=fetch_timeout_seconds)
565573
if not os.path.isfile(os.path.join(harness, action)):
566574
raise GitFailure(1)
567575
check_cancelled()

‎test/scripts/ci-linux-git.test.ts‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import path from "node:path";
2+
import { expectDefined } from "@openclaw/normalization-core";
23
import { expect, it } from "vitest";
34
import { runCiGitStep, type FetchResult } from "./ci-git-owner.test-support.js";
45

56
const candidate = "a".repeat(40);
7+
const harness = "b".repeat(40);
68
const base = "c".repeat(40);
79
const moved = "d".repeat(40);
810
const merge = "e".repeat(40);
911
const linuxIt = it.skipIf(process.platform !== "linux");
12+
// Command-shape assertions need no process-group census, so they also run on macOS.
13+
const posixIt = it.skipIf(process.platform === "win32");
1014

1115
const resetProfiles = [
1216
{
@@ -440,3 +444,37 @@ linuxIt(
440444
},
441445
55_000,
442446
);
447+
448+
posixIt(
449+
"fetches the CI harness without a second full-repository snapshot",
450+
async () => {
451+
const report = await runCiGitStep({ job: "checks-fast-core", fetchResults: [0, 0] });
452+
expect(report.code).toBe(0);
453+
const harnessDirectory = path.join(report.workspace, ".ci-harness");
454+
const harnessCommands = report.commands.filter(
455+
({ tool, cwd }) => tool === "git" && cwd === harnessDirectory,
456+
);
457+
// The harness supplies only .github/actions: narrowing must be in place before the
458+
// fetch runs, so it never downloads the blobs the sparse checkout discards.
459+
expect(harnessCommands.map(({ args }) => args[0])).toEqual([
460+
"init",
461+
"remote",
462+
"sparse-checkout",
463+
"fetch",
464+
"checkout",
465+
]);
466+
const harnessFetch = expectDefined(
467+
harnessCommands.find(({ args }) => args[0] === "fetch"),
468+
"harness fetch",
469+
);
470+
expect(harnessFetch.args).toEqual(expect.arrayContaining(["--filter=blob:none"]));
471+
expect(harnessFetch.args.at(-1)).toBe(`+${harness}:refs/remotes/origin/ci-harness`);
472+
// The selected checkout still needs real file contents, so it must stay unfiltered.
473+
const workspaceFetch = expectDefined(
474+
report.fetches.find(({ cwd }) => cwd === report.workspace),
475+
"workspace fetch",
476+
);
477+
expect(workspaceFetch.args).not.toContain("--filter=blob:none");
478+
},
479+
55_000,
480+
);

0 commit comments

Comments
 (0)