Skip to content

Commit 2d2afcc

Browse files
committed
asked its context window, eli dumped a code map and then said the evidence did not specify it: n_ctx was 12192 and in the startup snapshot, but EXPLAIN_COGNITION_RUNTIME described the architecture and carried no inference parameters at all — and the router's diagnostic_focus=inference_runtime was ignored by both producers
1 parent ff315d5 commit 2d2afcc

3 files changed

Lines changed: 200 additions & 4 deletions

File tree

eli/execution/executor_enhanced.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1688,7 +1688,20 @@ def _explain_cognition_runtime_report() -> Dict[str, Any]:
16881688
def _format_cognition_runtime(report: Dict[str, Any]) -> str:
16891689
if not report.get('ok'):
16901690
return str(report.get('error') or 'Cognition runtime report failed')
1691-
lines = [
1691+
lines = []
1692+
# The live INFERENCE parameters go first. Asked "what is your current context
1693+
# window?", this report answered with module paths, grep line numbers and
1694+
# SQLite table counts — and the synthesis on top of it then said "the
1695+
# provided evidence does not specify the current context window size". It
1696+
# did not: n_ctx was 12192, written to runtime_snapshot.json at startup, and
1697+
# this report — named for the runtime — had no field for it.
1698+
try:
1699+
from eli.runtime.deterministic_grounding_gate import _inference_runtime_lines
1700+
lines.append(_inference_runtime_lines())
1701+
lines.append("")
1702+
except Exception:
1703+
log.debug("[EXECUTOR] inference runtime block unavailable", exc_info=True)
1704+
lines += [
16921705
f"Cognition runtime: {report.get('path')}",
16931706
f"Memory module: {report.get('memory_path')}",
16941707
f"Router module: {report.get('router_path')}",

eli/runtime/deterministic_grounding_gate.py

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -955,8 +955,63 @@ def table_block(title: str, db: _EliPath, counts: dict[str, int]) -> list[str]:
955955
return "\n".join(lines)
956956

957957

958-
def _eli_cognition_pipeline_v2() -> str:
959-
return """Cognition pipeline, input to output:
958+
def _inference_runtime_lines() -> str:
959+
"""The live inference parameters, as plain lines of evidence.
960+
961+
Asked "what is your current context window?", ELI answered "The provided
962+
evidence does not specify the current context window size." It was running
963+
at n_ctx=12192 and had written that number to runtime_snapshot.json at
964+
startup — the evidence bundle for EXPLAIN_COGNITION_RUNTIME simply had no
965+
field for it. The action is named for the runtime and described only the
966+
architecture: module paths, line numbers and table counts.
967+
968+
Requested and effective are BOTH reported, because they diverge and the
969+
difference is the answer to most questions in this area: on that session the
970+
user asked for 99 GPU layers and got 8, which is why replies took minutes.
971+
"""
972+
snap = _runtime_snapshot() or {}
973+
req = snap.get("requested") or {}
974+
eff = snap.get("effective") or {}
975+
976+
def pick(key, fallback_top=True):
977+
for src in (eff, snap if fallback_top else {}):
978+
if src.get(key) not in (None, ""):
979+
return src.get(key)
980+
return "unknown"
981+
982+
lines = ["Inference runtime (live, from the loaded model):"]
983+
model = snap.get("model_name") or snap.get("model_path") or "unknown"
984+
lines.append(f"- model: {model}")
985+
lines.append(f"- provider: {snap.get('provider', 'unknown')}")
986+
lines.append(f"- context window (n_ctx): {pick('n_ctx')}")
987+
if req.get("n_ctx") not in (None, "") and req.get("n_ctx") != eff.get("n_ctx"):
988+
lines.append(f" (requested {req.get('n_ctx')}, reduced to fit VRAM)")
989+
lines.append(f"- GPU layers offloaded: {pick('n_gpu_layers')}")
990+
if req.get("n_gpu_layers") not in (None, "") and req.get("n_gpu_layers") != eff.get("n_gpu_layers"):
991+
lines.append(f" (requested {req.get('n_gpu_layers')} — the rest run on CPU, which is the "
992+
f"dominant cost of a slow reply)")
993+
lines.append(f"- batch: {pick('n_batch')} threads: {pick('n_threads')}")
994+
lines.append(f"- load mode: {snap.get('load_mode', 'unknown')}")
995+
return "\n".join(lines)
996+
997+
998+
def _eli_cognition_pipeline_v2(focus: str = "") -> str:
999+
runtime_block = ""
1000+
try:
1001+
runtime_block = _inference_runtime_lines()
1002+
except Exception:
1003+
log.debug("inference runtime block unavailable", exc_info=True)
1004+
1005+
# A question about the inference runtime gets the NUMBERS, not a code map.
1006+
# The router already classifies this (diagnostic_focus=inference_runtime) and
1007+
# the answer ignored it, returning the architecture description regardless.
1008+
if runtime_block and str(focus or "").strip().lower() == "inference_runtime":
1009+
return runtime_block + "\n\n" + _COGNITION_PIPELINE_TEXT
1010+
1011+
return ((runtime_block + "\n\n") if runtime_block else "") + _COGNITION_PIPELINE_TEXT
1012+
1013+
1014+
_COGNITION_PIPELINE_TEXT = """Cognition pipeline, input to output:
9601015
9611016
1. GUI / voice capture
9621017
- Text input enters through eli/gui/eli_pro_audio_gui_v2_0.py.
@@ -1102,7 +1157,10 @@ def render_action(action: str, args: _EliMapping[str, _EliAny] | None = None, us
11021157
return _eli_runtime_audit_v2()
11031158

11041159
if a == "EXPLAIN_COGNITION_RUNTIME":
1105-
return _eli_cognition_pipeline_v2()
1160+
# The router already decides this ("diagnostic_focus": "inference_runtime"
1161+
# for a question about the context window / model / GPU) — pass it through
1162+
# instead of returning the same architecture text for every question.
1163+
return _eli_cognition_pipeline_v2(str((args or {}).get("diagnostic_focus") or ""))
11061164

11071165
if a in {"EXPLAIN_MEMORY_RUNTIME", "MEMORY_STATUS", "PERSONAL_MEMORY_DEEP_EXPLAIN"}:
11081166
if _eli_wants_personal_memory_v2(text):
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
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

Comments
 (0)