fix(sessions): extract session_search_entry to fix ELC OOM in session_search

The while loop in session_search had too many let bindings in scope;
the ELC compiler's exponential rebinding accumulation caused OOM and
truncation of dist/sessions.c since June 30. Moving the per-node logic
into session_search_entry gives the compiler a clean scope boundary per
call, restoring O(N) compile behaviour.
This commit is contained in:
2026-07-01 11:25:45 -05:00
parent 1496a5f510
commit 9d266aac4c
2 changed files with 52 additions and 30 deletions
Generated Vendored
+25 -14
View File
@@ -61,6 +61,7 @@ el_val_t resolve_in_root(el_val_t path, el_val_t root);
el_val_t dispatch_tool(el_val_t tool_name, el_val_t tool_input);
el_val_t is_builtin_tool(el_val_t tool_name);
el_val_t next_bridge_id(void);
el_val_t handle_chat_plan(el_val_t body);
el_val_t handle_chat_agentic(el_val_t body);
el_val_t agentic_loop(el_val_t session_id, el_val_t model, el_val_t safe_sys, el_val_t tools_json, el_val_t messages_in, el_val_t h, el_val_t tools_log_in);
el_val_t bridge_save(el_val_t session_id, el_val_t model, el_val_t safe_sys, el_val_t tools_json, el_val_t messages, el_val_t tools_log, el_val_t tool_use_id);
@@ -83,6 +84,7 @@ el_val_t session_list(void);
el_val_t session_get(el_val_t session_id);
el_val_t session_delete(el_val_t session_id);
el_val_t session_update_patch(el_val_t session_id, el_val_t body);
el_val_t session_search_entry(el_val_t node);
el_val_t session_search(el_val_t query);
el_val_t session_hist_load(el_val_t session_id);
el_val_t session_hist_save(el_val_t session_id, el_val_t hist);
@@ -337,6 +339,28 @@ el_val_t session_update_patch(el_val_t session_id, el_val_t body) {
return 0;
}
el_val_t session_search_entry(el_val_t node) {
el_val_t label = json_get(node, EL_STR("label"));
if (!str_eq(label, EL_STR("session:meta"))) {
return EL_STR("");
}
el_val_t content = json_get(node, EL_STR("content"));
el_val_t sess_id = json_get(content, EL_STR("id"));
if (str_eq(sess_id, EL_STR(""))) {
return EL_STR("");
}
el_val_t title = json_get(content, EL_STR("title"));
el_val_t created_raw = json_get(content, EL_STR("created_at"));
el_val_t updated_raw = json_get(content, EL_STR("updated_at"));
el_val_t eff_created = ({ el_val_t _if_result_33 = 0; if (str_eq(created_raw, EL_STR(""))) { _if_result_33 = (EL_STR("0")); } else { _if_result_33 = (created_raw); } _if_result_33; });
el_val_t eff_updated = ({ el_val_t _if_result_34 = 0; if (str_eq(updated_raw, EL_STR(""))) { _if_result_34 = (eff_created); } else { _if_result_34 = (updated_raw); } _if_result_34; });
el_val_t e_id = el_str_concat(el_str_concat(EL_STR("{\"id\":\""), json_safe(sess_id)), EL_STR("\""));
el_val_t e_title = el_str_concat(el_str_concat(EL_STR(",\"title\":\""), json_safe(title)), EL_STR("\""));
el_val_t e_ts = el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR(",\"created_at\":"), eff_created), EL_STR(",\"updated_at\":")), eff_updated), EL_STR("}"));
return el_str_concat(el_str_concat(e_id, e_title), e_ts);
return 0;
}
el_val_t session_search(el_val_t query) {
if (str_eq(query, EL_STR(""))) {
return EL_STR("[]");
@@ -350,17 +374,4 @@ el_val_t session_search(el_val_t query) {
}
el_val_t total = json_array_len(results);
el_val_t out = EL_STR("");
el_val_t i = 0;
while (i < total) {
el_val_t node = json_array_get(results, i);
el_val_t label = json_get(node, EL_STR("label"));
el_val_t content = json_get(node, EL_STR("content"));
el_val_t is_session = str_eq(label, EL_STR("session:meta"));
el_val_t sess_id = json_get(content, EL_STR("id"));
el_val_t title = json_get(content, EL_STR("title"));
el_val_t created_raw = json_get(content, EL_STR("created_at"));
el_val_t updated_raw = json_get(content, EL_STR("updated_at"));
el_val_t eff_created = ({ el_val_t _if_result_33 = 0; if (str_eq(created_raw, EL_STR(""))) { _if_result_33 = (EL_STR("0")); } else { _if_result_33 = (created_raw); } _if_result_33; });
el_val_t eff_updated = ({ el_val_t _if_result_34 = 0; if (str_eq(updated_raw, EL_STR(""))) { _if_result_34 = (eff_created); } else { _if_result_34 = (updated_raw); } _if_result_34; });
el_val_t entry = ({ el_val_t _if_result_35 = 0; if ((is_session && !str_eq(sess_id, EL_STR("")))) { _if_result_35 = (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("{\"id\":\""), json_safe(sess_id)), EL_STR("\"")), EL_STR(",\"title\":\"")), json_safe(title)), EL_STR("\"")), EL_STR(",\"created_at\":")), eff_created), EL_STR(",\"updated_at\":")), eff_updated), EL_STR("}"))); } else { _if_result_35 = (EL_STR("")); } _if_result_35; });
out = ({ el_val_t _if_result_36 = 0; i
el_val_t i = 0;