feat(loop): complete Issue #5 Phase 4 immutable runtime and freeze removal

- Implement eager module loading (lib_py.loop.eager) to preload all framework
  dependencies into sys.modules and enforce PYTHONDONTWRITEBYTECODE=1.
- Synchronize runtime protocol version with MAM_VERSION constant (4.3.0).
- Bypass /tmp/mam-loop-freeze.XXXXXX copy overhead by default in Python mode
  while preserving legacy rollback fallback (MAM_LOOP_PY=0 / MAM_LOOP_FREEZE=1).
- Add tests/test_issue5_phase4_runtime.py verifying eager import completeness,
  mid-flight code modification immunity (B-13), and freeze bypass.
- Pass full test suite (749 tests, 0 failures).
This commit is contained in:
Godopu committed 2026-09-07 12:59:45 +09:00
1 parent 8cd256cc7a
commit f413f6ada6
6 files changed
+390 -11

No files matched your search

@@ -112,11 +112,19 @@ if [ -z "${AGENT_PYTHON_BIN:-}" ]; then
fi
# --- B-13 Stage 2: freeze the runtime before the loop can be edited under us ---
# bash keeps reading a running script from disk by byte offset, so a worker that
# edits .agents/skills/ mid-loop can break this very file (measured: even a valid
# replacement died with "unexpected EOF"). Re-exec once from a snapshot.
# NOTE: log_* are not defined until :114 — use echo here, not log_warn (C2).
if [ -z "${MAM_LOOP_FREEZE_DIR:-}" ] && [ "${MAM_LOOP_NO_FREEZE:-0}" != "1" ]; then
# In Python mode (MAM_LOOP_PY=1, default), the Python process holds all modules in memory
# (eager import), providing immunity against mid-flight file mutations without disk copying.
# The legacy freeze snapshot (/tmp/mam-loop-freeze.XXXXXX) is only activated when
# legacy shell mode (MAM_LOOP_PY=0) is selected or freeze is explicitly forced (MAM_LOOP_FREEZE=1).
# NOTE: log_* are not defined until :163 — use echo here, not log_warn (C2).
_should_freeze=0
if [ "${MAM_LOOP_NO_FREEZE:-0}" != "1" ] && [ -z "${MAM_LOOP_FREEZE_DIR:-}" ]; then
if [ "${MAM_LOOP_FREEZE:-0}" = "1" ] || [ "${MAM_LOOP_PY:-1}" = "0" ]; then
_should_freeze=1
fi
fi
if [ "$_should_freeze" = "1" ]; then
_freeze=""
_freeze="$(mktemp -d "${TMPDIR:-/tmp}/mam-loop-freeze.XXXXXX" 2>/dev/null)" || _freeze=""
if [ -n "$_freeze" ] && mkdir -p "$_freeze/.agents" 2>/dev/null \