Integrate Cesium Gaussian lifecycle and source-based cleanup rebuilds

This commit is contained in:
DCCONSTRUCTIONS
2026-11-16 22:16:12 +03:00
parent 7c0dbd4e06
commit 0a29522f2f
13 changed files with 123 additions and 46 deletions
@@ -237,7 +237,7 @@ class GaussianPipelineGateway:
members=members,
)
def upload_source_archive(self, archive_path: Path) -> GaussianArchiveUpload:
def upload_source_archive(self, archive_path: Path, *, owner_id: str | None = None) -> GaussianArchiveUpload:
source_candidate = archive_path.expanduser().absolute()
if source_candidate.is_symlink() or not source_candidate.is_file():
raise GaussianPipelineIntegrityError(
@@ -266,6 +266,24 @@ class GaussianPipelineGateway:
raise GaussianPipelineIntegrityError(
"Gaussian source archive exceeds provider byte admission"
)
if owner_id is not None:
self.require_shared_source_retention(capabilities)
claimed = self._json("POST", "/v1/sources/claim", document={
"owner_id": owner_id,
"archive": {"archive_name": archive_name, "format": archive_format,
"sha256": digest, "byte_length": byte_length},
}, timeout_seconds=self.ingest_timeout_seconds).get("receipt")
if claimed is not None:
from k1link.simulation.source_retention import validate_receipt
validate_receipt(claimed)
original = claimed["input"]
if (claimed.get("owner_id") != owner_id or original["kind"] != "archive"
or {k: v for k, v in original["archive"].items() if k != "upload_id"} != {
"archive_name": archive_name, "format": archive_format,
"sha256": digest, "byte_length": byte_length,
}):
raise GaussianPipelineIntegrityError("Worker claimed different source bytes or owner")
return GaussianArchiveUpload(**original["archive"])
upload_id = self._upload_file(
source,
{"archive_name": archive_name, "sha256": digest},
@@ -304,11 +322,32 @@ class GaussianPipelineGateway:
"Worker не поддерживает постоянное хранение исходников. Обновите Gaussian Pipeline."
)
def retain_source(self, original: dict[str, Any]) -> dict[str, Any]:
@staticmethod
def require_shared_source_retention(capabilities: dict[str, Any]) -> None:
if capabilities.get("source_deduplication") != "owned-archive-sha256/v1":
raise GaussianPipelineGatewayError(
"Worker не поддерживает общий дедуп исходников. Обновите Gaussian Pipeline."
)
def retain_source(self, original: dict[str, Any], *, owner_id: str | None = None) -> dict[str, Any]:
from k1link.simulation.source_retention import validate_receipt
receipt = self._json("POST", "/v1/sources", document=original,
timeout_seconds=self.ingest_timeout_seconds)
validate_receipt(receipt, expected=original)
if owner_id is None:
receipt = self._json("POST", "/v1/sources", document=original,
timeout_seconds=self.ingest_timeout_seconds)
validate_receipt(receipt, expected=original)
return receipt
self.require_shared_source_retention(self.capabilities())
receipt = self._json("POST", "/v1/sources/retain",
document={"owner_id": owner_id, "input": original},
timeout_seconds=self.ingest_timeout_seconds).get("receipt")
validate_receipt(receipt)
expected = original
if original["kind"] == "archive" and receipt["input"]["kind"] == "archive":
expected = {"kind": "archive", "archive": {**original["archive"],
"upload_id": receipt["input"]["archive"]["upload_id"]}}
validate_receipt(receipt, expected=expected)
if receipt.get("owner_id") != owner_id:
raise GaussianPipelineIntegrityError("Worker retained source for a different owner")
return receipt
def retained_source(self, receipt: dict[str, Any], *, verify: bool = False) -> dict[str, Any]:
+4 -3
View File
@@ -196,7 +196,7 @@ def prepare_source(
root = store.source_root(project_id)
if project["source"]["kind"] == "archive":
item = project["source"]["files"][0]
archive = provider.upload_source_archive(root / item["logical_path"])
archive = provider.upload_source_archive(root / item["logical_path"], owner_id=f"simulation/{project_id}/original")
original = {"kind": "archive", "archive": archive.to_dict()}
else:
entrypoint, source_format = discover_gaussian_source_bundle(root)
@@ -207,7 +207,7 @@ def prepare_source(
additional_paths=[f["logical_path"] for f in project["source"]["files"]],
)
original = {"kind": "folder", "source": bundle.to_dict()}
receipt = provider.retain_source(original)
receipt = provider.retain_source(original, owner_id=f"simulation/{project_id}/original")
confirm_storage(store, project_id, provider, receipt)
retire_local_source(store, project_id, provider)
original = receipt["input"]
@@ -217,7 +217,8 @@ def prepare_source(
if prepared:
return _source_bundle_upload(provider.retained_source(prepared)["input"]["source"])
bundle = provider.normalize_archive(GaussianArchiveUpload(**original["archive"]))
prepared = provider.retain_source({"kind": "folder", "source": bundle.to_dict()})
prepared = provider.retain_source({"kind": "folder", "source": bundle.to_dict()},
owner_id=f"simulation/{project_id}/prepared")
store.update_source_storage(project_id, prepared_receipt=prepared)
return bundle
+6 -1
View File
@@ -82,8 +82,13 @@ class BimModuleSurface:
)
services = None
try:
from k1link.simulation.gaussian_pipeline_gateway import configured_gaussian_pipeline_gateway
gaussian = configured_gaussian_pipeline_gateway()
services = HostServices(
ProjectStore(root / "documents"), copies, BoundWorker(binding)
ProjectStore(root / "documents"), copies, BoundWorker(binding),
gaussian_endpoint=gaussian.endpoint if gaussian else None,
gaussian_token_file=gaussian.token_file if gaussian else None,
)
application = create_host_app(services, authorize_operator)
except BaseException: