Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .agents/skills/manage-ci/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,14 @@ contract; no downstream product's workflow topology applies here.
committed native changes against upstream. Upload unverified recovery on
failure/cancellation before verbose logs; never admit it as CI evidence.
A repaired candidate receives fresh full CI.
Re-export the applied core/model queue against the selected upstream before
generating compiler-owned shards. Before freezing, replay the complete queue
in a fresh repository fetched from upstream's reachable history only, without
local clone objects or alternates, and require the identical prepared native
SHA. Retain cold-replay evidence and failures with preparation diagnostics.
Patch application failures in `Run just llama-prepare` are candidate failures
and return to bounded source repair; recognized network/disk/runner failures
still stop source repair.
Every local verification pass must run the existing CPU `just lint`,
`just test` and `just llama-check` gates against the same prepared native
tree before freezing a candidate. Source failures return to the same Goose
Expand Down
11 changes: 11 additions & 0 deletions ci/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,17 @@ open upgrade PRs fail for reconciliation instead of discarding work. If the
previous PR was merged or closed before resolution and a newer upstream release
exists, the pipeline creates a new PR. Main already current still stops first.

Preparation re-exports applied core/model commits so their patch preimages and
contexts match the selected upstream; generated shards stay compiler-owned.
It then independently replays the complete queue in a fresh Git repository
containing only upstream's reachable history and requires the same native SHA.
This catches queues that passed only because the preparation runner retained
old intermediate patch objects. `cold-replay.json` is retained in preparation
recovery evidence; failed replay status and mail patches reach the repair agent.
Patch application failure in the Quality canary's `Run just llama-prepare` step
is sent to candidate repair, while recognized network, disk and runner failures
remain infrastructure failures.

The successful path has one full CI pass. A failed candidate may receive one
agent repair followed by full CI on a fresh candidate. Preparation and repair
run directly on the native JY Linux runner in group
Expand Down
4 changes: 3 additions & 1 deletion scripts/lib/upgrade_ci_failure.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import re

SOURCE_STEPS = {"Run just test", "Run just lint", "Run just llama-check",
"Run just skippy-ffi-bindgen-check", "Run ./.github/actions/ci-package"}
"Run just llama-prepare", "Run just skippy-ffi-bindgen-check", "Run ./.github/actions/ci-package"}
ENVIRONMENT_ERRORS = (
r"fatal error(?: C[0-9]+)?:.*nvml[.]h.*No such file or directory",
r"fatal error:.*['\"]nvml[.]h['\"] file not found",
r"No space left on device",
r"Cannot connect to the Docker daemon",
r"Error response from daemon:",
r"fatal: unable to access .*Could not resolve host",
r"fatal: unable to access .*Failed to connect",
)


Expand Down
3 changes: 3 additions & 0 deletions scripts/lib/upgrade_regeneration.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from .ci_process import capture, command
from .upgrade_source import PIN, git
from .upgrade_replay import normalize_core, verify_replay

SCRIPTS = Path(__file__).resolve().parents[1]

