fix(context-dedup): include scan_part and affective_part IDs in seen set
Two design bugs in the state_set placement caused the dedup seen-ID set
to be incomplete even with callsites wired up:
1. state_set("engram_compile_seen_ids") was called immediately after
merging the main node pools, before scan_part (persona fallback) and
affective_part (bell node) were computed. Nodes appearing only in
those segments were never added to the seen set.
2. affective_part is a bare JSON object (bn0 from json_array_get), not
a JSON array. Passing it to engram_extract_ids would have gotten
json_array_len == 0 and silently skipped the affective node's ID.
Fix: move state_set to after ctx is assembled from all three segments.
Extract ids_from_merged and ids_from_scan via engram_extract_ids (both
are JSON arrays), and extract ids_from_affective via json_get(affective_part, "id")
directly since it is a bare object. Merge all three via add_to_seen
before publishing to state.
This commit is contained in:
@@ -380,11 +380,6 @@ fn engram_compile(intent: String) -> String {
|
||||
let merged: String = engram_nodes_merge(merged, recall_boost)
|
||||
let merged_nodes: String = merged
|
||||
|
||||
// Dedup fix: publish seen node IDs so downstream callers (session_preload, affective_prefix)
|
||||
// can skip nodes already present here. EL has no tuple returns so we use state as out-param.
|
||||
let compile_seen_ids: String = engram_extract_ids(merged_nodes)
|
||||
state_set("engram_compile_seen_ids", compile_seen_ids)
|
||||
|
||||
// Fallback: when all searches return nothing, fetch persona nodes.
|
||||
let scan_part: String = if str_eq(merged_nodes, "") || str_eq(merged_nodes, "[]") {
|
||||
let persona_fallback: String = engram_search_json("soul:persona Persona identity", 5)
|
||||
@@ -424,6 +419,18 @@ fn engram_compile(intent: String) -> String {
|
||||
let sep_ma: String = if !str_eq(main_part, "") && !str_eq(affective_part, "") { "\n" } else { "" }
|
||||
let ctx: String = main_part + sep_ma + affective_part
|
||||
|
||||
// Dedup fix: publish seen node IDs so downstream callers (session_preload) can skip
|
||||
// nodes already present in the compiled context. Must be computed after scan_part and
|
||||
// affective_part are resolved so all three segments are represented in the seen set.
|
||||
// EL has no tuple returns so we use state as an out-param.
|
||||
// scan_part is a JSON array — extract with engram_extract_ids.
|
||||
// affective_part is a bare JSON object (bn0), not an array — extract its id directly.
|
||||
let ids_from_merged: String = engram_extract_ids(merged_nodes)
|
||||
let ids_from_scan: String = engram_extract_ids(scan_part)
|
||||
let ids_from_affective: String = json_get(affective_part, "id")
|
||||
let compile_seen_ids: String = add_to_seen(add_to_seen(ids_from_merged, ids_from_scan), ids_from_affective)
|
||||
state_set("engram_compile_seen_ids", compile_seen_ids)
|
||||
|
||||
if str_eq(ctx, "") { return "" }
|
||||
|
||||
// Issue 7 fix: safe JSON truncation — find last closing brace before budget cap.
|
||||
|
||||
Reference in New Issue
Block a user