fix(reliability): engram write
This commit is contained in:
+4
-1
@@ -23,11 +23,14 @@ fn ise_post(content: String) -> Void {
|
|||||||
let ise_url: String = env("SOUL_ISE_URL")
|
let ise_url: String = env("SOUL_ISE_URL")
|
||||||
let engram_url: String = if str_eq(ise_url, "") { state_get("soul_engram_url") } else { ise_url }
|
let engram_url: String = if str_eq(ise_url, "") { state_get("soul_engram_url") } else { ise_url }
|
||||||
if str_eq(engram_url, "") {
|
if str_eq(engram_url, "") {
|
||||||
let discard: String = engram_node_full(
|
let local_id: String = engram_node_full(
|
||||||
content, "InternalStateEvent", "state-event",
|
content, "InternalStateEvent", "state-event",
|
||||||
el_from_float(0.3), el_from_float(0.3), el_from_float(0.8),
|
el_from_float(0.3), el_from_float(0.3), el_from_float(0.8),
|
||||||
"Episodic", "[\"internal-state\",\"InternalStateEvent\"]"
|
"Episodic", "[\"internal-state\",\"InternalStateEvent\"]"
|
||||||
)
|
)
|
||||||
|
if str_eq(local_id, "") {
|
||||||
|
println("[awareness] ise_post: local engram_node_full failed — ISE lost")
|
||||||
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
// Proper JSON string escaping: backslashes first, then quotes, then control chars.
|
// Proper JSON string escaping: backslashes first, then quotes, then control chars.
|
||||||
|
|||||||
@@ -1072,7 +1072,7 @@ fn handle_chat_agentic(body: String) -> String {
|
|||||||
let session_valid: Bool = if str_eq(req_session, "") {
|
let session_valid: Bool = if str_eq(req_session, "") {
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
session_exists(req_session)
|
!str_contains(session_get(req_session), "\"error\"")
|
||||||
}
|
}
|
||||||
if !session_valid {
|
if !session_valid {
|
||||||
return "{\"error\":\"session not found\",\"session_id\":\"" + req_session + "\",\"reply\":\"\"}"
|
return "{\"error\":\"session not found\",\"session_id\":\"" + req_session + "\",\"reply\":\"\"}"
|
||||||
@@ -1699,6 +1699,8 @@ fn auto_persist(req: String, resp: String) -> Void {
|
|||||||
"session_bell_signal:" + sess_id
|
"session_bell_signal:" + sess_id
|
||||||
}
|
}
|
||||||
state_set(signal_key, safe_summary)
|
state_set(signal_key, safe_summary)
|
||||||
|
if str_eq(conv_node_id, "") {
|
||||||
|
println("[chat] auto_persist: engram_node_full returned empty — conversation node lost (ts=" + ts_str + ")")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,10 @@ fn mem_consolidate() -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn mem_save(path: String) -> Void {
|
fn mem_save(path: String) -> Void {
|
||||||
engram_save(path)
|
let save_result: String = engram_save(path)
|
||||||
|
if str_eq(save_result, "") {
|
||||||
|
println("[memory] mem_save: engram_save failed for " + path + " — snapshot may be incomplete")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mem_load(path: String) -> Void {
|
fn mem_load(path: String) -> Void {
|
||||||
@@ -76,11 +79,14 @@ fn mem_boot_count_inc() -> Int {
|
|||||||
let next: Int = current + 1
|
let next: Int = current + 1
|
||||||
let content: String = "soul:boot_count:" + int_to_str(next)
|
let content: String = "soul:boot_count:" + int_to_str(next)
|
||||||
let tags: String = "[\"soul-meta\",\"boot-counter\"]"
|
let tags: String = "[\"soul-meta\",\"boot-counter\"]"
|
||||||
let discard: String = engram_node_full(
|
let boot_node_id: String = engram_node_full(
|
||||||
content, "Memory", "soul:boot_count",
|
content, "Memory", "soul:boot_count",
|
||||||
el_from_float(0.9), el_from_float(0.9), el_from_float(1.0),
|
el_from_float(0.9), el_from_float(0.9), el_from_float(1.0),
|
||||||
"Canonical", tags
|
"Canonical", tags
|
||||||
)
|
)
|
||||||
|
if str_eq(boot_node_id, "") {
|
||||||
|
println("[memory] mem_boot_count_inc: engram write failed — boot counter node lost (count=" + int_to_str(next) + ")")
|
||||||
|
}
|
||||||
return next
|
return next
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+10
-2
@@ -400,6 +400,7 @@ fn handle_api_log_state_event(body: String) -> String {
|
|||||||
let id: String = engram_node_full(parts, "InternalStateEvent", "state-event:manual",
|
let id: String = engram_node_full(parts, "InternalStateEvent", "state-event:manual",
|
||||||
el_from_float(0.85), el_from_float(0.85), el_from_float(0.9),
|
el_from_float(0.85), el_from_float(0.85), el_from_float(0.9),
|
||||||
"Episodic", tags)
|
"Episodic", tags)
|
||||||
|
if !api_persisted(id) { return api_not_persisted(id) }
|
||||||
return "{\"ok\":true,\"id\":\"" + id + "\",\"boot\":\"" + boot + "\"}"
|
return "{\"ok\":true,\"id\":\"" + id + "\",\"boot\":\"" + boot + "\"}"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -452,6 +453,7 @@ fn handle_api_tune_config(body: String) -> String {
|
|||||||
let id: String = engram_node_full(content, "ConfigEntry", key,
|
let id: String = engram_node_full(content, "ConfigEntry", key,
|
||||||
el_from_float(0.85), el_from_float(0.85), el_from_float(0.9),
|
el_from_float(0.85), el_from_float(0.85), el_from_float(0.9),
|
||||||
"Canonical", tags)
|
"Canonical", tags)
|
||||||
|
if !api_persisted(id) { return api_not_persisted(id) }
|
||||||
return "{\"ok\":true,\"key\":\"" + key + "\",\"value\":\"" + value + "\",\"id\":\"" + id + "\"}"
|
return "{\"ok\":true,\"key\":\"" + key + "\",\"value\":\"" + value + "\",\"id\":\"" + id + "\"}"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -651,17 +653,23 @@ fn handle_api_consolidate(body: String) -> String {
|
|||||||
let summary: String = json_get(body, "summary")
|
let summary: String = json_get(body, "summary")
|
||||||
let snap: String = state_get("soul_snapshot_path")
|
let snap: String = state_get("soul_snapshot_path")
|
||||||
if !str_eq(snap, "") {
|
if !str_eq(snap, "") {
|
||||||
engram_save(snap)
|
let save_result: String = engram_save(snap)
|
||||||
|
if str_eq(save_result, "") {
|
||||||
|
println("[api] consolidate: engram_save failed for " + snap + " — snapshot may be out of sync")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if !str_eq(summary, "") {
|
if !str_eq(summary, "") {
|
||||||
let safe_summary: String = str_replace(summary, "\"", "'")
|
let safe_summary: String = str_replace(summary, "\"", "'")
|
||||||
let tags: String = "[\"SessionSummary\",\"consolidate\"]"
|
let tags: String = "[\"SessionSummary\",\"consolidate\"]"
|
||||||
let discard: String = engram_node_full(
|
let summary_id: String = engram_node_full(
|
||||||
"[session-summary] " + safe_summary,
|
"[session-summary] " + safe_summary,
|
||||||
"SessionSummary", "session:summary",
|
"SessionSummary", "session:summary",
|
||||||
el_from_float(0.7), el_from_float(0.7), el_from_float(0.9),
|
el_from_float(0.7), el_from_float(0.7), el_from_float(0.9),
|
||||||
"Episodic", tags
|
"Episodic", tags
|
||||||
)
|
)
|
||||||
|
if str_eq(summary_id, "") {
|
||||||
|
println("[api] consolidate: session summary engram write failed — summary node lost")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return "{\"ok\":true,\"snapshot\":\"" + snap + "\"}"
|
return "{\"ok\":true,\"snapshot\":\"" + snap + "\"}"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -241,8 +241,13 @@ fn seed_persona_from_env() -> Void {
|
|||||||
let h: Map = {}
|
let h: Map = {}
|
||||||
map_set(h, "Content-Type", "application/json")
|
map_set(h, "Content-Type", "application/json")
|
||||||
let resp: String = http_post_with_headers(engram_url + "/api/nodes", body, h)
|
let resp: String = http_post_with_headers(engram_url + "/api/nodes", body, h)
|
||||||
if str_contains(resp, "\"error\"") {
|
// Check for empty response (timeout/network error), explicit error, or missing id.
|
||||||
|
if str_eq(resp, "") {
|
||||||
|
println("[soul] persona HTTP write-back failed: empty response (timeout or network error) — in-memory only this session")
|
||||||
|
} else if str_contains(resp, "\"error\"") {
|
||||||
println("[soul] persona HTTP write-back failed (in-memory only this session): " + resp)
|
println("[soul] persona HTTP write-back failed (in-memory only this session): " + resp)
|
||||||
|
} else if !str_contains(resp, "\"id\"") {
|
||||||
|
println("[soul] persona HTTP write-back: unexpected response (no id field) — in-memory only this session: " + resp)
|
||||||
} else {
|
} else {
|
||||||
println("[soul] persona persisted to HTTP engram at " + engram_url)
|
println("[soul] persona persisted to HTTP engram at " + engram_url)
|
||||||
}
|
}
|
||||||
@@ -275,11 +280,14 @@ fn emit_session_start_event() -> Void {
|
|||||||
+ ",\"ts\":" + int_to_str(ts) + "}"
|
+ ",\"ts\":" + int_to_str(ts) + "}"
|
||||||
|
|
||||||
let tags: String = "[\"internal-state\",\"session-start\",\"InternalStateEvent\"]"
|
let tags: String = "[\"internal-state\",\"session-start\",\"InternalStateEvent\"]"
|
||||||
let discard: String = engram_node_full(
|
let session_event_id: String = engram_node_full(
|
||||||
payload, "InternalStateEvent", "session-start",
|
payload, "InternalStateEvent", "session-start",
|
||||||
el_from_float(0.9), el_from_float(0.9), el_from_float(1.0),
|
el_from_float(0.9), el_from_float(0.9), el_from_float(1.0),
|
||||||
"Episodic", tags
|
"Episodic", tags
|
||||||
)
|
)
|
||||||
|
if str_eq(session_event_id, "") {
|
||||||
|
println("[soul] emit_session_start_event: engram write failed — session-start event lost")
|
||||||
|
}
|
||||||
println("[soul] session-start event logged (boot=" + boot_num + " nodes=" + int_to_str(node_ct) + " edges=" + int_to_str(edge_ct) + ")")
|
println("[soul] session-start event logged (boot=" + boot_num + " nodes=" + int_to_str(node_ct) + " edges=" + int_to_str(edge_ct) + ")")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user