"""Subprocess entrypoint for safe_probe.probe_archive — see safe_probe.py.

probe_archive spawns this via subprocess (not multiprocessing.Process)
because Celery's prefork worker pool runs tasks in DAEMON processes and
Python's multiprocessing forbids daemon processes from spawning children
("AssertionError: daemonic processes are not allowed to have children",
operator-flagged 2026-05-30 — every archive import failed at task
startup). subprocess has no such restriction; we still get crash-
isolation because a probe segfault/OOM exits non-zero rather than
killing the worker.

Prints a single JSON line on stdout: {"status": "ok"|"error",
"detail": "..."?}. Exit code 0 for clean outcomes; non-zero exit
(signal / OOM-kill / unhandled exception) is the poison-pill signature
the parent maps to ProbeResult(crashed=True).
"""
import json
import sys

from .safe_probe import _run_probe


def main() -> int:
    if len(sys.argv) != 2:
        print(json.dumps({"status": "error", "detail": "usage: <path>"}))
        return 2
    status, detail = _run_probe(sys.argv[1])
    print(json.dumps({"status": status, "detail": detail}))
    return 0


if __name__ == "__main__":
    sys.exit(main())
