self-review 2026-05-18: add embed_ok to heartbeat ISE

Ollama availability is a silent failure mode: when the embedding service
is down, semantic seed injection falls back to lexical-only activation with
no signal in the ISE stream. Add embed_ok field (0/1) to every heartbeat
by probing http://localhost:11434 — makes Ollama health visible without
a separate monitoring path.
This commit is contained in:
2026-05-18 08:41:07 -05:00
parent ffd17b2774
commit 2099522c28
4 changed files with 26 additions and 2 deletions
+13 -1
View File
@@ -61,6 +61,17 @@ fn elapsed_human() -> String {
return int_to_str(s) + "s"
}
// embed_ok returns 1 if Ollama embedding service is reachable, 0 if not.
// Probes http://localhost:11434 (Ollama root) with a GET; any non-empty
// response means the service is up. Used in heartbeat for observability:
// when embed_ok=0, semantic seed injection silently falls back to lexical-
// only activation and that gap should be visible in the ISE stream.
fn embed_ok() -> Int {
let resp: String = http_get("http://localhost:11434")
if str_eq(resp, "") { return 0 }
return 1
}
fn emit_heartbeat() -> Void {
// Guard against empty state values producing invalid JSON (e.g. "pulse":,).
// state_get returns "" for unset keys; default to "0" for numeric fields.
@@ -75,7 +86,8 @@ fn emit_heartbeat() -> Void {
let wmc: Int = engram_wm_count()
let up_ms: Int = elapsed_ms()
let up_human: String = elapsed_human()
let payload: String = "{\"event\":\"heartbeat\",\"pulse\":" + pulse + ",\"boot\":" + boot + ",\"idle\":" + idle + ",\"node_count\":" + int_to_str(nc) + ",\"edge_count\":" + int_to_str(ec) + ",\"wm_active\":" + int_to_str(wmc) + ",\"ts\":" + int_to_str(ts) + ",\"uptime_ms\":" + int_to_str(up_ms) + ",\"uptime\":\"" + up_human + "\"}"
let emb_ok: Int = embed_ok()
let payload: String = "{\"event\":\"heartbeat\",\"pulse\":" + pulse + ",\"boot\":" + boot + ",\"idle\":" + idle + ",\"node_count\":" + int_to_str(nc) + ",\"edge_count\":" + int_to_str(ec) + ",\"wm_active\":" + int_to_str(wmc) + ",\"ts\":" + int_to_str(ts) + ",\"uptime_ms\":" + int_to_str(up_ms) + ",\"uptime\":\"" + up_human + "\",\"embed_ok\":" + int_to_str(emb_ok) + "}"
ise_post(payload)
}
+12 -1
View File
@@ -23,6 +23,7 @@ el_val_t idle_reset(void);
el_val_t ise_post(el_val_t content);
el_val_t elapsed_ms(void);
el_val_t elapsed_human(void);
el_val_t embed_ok(void);
el_val_t emit_heartbeat(void);
el_val_t pulse_count(void);
el_val_t pulse_inc(void);
@@ -102,6 +103,15 @@ el_val_t elapsed_human(void) {
return 0;
}
el_val_t embed_ok(void) {
el_val_t resp = http_get(EL_STR("http://localhost:11434"));
if (str_eq(resp, EL_STR(""))) {
return 0;
}
return 1;
return 0;
}
el_val_t emit_heartbeat(void) {
el_val_t pulse_raw = state_get(EL_STR("soul.pulse"));
el_val_t pulse = ({ el_val_t _if_result_2 = 0; if (str_eq(pulse_raw, EL_STR(""))) { _if_result_2 = (EL_STR("0")); } else { _if_result_2 = (pulse_raw); } _if_result_2; });
@@ -114,7 +124,8 @@ el_val_t emit_heartbeat(void) {
el_val_t wmc = engram_wm_count();
el_val_t up_ms = elapsed_ms();
el_val_t up_human = elapsed_human();
el_val_t payload = el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"event\":\"heartbeat\",\"pulse\":"), pulse), EL_STR(",\"boot\":")), boot), EL_STR(",\"idle\":")), idle), EL_STR(",\"node_count\":")), int_to_str(nc)), EL_STR(",\"edge_count\":")), int_to_str(ec)), EL_STR(",\"wm_active\":")), int_to_str(wmc)), EL_STR(",\"ts\":")), int_to_str(ts)), EL_STR(",\"uptime_ms\":")), int_to_str(up_ms)), EL_STR(",\"uptime\":\"")), up_human), EL_STR("\"}"));
el_val_t emb_ok = embed_ok();
el_val_t payload = el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("{\"event\":\"heartbeat\",\"pulse\":"), pulse), EL_STR(",\"boot\":")), boot), EL_STR(",\"idle\":")), idle), EL_STR(",\"node_count\":")), int_to_str(nc)), EL_STR(",\"edge_count\":")), int_to_str(ec)), EL_STR(",\"wm_active\":")), int_to_str(wmc)), EL_STR(",\"ts\":")), int_to_str(ts)), EL_STR(",\"uptime_ms\":")), int_to_str(up_ms)), EL_STR(",\"uptime\":\"")), up_human), EL_STR("\",\"embed_ok\":")), int_to_str(emb_ok)), EL_STR("}"));
ise_post(payload);
return 0;
}
+1
View File
@@ -226,6 +226,7 @@ el_val_t elapsed_ms(void);
el_val_t elp_detect_predicate(el_val_t msg);
el_val_t elp_extract_topic(el_val_t msg);
el_val_t elp_parse(el_val_t msg);
el_val_t embed_ok(void);
el_val_t emit_heartbeat(void);
el_val_t emit_session_start_event(void);
el_val_t en_irregular_plural(el_val_t word);
Vendored
BIN
View File
Binary file not shown.