Skip to content

Commit ecb3b01

Browse files
fix: respect nonadditive token counters, finer importance steps, galaxy live-limit guard
Three small fixes salvaged from local review-worktree iteration: - core/context.py: the compact-header retry path recomputed available budget as `budget - self._count(base)` without guarding against nonadditive custom token counters (a header-aware counter can make base grow after compaction, driving `available` negative). Clamp to zero and skip the excerpt when no positive room remains; also propagate `compact_available` after adopting a compact header so subsequent accounting stays truthful. Covered by a new deterministic regression test. - dashboard editor: importance slider step 0.05 -> 0.025 for finer memory weighting; asserted in test_dashboard_v2. - ledger.js: galaxy engine selection now requires the scene to be within GRAPH_INITIAL_NODE_LIMIT/EDGE_LIMIT before engaging full physics; oversized complete scenes fall back to the lightweight Every renderer. Folded into main's transactional candidate pipeline (scene-marker keyed detection kept; the stale pre-refactor graphIsGalaxy() condition dropped).
1 parent 68dcc3a commit ecb3b01

5 files changed

Lines changed: 37 additions & 5 deletions

File tree

engraphis/core/context.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ def pack(
115115
excerpt = ""
116116
truncated = False
117117
reason = ""
118-
if self._count(base) < budget:
119-
available = budget - self._count(base)
118+
available = max(0, budget - self._count(base))
119+
if available:
120120
excerpt, truncated, reason = self._excerpt(
121121
query, candidate, available
122122
)

engraphis/dashboard_assets/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ <h2 id="memory-detail-title">Choose a memory</h2>
221221
<label>Type<select id="editor-memory-type"><option>working</option><option>episodic</option><option selected>semantic</option><option>procedural</option></select></label>
222222
<label>Content<textarea id="editor-memory-content" rows="12" maxlength="10000" required placeholder="A discrete, durable fact or procedure…"></textarea></label>
223223
<p id="editor-error" class="form-error" role="alert" hidden></p>
224-
<label for="editor-memory-importance">Importance<input id="editor-memory-importance" type="range" min="0" max="1" step="0.05" value="0.5" aria-label="Memory importance"></label>
224+
<label for="editor-memory-importance">Importance<input id="editor-memory-importance" type="range" min="0" max="1" step="0.025" value="0.5" aria-label="Memory importance"></label>
225225
<div class="form-actions">
226226
<button id="editor-cancel" class="secondary-button" type="button">Cancel</button>
227227
<button class="primary-button" type="submit">Save memory</button>

engraphis/dashboard_assets/ledger.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3388,8 +3388,12 @@
33883388
oldHost.insertAdjacentElement('afterend', candidateHost);
33893389
/* Authored-Galaxy detection must key off scene markers, not the toolbar preset:
33903390
entering Every via its chip sets the preset to 'every', but a complete scene
3391-
with system anchors still needs the hierarchical orbit engine and overlay. */
3392-
const galaxyQuality = fullGraph
3391+
with system anchors still needs the hierarchical orbit engine and overlay.
3392+
The live-limit guard keeps very large complete scenes on the lightweight
3393+
Every renderer instead of the full physics galaxy. */
3394+
const galaxyWithinLiveLimit = data.nodes.length <= GRAPH_INITIAL_NODE_LIMIT
3395+
&& data.links.length <= GRAPH_INITIAL_EDGE_LIMIT;
3396+
const galaxyQuality = fullGraph && galaxyWithinLiveLimit
33933397
&& data.nodes.some(node => node.anchor_role === 'community'
33943398
&& (node.system_anchor_id !== undefined
33953399
|| Number.isFinite(Number(node.galactic_radius))));

tests/test_context_packing.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,32 @@ def test_nonduplicate_title_remains_in_the_citation_header() -> None:
147147
assert chunks[0].excerpt == "Deploy only after signed checks."
148148

149149

150+
def test_compact_header_respects_nonadditive_counter_budget() -> None:
151+
class HeaderOverheadCounter:
152+
identity = "test.header-overhead"
153+
154+
def __call__(self, text: str) -> int:
155+
count = len(text.split())
156+
if text.startswith("[1]") and len(text) > 4:
157+
count += 3 if text.splitlines()[0] != "[1]" else (
158+
1 if text == "[1]\nAlpha rest" else 0
159+
)
160+
return count
161+
162+
packer = DeterministicContextPacker(HeaderOverheadCounter())
163+
candidate = _candidate(
164+
"mem_compact_header",
165+
"Alpha rest",
166+
title="Alpha",
167+
)
168+
169+
context, chunks, usage = packer.pack("alpha", [candidate], token_budget=3)
170+
171+
assert context.startswith("[1]\nAlpha")
172+
assert chunks[0].excerpt.startswith("Alpha")
173+
assert usage.context_tokens <= usage.budget_tokens == 3
174+
175+
150176
def test_sentence_excerpt_marks_omission_and_preserves_qualifying_evidence() -> None:
151177
packer = DeterministicContextPacker()
152178
candidate = _candidate(

tests/test_dashboard_v2.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,7 @@ def test_graph_motion_saved_views_and_tuning_controls_are_wired(monkeypatch, tmp
914914
assert behavior in script.text
915915
assert "syncGraphSpacetimeTuning(" in script.text
916916
assert "state.graphSpacetimeOverlay.setEnabled(graphIsGalaxy())" in script.text
917+
assert 'id="editor-memory-importance" type="range" min="0" max="1" step="0.025"' in page.text
917918

918919

919920
def test_code_overlay_scopes_only_to_known_repositories(monkeypatch, tmp_path):
@@ -940,6 +941,7 @@ def test_all_nodes_mode_preserves_scope_preferences_and_bounds_heavy_work(monkey
940941
assert "if (loadAll) {" in script.text
941942
assert "return Promise.all([ensureGraphAllAsset(), ensureGraphAssets(false)]);" in script.text
942943
assert "const graphFactory = galaxyQuality ? window.EngraphisGraph" in script.text
944+
assert "const galaxyWithinLiveLimit = data.nodes.length <= GRAPH_INITIAL_NODE_LIMIT" in script.text
943945
assert "scopeControl.disabled = full" not in script.text
944946
assert "graph.setCollapse(byId('graph-collapse').checked ? 'auto' : false)" in script.text
945947
assert "const includeCode = targetIncludeCode ? '&include_code=true' : '';" in script.text

0 commit comments

Comments
 (0)