|
| 1 | +"""Locks on "what is your context window?" being answered with the number. |
| 2 | +
|
| 3 | +Live at 2.2.0, running a 30B model with 8 of 99 layers on GPU: |
| 4 | +
|
| 5 | + user> What is your current context window? You should have a reasonably |
| 6 | + high context window, no? |
| 7 | + ELI > Cognition runtime: /…/engine.py |
| 8 | + Memory module: /…/memory.py |
| 9 | + - gguf: lines [67, 69, 1712, 3775, …] <- 60 grep line numbers |
| 10 | + - active_db: capability_proposals(0), conversation_turns(672), … |
| 11 | + user> What is your current context window? |
| 12 | + ELI > The provided evidence does not specify the current context window size. |
| 13 | +
|
| 14 | +It did not — and n_ctx was 12192, written to runtime_snapshot.json at startup |
| 15 | +and printed six times in the same log. EXPLAIN_COGNITION_RUNTIME, the action |
| 16 | +named for the runtime, described the ARCHITECTURE: module paths, grep hits and |
| 17 | +SQLite table counts, with no field anywhere for the inference parameters. |
| 18 | +
|
| 19 | +The router had already worked it out — it routed with |
| 20 | +``diagnostic_focus: "inference_runtime"`` — and both evidence producers ignored |
| 21 | +that argument and returned the same text for every question. |
| 22 | +
|
| 23 | +Requested and effective are both reported because their divergence is usually |
| 24 | +the real answer: that session asked for 99 GPU layers and got 8, which is why |
| 25 | +single replies took 136 seconds. |
| 26 | +""" |
| 27 | +import json |
| 28 | + |
| 29 | +import pytest |
| 30 | + |
| 31 | +from eli.runtime import deterministic_grounding_gate as G |
| 32 | + |
| 33 | +SNAPSHOT = { |
| 34 | + "provider": "gguf", |
| 35 | + "model_name": "NVIDIA-Nemotron-3-Nano-Omni-30B-A3B-Reasoning-UD-Q4_K_XL.gguf", |
| 36 | + "n_ctx": 12192, "n_gpu_layers": 8, "n_batch": 128, "load_mode": "GPU", |
| 37 | + "requested": {"n_ctx": 12192, "n_gpu_layers": 99, "n_threads": 10, "n_batch": 128}, |
| 38 | + "effective": {"n_ctx": 12192, "n_gpu_layers": 8, "n_threads": 10, "n_batch": 128}, |
| 39 | +} |
| 40 | + |
| 41 | + |
| 42 | +@pytest.fixture |
| 43 | +def live_snapshot(monkeypatch): |
| 44 | + monkeypatch.setattr(G, "_runtime_snapshot", lambda: dict(SNAPSHOT)) |
| 45 | + |
| 46 | + |
| 47 | +# ── the question must be answerable from the evidence ─────────────────────── |
| 48 | +def test_the_context_window_is_in_the_evidence(live_snapshot): |
| 49 | + assert "12192" in G._inference_runtime_lines() |
| 50 | + |
| 51 | + |
| 52 | +def test_the_model_is_named(live_snapshot): |
| 53 | + assert "Nemotron" in G._inference_runtime_lines() |
| 54 | + |
| 55 | + |
| 56 | +def test_requested_and_effective_gpu_layers_are_both_shown(live_snapshot): |
| 57 | + """8 of a requested 99 is the reason a reply took over two minutes. Showing |
| 58 | + only the effective number hides the cause; only the requested one lies.""" |
| 59 | + out = G._inference_runtime_lines() |
| 60 | + assert "8" in out and "99" in out |
| 61 | + |
| 62 | + |
| 63 | +def test_a_divergence_is_explained_not_just_printed(live_snapshot): |
| 64 | + out = G._inference_runtime_lines() |
| 65 | + assert "CPU" in out, "the reason the missing layers cost time is not stated" |
| 66 | + |
| 67 | + |
| 68 | +def test_no_divergence_means_no_noise(monkeypatch): |
| 69 | + """When requested == effective there is nothing to explain.""" |
| 70 | + snap = dict(SNAPSHOT) |
| 71 | + snap["requested"] = dict(snap["effective"]) |
| 72 | + monkeypatch.setattr(G, "_runtime_snapshot", lambda: snap) |
| 73 | + assert "requested" not in G._inference_runtime_lines() |
| 74 | + |
| 75 | + |
| 76 | +# ── the focus the router already computed must be honoured ────────────────── |
| 77 | +def test_an_inference_question_leads_with_the_numbers(live_snapshot): |
| 78 | + out = G._eli_cognition_pipeline_v2("inference_runtime") |
| 79 | + assert out.index("12192") < out.index("Cognition pipeline"), \ |
| 80 | + "still leading with the architecture description" |
| 81 | + |
| 82 | + |
| 83 | +def test_the_architecture_description_is_not_lost(live_snapshot): |
| 84 | + """Someone asking how ELI works still needs the pipeline text.""" |
| 85 | + out = G._eli_cognition_pipeline_v2("inference_runtime") |
| 86 | + assert "Cognition pipeline" in out |
| 87 | + assert "Router" in out |
| 88 | + |
| 89 | + |
| 90 | +def test_the_runtime_is_present_even_without_a_focus(live_snapshot): |
| 91 | + """A report named for the runtime should carry it regardless.""" |
| 92 | + assert "12192" in G._eli_cognition_pipeline_v2("") |
| 93 | + |
| 94 | + |
| 95 | +# ── the executor's copy of the report, which is what the user saw ────────── |
| 96 | +def test_the_executor_report_also_leads_with_the_runtime(live_snapshot): |
| 97 | + from eli.execution.executor_enhanced import _format_cognition_runtime |
| 98 | + out = _format_cognition_runtime({ |
| 99 | + "ok": True, "path": "engine.py", "memory_path": "memory.py", |
| 100 | + "router_path": "router.py", "executor_path": "executor.py", "checks": {}, |
| 101 | + }) |
| 102 | + assert "12192" in out |
| 103 | + assert out.index("12192") < out.index("Cognition runtime:") |
| 104 | + |
| 105 | + |
| 106 | +# ── failure modes ────────────────────────────────────────────────────────── |
| 107 | +def test_a_missing_snapshot_does_not_break_the_report(monkeypatch): |
| 108 | + monkeypatch.setattr(G, "_runtime_snapshot", lambda: {}) |
| 109 | + out = G._eli_cognition_pipeline_v2("inference_runtime") |
| 110 | + assert "Cognition pipeline" in out, "lost the whole report over a missing snapshot" |
| 111 | + assert "unknown" in out |
| 112 | + |
| 113 | + |
| 114 | +def test_a_raising_snapshot_does_not_break_the_report(monkeypatch): |
| 115 | + def boom(): |
| 116 | + raise RuntimeError("snapshot unreadable") |
| 117 | + monkeypatch.setattr(G, "_runtime_snapshot", boom) |
| 118 | + out = G._eli_cognition_pipeline_v2("inference_runtime") |
| 119 | + assert "Cognition pipeline" in out |
| 120 | + |
| 121 | + |
| 122 | +def test_the_pipeline_text_is_a_constant_not_rebuilt_per_call(): |
| 123 | + """It is static prose; only the runtime block is live.""" |
| 124 | + assert isinstance(G._COGNITION_PIPELINE_TEXT, str) |
| 125 | + assert "Cognition pipeline" in G._COGNITION_PIPELINE_TEXT |
0 commit comments