优化流程
This commit is contained in:
@@ -153,6 +153,7 @@ class ProfileCadRuntime:
|
||||
fragment,
|
||||
selector_tokens=allowed_selectors,
|
||||
reference_tokens=list(reference_tokens),
|
||||
root_xy_datum=not bool((base_cdsl or {}).get("features")),
|
||||
)
|
||||
if errors:
|
||||
raise RuntimeAdapterError(
|
||||
@@ -262,6 +263,73 @@ class ProfileCadRuntime:
|
||||
except Exception as error:
|
||||
raise RuntimeAdapterError(f"RUNTIME_EXECUTION_FAILURE: {error}") from error
|
||||
|
||||
def rebuild_best_effort(
|
||||
self,
|
||||
cdsl: dict[str, Any],
|
||||
output_dir: str,
|
||||
task_id: str,
|
||||
revision_id: str,
|
||||
) -> tuple[dict[str, Any], list[dict[str, Any]]]:
|
||||
"""Build independent feature prefixes without discarding prior geometry.
|
||||
|
||||
A full CDSL document can contain several features even though the
|
||||
action protocol normally appends one at a time. Engine validation is
|
||||
all-or-nothing, so replay features in source order and retain each
|
||||
executable feature. A failed feature is reported as a diagnostic;
|
||||
it does not erase already executable geometry or prevent later,
|
||||
independent features from being tried.
|
||||
"""
|
||||
features = cdsl.get("features") if isinstance(cdsl.get("features"), list) else []
|
||||
accepted: list[dict[str, Any]] = []
|
||||
accepted_ids: set[str] = set()
|
||||
failures: list[dict[str, Any]] = []
|
||||
latest: dict[str, Any] | None = None
|
||||
for index, feature in enumerate(features):
|
||||
if not isinstance(feature, dict):
|
||||
failures.append({"feature_index": index, "feature_id": "", "message": "Feature must be an object."})
|
||||
continue
|
||||
feature_id = str(feature.get("id") or f"feature_{index + 1:03d}")
|
||||
dependencies = [str(value) for value in feature.get("depends_on") or () if isinstance(value, str)]
|
||||
unavailable = [value for value in dependencies if value not in accepted_ids]
|
||||
if unavailable:
|
||||
failures.append({
|
||||
"feature_index": index,
|
||||
"feature_id": feature_id,
|
||||
"message": "Feature was skipped because an earlier dependency did not execute.",
|
||||
"dependencies": unavailable,
|
||||
})
|
||||
continue
|
||||
candidate = self._feature_subset(cdsl, [*accepted, feature])
|
||||
try:
|
||||
latest = self.rebuild(candidate, output_dir, task_id, revision_id)
|
||||
except Exception as error:
|
||||
failures.append({"feature_index": index, "feature_id": feature_id, "message": str(error)[:1000]})
|
||||
continue
|
||||
accepted.append(deepcopy(feature))
|
||||
accepted_ids.add(feature_id)
|
||||
if not accepted:
|
||||
if failures:
|
||||
raise RuntimeAdapterError(str(failures[0].get("message") or "RUNTIME_EXECUTION_FAILURE: no feature could be rebuilt"))
|
||||
raise RuntimeAdapterError("RUNTIME_EXECUTION_FAILURE: CDSL document has no executable features")
|
||||
# A failed later attempt may have left partial files in the stage.
|
||||
# Rebuild the retained feature set once so all published artifacts are
|
||||
# guaranteed to describe the same successful checkpoint.
|
||||
latest = self.rebuild(self._feature_subset(cdsl, accepted), output_dir, task_id, revision_id)
|
||||
return {**latest, "executed_feature_ids": sorted(accepted_ids)}, failures
|
||||
|
||||
@staticmethod
|
||||
def _feature_subset(cdsl: dict[str, Any], features: list[dict[str, Any]]) -> dict[str, Any]:
|
||||
document = deepcopy(cdsl)
|
||||
document["features"] = deepcopy(features)
|
||||
geometry = document.get("geometry") if isinstance(document.get("geometry"), dict) else {}
|
||||
sketches = geometry.get("sketches") if isinstance(geometry.get("sketches"), list) else []
|
||||
sketch_ids = {str(feature.get("sketch_id") or "") for feature in features}
|
||||
document["geometry"] = {
|
||||
**geometry,
|
||||
"sketches": [deepcopy(sketch) for sketch in sketches if isinstance(sketch, dict) and str(sketch.get("id") or "") in sketch_ids],
|
||||
}
|
||||
return document
|
||||
|
||||
def _semantic_preflight(self, fragment: dict[str, Any], contract: dict[str, Any], selector_tokens: dict[str, dict[str, Any]], base_cdsl: dict[str, Any] | None, *, require_through: bool) -> None:
|
||||
if fragment.get("feature", {}).get("atomic_id") != contract.get("atomic_id"):
|
||||
raise RuntimeAdapterError("RUNTIME_PRECONDITION_FAILED: atomic_id does not match active contract")
|
||||
|
||||
Reference in New Issue
Block a user