Fix five latent bugs from temporal-precision code review
1. parse_salience_100: handle 3+ decimal digit salience strings correctly.
The two-branch 'else { stripped }' case treated any N-digit decimal value
as hundredths, so "0.125" (stripped=125) clamped to 100 instead of 12.
Now divides by 10^(N-2) for N>2, mapping "0.125"->12, "0.375"->37, etc.
2. mem_consolidate Canonical scan: replaced single engram_scan_nodes_json(50,0)
call with a paginated loop (page_size=50, advancing offset) so Canonical nodes
beyond index 50 are no longer silently excluded from the periodic boost.
3. mem_consolidate Canonical strengthening: add salience ceiling guard so nodes
already at the runtime maximum (serialised as "1" by %g) are skipped. Prevents
monotonic unbounded salience growth across successive consolidation passes.
4. soul.el affective cutoff: replaced json_get(aff_node, "ts") with
json_get(aff_node, "created_at") / "updated_at" fallback, consistent with
handle_chat. The old "ts" field is not a standard engram node field; missing
it caused the fallback to ts_now (always passes cutoff), over-including stale
nodes. New behaviour defaults to 0 on missing timestamps (conservative exclude).
5. History byte-cap: implemented the existing TODO 32KB byte-cap. Added
hist_trim_to_byte_cap() and applied it after count-based trim in both
handle_chat and handle_chat_agentic. Prevents 100KB+ state entries at 40 turns
during long technical sessions with large assistant responses.
This commit is contained in:
@@ -73,20 +73,49 @@ fn mem_consolidate() -> String {
|
||||
let wi = wi + 1
|
||||
}
|
||||
|
||||
// (b) Strengthen Canonical-tier nodes from a scan so they resist temporal decay.
|
||||
// Canonical nodes encode foundational identity — they must not silently floor at 10.
|
||||
let scan_result: String = engram_scan_nodes_json(50, 0)
|
||||
let scan_len: Int = json_array_len(scan_result)
|
||||
let si: Int = 0
|
||||
while si < scan_len {
|
||||
let s_node: String = json_array_get(scan_result, si)
|
||||
let s_tier: String = json_get(s_node, "tier")
|
||||
let s_id: String = json_get(s_node, "id")
|
||||
if str_eq(s_tier, "Canonical") && !str_eq(s_id, "") {
|
||||
engram_strengthen(s_id)
|
||||
let strengthened = strengthened + 1
|
||||
// (b) Strengthen Canonical-tier nodes from a full paginated scan so they resist
|
||||
// temporal decay. Canonical nodes encode foundational identity — they must not
|
||||
// silently floor at 10. Page size 50, scanning until fewer than 50 nodes are
|
||||
// returned (last page), so all Canonical nodes are reached even in large graphs.
|
||||
// Without pagination, only the first 50 nodes in the graph were eligible; any
|
||||
// Canonical node at index 50+ was silently excluded from the boost.
|
||||
// Strengthening is skipped if the node's current salience is already at the
|
||||
// runtime ceiling (represented as "1" by %g) to avoid monotonic unbounded growth.
|
||||
// Canonical nodes with salience < 1.0 are strengthened each consolidation pass;
|
||||
// once they reach the ceiling the runtime will no longer raise them further, so
|
||||
// calling engram_strengthen at the ceiling is a no-op in the runtime anyway, but
|
||||
// the explicit check makes the intent clear and avoids any runtime log noise.
|
||||
let page_size: Int = 50
|
||||
let scan_offset: Int = 0
|
||||
let scan_done: Bool = false
|
||||
while !scan_done {
|
||||
let scan_result: String = engram_scan_nodes_json(page_size, scan_offset)
|
||||
let scan_len: Int = json_array_len(scan_result)
|
||||
if scan_len == 0 {
|
||||
let scan_done = true
|
||||
} else {
|
||||
let si: Int = 0
|
||||
while si < scan_len {
|
||||
let s_node: String = json_array_get(scan_result, si)
|
||||
let s_tier: String = json_get(s_node, "tier")
|
||||
let s_id: String = json_get(s_node, "id")
|
||||
let s_sal: String = json_get(s_node, "salience")
|
||||
// Only strengthen if below the ceiling to prevent unbounded salience growth.
|
||||
// engram serialises the ceiling as "1" (%g drops the decimal part when it
|
||||
// is exactly zero). Any other value is below ceiling and should be boosted.
|
||||
let at_ceiling: Bool = str_eq(s_sal, "1")
|
||||
if str_eq(s_tier, "Canonical") && !str_eq(s_id, "") && !at_ceiling {
|
||||
engram_strengthen(s_id)
|
||||
let strengthened = strengthened + 1
|
||||
}
|
||||
let si = si + 1
|
||||
}
|
||||
let scan_offset = scan_offset + scan_len
|
||||
// Fewer results than page_size means we've reached the last page.
|
||||
if scan_len < page_size {
|
||||
let scan_done = true
|
||||
}
|
||||
}
|
||||
let si = si + 1
|
||||
}
|
||||
|
||||
let total_nodes: Int = engram_node_count()
|
||||
|
||||
Reference in New Issue
Block a user