self-review 2026-05-17: fix heartbeat JSON validity for unset state keys
state_get() returns "" for unset keys. Both soul.pulse and soul_boot_count
could be empty on first heartbeat cycle, producing invalid JSON like
{"event":"heartbeat","pulse":,"boot":,...}. Add defensive guards:
if str_eq(raw, "") { "0" } else { raw } for both fields.
This commit is contained in:
+6
-2
@@ -62,8 +62,12 @@ fn elapsed_human() -> String {
|
||||
}
|
||||
|
||||
fn emit_heartbeat() -> Void {
|
||||
let pulse: String = state_get("soul.pulse")
|
||||
let boot: String = state_get("soul_boot_count")
|
||||
// Guard against empty state values producing invalid JSON (e.g. "pulse":,).
|
||||
// state_get returns "" for unset keys; default to "0" for numeric fields.
|
||||
let pulse_raw: String = state_get("soul.pulse")
|
||||
let pulse: String = if str_eq(pulse_raw, "") { "0" } else { pulse_raw }
|
||||
let boot_raw: String = state_get("soul_boot_count")
|
||||
let boot: String = if str_eq(boot_raw, "") { "0" } else { boot_raw }
|
||||
let idle: String = int_to_str(idle_count())
|
||||
let ts: Int = time_now()
|
||||
let nc: Int = engram_node_count()
|
||||
|
||||
Reference in New Issue
Block a user