Skip to content

Commit 08453de

Browse files
cdeustclaude
andauthored
fix(core): remove os/pathlib from ablation.py and 8 retrieval env-flag modules (#560, 2/3) (#568)
* fix(core): remove os/pathlib from ablation.py and 8 retrieval env-flag modules (#560, 3/3) Last of the three #560 PRs (after #564 and #569): ablation.py, conflict_monitor.py, pg_recall_weights.py, recall_pipeline.py, reconsolidation.py, reranker_model.py, retrieval_dispatch.py, telemetry.py and thermodynamics.py no longer import os or pathlib. - core/environment.py: read_environment_variable/read_environment_float read through an injected reader, evaluated on every call, so runtime toggles (CORTEX_ABLATE_*, CORTEX_DECAY_DISABLED, CORTEX_*_BETA) still take effect after import. An unconfigured reader raises: returning "unset" silently would make every ablation run measure the un-ablated system (benchmarks set CORTEX_ABLATE_* without importing __main__). - core/reranker_model.py: the FlashRank cache lookup, existence check and sha256 move to infrastructure/reranker_cache.py behind a seam that raises when unwired. - Both seams join the wiki seams in mcp_server.hooks.wiring .wire_composition_root(), the single function every entry point calls. It now re-applies its bindings on every call instead of short-circuiting after the first, so a seam reset by a test is restored. The per-hook copies, benchmarks/lib/_environment_wiring.py, _reranker_wiring.py and the import-time wiring in hooks/_telemetry.py are gone; benchmarks/lib/_composition_root_wiring.py calls the same function. - doctor.ensure_reranker_ready() wires through that function; CI's reranker preload step calls it instead of reaching into core directly. - tests_py/benchmarks/test_ablation_runner_wiring.py drives the ablation-runner path with a CORTEX_ABLATE_* flag and proves the mechanism is disabled. Fixes #560 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * test(ablation): the runner wiring test needs psycopg, like the runner (#560) benchmarks/lib/ablation_runner.py imports db_snapshot, which imports psycopg; the SQLite-only CI job has no postgresql extra and failed at import. The PostgreSQL test jobs keep running it. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
1 parent 872855f commit 08453de

35 files changed

Lines changed: 583 additions & 203 deletions

‎.craftsmanship-baseline.json‎

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -627,11 +627,6 @@
627627
"kind": "unsourced-constant",
628628
"detail": "MAX_RESULTS"
629629
},
630-
{
631-
"file": "mcp_server/core/ablation.py",
632-
"kind": "layer-violation",
633-
"detail": "os"
634-
},
635630
{
636631
"file": "mcp_server/core/ablation.py",
637632
"kind": "unsourced-constant",
@@ -1002,11 +997,6 @@
1002997
"kind": "file-size",
1003998
"detail": "exceeds 300-line cap"
1004999
},
1005-
{
1006-
"file": "mcp_server/core/conflict_monitor.py",
1007-
"kind": "layer-violation",
1008-
"detail": "os"
1009-
},
10101000
{
10111001
"file": "mcp_server/core/conflict_monitor.py",
10121002
"kind": "method-size",
@@ -1772,11 +1762,6 @@
17721762
"kind": "layer-violation",
17731763
"detail": "mcp_server.observability"
17741764
},
1775-
{
1776-
"file": "mcp_server/core/pg_recall_weights.py",
1777-
"kind": "layer-violation",
1778-
"detail": "os"
1779-
},
17801765
{
17811766
"file": "mcp_server/core/platt_calibration.py",
17821767
"kind": "method-size",
@@ -1887,11 +1872,6 @@
18871872
"kind": "layer-violation",
18881873
"detail": "mcp_server.observability"
18891874
},
1890-
{
1891-
"file": "mcp_server/core/recall_pipeline.py",
1892-
"kind": "layer-violation",
1893-
"detail": "os"
1894-
},
18951875
{
18961876
"file": "mcp_server/core/recall_pipeline.py",
18971877
"kind": "method-size",
@@ -1957,11 +1937,6 @@
19571937
"kind": "file-size",
19581938
"detail": "exceeds 300-line cap"
19591939
},
1960-
{
1961-
"file": "mcp_server/core/reconsolidation.py",
1962-
"kind": "layer-violation",
1963-
"detail": "os"
1964-
},
19651940
{
19661941
"file": "mcp_server/core/reconsolidation.py",
19671942
"kind": "method-size",
@@ -2042,26 +2017,11 @@
20422017
"kind": "unsourced-constant",
20432018
"detail": "REFIT_EVERY"
20442019
},
2045-
{
2046-
"file": "mcp_server/core/reranker_model.py",
2047-
"kind": "layer-violation",
2048-
"detail": "os"
2049-
},
2050-
{
2051-
"file": "mcp_server/core/reranker_model.py",
2052-
"kind": "layer-violation",
2053-
"detail": "pathlib"
2054-
},
20552020
{
20562021
"file": "mcp_server/core/retrieval_dispatch.py",
20572022
"kind": "layer-violation",
20582023
"detail": "mcp_server.observability"
20592024
},
2060-
{
2061-
"file": "mcp_server/core/retrieval_dispatch.py",
2062-
"kind": "layer-violation",
2063-
"detail": "os"
2064-
},
20652025
{
20662026
"file": "mcp_server/core/retrieval_dispatch.py",
20672027
"kind": "method-size",
@@ -2507,26 +2467,11 @@
25072467
"kind": "unsourced-constant",
25082468
"detail": "_DEFAULT_TRIGGER_IMPORTANCE"
25092469
},
2510-
{
2511-
"file": "mcp_server/core/telemetry.py",
2512-
"kind": "layer-violation",
2513-
"detail": "os"
2514-
},
2515-
{
2516-
"file": "mcp_server/core/telemetry.py",
2517-
"kind": "layer-violation",
2518-
"detail": "pathlib"
2519-
},
25202470
{
25212471
"file": "mcp_server/core/thermodynamics.py",
25222472
"kind": "file-size",
25232473
"detail": "exceeds 300-line cap"
25242474
},
2525-
{
2526-
"file": "mcp_server/core/thermodynamics.py",
2527-
"kind": "layer-violation",
2528-
"detail": "os"
2529-
},
25302475
{
25312476
"file": "mcp_server/core/thermodynamics.py",
25322477
"kind": "method-size",

‎.github/actions/test-suite/action.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ runs:
202202
shell: bash
203203
run: |
204204
for attempt in 1 2 3 4 5; do
205-
python -c "from mcp_server.core.reranker import ensure_reranker_loaded as e; s = e(); assert s.state == 'loaded', s" && exit 0
205+
python -c "from mcp_server.doctor import ensure_reranker_ready as e; s = e(); assert s.state == 'loaded', s" && exit 0
206206
echo "FlashRank pre-download attempt ${attempt} failed; retrying in $((attempt * 10))s" >&2
207207
sleep $((attempt * 10))
208208
done

‎benchmarks/_repro.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from typing import Any
1414
from importlib.metadata import version
1515
from mcp_server.core.reranker import ensure_reranker_loaded, model_sha256
16+
import benchmarks.lib._composition_root_wiring # noqa: F401 — source: issue #560
1617

1718

1819
def _git_sha() -> str:

‎benchmarks/active_forgetting/run_benchmark.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
REPO = Path(__file__).resolve().parents[2]
1414
sys.path.insert(0, str(REPO))
1515

16+
import benchmarks.lib._composition_root_wiring # noqa: E402,F401 — source: issue #560
17+
1618
# The core under test (the same functions production calls).
1719
from mcp_server.hooks.wiring import wire_composition_root # noqa: E402 — source: issue #560
1820

‎benchmarks/energy/run_embedding_energy.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ def _run(args: argparse.Namespace) -> dict[str, object]:
6363
# source: ADR-0822
6464
if str(REPO) not in sys.path:
6565
sys.path.insert(0, str(REPO))
66+
import benchmarks.lib._composition_root_wiring # noqa: PLC0415,F401 — source: issue #560
67+
6668
# Deferred: these modules require NumPy and the optional embedding stack.
6769
from benchmarks.energy import measurement, workload # noqa: PLC0415
6870

‎benchmarks/forgetting_curve/run_benchmark.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
REPO = Path(__file__).resolve().parents[2]
1515
sys.path.insert(0, str(REPO))
1616

17+
import benchmarks.lib._composition_root_wiring # noqa: E402,F401 — source: issue #560
1718
import psycopg # noqa: E402
1819

1920
from benchmarks.forgetting_curve import criteria # noqa: E402
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"""Benchmark composition-root bootstrap (issue #560).
2+
3+
Benchmarks never run through mcp_server/__main__.py or scripts/launcher.py,
4+
so a benchmark entry point that reaches core imports this module for its
5+
side effect (``import benchmarks.lib._composition_root_wiring # noqa: F401``)
6+
or calls ``wire_composition_root()`` itself. Both wire every core seam
7+
through the one production function, mcp_server.hooks.wiring.
8+
"""
9+
10+
from __future__ import annotations
11+
12+
from mcp_server.hooks.wiring import wire_composition_root
13+
14+
wire_composition_root()

‎benchmarks/lib/ablation_runner.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
if str(_ROOT) not in sys.path:
2929
sys.path.insert(0, str(_ROOT))
3030

31+
import benchmarks.lib._composition_root_wiring # noqa: E402,F401 — source: issue #560
3132
from mcp_server.core import ablation as _ablation # noqa: E402
3233
from mcp_server.core.ablation import Mechanism # noqa: E402
3334
from benchmarks.lib.db_snapshot import ( # noqa: E402

‎benchmarks/lib/bench_db.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from mcp_server.core.reranker import ensure_reranker_loaded
2525
from mcp_server.infrastructure.embedding_engine import EmbeddingEngine
2626
from mcp_server.infrastructure.pg_store import PgMemoryStore
27+
import benchmarks.lib._composition_root_wiring # noqa: F401 — source: issue #560
2728

2829

2930
def _apply_capture_origin_mix(memories: list[dict[str, Any]]) -> None:

‎benchmarks/lib/retriever.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
)
3333
from mcp_server.infrastructure.embedding_engine import EmbeddingEngine
3434
from mcp_server.core.reranker import reranker_cache_dir
35+
import benchmarks.lib._composition_root_wiring # noqa: F401 — source: issue #560
3536

3637
logger = logging.getLogger(__name__)
3738

0 commit comments

Comments
 (0)