Skip to content

Commit 511f284

Browse files
Harden the native Hy3 build contract
1 parent ae671ec commit 511f284

8 files changed

Lines changed: 369 additions & 29 deletions

‎config/ulysses/colibri-providers.json‎

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,14 @@
177177
"setup_path": "c/setup.sh",
178178
"build_cwd": "c",
179179
"build_argv": ["make", "hy3", "CUDA=1", "IOURING=1"],
180+
"build_compatibility": {
181+
"id": "hy3-cuda-matmul-group-size",
182+
"source_commit": "08f8439ebfe1994b607aed6adf857c80e8894c4c",
183+
"path": "c/hy3.c",
184+
"before": "coli_cuda_matmul(&w->cuda,y,x,weights,w->s,w->fmt,S,w->I,w->O,w->cuda_device))",
185+
"after": "coli_cuda_matmul(&w->cuda,y,x,weights,w->s,w->fmt,S,w->I,w->O,w->cuda_device,0))",
186+
"reason": "The official Hy3 merge adopted the grouped CUDA backend signature but left the non-grouped Hy3 call site one argument behind."
187+
},
180188
"validation_steps": [
181189
{
182190
"label": "Run upstream Colibri-Hy3 tests",
@@ -198,31 +206,40 @@
198206
"plan_args": [
199207
"plan",
200208
"--ram",
201-
"56",
209+
"0",
210+
"--auto-tier",
202211
"--gpu",
203212
"0",
204213
"--vram",
205-
"16",
214+
"0",
215+
"--policy",
216+
"balanced",
206217
"--json"
207218
],
208219
"doctor_args": [
209220
"doctor",
210221
"--ram",
211-
"56",
222+
"0",
223+
"--auto-tier",
212224
"--gpu",
213225
"0",
214226
"--vram",
215-
"16",
227+
"0",
228+
"--policy",
229+
"balanced",
216230
"--json"
217231
],
218232
"serve_args": [
219233
"serve",
220234
"--ram",
221-
"56",
235+
"0",
236+
"--auto-tier",
222237
"--gpu",
223238
"0",
224239
"--vram",
225-
"16",
240+
"0",
241+
"--policy",
242+
"balanced",
226243
"--host",
227244
"127.0.0.1"
228245
],
@@ -232,8 +249,8 @@
232249
"profiles": {
233250
"rtx5090-high-ram": {
234251
"label": "RTX 5090 · high RAM",
235-
"description": "5090 profile using the upstream auto-tier to fill measured free VRAM while reserving dense/KV headroom, with the documented direct-I/O and io_uring pipeline options.",
236-
"ram": "56",
252+
"description": "5090 profile using the upstream auto-tier to size both RAM and free VRAM at launch, with direct I/O, io_uring, and the planner-recommended single-GPU CUDA pipeline.",
253+
"ram": "0",
237254
"auto_tier": true,
238255
"ctx": "4096",
239256
"gpu": "0",
@@ -243,6 +260,7 @@
243260
"env": {
244261
"COLI_CUDA": "1",
245262
"CUDA_ATTN": "1",
263+
"COLI_CUDA_PIPE": "1",
246264
"DIRECT": "1",
247265
"PIPE": "2",
248266
"PIPE_WORKERS": "8",

‎src/ulysses_colibri.py‎

Lines changed: 125 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class ColibriProvider:
5757
setup_path: Path
5858
build_cwd: Path
5959
build_argv: tuple[str, ...]
60+
build_compatibility: dict[str, str] | None
6061
validation_steps: tuple[dict[str, Any], ...]
6162
plan_args: tuple[str, ...]
6263
doctor_args: tuple[str, ...]
@@ -145,6 +146,51 @@ def load_colibri_catalog(
145146
isinstance(item, str) and item for item in build_argv
146147
):
147148
raise ColibriCatalogError("Colibri build argv is invalid")
149+
build_compatibility = raw.get("build_compatibility")
150+
normalized_compatibility: dict[str, str] | None = None
151+
if build_compatibility is not None:
152+
if not isinstance(build_compatibility, dict):
153+
raise ColibriCatalogError(
154+
"Colibri build compatibility must be an object"
155+
)
156+
compatibility_id = str(build_compatibility.get("id") or "")
157+
compatibility_commit = str(
158+
build_compatibility.get("source_commit") or ""
159+
)
160+
compatibility_path = str(build_compatibility.get("path") or "")
161+
compatibility_before = str(build_compatibility.get("before") or "")
162+
compatibility_after = str(build_compatibility.get("after") or "")
163+
if not re.fullmatch(
164+
r"[a-z0-9][a-z0-9.-]*", compatibility_id
165+
):
166+
raise ColibriCatalogError(
167+
"Colibri build compatibility id is invalid"
168+
)
169+
if not re.fullmatch(r"[0-9a-f]{40}", compatibility_commit):
170+
raise ColibriCatalogError(
171+
"Colibri build compatibility commit must be pinned"
172+
)
173+
_safe_relative(
174+
source_root,
175+
compatibility_path,
176+
"build_compatibility.path",
177+
)
178+
if (
179+
not compatibility_before
180+
or not compatibility_after
181+
or compatibility_before == compatibility_after
182+
):
183+
raise ColibriCatalogError(
184+
"Colibri build compatibility replacement is invalid"
185+
)
186+
normalized_compatibility = {
187+
"id": compatibility_id,
188+
"source_commit": compatibility_commit,
189+
"path": compatibility_path,
190+
"before": compatibility_before,
191+
"after": compatibility_after,
192+
"reason": str(build_compatibility.get("reason") or ""),
193+
}
148194
model_variants = raw.get("model_variants")
149195
if not isinstance(model_variants, list) or not model_variants:
150196
raise ColibriCatalogError("Colibri model variants are required")
@@ -284,6 +330,7 @@ def load_colibri_catalog(
284330
source_root, raw["build_cwd"], "build_cwd"
285331
),
286332
build_argv=tuple(build_argv),
333+
build_compatibility=normalized_compatibility,
287334
validation_steps=tuple(normalized_validation),
288335
plan_args=tuple(str(item) for item in raw.get("plan_args") or []),
289336
doctor_args=tuple(
@@ -337,6 +384,9 @@ def _git(provider: ColibriProvider) -> dict[str, Any]:
337384
"commit": None,
338385
"origin": None,
339386
"dirty": False,
387+
"dirty_paths": [],
388+
"unexpected_dirty": False,
389+
"unexpected_dirty_paths": [],
340390
"minimum_commit_present": False,
341391
"upstream_commit": None,
342392
"ahead": 0,
@@ -371,17 +421,43 @@ def _git(provider: ColibriProvider) -> dict[str, Any]:
371421
).split()
372422
if len(counts) == 2 and all(item.isdigit() for item in counts):
373423
ahead, behind = (int(item) for item in counts)
374-
dirty = bool(
375-
_run(
424+
try:
425+
status_result = subprocess.run(
376426
[
377427
"git",
378428
"-C",
379429
str(root),
380430
"status",
381-
"--porcelain",
431+
"--porcelain=v1",
382432
"--untracked-files=all",
383-
]
433+
],
434+
capture_output=True,
435+
text=True,
436+
check=False,
437+
timeout=8,
384438
)
439+
status = (
440+
status_result.stdout if status_result.returncode == 0 else ""
441+
)
442+
except (OSError, subprocess.TimeoutExpired):
443+
status = ""
444+
dirty_paths = []
445+
for line in status.splitlines():
446+
value = line[3:] if len(line) > 3 else ""
447+
if " -> " in value:
448+
value = value.rsplit(" -> ", 1)[-1]
449+
if value:
450+
dirty_paths.append(value.strip('"'))
451+
expected_dirty_paths = {
452+
str(provider.engine_path.relative_to(provider.source_root)),
453+
str(
454+
(provider.build_cwd / ".ulysses-build.json").relative_to(
455+
provider.source_root
456+
)
457+
),
458+
}
459+
unexpected_dirty_paths = sorted(
460+
set(dirty_paths) - expected_dirty_paths
385461
)
386462
minimum_present = True
387463
if provider.minimum_commit:
@@ -410,7 +486,10 @@ def _git(provider: ColibriProvider) -> dict[str, Any]:
410486
"branch": branch or None,
411487
"commit": commit or None,
412488
"origin": origin or None,
413-
"dirty": dirty,
489+
"dirty": bool(dirty_paths),
490+
"dirty_paths": sorted(set(dirty_paths)),
491+
"unexpected_dirty": bool(unexpected_dirty_paths),
492+
"unexpected_dirty_paths": unexpected_dirty_paths,
414493
"minimum_commit_present": minimum_present,
415494
"upstream_commit": upstream_commit or None,
416495
"ahead": ahead,
@@ -651,6 +730,8 @@ def _validate_build_manifest(
651730
source_commit: str | None,
652731
build_config: str,
653732
) -> tuple[bool, list[str]]:
733+
from src.ulysses_colibri_build import compatibility_manifest
734+
654735
if not isinstance(manifest, dict):
655736
return False, ["build manifest is missing or unreadable"]
656737
expected = {
@@ -660,6 +741,7 @@ def _validate_build_manifest(
660741
"source_branch": provider.source_branch,
661742
"source_commit": source_commit,
662743
"build_argv": list(provider.build_argv),
744+
"build_compatibility": compatibility_manifest(provider),
663745
"validation_steps": list(provider.validation_steps),
664746
"build_config": build_config or None,
665747
"engine_path": str(provider.engine_path),
@@ -742,13 +824,26 @@ def observe_colibri_provider(provider: ColibriProvider) -> dict[str, Any]:
742824
source_ready = provenance_ready and bool(git["current"])
743825
built = provider.engine_path.is_file()
744826
cuda_built = built and ("CUDA=1" in build_config or "CUDA=ON" in build_config)
827+
required_build_flags = [
828+
item
829+
for item in provider.build_argv
830+
if item in {"CUDA=1", "CUDA=ON", "IOURING=1"}
831+
]
832+
missing_build_flags = [
833+
item for item in required_build_flags if item not in build_config
834+
]
745835
manifest_valid, manifest_reasons = _validate_build_manifest(
746836
provider,
747837
build_manifest,
748838
source_commit=git.get("commit"),
749839
build_config=build_config,
750840
)
751-
build_ready = built and cuda_built and manifest_valid
841+
build_ready = (
842+
built
843+
and cuda_built
844+
and not missing_build_flags
845+
and manifest_valid
846+
)
752847
prerequisites = _build_prerequisites(provider)
753848
running = health is not None and provider.model_id in served_ids
754849
collision = port_open and health is None
@@ -774,13 +869,24 @@ def observe_colibri_provider(provider: ColibriProvider) -> dict[str, Any]:
774869
),
775870
}
776871
)
777-
if git.get("dirty"):
872+
if git.get("unexpected_dirty"):
778873
findings.append(
779874
{
780875
"code": f"{provider.provider_id}.source_dirty",
781876
"severity": "warning",
782877
"summary": "Colibri source contains local changes.",
783-
"evidence": str(provider.source_root),
878+
"evidence": ", ".join(
879+
git.get("unexpected_dirty_paths") or [str(provider.source_root)]
880+
),
881+
}
882+
)
883+
elif git.get("dirty"):
884+
findings.append(
885+
{
886+
"code": f"{provider.provider_id}.build_output_modified",
887+
"severity": "info",
888+
"summary": "Tracked upstream engine contains the local CUDA build.",
889+
"evidence": ", ".join(git.get("dirty_paths") or []),
784890
}
785891
)
786892
if git["present"] and (git.get("ahead") or git.get("behind")):
@@ -826,6 +932,15 @@ def observe_colibri_provider(provider: ColibriProvider) -> dict[str, Any]:
826932
"evidence": "; ".join(manifest_reasons),
827933
}
828934
)
935+
if built and missing_build_flags:
936+
findings.append(
937+
{
938+
"code": f"{provider.provider_id}.build_flags_missing",
939+
"severity": "error",
940+
"summary": "Colibri build is missing required native features.",
941+
"evidence": ", ".join(missing_build_flags),
942+
}
943+
)
829944
if not prerequisites["ready"]:
830945
findings.append(
831946
{
@@ -865,6 +980,8 @@ def observe_colibri_provider(provider: ColibriProvider) -> dict[str, Any]:
865980
"cuda_built": cuda_built,
866981
"ready": build_ready,
867982
"build_config": build_config or None,
983+
"required_flags": required_build_flags,
984+
"missing_flags": missing_build_flags,
868985
"cwd": str(provider.build_cwd),
869986
"argv": list(provider.build_argv),
870987
"manifest_path": str(manifest_path),

0 commit comments

Comments
 (0)