diff --git a/contracts/job-allocation/v2/schema.json b/contracts/job-allocation/v2/schema.json index a5aac98..2f34b79 100644 --- a/contracts/job-allocation/v2/schema.json +++ b/contracts/job-allocation/v2/schema.json @@ -573,7 +573,6 @@ "node", "cluster", "observed_at", - "expires_at", "cpu_topology", "numa", "gpus", @@ -611,7 +610,10 @@ }, "properties": { "schema_version": { - "const": "node.interconnect/v1" + "enum": [ + "node.interconnect/v1", + "node.interconnect/v2" + ] }, "node": { "$ref": "#/$defs/hardware_record/$defs/ref" @@ -863,6 +865,33 @@ "$ref": "#/$defs/hardware_record/$defs/cpuIds" } } + }, + "review_after": { + "$ref": "#/$defs/hardware_record/$defs/timestamp" + } + }, + "if": { + "properties": { + "schema_version": { + "const": "node.interconnect/v1" + } + } + }, + "then": { + "required": [ + "expires_at" + ], + "not": { + "required": [ + "review_after" + ] + } + }, + "else": { + "not": { + "required": [ + "expires_at" + ] } } }, @@ -926,7 +955,8 @@ "record_invalid", "node_limit", "size_limit", - "node_restarted" + "node_restarted", + "not_yet_observed" ] } } diff --git a/contracts/job-allocation/v3/schema.json b/contracts/job-allocation/v3/schema.json index e7b35d4..5193c10 100644 --- a/contracts/job-allocation/v3/schema.json +++ b/contracts/job-allocation/v3/schema.json @@ -573,7 +573,6 @@ "node", "cluster", "observed_at", - "expires_at", "cpu_topology", "numa", "gpus", @@ -611,7 +610,10 @@ }, "properties": { "schema_version": { - "const": "node.interconnect/v1" + "enum": [ + "node.interconnect/v1", + "node.interconnect/v2" + ] }, "node": { "$ref": "#/$defs/hardware_record/$defs/ref" @@ -863,6 +865,33 @@ "$ref": "#/$defs/hardware_record/$defs/cpuIds" } } + }, + "review_after": { + "$ref": "#/$defs/hardware_record/$defs/timestamp" + } + }, + "if": { + "properties": { + "schema_version": { + "const": "node.interconnect/v1" + } + } + }, + "then": { + "required": [ + "expires_at" + ], + "not": { + "required": [ + "review_after" + ] + } + }, + "else": { + "not": { + "required": [ + "expires_at" + ] } } }, @@ -926,7 +955,8 @@ "record_invalid", "node_limit", "size_limit", - "node_restarted" + "node_restarted", + "not_yet_observed" ] } } diff --git a/contracts/job-placement/v1/schema.json b/contracts/job-placement/v1/schema.json index 6ff2baf..43f00a6 100644 --- a/contracts/job-placement/v1/schema.json +++ b/contracts/job-placement/v1/schema.json @@ -826,7 +826,6 @@ "node", "cluster", "observed_at", - "expires_at", "cpu_topology", "numa", "gpus", @@ -864,7 +863,10 @@ }, "properties": { "schema_version": { - "const": "node.interconnect/v1" + "enum": [ + "node.interconnect/v1", + "node.interconnect/v2" + ] }, "node": { "$ref": "#/$defs/hardware_record/$defs/ref" @@ -1116,6 +1118,33 @@ "$ref": "#/$defs/hardware_record/$defs/cpuIds" } } + }, + "review_after": { + "$ref": "#/$defs/hardware_record/$defs/timestamp" + } + }, + "if": { + "properties": { + "schema_version": { + "const": "node.interconnect/v1" + } + } + }, + "then": { + "required": [ + "expires_at" + ], + "not": { + "required": [ + "review_after" + ] + } + }, + "else": { + "not": { + "required": [ + "expires_at" + ] } } }, @@ -1179,7 +1208,8 @@ "record_invalid", "node_limit", "size_limit", - "node_restarted" + "node_restarted", + "not_yet_observed" ] } } diff --git a/contracts/job-placement/v2/schema.json b/contracts/job-placement/v2/schema.json index e89032e..57691be 100644 --- a/contracts/job-placement/v2/schema.json +++ b/contracts/job-placement/v2/schema.json @@ -862,7 +862,6 @@ "node", "cluster", "observed_at", - "expires_at", "cpu_topology", "numa", "gpus", @@ -900,7 +899,10 @@ }, "properties": { "schema_version": { - "const": "node.interconnect/v1" + "enum": [ + "node.interconnect/v1", + "node.interconnect/v2" + ] }, "node": { "$ref": "#/$defs/hardware_record/$defs/ref" @@ -1152,6 +1154,33 @@ "$ref": "#/$defs/hardware_record/$defs/cpuIds" } } + }, + "review_after": { + "$ref": "#/$defs/hardware_record/$defs/timestamp" + } + }, + "if": { + "properties": { + "schema_version": { + "const": "node.interconnect/v1" + } + } + }, + "then": { + "required": [ + "expires_at" + ], + "not": { + "required": [ + "review_after" + ] + } + }, + "else": { + "not": { + "required": [ + "expires_at" + ] } } }, @@ -1215,7 +1244,8 @@ "record_invalid", "node_limit", "size_limit", - "node_restarted" + "node_restarted", + "not_yet_observed" ] } } diff --git a/contracts/managed-run-placement/v1/schema.json b/contracts/managed-run-placement/v1/schema.json index 472044b..9f94b01 100644 --- a/contracts/managed-run-placement/v1/schema.json +++ b/contracts/managed-run-placement/v1/schema.json @@ -1358,7 +1358,6 @@ "node", "cluster", "observed_at", - "expires_at", "cpu_topology", "numa", "gpus", @@ -1396,7 +1395,10 @@ }, "properties": { "schema_version": { - "const": "node.interconnect/v1" + "enum": [ + "node.interconnect/v1", + "node.interconnect/v2" + ] }, "node": { "$ref": "#/$defs/hardware_record/$defs/ref" @@ -1648,6 +1650,33 @@ "$ref": "#/$defs/hardware_record/$defs/cpuIds" } } + }, + "review_after": { + "$ref": "#/$defs/hardware_record/$defs/timestamp" + } + }, + "if": { + "properties": { + "schema_version": { + "const": "node.interconnect/v1" + } + } + }, + "then": { + "required": [ + "expires_at" + ], + "not": { + "required": [ + "review_after" + ] + } + }, + "else": { + "not": { + "required": [ + "expires_at" + ] } } }, @@ -1711,7 +1740,8 @@ "record_invalid", "node_limit", "size_limit", - "node_restarted" + "node_restarted", + "not_yet_observed" ] } } diff --git a/contracts/native-topology-source.json b/contracts/native-topology-source.json index 6adb783..ccbbbe4 100644 --- a/contracts/native-topology-source.json +++ b/contracts/native-topology-source.json @@ -1,6 +1,6 @@ { "repository": "AI4SAI/sai-portal", "path": "sai_native_topology.py", - "revision": "5becfe3d9f84767e1461aad342a48c49d98807b2", - "sha256": "e47bb673b644435c91086f3e7c2718256a410a9c1981782a1d01676d9de721df" + "revision": "15a5bcc7c2e38e0d1a7c0c36a068a605b915f104", + "sha256": "af9781be2dda2cfdf62ed77581b22f3ea2b71f9b65efbe62c86bb330593d2a1b" } diff --git a/contracts/node-interconnect/v1/README.md b/contracts/node-interconnect/v1/README.md index 1acca9f..a2ccbc1 100644 --- a/contracts/node-interconnect/v1/README.md +++ b/contracts/node-interconnect/v1/README.md @@ -1,5 +1,19 @@ # Node interconnect facts, v1 +The existing operator normalizer also emits `node.interconnect/v2` from a +capture by default. The v2 schema is in [the adjacent version](../v2/schema.json). +It keeps the hardware and optional CPU-map observation times. An optional +`--review-after` records when the operator plans to review the evidence. +Readers can continue to use a published v2 observation after that date when +the allocation, configuration and native daemon generation still match. +Hardware replacement, rewiring or an incompatible mapping requires the +publisher to withdraw or replace the affected record. Reuse of a node name or +unchanged device counts is insufficient evidence that its hardware is unchanged. + +An explicit `--expires-at` still emits v1 and its deadline remains binding. +The join envelope accepts both record versions. Upgrade stored-schema consumers +and their embedded validators before the publisher switches records to v2. + `node.interconnect/v1` is a bounded, read-only projection of one compute node's hardware relationships. It is a view over native observations, not a scheduler, asset database, or utilization stream. The producer records a node-local diff --git a/contracts/node-interconnect/v1/join.schema.json b/contracts/node-interconnect/v1/join.schema.json index c7fc517..e68aae5 100644 --- a/contracts/node-interconnect/v1/join.schema.json +++ b/contracts/node-interconnect/v1/join.schema.json @@ -58,7 +58,8 @@ "record_invalid", "node_limit", "size_limit", - "node_restarted" + "node_restarted", + "not_yet_observed" ] } } @@ -78,7 +79,6 @@ "node", "cluster", "observed_at", - "expires_at", "cpu_topology", "numa", "gpus", @@ -116,7 +116,10 @@ }, "properties": { "schema_version": { - "const": "node.interconnect/v1" + "enum": [ + "node.interconnect/v1", + "node.interconnect/v2" + ] }, "node": { "$ref": "#/$defs/hardware_record/$defs/ref" @@ -368,6 +371,33 @@ "$ref": "#/$defs/hardware_record/$defs/cpuIds" } } + }, + "review_after": { + "$ref": "#/$defs/hardware_record/$defs/timestamp" + } + }, + "if": { + "properties": { + "schema_version": { + "const": "node.interconnect/v1" + } + } + }, + "then": { + "required": [ + "expires_at" + ], + "not": { + "required": [ + "review_after" + ] + } + }, + "else": { + "not": { + "required": [ + "expires_at" + ] } } } diff --git a/contracts/node-interconnect/v2/schema.json b/contracts/node-interconnect/v2/schema.json new file mode 100644 index 0000000..aea4d1a --- /dev/null +++ b/contracts/node-interconnect/v2/schema.json @@ -0,0 +1,301 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "type": "object", + "additionalProperties": false, + "required": [ + "schema_version", + "node", + "cluster", + "observed_at", + "cpu_topology", + "numa", + "gpus", + "links", + "nics", + "boot_time", + "slurmd_start_time" + ], + "$defs": { + "ref": { + "type": "string", + "pattern": "^[A-Za-z0-9][A-Za-z0-9_.-]{0,127}$" + }, + "count": { + "type": "integer", + "minimum": 0, + "maximum": 65535 + }, + "path": { + "type": "string", + "pattern": "^(NV[1-9][0-9]{0,2}|PIX|PXB|PHB|NODE|SYS)$" + }, + "cpuIds": { + "type": "array", + "maxItems": 65536, + "items": { + "$ref": "#/$defs/count" + }, + "uniqueItems": true + }, + "timestamp": { + "type": "string", + "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(?:\\.[0-9]{1,6})?Z$" + } + }, + "properties": { + "schema_version": { + "const": "node.interconnect/v2" + }, + "node": { + "$ref": "#/$defs/ref" + }, + "cluster": { + "$ref": "#/$defs/ref" + }, + "observed_at": { + "$ref": "#/$defs/timestamp" + }, + "review_after": { + "$ref": "#/$defs/timestamp" + }, + "cpu_topology": { + "type": "object", + "additionalProperties": false, + "required": [ + "sockets", + "cores_per_socket", + "threads_per_core" + ], + "properties": { + "sockets": { + "type": "integer", + "minimum": 1, + "maximum": 65536 + }, + "cores_per_socket": { + "type": "integer", + "minimum": 1, + "maximum": 65536 + }, + "threads_per_core": { + "type": "integer", + "minimum": 1, + "maximum": 65536 + } + } + }, + "numa": { + "type": "array", + "maxItems": 256, + "items": { + "type": "object", + "additionalProperties": false, + "required": [ + "id", + "packages", + "linux_cpu_ids" + ], + "properties": { + "id": { + "$ref": "#/$defs/count" + }, + "packages": { + "$ref": "#/$defs/cpuIds" + }, + "linux_cpu_ids": { + "$ref": "#/$defs/cpuIds" + } + } + } + }, + "gpus": { + "type": "array", + "maxItems": 64, + "items": { + "type": "object", + "additionalProperties": false, + "required": [ + "index", + "numa", + "cpu_ids" + ], + "properties": { + "index": { + "type": "integer", + "minimum": 0, + "maximum": 63 + }, + "numa": { + "type": [ + "integer", + "null" + ], + "minimum": 0, + "maximum": 65535 + }, + "cpu_ids": { + "anyOf": [ + { + "$ref": "#/$defs/cpuIds" + }, + { + "type": "null" + } + ] + }, + "pcie_path": { + "type": [ + "array", + "null" + ], + "minItems": 1, + "maxItems": 32, + "uniqueItems": true, + "items": { + "type": "string", + "pattern": "^(root|bridge)-[0-9]{1,4}$" + } + } + } + } + }, + "links": { + "type": "array", + "maxItems": 2016, + "items": { + "type": "object", + "additionalProperties": false, + "required": [ + "a", + "b", + "kind" + ], + "properties": { + "a": { + "type": "integer", + "minimum": 0, + "maximum": 63 + }, + "b": { + "type": "integer", + "minimum": 0, + "maximum": 63 + }, + "kind": { + "$ref": "#/$defs/path" + } + } + } + }, + "nics": { + "type": "array", + "maxItems": 64, + "items": { + "type": "object", + "additionalProperties": false, + "required": [ + "index", + "gpu_paths", + "peer", + "rate_gbps" + ], + "properties": { + "index": { + "type": "integer", + "minimum": 0, + "maximum": 63 + }, + "gpu_paths": { + "type": "array", + "maxItems": 64, + "items": { + "type": "object", + "additionalProperties": false, + "required": [ + "gpu", + "kind" + ], + "properties": { + "gpu": { + "type": "integer", + "minimum": 0, + "maximum": 63 + }, + "kind": { + "$ref": "#/$defs/path" + } + } + } + }, + "peer": { + "type": [ + "string", + "null" + ], + "pattern": "^endpoint-[0-9a-f]{24}$" + }, + "rate_gbps": { + "type": [ + "integer", + "null" + ], + "minimum": 0, + "maximum": 100000 + } + } + } + }, + "boot_time": { + "type": "integer", + "minimum": 1, + "maximum": 9223372036854775807 + }, + "slurmd_start_time": { + "type": "integer", + "minimum": 1, + "maximum": 9223372036854775807 + }, + "fabric_links": { + "type": "array", + "maxItems": 4096, + "items": { + "type": "object", + "additionalProperties": false, + "required": [ + "a", + "b", + "kind" + ], + "properties": { + "a": { + "type": "string", + "pattern": "^endpoint-[0-9a-f]{24}$" + }, + "b": { + "type": "string", + "pattern": "^endpoint-[0-9a-f]{24}$" + }, + "kind": { + "const": "infiniband" + } + } + } + }, + "cpu_mapping": { + "type": "object", + "additionalProperties": false, + "required": [ + "observed_at", + "slurm_to_linux" + ], + "properties": { + "observed_at": { + "$ref": "#/$defs/timestamp" + }, + "slurm_to_linux": { + "$ref": "#/$defs/cpuIds" + } + } + } + } +} diff --git a/docs/runtime-design.md b/docs/runtime-design.md index 26cb8c3..96e1245 100644 --- a/docs/runtime-design.md +++ b/docs/runtime-design.md @@ -769,11 +769,14 @@ an ordinary user. The paired Web/Pilot source is merged; its production activation remains with the original Pilot release. Focused polling and account selection reuse the client reads described in [terminal scope](terminal-scope.md#focused-query-interaction). -Hardware interconnect is a separate recorded fact, `node.interconnect/v1`. -It is joined only when `sai jobs local --job-id ID --with-interconnect` is -requested, so ordinary allocation JSON remains stable and a missing mapping -cannot look like an empty topology. The record is site-published and time-bound; -it contains verified CPU/NUMA-to-GPU affinity, GPU path classes and safe +Hardware interconnect is a site-published observation. A v1 record expires at +its stated deadline. A `node.interconnect/v2` record can carry a review date. +Passing that date preserves the observation. The reader still checks the cluster, +node, hardware dimensions and Slurm daemon generation when joining a job. +The local CLI joins the observation on `sai jobs local --job-id ID --with-interconnect`, +so ordinary allocation JSON remains stable and a missing mapping +cannot look like an empty topology. The record contains verified +CPU/NUMA-to-GPU affinity, GPU path classes and safe node-fabric peer references. The same standard-library record reader and validator is exported from the Portal producer for the CLI and gateway. Capture parsing and record construction remain in its operator-only module, excluded from both diff --git a/src/sai_cli/allocation_view.py b/src/sai_cli/allocation_view.py index 8e7f1af..34e8af6 100644 --- a/src/sai_cli/allocation_view.py +++ b/src/sai_cli/allocation_view.py @@ -96,6 +96,7 @@ def _allocation_view(value: dict, *, language: str, width: int, expanded: bool = Text(ranges(assigned)) if expanded else Text("")) blocks.append(summary) reasons = {"expired": ("硬件记录已过期", "Hardware record expired"), + "not_yet_observed": ("硬件观测时间晚于当前时间", "Hardware observation is dated in the future"), "node_restarted": ("节点已重启,映射待更新", "Node restarted; mapping needs refresh"), "configuration_changed": ("硬件配置已变更", "Hardware configuration changed"), "record_invalid": ("硬件记录暂不可用", "Hardware record unavailable")} diff --git a/src/sai_cli/cli.py b/src/sai_cli/cli.py index e2a0856..5b9e9c6 100644 --- a/src/sai_cli/cli.py +++ b/src/sai_cli/cli.py @@ -35,7 +35,7 @@ _ALLOCATION_NOTES = ( "allocation.nodes[].cpu_ids and GPU gres[].indices are Slurm IDs, not Linux CPU or task CUDA IDs. Slurm sockets may represent NUMA groups.", - "--with-interconnect adds per-node recorded hardware or an unavailable reason. Match records to allocation nodes by name and respect observed_at/expires_at.", + "--with-interconnect adds each node's hardware observation or unavailable reason. Match nodes by name. A v1 record expires at expires_at. A v2 review_after marks when a review is due.", "For recorded CPU locality, cpu_mapping.slurm_to_linux[slurm_cpu_id] gives the Linux CPU ID; locate it in numa[].linux_cpu_ids. Missing mapping means unknown locality; never sort the mapping or substitute GPU affinity.", "Recorded gpus[].index and links[].a/b use Slurm GPU indices. NIC peers and fabric_links describe observed adjacency. Paths and link rates do not measure utilization, available bandwidth or application traffic.", ) diff --git a/src/sai_cli/tui.py b/src/sai_cli/tui.py index 11e51c1..ea2fa75 100644 --- a/src/sai_cli/tui.py +++ b/src/sai_cli/tui.py @@ -168,9 +168,11 @@ def _poll_current_view(self) -> None: if self._allocation_detail is not None: value = self._allocation_detail joined = value.get("interconnect") - if joined and any(row["status"] == "recorded" and datetime.fromisoformat( - row["value"]["expires_at"].replace("Z", "+00:00")).timestamp() <= time.time() - for row in joined["nodes"]): + if joined and any( + datetime.fromisoformat(row["value"]["expires_at"]).timestamp() <= time.time() + for row in joined["nodes"] + if row["status"] == "recorded" and "expires_at" in row["value"] + ): from sai_native_topology import normalize_join from .allocation_view import allocation_view value["interconnect"] = normalize_join(joined, value["allocation"], cluster=value["cluster"]) diff --git a/src/sai_native_topology.py b/src/sai_native_topology.py index 6888c69..6e3f5e4 100644 --- a/src/sai_native_topology.py +++ b/src/sai_native_topology.py @@ -13,6 +13,7 @@ import stat SCHEMA = "node.interconnect/v1" +REVIEWABLE_SCHEMA = "node.interconnect/v2" DEFAULT_ROOT = "/opt/sai/runtime/topology" MAX_BYTES = 512 * 1024 MAX_CPU_IDS = 65536 @@ -43,19 +44,30 @@ def _time(value): def normalize_interconnect(value): """Allowlist the same node DTO in the gateway, CLI and other consumers.""" - if not isinstance(value, dict) or value.get("schema_version") != SCHEMA: + if not isinstance(value, dict) or value.get("schema_version") not in (SCHEMA, REVIEWABLE_SCHEMA): raise ValueError("invalid interconnect schema") - result = {"schema_version": SCHEMA} + schema = value["schema_version"] + result = {"schema_version": schema} for key in ("node", "cluster"): item = value.get(key) if not isinstance(item, str) or _NAME.fullmatch(item) is None: raise ValueError("invalid topology binding") result[key] = item - start, end = _time(value.get("observed_at")), _time(value.get("expires_at")) - if start >= end: - raise ValueError("invalid topology observation interval") - result.update(observed_at=value["observed_at"], expires_at=value["expires_at"], - boot_time=_number(value.get("boot_time"), 2**63 - 1), + start = _time(value.get("observed_at")) + result["observed_at"] = value["observed_at"] + end = None + if schema == SCHEMA: + end = _time(value.get("expires_at")) + if start >= end or "review_after" in value: + raise ValueError("invalid topology observation interval") + result["expires_at"] = value["expires_at"] + elif "expires_at" in value: + raise ValueError("reviewable topology cannot declare an expiry") + elif "review_after" in value: + if _time(value["review_after"]) <= start: + raise ValueError("topology review must follow its observation") + result["review_after"] = value["review_after"] + result.update(boot_time=_number(value.get("boot_time"), 2**63 - 1), slurmd_start_time=_number(value.get("slurmd_start_time"), 2**63 - 1)) if not result["boot_time"] or not result["slurmd_start_time"]: raise ValueError("missing node generation") @@ -97,7 +109,8 @@ def normalize_interconnect(value): mapped = [_number(cpu) for cpu in mapped] if len(set(mapped)) != total or not set(mapped).issubset(seen_cpus): raise ValueError("CPU mapping is outside Linux topology") - if not start <= _time(mapping.get("observed_at")) < end: + mapped_at = _time(mapping.get("observed_at")) + if mapped_at < start or (end is not None and mapped_at >= end): raise ValueError("CPU mapping observation is outside record interval") result["cpu_mapping"] = {"observed_at": mapping["observed_at"], "slurm_to_linux": mapped} result["gpus"] = [] @@ -161,6 +174,16 @@ def normalize_interconnect(value): return result +def _observation_time_failure(record, current): + """Use only observation times and the legacy publisher's explicit cutoff.""" + newest = record.get("cpu_mapping", {}).get("observed_at", record["observed_at"]) + if current < _time(newest): + return "expired" if record["schema_version"] == SCHEMA else "not_yet_observed" + if record["schema_version"] == SCHEMA and current >= _time(record["expires_at"]): + return "expired" + return None + + def job_cpu_locality(record, cpu_ids): """Project allocation onto NUMA using only the recorded native CPU map.""" mapping = record.get("cpu_mapping") @@ -200,9 +223,9 @@ def read_interconnect(name, *, cluster, dimensions, gpu_total, root=DEFAULT_ROOT current = now or datetime.now(timezone.utc) if value["node"] != name or value["cluster"] != cluster: raise ValueError("topology identity differs") - newest = value.get("cpu_mapping", {}).get("observed_at", value["observed_at"]) - if not _time(newest) <= current < _time(value["expires_at"]): - return {"status": "unavailable", "reason": "expired"} + reason = _observation_time_failure(value, current) + if reason: + return {"status": "unavailable", "reason": reason} if value["cpu_topology"] != dimensions or len(value["gpus"]) != gpu_total: return {"status": "unavailable", "reason": "configuration_changed"} return {"status": "recorded", "value": value} @@ -264,9 +287,12 @@ def join_interconnect(allocation, *, cluster, read_node_state, root=DEFAULT_ROOT record.update(status="unavailable", reason="node_restarted") finished = clock() for record in available: - if record["status"] == "recorded" and not _time(record["value"]["observed_at"]) <= finished < _time(record["value"]["expires_at"]): + if record["status"] != "recorded": + continue + reason = _observation_time_failure(record["value"], finished) + if reason: record.pop("value") - record.update(status="unavailable", reason="expired") + record.update(status="unavailable", reason=reason) peers = {nic["peer"] for record in records if record["status"] == "recorded" for nic in record["value"]["nics"] if nic["peer"] is not None} for record in records: if record["status"] == "recorded": @@ -290,7 +316,7 @@ def normalize_join(value, allocation, *, cluster, now=None): raise ValueError("interconnect is outside allocation") seen.add(name) if row["status"] == "unavailable": - if row["reason"] not in {"not_recorded", "expired", "configuration_changed", "allocation_dimensions_unknown", + if row["reason"] not in {"not_recorded", "expired", "not_yet_observed", "configuration_changed", "allocation_dimensions_unknown", "record_invalid", "node_limit", "size_limit", "node_restarted"}: raise ValueError("invalid interconnect failure") clean.append({"node": name, "status": "unavailable", "reason": row["reason"]}) @@ -308,12 +334,14 @@ def normalize_join(value, allocation, *, cluster, now=None): else: raise ValueError("invalid interconnect status") for row in clean: - if row["status"] == "recorded" and any(edge["a"] not in published_peers or edge["b"] not in published_peers for edge in row["value"]["fabric_links"]): + if row["status"] != "recorded": + continue + if any(edge["a"] not in published_peers or edge["b"] not in published_peers for edge in row["value"]["fabric_links"]): raise ValueError("fabric connection is outside the job projection") - newest = row.get("value", {}).get("cpu_mapping", {}).get("observed_at", row.get("value", {}).get("observed_at")) - if row["status"] == "recorded" and not _time(newest) <= current < _time(row["value"]["expires_at"]): + reason = _observation_time_failure(row["value"], current) + if reason: row.pop("value") - row.update(status="unavailable", reason="expired") + row.update(status="unavailable", reason=reason) peers = {nic["peer"] for row in clean if row["status"] == "recorded" for nic in row["value"]["nics"] if nic["peer"] is not None} for row in clean: if row["status"] == "recorded": diff --git a/tests/test_site_transport.py b/tests/test_site_transport.py index 79d9dc4..ec214fd 100644 --- a/tests/test_site_transport.py +++ b/tests/test_site_transport.py @@ -206,13 +206,24 @@ def test_allocation_uses_exact_operation_and_gateway_path(tmp_path, site_allocat def test_optional_interconnect_uses_same_exact_capability_and_fails_if_absent(tmp_path, site_allocation_payload): nodes = site_allocation_payload['allocation']['nodes'] - site_allocation_payload['interconnect']={'schema_version':'node-interconnect-join/v1','nodes':[ - {'node':row['name'],'status':'unavailable','reason':'not_recorded'} for row in nodes]} + sample = Path(__file__).resolve().parents[1] / "contracts/node-interconnect/v1/sample.json" + hardware = json.loads(sample.read_text()) + hardware.update(node=nodes[1]["name"], schema_version="node.interconnect/v2") + hardware["review_after"] = hardware.pop("expires_at") + nodes[1].update(cpu_ids=list(range(8)), cpu_topology=hardware["cpu_topology"], gpu_total=2) + nodes[1]["gres"][0]["indices"] = [0, 1] + unknown = {"node": nodes[0]["name"], "status": "unavailable", "reason": "not_recorded"} + site_allocation_payload["interconnect"] = {"schema_version": "node-interconnect-join/v1", "nodes": [ + unknown, {"node": nodes[1]["name"], "status": "recorded", "value": hardware}, + ]} with http_endpoint(issuer) as (portal,issued), http_endpoint(lambda *_:(200,site_allocation_payload)) as (gateway,reads): config=profile(tmp_path,portal,gateway) code,text,error=invoke(config,tmp_path,['jobs','allocation','12345','--with-interconnect']) assert code==0,error - assert json.loads(text)['interconnect']==site_allocation_payload['interconnect'] + unavailable, recorded = json.loads(text)["interconnect"]["nodes"] + assert unavailable == unknown and recorded["status"] == "recorded" + assert recorded["value"]["review_after"] == hardware["review_after"] + assert recorded["value"]["links"] == hardware["links"] assert reads[0]['path']=='/v1/site-read/jobs/12345/allocation?include_interconnect=true' assert issued[0]['body']['operation']=='jobs.allocation' and reads[0]['bearer'] is None del site_allocation_payload['interconnect'] diff --git a/tests/test_tui_refresh.py b/tests/test_tui_refresh.py index d9c977f..07228e1 100644 --- a/tests/test_tui_refresh.py +++ b/tests/test_tui_refresh.py @@ -40,6 +40,51 @@ async def run(): assert closing_ticks == [True] +def test_mixed_topology_detail_keeps_reviewable_node_when_legacy_record_expires(job_client): + env, _, _ = job_client + queries = Queries(build_parser().parse_args(['tui']), env) + native_read = queries.read + sample = Path(__file__).resolve().parents[1] / "contracts/node-interconnect/v1/sample.json" + record = json.loads(sample.read_text()) + record["gpus"] += [{**gpu, "index": gpu["index"] + 2} for gpu in record["gpus"]] + record["links"] = [{"a": a, "b": b, "kind": "NV2"} for a in range(4) for b in range(a + 1, 4)] + + async def read(request): + result = await native_read(request) + if request.view == "allocation": + value = result.as_dict() + current, legacy = [node["name"] for node in value["allocation"]["nodes"]] + reviewable = {**record, "node": current, "schema_version": "node.interconnect/v2"} + reviewable["review_after"] = reviewable.pop("expires_at") + value["interconnect"] = {"schema_version": "node-interconnect-join/v1", "nodes": [ + {"node": current, "status": "recorded", "value": reviewable}, + {"node": legacy, "status": "recorded", "value": {**record, "node": legacy}}, + ]} + return result + + async def run(): + queries.read = read + app = QueryApp(queries, language="zh-CN") + async with app.run_test(size=(100, 50)) as pilot: + await loaded(app, pilot) + await pilot.press('enter') + await loaded(app, pilot) + app._poll_current_view() + app._poll_current_view() + detail = app._allocation_detail + reviewed, expired = detail["interconnect"]["nodes"] + assert reviewed["status"] == "recorded" and "review_after" in reviewed["value"] + assert expired == {"node": "compute-b", "status": "unavailable", "reason": "expired"} + assert all(node["gres"][0]["indices"] == [1, 3] for node in detail["allocation"]["nodes"]) + await app.wait_for_refresh() + screen = html.unescape(app.export_screenshot()) + assert "NUMA" in screen and "硬件记录已过期" in screen + await pilot.press('escape') + assert app.query_one('#job-table').has_focus + + asyncio.run(run()) + + def test_background_refresh_preserves_rows_selection_scroll_and_focus(job_client): env, path, payload = job_client payload['jobs'] = [{**deepcopy(payload['jobs'][0]), 'job_id': number} for number in range(100,180)]