From 1e2f5c57d3ce1d3f9a6423eec83c18878de30077 Mon Sep 17 00:00:00 2001 From: Rafael Lopez Date: Mon, 12 Oct 2026 00:30:00 -0500 Subject: [PATCH 1/5] fix(P0): use shared Intel Ollama fallback in actual Dev Swarm router and gate regression tests --- .github/workflows/inneros-runtime-gates.yml | 7 ++++ platform/raphiia_openai/local_model_router.py | 33 +++++++++++++-- .../tests/test_local_model_router_fallback.py | 41 +++++++++++++++++++ 3 files changed, 77 insertions(+), 4 deletions(-) diff --git a/.github/workflows/inneros-runtime-gates.yml b/.github/workflows/inneros-runtime-gates.yml index 827c0fa5..7bc7ee3c 100644 --- a/.github/workflows/inneros-runtime-gates.yml +++ b/.github/workflows/inneros-runtime-gates.yml @@ -3,6 +3,8 @@ name: InnerOS P0 Runtime Safety Gates on: pull_request: paths: + - "platform/raphiia_openai/local_model_router.py" + - "platform/tests/test_local_model_router_fallback.py" - "platform/inneros_core_runtime/execution_binding.py" - "platform/inneros_core_runtime/capability_gateway.py" - "platform/inneros_core_runtime/capability_gateway_peer.py" @@ -28,6 +30,8 @@ on: push: branches: [main] paths: + - "platform/raphiia_openai/local_model_router.py" + - "platform/tests/test_local_model_router_fallback.py" - "platform/inneros_core_runtime/execution_binding.py" - "platform/inneros_core_runtime/capability_gateway.py" - "platform/inneros_core_runtime/capability_gateway_peer.py" @@ -70,6 +74,8 @@ jobs: - name: Compile critical runtime contracts run: | python -m compileall -q \ + platform/raphiia_openai/local_model_router.py \ + platform/tests/test_local_model_router_fallback.py \ platform/inneros_core_runtime/execution_binding.py \ platform/inneros_core_runtime/capability_gateway.py \ platform/inneros_core_runtime/capability_gateway_peer.py \ @@ -90,6 +96,7 @@ jobs: python -m pytest -q \ platform/tests/test_global_coordination_guards.py \ platform/tests/test_execution_binding.py \ + platform/tests/test_local_model_router_fallback.py \ platform/tests/test_execution_receipts.py \ platform/tests/test_capability_gateway.py \ platform/tests/test_capability_gateway_regressions_p0.py \ diff --git a/platform/raphiia_openai/local_model_router.py b/platform/raphiia_openai/local_model_router.py index c8872126..ebfa898f 100644 --- a/platform/raphiia_openai/local_model_router.py +++ b/platform/raphiia_openai/local_model_router.py @@ -20,6 +20,8 @@ from raphiia_openai import capacity_governor_vnext, mongo_store, ralfia_time from raphiia_openai.settings import COL_AI_ROUTING_LOG, MCP_PUBLIC_URL +# Share the tested AMD -> Intel fallback rather than maintaining a third copy. +from inneros_core_runtime.local_model_router import _intel_ollama_fallback GPU_ROLE = os.getenv("INNEROS_GPU_ROLE", "").strip().lower() @@ -779,9 +781,19 @@ def run_local_model( health = local_model_health() provider_health = _http_ok(f"{vllm_url}/v1/models") if backend == "vllm" and provider_id == "local-amd-5" else _http_ok(f"{ollama_url}/api/tags") if backend == "vllm" and provider_id == "local-amd-5" and not provider_health.get("ok"): + reason = "amd_vllm_unreachable_from_intel" if GPU_ROLE == "ollama-primary" else "amd_vllm_unreachable" + # Same helper used by the core router; no cloud fallback, no silent provider switch. + fb = _intel_ollama_fallback( + task_type=classification["task_type"], prompt=prompt, + system_prompt="Responde con precision en la tarea local solicitada.", + max_tokens=max_tokens, temperature=temperature, + fallback_reason=reason, preferred_model=selected, + ) + if fb.get("ok"): + return fb return { "ok": False, - "error": "amd_vllm_unreachable_from_intel" if GPU_ROLE == "ollama-primary" else "amd_vllm_unreachable", + "error": reason, "endpoint": vllm_url, "health": health, "provider_health": provider_health, @@ -790,7 +802,9 @@ def run_local_model( "selected_node": "amd", "provider_id": provider_id, "fallback_silent": False, - "fallback_reason": "amd_vllm_unreachable_from_intel" if GPU_ROLE == "ollama-primary" else "amd_vllm_unreachable", + "fallback_reason": reason, + "intel_fallback_error": fb.get("error") or "intel_ollama_unavailable", + "external_needed": False, } if not (health.get("ok") or provider_health.get("ok")): return { @@ -828,16 +842,24 @@ def run_local_model( endpoint=vllm_url, ) if not result.get("ok"): + fb = _intel_ollama_fallback( + task_type=classification["task_type"], prompt=prompt, + system_prompt=system_prompt, max_tokens=max_tokens, + temperature=temperature, + fallback_reason="amd_vllm_generation_failed", preferred_model=selected, + ) + if fb.get("ok"): + return fb _log_route( title=classification["task_type"], body=prompt, task_type=classification["task_type"], runtime="local_vllm", model=selected, - local_ok=True, + local_ok=False, external_needed=False, approval_required=False, - reason="vLLM execution failed; no silent fallback", + reason="vLLM execution failed; Intel Ollama fallback unavailable", decision="error", ) return { @@ -847,6 +869,9 @@ def run_local_model( "selected_node": "amd", "provider_id": provider_id, "fallback_silent": False, + "fallback_reason": "amd_vllm_generation_failed", + "intel_fallback_error": fb.get("error") or "intel_ollama_unavailable", + "external_needed": False, } log = _log_route( title=classification["task_type"], diff --git a/platform/tests/test_local_model_router_fallback.py b/platform/tests/test_local_model_router_fallback.py index 2a4cc17e..d67fdeb5 100644 --- a/platform/tests/test_local_model_router_fallback.py +++ b/platform/tests/test_local_model_router_fallback.py @@ -35,5 +35,46 @@ def test_amd_vllm_unreachable_uses_ollama_fallback(self, mock_health, mock_ok, m mock_fallback.assert_called_once() + @patch.object(lmr, "_intel_ollama_fallback") + @patch.object(lmr, "_http_ok") + @patch.object(lmr, "local_model_health") + def test_vllm_generation_failure_uses_intel_ollama(self, mock_health, mock_ok, mock_fallback): + mock_health.return_value = {"ok": True} + mock_ok.return_value = {"ok": True} + mock_fallback.return_value = { + "ok": True, "runtime": "local_model", "selected_node": "intel", + "response": "fallback generated", "fallback_reason": "amd_vllm_generation_failed", + } + with patch.object(lmr, "classify_task_runtime") as classifier, patch.object(lmr, "_vllm_chat") as vllm: + classifier.return_value = { + "task_type": "coding", "recommended_model": "amd-qwen", + "recommended_provider": "local-amd-5", "recommended_backend": "vllm", + "reason": "test", + } + vllm.return_value = {"ok": False, "error": "vllm_unavailable"} + result = lmr.run_local_model(task_type="coding", prompt="test") + self.assertTrue(result["ok"]) + self.assertEqual(result["selected_node"], "intel") + self.assertEqual(mock_fallback.call_args.kwargs["fallback_reason"], "amd_vllm_generation_failed") + + @patch.object(lmr, "_intel_ollama_fallback") + @patch.object(lmr, "_http_ok") + @patch.object(lmr, "local_model_health") + def test_failed_fallback_remains_fail_closed(self, mock_health, mock_ok, mock_fallback): + mock_health.return_value = {"ok": True} + mock_ok.side_effect = lambda url: {"ok": "/v1/models" not in url} + mock_fallback.return_value = {"ok": False, "error": "intel_ollama_no_models"} + with patch.object(lmr, "classify_task_runtime") as classifier: + classifier.return_value = { + "task_type": "coding", "recommended_model": "amd-qwen", + "recommended_provider": "local-amd-5", "recommended_backend": "vllm", + "reason": "test", + } + result = lmr.run_local_model(task_type="coding", prompt="test") + self.assertFalse(result["ok"]) + self.assertEqual(result["intel_fallback_error"], "intel_ollama_no_models") + self.assertFalse(result["external_needed"]) + mock_fallback.assert_called_once() + if __name__ == "__main__": unittest.main() From 5885664f75580175eba77cc4b533e660bd6d76e5 Mon Sep 17 00:00:00 2001 From: Rafael Lopez Date: Mon, 12 Oct 2026 00:31:53 -0500 Subject: [PATCH 2/5] fix(scope): preserve unused legacy copy; actual router resolves through canonical package shim --- platform/raphiia_openai/local_model_router.py | 33 +++---------------- 1 file changed, 4 insertions(+), 29 deletions(-) diff --git a/platform/raphiia_openai/local_model_router.py b/platform/raphiia_openai/local_model_router.py index ebfa898f..c8872126 100644 --- a/platform/raphiia_openai/local_model_router.py +++ b/platform/raphiia_openai/local_model_router.py @@ -20,8 +20,6 @@ from raphiia_openai import capacity_governor_vnext, mongo_store, ralfia_time from raphiia_openai.settings import COL_AI_ROUTING_LOG, MCP_PUBLIC_URL -# Share the tested AMD -> Intel fallback rather than maintaining a third copy. -from inneros_core_runtime.local_model_router import _intel_ollama_fallback GPU_ROLE = os.getenv("INNEROS_GPU_ROLE", "").strip().lower() @@ -781,19 +779,9 @@ def run_local_model( health = local_model_health() provider_health = _http_ok(f"{vllm_url}/v1/models") if backend == "vllm" and provider_id == "local-amd-5" else _http_ok(f"{ollama_url}/api/tags") if backend == "vllm" and provider_id == "local-amd-5" and not provider_health.get("ok"): - reason = "amd_vllm_unreachable_from_intel" if GPU_ROLE == "ollama-primary" else "amd_vllm_unreachable" - # Same helper used by the core router; no cloud fallback, no silent provider switch. - fb = _intel_ollama_fallback( - task_type=classification["task_type"], prompt=prompt, - system_prompt="Responde con precision en la tarea local solicitada.", - max_tokens=max_tokens, temperature=temperature, - fallback_reason=reason, preferred_model=selected, - ) - if fb.get("ok"): - return fb return { "ok": False, - "error": reason, + "error": "amd_vllm_unreachable_from_intel" if GPU_ROLE == "ollama-primary" else "amd_vllm_unreachable", "endpoint": vllm_url, "health": health, "provider_health": provider_health, @@ -802,9 +790,7 @@ def run_local_model( "selected_node": "amd", "provider_id": provider_id, "fallback_silent": False, - "fallback_reason": reason, - "intel_fallback_error": fb.get("error") or "intel_ollama_unavailable", - "external_needed": False, + "fallback_reason": "amd_vllm_unreachable_from_intel" if GPU_ROLE == "ollama-primary" else "amd_vllm_unreachable", } if not (health.get("ok") or provider_health.get("ok")): return { @@ -842,24 +828,16 @@ def run_local_model( endpoint=vllm_url, ) if not result.get("ok"): - fb = _intel_ollama_fallback( - task_type=classification["task_type"], prompt=prompt, - system_prompt=system_prompt, max_tokens=max_tokens, - temperature=temperature, - fallback_reason="amd_vllm_generation_failed", preferred_model=selected, - ) - if fb.get("ok"): - return fb _log_route( title=classification["task_type"], body=prompt, task_type=classification["task_type"], runtime="local_vllm", model=selected, - local_ok=False, + local_ok=True, external_needed=False, approval_required=False, - reason="vLLM execution failed; Intel Ollama fallback unavailable", + reason="vLLM execution failed; no silent fallback", decision="error", ) return { @@ -869,9 +847,6 @@ def run_local_model( "selected_node": "amd", "provider_id": provider_id, "fallback_silent": False, - "fallback_reason": "amd_vllm_generation_failed", - "intel_fallback_error": fb.get("error") or "intel_ollama_unavailable", - "external_needed": False, } log = _log_route( title=classification["task_type"], From 19053ecc060c6588b43a6cfa07b9f0b860b29f47 Mon Sep 17 00:00:00 2001 From: Rafael Lopez Date: Mon, 12 Oct 2026 00:32:01 -0500 Subject: [PATCH 3/5] test(router): assert Dev Swarm imports canonical package through legacy shim --- platform/tests/test_local_model_router_fallback.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/platform/tests/test_local_model_router_fallback.py b/platform/tests/test_local_model_router_fallback.py index d67fdeb5..ee10f23e 100644 --- a/platform/tests/test_local_model_router_fallback.py +++ b/platform/tests/test_local_model_router_fallback.py @@ -2,12 +2,19 @@ from __future__ import annotations import unittest +from pathlib import Path from unittest.mock import patch from raphiia_openai import local_model_router as lmr class LocalModelRouterFallbackTests(unittest.TestCase): + def test_scheduler_uses_active_canonical_router_from_shim(self): + from inneros_core_runtime import dev_swarm_scheduler as scheduler + self.assertIs(scheduler.local_model_router, lmr) + self.assertEqual(Path(lmr.__file__).parent.name, "inneros_core_runtime") + self.assertTrue(callable(getattr(lmr, "_intel_ollama_fallback", None))) + @patch.object(lmr, "_intel_ollama_fallback") @patch.object(lmr, "_http_ok") @patch.object(lmr, "local_model_health") From de9d45b6bf77e285907bcbcf1f27e169472128e4 Mon Sep 17 00:00:00 2001 From: Rafael Lopez Date: Mon, 12 Oct 2026 00:32:11 -0500 Subject: [PATCH 4/5] ci(router): execute canonical shim/fallback tests when effective runtime module changes --- .github/workflows/inneros-runtime-gates.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/inneros-runtime-gates.yml b/.github/workflows/inneros-runtime-gates.yml index 7bc7ee3c..47d3f3b0 100644 --- a/.github/workflows/inneros-runtime-gates.yml +++ b/.github/workflows/inneros-runtime-gates.yml @@ -3,7 +3,8 @@ name: InnerOS P0 Runtime Safety Gates on: pull_request: paths: - - "platform/raphiia_openai/local_model_router.py" + - "platform/inneros_core_runtime/local_model_router.py" + - "platform/raphiia_openai/__init__.py" - "platform/tests/test_local_model_router_fallback.py" - "platform/inneros_core_runtime/execution_binding.py" - "platform/inneros_core_runtime/capability_gateway.py" @@ -30,7 +31,8 @@ on: push: branches: [main] paths: - - "platform/raphiia_openai/local_model_router.py" + - "platform/inneros_core_runtime/local_model_router.py" + - "platform/raphiia_openai/__init__.py" - "platform/tests/test_local_model_router_fallback.py" - "platform/inneros_core_runtime/execution_binding.py" - "platform/inneros_core_runtime/capability_gateway.py" @@ -74,7 +76,8 @@ jobs: - name: Compile critical runtime contracts run: | python -m compileall -q \ - platform/raphiia_openai/local_model_router.py \ + platform/inneros_core_runtime/local_model_router.py \ + platform/raphiia_openai/__init__.py \ platform/tests/test_local_model_router_fallback.py \ platform/inneros_core_runtime/execution_binding.py \ platform/inneros_core_runtime/capability_gateway.py \ From d2c429e3f25b9e7bfad7e83bbe15dce1c4247160 Mon Sep 17 00:00:00 2001 From: Rafael Lopez Date: Mon, 12 Oct 2026 00:34:22 -0500 Subject: [PATCH 5/5] test(router): assert canonical fallback error field from existing implementation --- platform/tests/test_local_model_router_fallback.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/tests/test_local_model_router_fallback.py b/platform/tests/test_local_model_router_fallback.py index ee10f23e..cd5c29e0 100644 --- a/platform/tests/test_local_model_router_fallback.py +++ b/platform/tests/test_local_model_router_fallback.py @@ -79,7 +79,7 @@ def test_failed_fallback_remains_fail_closed(self, mock_health, mock_ok, mock_fa } result = lmr.run_local_model(task_type="coding", prompt="test") self.assertFalse(result["ok"]) - self.assertEqual(result["intel_fallback_error"], "intel_ollama_no_models") + self.assertEqual(result["error"], "intel_ollama_no_models") self.assertFalse(result["external_needed"]) mock_fallback.assert_called_once()