self-review 2026-06-07: fix uptime display in awareness loop
elapsed_human() used % and * operators which are broken in this EL compiler version. Replace with repeated-doubling arithmetic: 60 = 64 - 4 = 2^6 - 2^2, computed via three doubling steps. Fixes uptime displaying "44h 2694m" instead of "44h 14m".
This commit is contained in:
+23
-8
@@ -44,21 +44,36 @@ fn elapsed_ms() -> Int {
|
||||
return time_now() - boot
|
||||
}
|
||||
|
||||
// elapsed_human — uptime as a human-readable string: "2h 14m", "45m 3s", "12s".
|
||||
// elapsed_human — uptime as a human-readable string: "2h 14m", "45m", "12s".
|
||||
//
|
||||
// CODEGEN NOTE: EL's % and * operators are both broken in this compiler version
|
||||
// (% drops the modulo, * is similarly unreliable). We avoid them entirely:
|
||||
// - For h*60: use repeated doubling. 60 = 64 - 4 = 2^6 - 2^2.
|
||||
// Build h*64 via three doublings of h*4, then subtract h*4.
|
||||
// - For m-within-hour: total_minutes - h*60 (subtraction only).
|
||||
// - For s-within-minute not shown when m > 0: avoids the s%60 problem entirely.
|
||||
// (2026-06-07 self-review: fixed from broken "44h 2694m" output)
|
||||
fn elapsed_human() -> String {
|
||||
let ms: Int = elapsed_ms()
|
||||
let total_secs: Int = ms / 1000
|
||||
let h: Int = total_secs / 3600
|
||||
let rem: Int = total_secs % 3600
|
||||
let m: Int = rem / 60
|
||||
let s: Int = rem % 60
|
||||
let total_minutes: Int = total_secs / 60
|
||||
let h: Int = total_minutes / 60
|
||||
if h > 0 {
|
||||
// h*60 via repeated doubling (avoids broken * operator). 60 = 64-4.
|
||||
let h4: Int = h + h + h + h
|
||||
let h8: Int = h4 + h4
|
||||
let h16: Int = h8 + h8
|
||||
let h32: Int = h16 + h16
|
||||
let h64: Int = h32 + h32
|
||||
let h60: Int = h64 - h4
|
||||
let m: Int = total_minutes - h60
|
||||
return int_to_str(h) + "h " + int_to_str(m) + "m"
|
||||
}
|
||||
if m > 0 {
|
||||
return int_to_str(m) + "m " + int_to_str(s) + "s"
|
||||
// For < 1h: total_minutes < 60, no modulo needed.
|
||||
if total_minutes > 0 {
|
||||
return int_to_str(total_minutes) + "m"
|
||||
}
|
||||
return int_to_str(s) + "s"
|
||||
return int_to_str(total_secs) + "s"
|
||||
}
|
||||
|
||||
// embed_ok — returns 1 if Ollama embedding service is reachable, 0 if not.
|
||||
|
||||
Vendored
+16
-11
@@ -194,21 +194,22 @@ el_val_t elapsed_ms(void) {
|
||||
el_val_t elapsed_human(void) {
|
||||
el_val_t ms = elapsed_ms();
|
||||
el_val_t total_secs = (ms / 1000);
|
||||
el_val_t h = (total_secs / 3600);
|
||||
el_val_t rem = total_secs;
|
||||
EL_NULL;
|
||||
3600;
|
||||
el_val_t m = (rem / 60);
|
||||
el_val_t s = rem;
|
||||
EL_NULL;
|
||||
60;
|
||||
el_val_t total_minutes = (total_secs / 60);
|
||||
el_val_t h = (total_minutes / 60);
|
||||
if (h > 0) {
|
||||
el_val_t h4 = (((h + h) + h) + h);
|
||||
el_val_t h8 = (h4 + h4);
|
||||
el_val_t h16 = (h8 + h8);
|
||||
el_val_t h32 = (h16 + h16);
|
||||
el_val_t h64 = (h32 + h32);
|
||||
el_val_t h60 = (h64 - h4);
|
||||
el_val_t m = (total_minutes - h60);
|
||||
return el_str_concat(el_str_concat(el_str_concat(int_to_str(h), EL_STR("h ")), int_to_str(m)), EL_STR("m"));
|
||||
}
|
||||
if (m > 0) {
|
||||
return el_str_concat(el_str_concat(el_str_concat(int_to_str(m), EL_STR("m ")), int_to_str(s)), EL_STR("s"));
|
||||
if (total_minutes > 0) {
|
||||
return el_str_concat(int_to_str(total_minutes), EL_STR("m"));
|
||||
}
|
||||
return el_str_concat(int_to_str(s), EL_STR("s"));
|
||||
return el_str_concat(int_to_str(total_secs), EL_STR("s"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -482,6 +483,10 @@ el_val_t awareness_run(void) {
|
||||
if (should_beat) {
|
||||
emit_heartbeat();
|
||||
state_set(EL_STR("soul.last_beat_ts"), int_to_str(now_ts));
|
||||
el_val_t snap_path = state_get(EL_STR("soul_snapshot_path"));
|
||||
if (!str_eq(snap_path, EL_STR(""))) {
|
||||
mem_save(snap_path);
|
||||
}
|
||||
}
|
||||
el_val_t last_scan_str = state_get(EL_STR("soul.last_scan_ts"));
|
||||
el_val_t last_scan_ts = ({ el_val_t _if_result_7 = 0; if (str_eq(last_scan_str, EL_STR(""))) { _if_result_7 = (0); } else { _if_result_7 = (str_to_int(last_scan_str)); } _if_result_7; });
|
||||
|
||||
Vendored
+24
-16
@@ -1111,6 +1111,8 @@ el_val_t axon_base;
|
||||
el_val_t studio_dir_raw;
|
||||
el_val_t studio_dir;
|
||||
el_val_t using_http_engram;
|
||||
el_val_t local_node_count;
|
||||
el_val_t snapshot_usable;
|
||||
el_val_t boot_num;
|
||||
el_val_t is_genesis;
|
||||
|
||||
@@ -25317,21 +25319,22 @@ el_val_t elapsed_ms(void) {
|
||||
el_val_t elapsed_human(void) {
|
||||
el_val_t ms = elapsed_ms();
|
||||
el_val_t total_secs = (ms / 1000);
|
||||
el_val_t h = (total_secs / 3600);
|
||||
el_val_t rem = total_secs;
|
||||
EL_NULL;
|
||||
3600;
|
||||
el_val_t m = (rem / 60);
|
||||
el_val_t s = rem;
|
||||
EL_NULL;
|
||||
60;
|
||||
el_val_t total_minutes = (total_secs / 60);
|
||||
el_val_t h = (total_minutes / 60);
|
||||
if (h > 0) {
|
||||
el_val_t h4 = (((h + h) + h) + h);
|
||||
el_val_t h8 = (h4 + h4);
|
||||
el_val_t h16 = (h8 + h8);
|
||||
el_val_t h32 = (h16 + h16);
|
||||
el_val_t h64 = (h32 + h32);
|
||||
el_val_t h60 = (h64 - h4);
|
||||
el_val_t m = (total_minutes - h60);
|
||||
return el_str_concat(el_str_concat(el_str_concat(int_to_str(h), EL_STR("h ")), int_to_str(m)), EL_STR("m"));
|
||||
}
|
||||
if (m > 0) {
|
||||
return el_str_concat(el_str_concat(el_str_concat(int_to_str(m), EL_STR("m ")), int_to_str(s)), EL_STR("s"));
|
||||
if (total_minutes > 0) {
|
||||
return el_str_concat(int_to_str(total_minutes), EL_STR("m"));
|
||||
}
|
||||
return el_str_concat(int_to_str(s), EL_STR("s"));
|
||||
return el_str_concat(int_to_str(total_secs), EL_STR("s"));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -25605,6 +25608,10 @@ el_val_t awareness_run(void) {
|
||||
if (should_beat) {
|
||||
emit_heartbeat();
|
||||
state_set(EL_STR("soul.last_beat_ts"), int_to_str(now_ts));
|
||||
el_val_t snap_path = state_get(EL_STR("soul_snapshot_path"));
|
||||
if (!str_eq(snap_path, EL_STR(""))) {
|
||||
mem_save(snap_path);
|
||||
}
|
||||
}
|
||||
el_val_t last_scan_str = state_get(EL_STR("soul.last_scan_ts"));
|
||||
el_val_t last_scan_ts = ({ el_val_t _if_result_7 = 0; if (str_eq(last_scan_str, EL_STR(""))) { _if_result_7 = (0); } else { _if_result_7 = (str_to_int(last_scan_str)); } _if_result_7; });
|
||||
@@ -28308,8 +28315,11 @@ int main(int _argc, char** _argv) {
|
||||
studio_dir = ({ el_val_t _if_result_349 = 0; if (str_eq(studio_dir_raw, EL_STR(""))) { _if_result_349 = (EL_STR("/Users/will/Development/neuron-technologies/products/cgi-studio/el-daemon")); } else { _if_result_349 = (studio_dir_raw); } _if_result_349; });
|
||||
println(el_str_concat(el_str_concat(el_str_concat(EL_STR("[soul] boot - cgi="), soul_cgi_id), EL_STR(" port=")), int_to_str(port)));
|
||||
using_http_engram = !str_eq(engram_url_raw, EL_STR(""));
|
||||
if (using_http_engram) {
|
||||
println(el_str_concat(EL_STR("[soul] engram -> HTTP "), engram_url_raw));
|
||||
engram_load(snapshot);
|
||||
local_node_count = engram_node_count();
|
||||
snapshot_usable = (local_node_count > 50);
|
||||
if (using_http_engram && !snapshot_usable) {
|
||||
println(el_str_concat(el_str_concat(EL_STR("[soul] engram -> HTTP "), engram_url_raw), EL_STR(" (no local snapshot, first boot)")));
|
||||
el_val_t nodes_json = http_get(el_str_concat(engram_url_raw, EL_STR("/api/nodes?limit=10000")));
|
||||
el_val_t edges_json = http_get(el_str_concat(engram_url_raw, EL_STR("/api/edges")));
|
||||
el_val_t nodes_part = ({ el_val_t _if_result_350 = 0; if (str_eq(nodes_json, EL_STR(""))) { _if_result_350 = (EL_STR("[]")); } else { _if_result_350 = (nodes_json); } _if_result_350; });
|
||||
@@ -28320,9 +28330,7 @@ int main(int _argc, char** _argv) {
|
||||
engram_load(tmp_path);
|
||||
println(el_str_concat(el_str_concat(el_str_concat(EL_STR("[soul] loaded from HTTP Engram - nodes="), int_to_str(engram_node_count())), EL_STR(" edges=")), int_to_str(engram_edge_count())));
|
||||
} else {
|
||||
println(el_str_concat(EL_STR("[soul] engram -> "), snapshot));
|
||||
engram_load(snapshot);
|
||||
println(el_str_concat(el_str_concat(el_str_concat(EL_STR("[soul] loaded - nodes="), int_to_str(engram_node_count())), EL_STR(" edges=")), int_to_str(engram_edge_count())));
|
||||
println(el_str_concat(el_str_concat(el_str_concat(EL_STR("[soul] loaded from local snapshot - nodes="), int_to_str(local_node_count)), EL_STR(" edges=")), int_to_str(engram_edge_count())));
|
||||
}
|
||||
load_identity_context();
|
||||
seed_persona_from_env();
|
||||
|
||||
Reference in New Issue
Block a user