Update real worker audit for external IPC capabilities

This commit is contained in:
Codex
2026-07-05 22:28:07 +08:00
parent 11c904bbb8
commit bb688d2a19
6 changed files with 273 additions and 82 deletions
+159 -21
View File
@@ -6,9 +6,9 @@ import subprocess
from pathlib import Path
def run_command(command: list[str]) -> dict:
def run_command(command: list[str], timeout: float = 10.0) -> dict:
try:
completed = subprocess.run(command, text=True, capture_output=True, timeout=10.0)
completed = subprocess.run(command, text=True, capture_output=True, timeout=timeout)
except subprocess.TimeoutExpired as exc:
return {
"command": command,
@@ -27,10 +27,51 @@ def run_command(command: list[str]) -> dict:
}
def run_standard_worker_probe(exe: Path, solver_id: str, case_file: Path) -> dict:
result = run_command([
def parse_key_value_output(text: str) -> dict[str, str]:
values: dict[str, str] = {}
for raw_line in text.splitlines():
line = raw_line.strip()
if not line or line.startswith("["):
continue
if "=" not in line:
continue
key, value = line.split("=", 1)
values[key.strip()] = value.strip()
return values
def is_yes(values: dict[str, str], key: str) -> bool:
return values.get(key, "").strip().lower() in {"yes", "true", "1", "on"}
def run_capabilities_probe(exe: Path) -> dict:
result = run_command([str(exe), "--cclite-capabilities"])
output = (result.get("stdout") or "") + "\n" + (result.get("stderr") or "")
capabilities = parse_key_value_output(output)
result["capabilities"] = capabilities
if result["exit_code"] == 0 and capabilities.get("cclite_worker", "").lower() == "yes":
result["status"] = "CAPABILITIES_AVAILABLE"
elif "unknown" in output.lower() and "capabilities" in output.lower():
result["status"] = "MISSING_CAPABILITIES_CLI"
else:
result["status"] = "CAPABILITIES_FAILED"
result["supports_real_ipc"] = is_yes(capabilities, "supports_real_ipc")
return result
def run_standard_worker_probe(
exe: Path,
solver_id: str,
case_file: Path,
extra_args: list[str] | None = None,
) -> dict:
command = [
str(exe),
"--cclite-worker",
]
if extra_args:
command.extend(extra_args)
command.extend([
"--solver-id",
solver_id,
"--case",
@@ -40,12 +81,20 @@ def run_standard_worker_probe(exe: Path, solver_id: str, case_file: Path) -> dic
"--timeout-ms",
"100",
])
result = run_command(command)
output = (result.get("stdout") or "") + "\n" + (result.get("stderr") or "")
recognized = "--solver-id" not in output and "unknown argument" not in output
output_lower = output.lower()
recognized = "--solver-id" not in output and "unknown argument" not in output_lower and "unknown worker argument" not in output_lower
unsupported = "not implemented" in output.lower() or "unsupported" in output.lower()
result["status"] = classify_standard_probe(recognized, unsupported, result["exit_code"])
attach_attempted = (
"ipc attach failed" in output_lower
or "failed to open cclite ipc transport" in output_lower
or ("failed to open" in output_lower and "ipc" in output_lower)
)
result["status"] = classify_standard_probe(recognized, unsupported, attach_attempted, result["exit_code"])
result["recognized_worker_cli"] = recognized
result["ipc_implemented"] = recognized and result["exit_code"] == 0 and not unsupported
result["real_ipc_attach_attempted"] = recognized and attach_attempted
result["ready_without_external_resources"] = recognized and result["exit_code"] == 0 and not unsupported
return result
@@ -67,9 +116,12 @@ def run_femlite_mock_probe(exe: Path, case_file: Path, report_path: Path) -> dic
"1",
])
output = (result.get("stdout") or "") + "\n" + (result.get("stderr") or "")
if result["exit_code"] == 0 and "worker mock completed" in output.lower():
output_lower = output.lower()
if result["exit_code"] == 0 and (
"worker mock completed" in output_lower or "worker completed: mock" in output_lower
):
result["status"] = "WORKER_MOCK_AVAILABLE"
elif "unknown worker argument" in output.lower() or "unknown argument" in output.lower():
elif "unknown worker argument" in output_lower or "unknown argument" in output_lower:
result["status"] = "MISSING_WORKER_MOCK_CLI"
else:
result["status"] = "WORKER_MOCK_FAILED"
@@ -78,9 +130,16 @@ def run_femlite_mock_probe(exe: Path, case_file: Path, report_path: Path) -> dic
return result
def classify_standard_probe(recognized: bool, unsupported: bool, exit_code: int | None) -> str:
def classify_standard_probe(
recognized: bool,
unsupported: bool,
attach_attempted: bool,
exit_code: int | None,
) -> str:
if recognized and unsupported:
return "CONTROLLED_UNSUPPORTED"
if recognized and attach_attempted:
return "IPC_ATTACH_ATTEMPTED"
if recognized and exit_code == 0:
return "READY_FOR_REAL_IPC"
if not recognized:
@@ -88,6 +147,60 @@ def classify_standard_probe(recognized: bool, unsupported: bool, exit_code: int
return "FAILED"
def build_protocol_alignment(fem_exe: Path) -> dict:
fem_include = fem_exe.parent.parent / "include" / "femlite_cclite_ipc.h"
fem_native_header = False
if fem_include.exists():
text = fem_include.read_text(encoding="utf-8", errors="ignore")
fem_native_header = (
"femlite_cclite_command_block" in text
and "femlite_cclite_data_header" in text
)
return {
"status": "CCLITE_PROTOCOL_ADAPTER_REQUIRED",
"cclite_current_protocol": {
"command_block": "CCLite generic command block v1",
"data_header": "CCLite generic data block header v0.1",
"control_names": [
"<prefix>_CCL_COMMAND_<solver>",
"<prefix>_EVENT_COMMAND_<solver>",
"<prefix>_EVENT_ACK_<solver>",
],
"data_names": [
"<prefix>_SPH_TO_CCL_PARTICLE",
"<prefix>_FEM_TO_CCL_FACET",
"<prefix>_CCL_TO_SPH_FORCE",
"<prefix>_CCL_TO_FEM_LOAD",
],
},
"sphlite_observed_protocol": {
"default_control_names": [
"<ipc_name>.command",
"<ipc_name>.command_event",
"<ipc_name>.done_event",
],
"supports_name_overrides": ["--command-block", "--data-prefix"],
"note": "SPHLite reports real IPC support, but true external CCLite process interop still requires a CCLite-side protocol/name adapter test.",
},
"femlite_observed_protocol": {
"native_header_detected": fem_native_header,
"header": str(fem_include),
"requires_worker_backend": "--worker-backend ipc",
"control_names": [
"<prefix>_COMMAND_BLOCK",
"<prefix>_COMMAND_EVENT",
"<prefix>_DONE_EVENT",
],
"data_names": [
"<data-prefix>_FEM_TO_CCL_FACET",
"<data-prefix>_CCL_TO_FEM_LOAD",
],
"note": "The current FEMLite package uses a native compact command block/data header that is not the same binary layout as CCLite 0.1.x generic blocks.",
},
}
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument("--sph-exe", required=True)
@@ -99,14 +212,34 @@ def main() -> int:
case_dir = Path(args.case_dir)
report_path = Path(args.report)
sph_standard = run_standard_worker_probe(Path(args.sph_exe), "SPH", case_dir / "mock_sph.inp")
fem_standard = run_standard_worker_probe(Path(args.fem_exe), "FEM", Path(args.fem_case))
fem_mock = run_femlite_mock_probe(Path(args.fem_exe), Path(args.fem_case), report_path)
sph_exe = Path(args.sph_exe)
fem_exe = Path(args.fem_exe)
sph_capabilities = run_capabilities_probe(sph_exe)
fem_capabilities = run_capabilities_probe(fem_exe)
sph_standard = run_standard_worker_probe(sph_exe, "SPH", case_dir / "mock_sph.inp")
fem_standard = run_standard_worker_probe(fem_exe, "FEM", Path(args.fem_case))
fem_explicit_ipc = run_standard_worker_probe(
fem_exe,
"FEM",
Path(args.fem_case),
["--worker-backend", "ipc", "--data-prefix", "CCLITE_REAL_WORKER_AUDIT"],
)
fem_mock = run_femlite_mock_probe(fem_exe, Path(args.fem_case), report_path)
protocol_alignment = build_protocol_alignment(fem_exe)
status = "PARTIAL_EXTERNAL_WORKER_SUPPORT"
if sph_standard["ipc_implemented"] and fem_standard["ipc_implemented"]:
status = "READY_FOR_REAL_IPC"
elif fem_mock["status"] != "WORKER_MOCK_AVAILABLE":
both_report_real_ipc = sph_capabilities["supports_real_ipc"] and fem_capabilities["supports_real_ipc"]
both_attach_attempted = (
sph_standard["real_ipc_attach_attempted"]
and (fem_standard["real_ipc_attach_attempted"] or fem_explicit_ipc["real_ipc_attach_attempted"])
)
if both_report_real_ipc and both_attach_attempted:
status = "EXTERNAL_WORKERS_READY_CCLITE_PROTOCOL_ADAPTER_REQUIRED"
elif both_report_real_ipc:
status = "EXTERNAL_WORKERS_REPORT_REAL_IPC"
elif fem_mock["status"] == "WORKER_MOCK_AVAILABLE":
status = "PARTIAL_EXTERNAL_WORKER_SUPPORT"
else:
status = "CONTROLLED_GAP"
report = {
@@ -118,14 +251,19 @@ def main() -> int:
"--ipc-name <prefix>",
"--timeout-ms <milliseconds>",
],
"sphlite_capabilities": sph_capabilities,
"femlite_capabilities": fem_capabilities,
"sphlite_standard_ipc": sph_standard,
"femlite_standard_ipc": fem_standard,
"femlite_explicit_ipc_backend": fem_explicit_ipc,
"femlite_worker_mock": fem_mock,
"protocol_alignment": protocol_alignment,
"conclusion": [
"SPHLite 0.8.2 recognizes worker mode but reports real IPC as not implemented.",
"FEMLite 0.6.4 provides a self-running CCLite worker mock.",
"FEMLite 0.6.4 does not yet accept the full CCLite standard IPC worker argument set.",
"CCLite 0.1.9 keeps mock-worker IPC integration as the executable acceptance path.",
"The current SPHLite package reports CCLite worker and Windows shared memory/named event support.",
"The current FEMLite package reports CCLite worker, worker mock, and Windows shared memory/named event support.",
"Both workers now attempt real IPC attach when launched without pre-created CCLite resources.",
"CCLite 0.1.10 still treats true external process interop as requiring a CCLite-side protocol/name adapter, because the published FEMLite IPC structures and names differ from CCLite 0.1.x generic blocks.",
"Mock-worker IPC integration remains the executable acceptance path until the adapter-level process tests pass.",
],
}