Expand Down Expand Up @@ -53,6 +54,7 @@ def regenerate(checkout):
"LLAMA_BUILD_DIR": str(native), "LLAMA_STAGE_BACKEND": "cpu", "LLAMA_STAGE_LINK_MODE": "static"}
just = ["just", "--justfile", str(checkout / "Justfile")]
command([*just, "llama-build"], overrides=env, timeout=7200)
normalize_core(checkout, source)
base = git(source, "rev-parse", "HEAD")
llvm = Path(os.environ["SKIPPY_REWRITER_LLVM_PREFIX"]).resolve(strict=True)
command(["cmake", "-S", str(checkout / "scripts/tools/skippy-stage-rewriter"), "-B", str(tools),
Expand Down Expand Up @@ -89,3 +91,4 @@ def regenerate(checkout):
overrides=dict(env, SKIPPY_FFI_BINDGEN="regen"), timeout=3600)
command([sys.executable, str(SCRIPTS / "generate-skippy-api-doc.py"),
"--include-dir", str(source / "include/skippy"), "--output", str(checkout / "docs/native-api.md")])
verify_replay(checkout, source)
4 changes: 4 additions & 0 deletions scripts/lib/upgrade_repair.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def repair(checkout, diagnostics, *, session=None, timeout=41400):
"Read last-check.json and the verification logs for the exact failed command. "
"Continue the same developer task and fix the actual failure. "
"Preserve model behavior, ABI contracts, the ordered patch queues and existing tests. "
"Read cold-replay.json and cold-failed.patch when present. Every exported patch must replay in a "
"fresh repository containing only the selected upstream history; private old patch-result blobs "
"are not portable inputs. The controller re-exports applied core/model commits before generation "
"and independently replays the complete queue before freezing. "
"If continuation.json or continuation-conflicts.txt is present, carry forward the previous open PR's "
"repairs onto the newly selected upstream release. Resolve recorded merge conflicts without discarding "
"working fixes; retire a fix only when the new upstream makes it obsolete and explain that in diagnostics. "
Expand Down
58 changes: 58 additions & 0 deletions scripts/lib/upgrade_replay.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"""Export rebased core repairs and prove their queue replays without private Git objects."""

import shutil

from .ci_artifacts import write_json
from .ci_process import command
from .upgrade_source import PIN, git, validate_sha


def normalize_core(checkout, native):
patches = checkout / "llama_cpp/patches"
paths = sorted(patches.glob("*.patch"))
models = patches / "model_support"
if models.exists():
for name in (models / "series").read_text().splitlines():
if not name or "/" in name or "\\" in name:
raise ValueError("invalid model support patch series member")
paths.append(models / name)
upstream = validate_sha((checkout / PIN).read_text().strip())
git(native, "merge-base", "--is-ancestor", upstream, "HEAD")
commits = git(native, "rev-list", "--reverse", f"{upstream}..HEAD").splitlines()
if len(commits) != len(paths):
raise ValueError("prepared core history does not match the ordered patch queue")
# git am may have used old intermediate blobs during a three-way rebase.
# Export each actual applied commit, preserving its author/message/date and
# queue position, so later consumers need only the selected upstream history.
# Generated shards remain exclusively owned by the compiler generator.
for path, commit in zip(paths, commits):
if len(git(native, "rev-list", "--parents", "-n1", commit).split()) != 2:
raise ValueError("prepared core patch history must be linear")
mail = command(["git", "-C", str(native), "format-patch", "--full-index", "--no-signature",
"-1", "--stdout", commit], capture_stdout=True)
path.write_text(mail, encoding="utf-8")


def verify_replay(checkout, native):
upstream = validate_sha((checkout / PIN).read_text().strip())
expected = validate_sha(git(native, "rev-parse", "HEAD"))
scratch = checkout / "target/llama-regeneration"
(scratch / "cold-replay.json").unlink(missing_ok=True)
cold = scratch / "cold-replay"
shutil.rmtree(cold, ignore_errors=True)
cold.mkdir(parents=True)
git(cold, "init", "--quiet")
git(cold, "remote", "add", "origin", str(native))
# Fetch only upstream's reachable history. A local clone/alternates would
# also admit cached patch-result blobs and reproduce the preparation blind spot.
git(cold, "fetch", "--no-tags", "origin", upstream, timeout=600)
git(cold, "checkout", "--detach", upstream)
command(["just", "--justfile", str(checkout / "Justfile"), "llama-prepare"],
cwd=checkout, overrides={"LLAMA_WORKDIR": str(cold), "LLAMA_UPSTREAM_URL": str(native),
"LLAMA_PIN_FILE": str(checkout / PIN),
"LLAMA_PATCH_DIR": str(checkout / "llama_cpp/patches")}, timeout=3600)
actual = validate_sha(git(cold, "rev-parse", "HEAD"))
if actual != expected:
raise ValueError("cold patch replay differs from the prepared native source identity")
write_json(scratch / "cold-replay.json", {"upstream_sha": upstream, "patched_sha": actual,
"tree_sha": git(cold, "rev-parse", "HEAD^{tree}")})
26 changes: 26 additions & 0 deletions scripts/tests/upgrade_contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from lib.upgrade_source import git
from lib.upgrade_repair import repair
from lib.upgrade_preimages import seed_patch_preimages
from lib.upgrade_replay import normalize_core, verify_replay

ROOT = Path(__file__).resolve().parents[2]
SHA = "a" * 40
Expand Down Expand Up @@ -265,6 +266,31 @@ def test_cold_queue_needs_old_patch_results_and_seed_preserves_selected_pin(self
expected = second.copy()
expected[23] = updated[23]
self.assertEqual((native / "native.cpp").read_text(), "".join(expected))
# Recreate the real deterministic preparation, then prove the
# cache-dependent queue fails in an independent upstream-only repo.
from lib.ci_process import command
command(["just", "--justfile", str(checkout / "Justfile"), "llama-prepare"], overrides={
"LLAMA_UPSTREAM_URL": str(upstream), "LLAMA_WORKDIR": str(native),
"LLAMA_PIN_FILE": str(pin), "LLAMA_PATCH_DIR": str(patches),
})
prepared = git(native, "rev-parse", "HEAD")
with self.assertRaises(subprocess.CalledProcessError):
verify_replay(checkout, native)
cold = checkout / "target/llama-regeneration/cold-replay"
self.assertNotEqual(subprocess.run(
["git", "-C", str(cold), "cat-file", "-e", preimage], capture_output=True).returncode, 0)
normalize_core(checkout, native)
verify_replay(checkout, native)
self.assertEqual(git(cold, "rev-parse", "HEAD"), prepared)
self.assertEqual((cold / "native.cpp").read_text(), "".join(expected))
# A stale success report cannot survive a later mismatched history.
git(native, "-c", "user.name=Fixture", "-c", "user.email=fixture@skippy.local",
"-c", "commit.gpgsign=false", "commit", "--allow-empty", "-m", "unexpected extra native commit")
with self.assertRaisesRegex(ValueError, "ordered patch queue"):
normalize_core(checkout, native)
with self.assertRaisesRegex(ValueError, "source identity"):
verify_replay(checkout, native)
self.assertFalse((cold.parent / "cold-replay.json").exists())

def test_unchanged_pin_needs_no_seed_or_native_checkout(self):
with tempfile.TemporaryDirectory() as tmp:
Expand Down
16 changes: 16 additions & 0 deletions scripts/tests/upgrade_verification.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,22 @@ def job(self, identifier=1, step='Run just llama-check', name='requalify / Graph
def test_native_compile_failure_is_repairable(self):
self.assertTrue(classify([self.job()], {1: 'error: undeclared LLM_FUSED_OP_LIGHTNING_INDEXER'})['repairable'])

def test_patch_replay_failure_returns_to_candidate_repair(self):
verdict = classify([self.job(step='Run just llama-prepare', name='qualify / Quality canary')],
{1: 'error: sha1 information is lacking or useless (tests/CMakeLists.txt).\n'
'error: could not build fake ancestor\nPatch failed at 0038'})
self.assertTrue(verdict['repairable'])
self.assertEqual(verdict['failure_class'], 'candidate')

def test_prepare_network_or_disk_failure_still_stops_source_repair(self):
for log in ('fatal: unable to access https://example/: Could not resolve host: example',
'fatal: unable to access https://example/: Failed to connect to example port 443',
'No space left on device'):
with self.subTest(log=log):
verdict = classify([self.job(step='Run just llama-prepare')], {1: log})
self.assertFalse(verdict['repairable'])
self.assertEqual(verdict['failure_class'], 'infrastructure')

def test_missing_nvml_stops_even_when_another_source_failure_is_repairable(self):
jobs = [self.job(), self.job(2, 'Run ./.github/actions/ci-package', 'requalify / ARM64 CUDA 13')]
for error in ('fatal error: nvml.h: No such file or directory',
Expand Down
36 changes: 19 additions & 17 deletions scripts/upgrade-source.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,29 @@ def resolve(upstream, force):

def save_preparation_diagnostics(checkout, destination):
"""Keep patch failures inspectable after the disposable checkout is removed."""
source = checkout / ".deps/llama.cpp"
for name in ("graph-coverage.json", "abi-compatibility.json"):
for name in ("graph-coverage.json", "abi-compatibility.json", "cold-replay.json"):
report = checkout / "target/llama-regeneration" / name
if report.is_file():
destination.mkdir(parents=True, exist_ok=True)
shutil.copyfile(report, destination / name)
if not (source / ".git").is_dir():
return
destination.mkdir(parents=True, exist_ok=True)
for name, args in {
"source-status.txt": ("status", "--short"),
"source.diff": ("diff", "HEAD", "--"),
# Even this read-only am operation checks committer identity on clean CI hosts.
"failed.patch": ("-c", "user.name=Skippy diagnostics", "-c", "user.email=ci@skippy.local",
"am", "--show-current-patch=diff"),
}.items():
try:
text = git(source, *args)
except (OSError, ValueError, RuntimeError, subprocess.SubprocessError):
# There is no active mail patch when failure occurs during compilation.
for prefix, source in (("", checkout / ".deps/llama.cpp"),
("cold-", checkout / "target/llama-regeneration/cold-replay")):
if not (source / ".git").is_dir():
continue
(destination / name).write_text(text + "\n", encoding="utf-8")
destination.mkdir(parents=True, exist_ok=True)
for name, args in {
"source-status.txt": ("status", "--short"),
"source.diff": ("diff", "HEAD", "--"),
# Even this read-only am operation checks committer identity on clean CI hosts.
"failed.patch": ("-c", "user.name=Skippy diagnostics", "-c", "user.email=ci@skippy.local",
"am", "--show-current-patch=diff"),
}.items():
try:
text = git(source, *args)
except (OSError, ValueError, RuntimeError, subprocess.SubprocessError):
# There is no active mail patch when failure occurs during compilation.
continue
(destination / (prefix + name)).write_text(text + "\n", encoding="utf-8")


def prepare(upstream, repair_bundle=None, diagnostics=None, previous=None):
Expand Down Expand Up @@ -113,6 +114,7 @@ def verify():

verify_or_repair(checkout, directory / "diagnostics", verify, repair, save_preparation_diagnostics,
initial_repair=bool(repair_bundle) or conflicts)
save_preparation_diagnostics(checkout, directory / "diagnostics/recovery")
check_changes(checkout, "HEAD")
git(checkout, "add", "--", *(path for path in ALLOWED if (checkout / path).exists()))
timestamp = int(git(checkout, "show", "-s", "--format=%ct", base)) + 1
Expand Down
Loading