Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d008649c3e | |||
| aa70c5dde6 | |||
| ddd858d2ec | |||
| 996dd3860a | |||
| 6f4adf7640 |
@@ -214,23 +214,10 @@ jobs:
|
|||||||
cd /tmp/infra-update
|
cd /tmp/infra-update
|
||||||
|
|
||||||
DEPLOY_DIR="platform/k8s/neuron-mcp"
|
DEPLOY_DIR="platform/k8s/neuron-mcp"
|
||||||
python3 -c "
|
sed -i "s/^ replicas: .*/ replicas: 1/" "${DEPLOY_DIR}/deployment-${SLOT}.yaml"
|
||||||
import re, sys
|
sed -i "s/^ replicas: .*/ replicas: 0/" "${DEPLOY_DIR}/deployment-${IDLE}.yaml"
|
||||||
|
echo " deployment-${SLOT}.yaml: replicas set to 1"
|
||||||
slot = sys.argv[1]
|
echo " deployment-${IDLE}.yaml: replicas set to 0"
|
||||||
idle = sys.argv[2]
|
|
||||||
|
|
||||||
def set_replicas(path, count):
|
|
||||||
with open(path) as f:
|
|
||||||
content = f.read()
|
|
||||||
content = re.sub(r'^( replicas: )\d+', r'\g<1>' + str(count), content, count=1, flags=re.MULTILINE)
|
|
||||||
with open(path, 'w') as f:
|
|
||||||
f.write(content)
|
|
||||||
print(f' {path}: replicas set to {count}')
|
|
||||||
|
|
||||||
set_replicas(f'{DEPLOY_DIR}/deployment-{slot}.yaml', 1)
|
|
||||||
set_replicas(f'{DEPLOY_DIR}/deployment-{idle}.yaml', 0)
|
|
||||||
" "$SLOT" "$IDLE"
|
|
||||||
|
|
||||||
git config user.email "ci@neurontechnologies.ai"
|
git config user.email "ci@neurontechnologies.ai"
|
||||||
git config user.name "Neuron CI"
|
git config user.name "Neuron CI"
|
||||||
@@ -246,7 +233,7 @@ set_replicas(f'{DEPLOY_DIR}/deployment-{idle}.yaml', 0)
|
|||||||
echo "Verifying neuron-mcp-${SLOT} is healthy..."
|
echo "Verifying neuron-mcp-${SLOT} is healthy..."
|
||||||
kubectl rollout status deployment/"neuron-mcp-${SLOT}" \
|
kubectl rollout status deployment/"neuron-mcp-${SLOT}" \
|
||||||
--namespace=neuron-prod \
|
--namespace=neuron-prod \
|
||||||
--timeout=3m
|
--timeout=8m
|
||||||
|
|
||||||
echo "Active service endpoints:"
|
echo "Active service endpoints:"
|
||||||
kubectl get endpoints neuron-mcp -n neuron-prod
|
kubectl get endpoints neuron-mcp -n neuron-prod
|
||||||
|
|||||||
+51
-4
@@ -40,7 +40,32 @@ fn ise_post(content: String) -> Void {
|
|||||||
let safe3: String = str_replace(safe2, "\n", "\\n")
|
let safe3: String = str_replace(safe2, "\n", "\\n")
|
||||||
let safe4: String = str_replace(safe3, "\r", "\\r")
|
let safe4: String = str_replace(safe3, "\r", "\\r")
|
||||||
let body: String = "{\"content\":\"" + safe4 + "\"}"
|
let body: String = "{\"content\":\"" + safe4 + "\"}"
|
||||||
let discard: String = http_post_json(engram_url + "/api/neuron/state-events", body)
|
// Soft circuit-breaker: skip HTTP call when engram is known-down (30s backoff).
|
||||||
|
// Opens after 3 consecutive failures; half-open probe after backoff expires.
|
||||||
|
// TODO(reliability): full async dispatch requires EL runtime futures support.
|
||||||
|
let cb_open: String = state_get("engram_cb_open")
|
||||||
|
if str_eq(cb_open, "1") {
|
||||||
|
let cb_ts_s: String = state_get("engram_cb_open_ts")
|
||||||
|
let cb_ts: Int = if str_eq(cb_ts_s, "") { 0 } else { str_to_int(cb_ts_s) }
|
||||||
|
let cb_elapsed: Int = time_now() - cb_ts
|
||||||
|
if cb_elapsed < 30000 { return "" }
|
||||||
|
state_set("engram_cb_open", "0")
|
||||||
|
}
|
||||||
|
let resp: String = http_post_json(engram_url + "/api/neuron/state-events", body)
|
||||||
|
let cb_failed: Bool = str_eq(resp, "") || str_starts_with(resp, "{"error":")
|
||||||
|
if cb_failed {
|
||||||
|
let fn_s: String = state_get("engram_cb_fails")
|
||||||
|
let fn_n: Int = if str_eq(fn_s, "") { 0 } else { str_to_int(fn_s) }
|
||||||
|
let fn_n = fn_n + 1
|
||||||
|
state_set("engram_cb_fails", int_to_str(fn_n))
|
||||||
|
if fn_n >= 3 {
|
||||||
|
state_set("engram_cb_open", "1")
|
||||||
|
state_set("engram_cb_open_ts", int_to_str(time_now()))
|
||||||
|
println("[awareness] engram circuit-breaker OPEN after " + int_to_str(fn_n) + " failures")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
state_set("engram_cb_fails", "0")
|
||||||
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,17 +244,34 @@ fn proactive_curiosity() -> Bool {
|
|||||||
// str_find_chars finds the first space/colon/bracket delimiter. sp > 3 guards against
|
// str_find_chars finds the first space/colon/bracket delimiter. sp > 3 guards against
|
||||||
// very short or bracket-prefixed labels like "[BacklogItem]" (sp=0, not > 3 → skipped).
|
// very short or bracket-prefixed labels like "[BacklogItem]" (sp=0, not > 3 → skipped).
|
||||||
// EL scoping: state_set/state_get pattern used because let inside if creates inner scope.
|
// EL scoping: state_set/state_get pattern used because let inside if creates inner scope.
|
||||||
// (2026-06-11 self-review)
|
//
|
||||||
|
// NODE TYPE FILTER (2026-06-19 self-review): only derive auto_term from Memory,
|
||||||
|
// BacklogItem, or Entity nodes. Knowledge nodes are stable reference material —
|
||||||
|
// using their first word as a curiosity seed creates a self-reinforcing loop: e.g.
|
||||||
|
// "Numeric tier strings in Engram..." (a Knowledge node) -> auto_term="Numeric" ->
|
||||||
|
// activates all "Numeric" nodes -> keeps that Knowledge node dominant in WM forever.
|
||||||
|
// Knowledge nodes should be REACHED by curiosity seeds, not drive them. Only dynamic
|
||||||
|
// personal/work nodes (Memory, BacklogItem, Entity) carry live contextual salience
|
||||||
|
// worth radiating from. (2026-06-11 origin; filter added 2026-06-19 self-review)
|
||||||
state_set("cseed_auto", "")
|
state_set("cseed_auto", "")
|
||||||
let wm_top_j: String = engram_wm_top_json(1)
|
let wm_top_j: String = engram_wm_top_json(1)
|
||||||
let wm_top_n: String = json_array_get(wm_top_j, 0)
|
let wm_top_n: String = json_array_get(wm_top_j, 0)
|
||||||
let wm_top_lbl: String = json_get(wm_top_n, "label")
|
let wm_top_lbl: String = json_get(wm_top_n, "label")
|
||||||
|
let wm_top_type: String = json_get(wm_top_n, "node_type")
|
||||||
|
// state_set/state_get pattern: EL let-inside-if creates inner scope only.
|
||||||
|
state_set("allow_auto", "0")
|
||||||
|
if str_eq(wm_top_type, "Memory") { state_set("allow_auto", "1") }
|
||||||
|
if str_eq(wm_top_type, "BacklogItem") { state_set("allow_auto", "1") }
|
||||||
|
if str_eq(wm_top_type, "Entity") { state_set("allow_auto", "1") }
|
||||||
|
let allow_auto: String = state_get("allow_auto")
|
||||||
|
if str_eq(allow_auto, "1") {
|
||||||
if !str_eq(wm_top_lbl, "") {
|
if !str_eq(wm_top_lbl, "") {
|
||||||
let sp: Int = str_find_chars(wm_top_lbl, " :([")
|
let sp: Int = str_find_chars(wm_top_lbl, " :([")
|
||||||
if sp > 3 {
|
if sp > 3 {
|
||||||
state_set("cseed_auto", str_slice(wm_top_lbl, 0, sp))
|
state_set("cseed_auto", str_slice(wm_top_lbl, 0, sp))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
let auto_term: String = state_get("cseed_auto")
|
let auto_term: String = state_get("cseed_auto")
|
||||||
let results_auto: String = if str_eq(auto_term, "") { "[]" } else { engram_activate_json(auto_term, 1) }
|
let results_auto: String = if str_eq(auto_term, "") { "[]" } else { engram_activate_json(auto_term, 1) }
|
||||||
let found_auto: Int = json_array_len(results_auto)
|
let found_auto: Int = json_array_len(results_auto)
|
||||||
@@ -523,9 +565,14 @@ fn awareness_run() -> Void {
|
|||||||
let should_refresh: Bool = refresh_elapsed >= refresh_ms
|
let should_refresh: Bool = refresh_elapsed >= refresh_ms
|
||||||
if should_refresh {
|
if should_refresh {
|
||||||
let engram_url: String = state_get("soul_engram_url")
|
let engram_url: String = state_get("soul_engram_url")
|
||||||
if !str_eq(engram_url, "") {
|
let sc: String = state_get("engram_cb_open")
|
||||||
|
let sc_ts_s: String = state_get("engram_cb_open_ts")
|
||||||
|
let sc_ts: Int = if str_eq(sc_ts_s, "") { 0 } else { str_to_int(sc_ts_s) }
|
||||||
|
let sc_elapsed: Int = now_ts - sc_ts
|
||||||
|
let sync_allowed: Bool = !str_eq(sc, "1") || sc_elapsed >= 30000
|
||||||
|
if !str_eq(engram_url, "") && sync_allowed {
|
||||||
let sync_json: String = http_get(engram_url + "/api/sync")
|
let sync_json: String = http_get(engram_url + "/api/sync")
|
||||||
if !str_eq(sync_json, "") && !str_eq(sync_json, "{}") {
|
if !str_eq(sync_json, "") && !str_eq(sync_json, "{}") && !str_starts_with(sync_json, "{\"error\":") {
|
||||||
let cgi_id: String = state_get("soul_cgi_id")
|
let cgi_id: String = state_get("soul_cgi_id")
|
||||||
let tmp: String = "/tmp/soul-sync-" + cgi_id + ".json"
|
let tmp: String = "/tmp/soul-sync-" + cgi_id + ".json"
|
||||||
fs_write(tmp, sync_json)
|
fs_write(tmp, sync_json)
|
||||||
|
|||||||
@@ -186,6 +186,10 @@ fn handle_chat(body: String) -> String {
|
|||||||
let req_model: String = json_get(body, "model")
|
let req_model: String = json_get(body, "model")
|
||||||
let model: String = if str_eq(req_model, "") { chat_default_model() } else { req_model }
|
let model: String = if str_eq(req_model, "") { chat_default_model() } else { req_model }
|
||||||
|
|
||||||
|
// ISSUE 9: add safety_augment_system to primary /api/chat path.
|
||||||
|
// handle_chat was the only LLM path missing bell directive injection.
|
||||||
|
let full_system = safety_augment_system(full_system, message)
|
||||||
|
|
||||||
let raw_response: String = llm_call_system(model, full_system, message)
|
let raw_response: String = llm_call_system(model, full_system, message)
|
||||||
|
|
||||||
let is_error: Bool = str_starts_with(raw_response, "{\"error\"")
|
let is_error: Bool = str_starts_with(raw_response, "{\"error\"")
|
||||||
|
|||||||
+14
@@ -285,12 +285,26 @@ el_val_t proactive_curiosity(void) {
|
|||||||
el_val_t wm_top_j = engram_wm_top_json(1);
|
el_val_t wm_top_j = engram_wm_top_json(1);
|
||||||
el_val_t wm_top_n = json_array_get(wm_top_j, 0);
|
el_val_t wm_top_n = json_array_get(wm_top_j, 0);
|
||||||
el_val_t wm_top_lbl = json_get(wm_top_n, EL_STR("label"));
|
el_val_t wm_top_lbl = json_get(wm_top_n, EL_STR("label"));
|
||||||
|
el_val_t wm_top_type = json_get(wm_top_n, EL_STR("node_type"));
|
||||||
|
state_set(EL_STR("allow_auto"), EL_STR("0"));
|
||||||
|
if (str_eq(wm_top_type, EL_STR("Memory"))) {
|
||||||
|
state_set(EL_STR("allow_auto"), EL_STR("1"));
|
||||||
|
}
|
||||||
|
if (str_eq(wm_top_type, EL_STR("BacklogItem"))) {
|
||||||
|
state_set(EL_STR("allow_auto"), EL_STR("1"));
|
||||||
|
}
|
||||||
|
if (str_eq(wm_top_type, EL_STR("Entity"))) {
|
||||||
|
state_set(EL_STR("allow_auto"), EL_STR("1"));
|
||||||
|
}
|
||||||
|
el_val_t allow_auto = state_get(EL_STR("allow_auto"));
|
||||||
|
if (str_eq(allow_auto, EL_STR("1"))) {
|
||||||
if (!str_eq(wm_top_lbl, EL_STR(""))) {
|
if (!str_eq(wm_top_lbl, EL_STR(""))) {
|
||||||
el_val_t sp = str_find_chars(wm_top_lbl, EL_STR(" :(["));
|
el_val_t sp = str_find_chars(wm_top_lbl, EL_STR(" :(["));
|
||||||
if (sp > 3) {
|
if (sp > 3) {
|
||||||
state_set(EL_STR("cseed_auto"), str_slice(wm_top_lbl, 0, sp));
|
state_set(EL_STR("cseed_auto"), str_slice(wm_top_lbl, 0, sp));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
el_val_t auto_term = state_get(EL_STR("cseed_auto"));
|
el_val_t auto_term = state_get(EL_STR("cseed_auto"));
|
||||||
el_val_t results_auto = ({ el_val_t _if_result_3 = 0; if (str_eq(auto_term, EL_STR(""))) { _if_result_3 = (EL_STR("[]")); } else { _if_result_3 = (engram_activate_json(auto_term, 1)); } _if_result_3; });
|
el_val_t results_auto = ({ el_val_t _if_result_3 = 0; if (str_eq(auto_term, EL_STR(""))) { _if_result_3 = (EL_STR("[]")); } else { _if_result_3 = (engram_activate_json(auto_term, 1)); } _if_result_3; });
|
||||||
el_val_t found_auto = json_array_len(results_auto);
|
el_val_t found_auto = json_array_len(results_auto);
|
||||||
|
|||||||
+52
-3
@@ -1042,12 +1042,36 @@ el_val_t call_neuron_mcp(el_val_t tool_name, el_val_t args_json);
|
|||||||
el_val_t agentic_tools_literal(void);
|
el_val_t agentic_tools_literal(void);
|
||||||
el_val_t agentic_tools_with_web(void);
|
el_val_t agentic_tools_with_web(void);
|
||||||
el_val_t dispatch_tool(el_val_t tool_name, el_val_t tool_input);
|
el_val_t dispatch_tool(el_val_t tool_name, el_val_t tool_input);
|
||||||
|
el_val_t json_array_append(el_val_t arr, el_val_t item);
|
||||||
|
el_val_t append_tool_log(el_val_t log, el_val_t name);
|
||||||
|
el_val_t exec_tool_block(el_val_t block);
|
||||||
|
el_val_t agentic_blob(el_val_t model, el_val_t system, el_val_t tools_json, el_val_t messages, el_val_t origin, el_val_t approval, el_val_t iteration, el_val_t tools_log, el_val_t content, el_val_t queue, el_val_t results, el_val_t next);
|
||||||
|
el_val_t extract_all_text(el_val_t s);
|
||||||
|
el_val_t strip_citations(el_val_t s);
|
||||||
|
el_val_t agentic_api_turn(el_val_t model, el_val_t safe_sys, el_val_t tools_json, el_val_t messages);
|
||||||
|
el_val_t agentic_engine(el_val_t session_id, el_val_t blob);
|
||||||
el_val_t handle_chat_agentic(el_val_t body);
|
el_val_t handle_chat_agentic(el_val_t body);
|
||||||
|
el_val_t handle_session_approve(el_val_t session_id, el_val_t body);
|
||||||
el_val_t handle_chat_as_soul(el_val_t body);
|
el_val_t handle_chat_as_soul(el_val_t body);
|
||||||
el_val_t handle_dharma_room_turn(el_val_t body);
|
el_val_t handle_dharma_room_turn(el_val_t body);
|
||||||
el_val_t handle_dharma_room_turn_agentic(el_val_t body);
|
el_val_t handle_dharma_room_turn_agentic(el_val_t body);
|
||||||
el_val_t auto_persist(el_val_t req, el_val_t resp);
|
el_val_t auto_persist(el_val_t req, el_val_t resp);
|
||||||
el_val_t strengthen_chat_nodes(el_val_t activation_nodes);
|
el_val_t strengthen_chat_nodes(el_val_t activation_nodes);
|
||||||
|
el_val_t safety_self_harm_phrases(void);
|
||||||
|
el_val_t safety_abuse_phrases(void);
|
||||||
|
el_val_t safety_general_hard_phrases(void);
|
||||||
|
el_val_t safety_soft_phrases(void);
|
||||||
|
el_val_t safety_normalize(el_val_t message);
|
||||||
|
el_val_t safety_any_match(el_val_t text, el_val_t phrases_json);
|
||||||
|
el_val_t safety_count_match(el_val_t text, el_val_t phrases_json);
|
||||||
|
el_val_t safety_detect_bell_level(el_val_t message);
|
||||||
|
el_val_t safety_classify_hard_bell(el_val_t message);
|
||||||
|
el_val_t safety_soft_directive(void);
|
||||||
|
el_val_t safety_hard_directive(el_val_t hard_type);
|
||||||
|
el_val_t safety_augment_system(el_val_t system, el_val_t user_msg);
|
||||||
|
el_val_t safety_contact_path(void);
|
||||||
|
el_val_t handle_safety_contact_get(void);
|
||||||
|
el_val_t handle_safety_contact_post(el_val_t body);
|
||||||
el_val_t auth_headers(el_val_t tok);
|
el_val_t auth_headers(el_val_t tok);
|
||||||
el_val_t axon_get(el_val_t path);
|
el_val_t axon_get(el_val_t path);
|
||||||
el_val_t axon_post(el_val_t path, el_val_t body);
|
el_val_t axon_post(el_val_t path, el_val_t body);
|
||||||
@@ -1110,6 +1134,7 @@ el_val_t session_update_meta_timestamp(el_val_t session_id);
|
|||||||
el_val_t session_auto_title(el_val_t session_id, el_val_t first_message);
|
el_val_t session_auto_title(el_val_t session_id, el_val_t first_message);
|
||||||
el_val_t handle_session_approve(el_val_t session_id, el_val_t body);
|
el_val_t handle_session_approve(el_val_t session_id, el_val_t body);
|
||||||
el_val_t strip_query(el_val_t path);
|
el_val_t strip_query(el_val_t path);
|
||||||
|
el_val_t flag_true(el_val_t body, el_val_t key);
|
||||||
el_val_t err_404(el_val_t path);
|
el_val_t err_404(el_val_t path);
|
||||||
el_val_t err_405(el_val_t method, el_val_t path);
|
el_val_t err_405(el_val_t method, el_val_t path);
|
||||||
el_val_t route_health(void);
|
el_val_t route_health(void);
|
||||||
@@ -1144,6 +1169,9 @@ el_val_t local_node_count;
|
|||||||
el_val_t snapshot_usable;
|
el_val_t snapshot_usable;
|
||||||
el_val_t boot_num;
|
el_val_t boot_num;
|
||||||
el_val_t is_genesis;
|
el_val_t is_genesis;
|
||||||
|
el_val_t guard_disk;
|
||||||
|
el_val_t guard_disk_len;
|
||||||
|
el_val_t safe_to_seed;
|
||||||
|
|
||||||
el_val_t lang_profile(el_val_t code, el_val_t word_order, el_val_t morph_type, el_val_t has_case, el_val_t has_gender, el_val_t script_dir, el_val_t agreement, el_val_t null_subject) {
|
el_val_t lang_profile(el_val_t code, el_val_t word_order, el_val_t morph_type, el_val_t has_case, el_val_t has_gender, el_val_t script_dir, el_val_t agreement, el_val_t null_subject) {
|
||||||
el_val_t r = native_list_empty();
|
el_val_t r = native_list_empty();
|
||||||
@@ -25890,14 +25918,28 @@ el_val_t proactive_curiosity(void) {
|
|||||||
el_val_t wm_top_j = engram_wm_top_json(1);
|
el_val_t wm_top_j = engram_wm_top_json(1);
|
||||||
el_val_t wm_top_n = json_array_get(wm_top_j, 0);
|
el_val_t wm_top_n = json_array_get(wm_top_j, 0);
|
||||||
el_val_t wm_top_lbl = json_get(wm_top_n, EL_STR("label"));
|
el_val_t wm_top_lbl = json_get(wm_top_n, EL_STR("label"));
|
||||||
|
el_val_t wm_top_type = json_get(wm_top_n, EL_STR("node_type"));
|
||||||
|
state_set(EL_STR("allow_auto"), EL_STR("0"));
|
||||||
|
if (str_eq(wm_top_type, EL_STR("Memory"))) {
|
||||||
|
state_set(EL_STR("allow_auto"), EL_STR("1"));
|
||||||
|
}
|
||||||
|
if (str_eq(wm_top_type, EL_STR("BacklogItem"))) {
|
||||||
|
state_set(EL_STR("allow_auto"), EL_STR("1"));
|
||||||
|
}
|
||||||
|
if (str_eq(wm_top_type, EL_STR("Entity"))) {
|
||||||
|
state_set(EL_STR("allow_auto"), EL_STR("1"));
|
||||||
|
}
|
||||||
|
el_val_t allow_auto = state_get(EL_STR("allow_auto"));
|
||||||
|
if (str_eq(allow_auto, EL_STR("1"))) {
|
||||||
if (!str_eq(wm_top_lbl, EL_STR(""))) {
|
if (!str_eq(wm_top_lbl, EL_STR(""))) {
|
||||||
el_val_t sp = str_find_chars(wm_top_lbl, EL_STR(" :(["));
|
el_val_t sp = str_find_chars(wm_top_lbl, EL_STR(" :(["));
|
||||||
if (sp > 3) {
|
if (sp > 3) {
|
||||||
state_set(EL_STR("cseed_auto"), str_slice(wm_top_lbl, 0, sp));
|
state_set(EL_STR("cseed_auto"), str_slice(wm_top_lbl, 0, sp));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
el_val_t auto_term = state_get(EL_STR("cseed_auto"));
|
el_val_t auto_term = state_get(EL_STR("cseed_auto"));
|
||||||
el_val_t results_auto = ({ el_val_t _if_result_101 = 0; if (str_eq(auto_term, EL_STR(""))) { _if_result_101 = (EL_STR("[]")); } else { _if_result_101 = (engram_activate_json(auto_term, 1)); } _if_result_101; });
|
el_val_t results_auto = ({ el_val_t _if_result_3 = 0; if (str_eq(auto_term, EL_STR(""))) { _if_result_3 = (EL_STR("[]")); } else { _if_result_3 = (engram_activate_json(auto_term, 1)); } _if_result_3; });
|
||||||
el_val_t found_auto = json_array_len(results_auto);
|
el_val_t found_auto = json_array_len(results_auto);
|
||||||
el_val_t total_found = (found + found_auto);
|
el_val_t total_found = (found + found_auto);
|
||||||
el_val_t safe_auto = str_replace(auto_term, EL_STR("\""), EL_STR("'"));
|
el_val_t safe_auto = str_replace(auto_term, EL_STR("\""), EL_STR("'"));
|
||||||
@@ -25908,6 +25950,7 @@ el_val_t proactive_curiosity(void) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
el_val_t pulse_count(void) {
|
el_val_t pulse_count(void) {
|
||||||
el_val_t s = state_get(EL_STR("soul.pulse"));
|
el_val_t s = state_get(EL_STR("soul.pulse"));
|
||||||
if (str_eq(s, EL_STR(""))) {
|
if (str_eq(s, EL_STR(""))) {
|
||||||
@@ -28915,7 +28958,13 @@ int main(int _argc, char** _argv) {
|
|||||||
state_set(EL_STR("soul_engram_api_key"), engram_api_key_raw);
|
state_set(EL_STR("soul_engram_api_key"), engram_api_key_raw);
|
||||||
state_set(EL_STR("soul.running"), EL_STR("true"));
|
state_set(EL_STR("soul.running"), EL_STR("true"));
|
||||||
is_genesis = str_eq(soul_cgi_id, EL_STR("ntn-genesis"));
|
is_genesis = str_eq(soul_cgi_id, EL_STR("ntn-genesis"));
|
||||||
if (is_genesis) {
|
guard_disk = ({ el_val_t _if_result_25 = 0; if (str_eq(engram_url_raw, EL_STR(""))) { _if_result_25 = (fs_read(snapshot)); } else { _if_result_25 = (EL_STR("")); } _if_result_25; });
|
||||||
|
guard_disk_len = str_len(guard_disk);
|
||||||
|
safe_to_seed = !((guard_disk_len > 200000) && (engram_node_count() < (guard_disk_len / 16000)));
|
||||||
|
if (is_genesis && !safe_to_seed) {
|
||||||
|
println(el_str_concat(el_str_concat(el_str_concat(el_str_concat(EL_STR("[soul] GUARD: loaded "), int_to_str(engram_node_count())), EL_STR(" nodes but snapshot file is ")), int_to_str(guard_disk_len)), EL_STR(" bytes \xe2\x80\x94 refusing to seed/save over a real graph")));
|
||||||
|
}
|
||||||
|
if (is_genesis && safe_to_seed) {
|
||||||
el_val_t edge_count_now = engram_edge_count();
|
el_val_t edge_count_now = engram_edge_count();
|
||||||
if (edge_count_now < 100) {
|
if (edge_count_now < 100) {
|
||||||
init_soul_edges();
|
init_soul_edges();
|
||||||
@@ -28926,7 +28975,7 @@ int main(int _argc, char** _argv) {
|
|||||||
state_set(EL_STR("soul_snapshot_path"), snapshot);
|
state_set(EL_STR("soul_snapshot_path"), snapshot);
|
||||||
engram_save(snapshot);
|
engram_save(snapshot);
|
||||||
}
|
}
|
||||||
if (is_genesis) {
|
if (is_genesis && safe_to_seed) {
|
||||||
el_val_t snap = state_get(EL_STR("soul_snapshot_path"));
|
el_val_t snap = state_get(EL_STR("soul_snapshot_path"));
|
||||||
if (!str_eq(snap, EL_STR(""))) {
|
if (!str_eq(snap, EL_STR(""))) {
|
||||||
engram_save(snap);
|
engram_save(snap);
|
||||||
|
|||||||
+8
-4
@@ -24,19 +24,23 @@ ENGRAM_DATA_DIR="$ENGRAM_DATA_DIR" \
|
|||||||
|
|
||||||
ENGRAM_PID=$!
|
ENGRAM_PID=$!
|
||||||
|
|
||||||
# Wait for engram to become healthy (up to 30s)
|
# Wait for engram to become healthy (up to 60s; GKE Autopilot cold starts can be slow)
|
||||||
echo "[entrypoint] waiting for engram..."
|
echo "[entrypoint] waiting for engram..."
|
||||||
TRIES=0
|
TRIES=0
|
||||||
until curl -sf "$ENGRAM_HEALTH_URL" > /dev/null 2>&1; do
|
until curl -sf "$ENGRAM_HEALTH_URL" > /dev/null 2>&1; do
|
||||||
TRIES=$((TRIES + 1))
|
TRIES=$((TRIES + 1))
|
||||||
if [ "$TRIES" -ge 30 ]; then
|
if [ "$TRIES" -ge 60 ]; then
|
||||||
echo "[entrypoint] ERROR: engram did not become healthy after 30s" >&2
|
echo "[entrypoint] ERROR: engram did not become healthy after 60s" >&2
|
||||||
kill "$ENGRAM_PID" 2>/dev/null || true
|
kill "$ENGRAM_PID" 2>/dev/null || true
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
echo "[entrypoint] engram ready"
|
echo "[entrypoint] engram ready after ${TRIES}s"
|
||||||
|
|
||||||
|
# Tune EL HTTP runtime: reduce per-call timeout 60s->10s, connect timeout 3s.
|
||||||
|
export EL_HTTP_TIMEOUT_MS="${EL_HTTP_TIMEOUT_MS:-10000}"
|
||||||
|
export EL_HTTP_CONNECT_TIMEOUT_MS="${EL_HTTP_CONNECT_TIMEOUT_MS:-3000}"
|
||||||
|
|
||||||
# Start soul — it takes over as PID 1's foreground process.
|
# Start soul — it takes over as PID 1's foreground process.
|
||||||
# SOUL_ENGRAM_PATH must NOT be set; ENGRAM_URL triggers HTTP mode.
|
# SOUL_ENGRAM_PATH must NOT be set; ENGRAM_URL triggers HTTP mode.
|
||||||
|
|||||||
@@ -144,17 +144,22 @@ fn safety_screen(input: String, history: String) -> String {
|
|||||||
if score >= soft {
|
if score >= soft {
|
||||||
let summary: String = str_slice(input, 0, 80)
|
let summary: String = str_slice(input, 0, 80)
|
||||||
let discard: String = safety_log_bell("soft", "wellbeing check needed", summary)
|
let discard: String = safety_log_bell("soft", "wellbeing check needed", summary)
|
||||||
|
// ISSUE 7 fix: escape tab chars in addition to backslash/quote/newline/CR.
|
||||||
|
// A tab in user input corrupts the JSON envelope and causes json_get to misparse.
|
||||||
let e1: String = str_replace(input, "\\", "\\\\")
|
let e1: String = str_replace(input, "\\", "\\\\")
|
||||||
let e2: String = str_replace(e1, "\"", "\\\"")
|
let e2: String = str_replace(e1, "\"", "\\\"")
|
||||||
let e3: String = str_replace(e2, "\n", "\\n")
|
let e3: String = str_replace(e2, "\n", "\\n")
|
||||||
let safe_input: String = str_replace(e3, "\r", "\\r")
|
let e4: String = str_replace(e3, "\r", "\\r")
|
||||||
|
let safe_input: String = str_replace(e4, "\t", "\\t")
|
||||||
return "{\"action\":\"soft_bell\",\"reason\":\"wellbeing check needed\",\"content\":\"" + safe_input + "\"}"
|
return "{\"action\":\"soft_bell\",\"reason\":\"wellbeing check needed\",\"content\":\"" + safe_input + "\"}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ISSUE 7 fix: escape tab chars (see soft_bell branch above for rationale).
|
||||||
let e1: String = str_replace(input, "\\", "\\\\")
|
let e1: String = str_replace(input, "\\", "\\\\")
|
||||||
let e2: String = str_replace(e1, "\"", "\\\"")
|
let e2: String = str_replace(e1, "\"", "\\\"")
|
||||||
let e3: String = str_replace(e2, "\n", "\\n")
|
let e3: String = str_replace(e2, "\n", "\\n")
|
||||||
let safe_input: String = str_replace(e3, "\r", "\\r")
|
let e4: String = str_replace(e3, "\r", "\\r")
|
||||||
|
let safe_input: String = str_replace(e4, "\t", "\\t")
|
||||||
return "{\"action\":\"pass\",\"content\":\"" + safe_input + "\"}"
|
return "{\"action\":\"pass\",\"content\":\"" + safe_input + "\"}"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,7 +200,11 @@ fn safety_validate(output: String, action: String) -> String {
|
|||||||
fn safety_log_bell(level: String, reason: String, input_summary: String) -> String {
|
fn safety_log_bell(level: String, reason: String, input_summary: String) -> String {
|
||||||
let content: String = "BELL:" + level + " | " + reason + " | summary:" + input_summary
|
let content: String = "BELL:" + level + " | " + reason + " | summary:" + input_summary
|
||||||
let tags: String = "[\"safety\",\"bell\",\"bell:" + level + "\"]"
|
let tags: String = "[\"safety\",\"bell\",\"bell:" + level + "\"]"
|
||||||
let discard: String = engram_node_full(
|
// ISSUE 2 fix: if engram_node_full returns empty the write silently failed.
|
||||||
|
// Emit a fallback println so the bell event leaves at least a log trace even
|
||||||
|
// when engram is degraded. This does not replace engram persistence -- it is a
|
||||||
|
// last-resort audit trail when the primary write cannot be confirmed.
|
||||||
|
let node_id: String = engram_node_full(
|
||||||
content,
|
content,
|
||||||
"BellEvent",
|
"BellEvent",
|
||||||
"bell:" + level,
|
"bell:" + level,
|
||||||
@@ -205,6 +214,9 @@ fn safety_log_bell(level: String, reason: String, input_summary: String) -> Stri
|
|||||||
"Episodic",
|
"Episodic",
|
||||||
tags
|
tags
|
||||||
)
|
)
|
||||||
|
if str_eq(node_id, "") {
|
||||||
|
println("[safety] WARN: bell event engram write failed -- fallback log: " + content)
|
||||||
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,6 +247,17 @@ fn safety_soft_phrases() -> String {
|
|||||||
return "[\"stressed\",\"overwhelmed\",\"can't cope\",\"cannot cope\",\"struggling\",\"anxious\",\"anxiety\",\"depressed\",\"depression\",\"lonely\",\"isolated\",\"hopeless\",\"hopelessness\",\"exhausted\",\"burnt out\",\"burned out\",\"burnout\",\"panic\",\"panicking\",\"falling apart\",\"breaking down\",\"can't handle\",\"cannot handle\",\"losing it\",\"nothing matters\",\"don't care anymore\",\"given up\",\"giving up\",\"helpless\",\"worthless\",\"useless\",\"hate myself\",\"no one cares\",\"nobody cares\",\"no one understands\",\"nobody understands\",\"empty inside\",\"can't stop crying\",\"breaking point\",\"at my limit\",\"having a breakdown\"]"
|
return "[\"stressed\",\"overwhelmed\",\"can't cope\",\"cannot cope\",\"struggling\",\"anxious\",\"anxiety\",\"depressed\",\"depression\",\"lonely\",\"isolated\",\"hopeless\",\"hopelessness\",\"exhausted\",\"burnt out\",\"burned out\",\"burnout\",\"panic\",\"panicking\",\"falling apart\",\"breaking down\",\"can't handle\",\"cannot handle\",\"losing it\",\"nothing matters\",\"don't care anymore\",\"given up\",\"giving up\",\"helpless\",\"worthless\",\"useless\",\"hate myself\",\"no one cares\",\"nobody cares\",\"no one understands\",\"nobody understands\",\"empty inside\",\"can't stop crying\",\"breaking point\",\"at my limit\",\"having a breakdown\"]"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ISSUE 5 TODO: phrase lists are rebuilt from JSON literals on every call.
|
||||||
|
// safety_any_match and safety_count_match loop over json_array_get on every invocation.
|
||||||
|
// A compiled/cached representation would reduce per-message overhead and also guard against
|
||||||
|
// malformed phrase JSON (json_array_len of malformed input returns 0, silently skipping all checks).
|
||||||
|
// Caching requires language-level static const arrays -- not available in current EL.
|
||||||
|
// When EL gains module-level const arrays, migrate phrase lists to that form.
|
||||||
|
//
|
||||||
|
// ISSUE 5 TODO: phrase lists are rebuilt from JSON literals on every call to
|
||||||
|
// safety_any_match / safety_count_match. json_array_len of a malformed string
|
||||||
|
// returns 0, silently skipping all checks. Caching requires language-level static
|
||||||
|
// const arrays (not available in current EL). Migrate when EL gains that feature.
|
||||||
// ── Matching helpers (single loops only — el escapes while-body mutation via
|
// ── Matching helpers (single loops only — el escapes while-body mutation via
|
||||||
// top-level let rebinds; nested loops would not advance) ────────────────────
|
// top-level let rebinds; nested loops would not advance) ────────────────────
|
||||||
|
|
||||||
|
|||||||
@@ -5,13 +5,9 @@ import "stewardship.el"
|
|||||||
import "imprint.el"
|
import "imprint.el"
|
||||||
import "awareness.el"
|
import "awareness.el"
|
||||||
import "chat.el"
|
import "chat.el"
|
||||||
import "safety.el"
|
|
||||||
import "studio.el"
|
import "studio.el"
|
||||||
import "elp-input.el"
|
import "elp-input.el"
|
||||||
import "routes.el"
|
import "routes.el"
|
||||||
import "safety.el"
|
|
||||||
import "stewardship.el"
|
|
||||||
import "imprint.el"
|
|
||||||
|
|
||||||
cgi "neuron-soul" {
|
cgi "neuron-soul" {
|
||||||
dharma_id: "ntn-genesis@http://localhost:7770",
|
dharma_id: "ntn-genesis@http://localhost:7770",
|
||||||
@@ -265,19 +261,32 @@ fn layered_cycle(raw_input: String) -> String {
|
|||||||
let screen_result: String = safety_screen(raw_input, history)
|
let screen_result: String = safety_screen(raw_input, history)
|
||||||
let screen_action: String = json_get(screen_result, "action")
|
let screen_action: String = json_get(screen_result, "action")
|
||||||
|
|
||||||
|
// ISSUE 4: safe-mode guard -- if safety_screen returned invalid/empty action,
|
||||||
|
// refuse the turn rather than silently passing unscreened input to upper layers.
|
||||||
|
// Valid actions: "hard_bell", "soft_bell", "pass". Anything else = corrupt envelope.
|
||||||
|
let valid_action: Bool = str_eq(screen_action, "hard_bell")
|
||||||
|
|| str_eq(screen_action, "soft_bell")
|
||||||
|
|| str_eq(screen_action, "pass")
|
||||||
|
if !valid_action {
|
||||||
|
println("[soul] layered_cycle: safety_screen invalid action -- safe mode refusal")
|
||||||
|
return safety_validate("", "hard_bell")
|
||||||
|
}
|
||||||
|
|
||||||
// Hard bell: bypass all upper layers, log and escalate.
|
// Hard bell: bypass all upper layers, log and escalate.
|
||||||
// Intentionally does NOT update conversation_history or call auto_persist():
|
// Intentionally does NOT update conversation_history or call auto_persist():
|
||||||
// hard bell events are security-sensitive and must not appear in engram conversation
|
// hard bell events are security-sensitive and must not appear in engram conversation
|
||||||
// history where they could leak context to subsequent turns. They are persisted
|
// history where they could leak context to subsequent turns. They are persisted
|
||||||
// separately by safety_log_bell() into the Episodic tier with restricted labels.
|
// separately by safety_log_bell() into the Episodic tier with restricted labels.
|
||||||
//
|
//
|
||||||
|
// ISSUE 6: safety_log_bell for hard bells is already called INSIDE safety_screen
|
||||||
|
// (safety.el line 140). Do NOT call it again here -- double-log avoided.
|
||||||
|
//
|
||||||
// safety_validate second param: when screen_action is "hard_bell", safety_validate
|
// safety_validate second param: when screen_action is "hard_bell", safety_validate
|
||||||
// receives the sentinel string "hard_bell" (not a normal screen action). The safety
|
// receives the sentinel string "hard_bell" (not a normal screen action). The safety
|
||||||
// layer contract requires it to return a fixed refusal regardless of the output arg.
|
// layer contract requires it to return a fixed refusal regardless of the output arg.
|
||||||
// On the normal path, safety_validate receives the original screen_action ("pass")
|
// On the normal path, safety_validate receives the original screen_action ("pass")
|
||||||
// so it can apply action-specific post-output checks.
|
// so it can apply action-specific post-output checks.
|
||||||
if str_eq(screen_action, "hard_bell") {
|
if str_eq(screen_action, "hard_bell") {
|
||||||
safety_log_bell("hard", json_get(screen_result, "reason"), str_slice(raw_input, 0, 80))
|
|
||||||
return safety_validate("", "hard_bell")
|
return safety_validate("", "hard_bell")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -312,6 +321,16 @@ fn layered_cycle(raw_input: String) -> String {
|
|||||||
json_get(steward_result, "redirect_to")
|
json_get(steward_result, "redirect_to")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ISSUE 1: apply pre-LLM bell augmentation on layered_cycle path.
|
||||||
|
// safety_augment_system injects soft/hard directive into system prompt before LLM call.
|
||||||
|
// Stored in state so imprint_respond can consume it.
|
||||||
|
// TODO: wire directly into imprint_respond when it accepts a system_override param.
|
||||||
|
// ISSUE 3 TODO: no semantic/embedding crisis detection. Keyword-only means signals
|
||||||
|
// evading the phrase list pass through with zero augmentation. Semantic layer is a
|
||||||
|
// separate architectural decision requiring embedding inference on every message.
|
||||||
|
let augmented_addendum: String = safety_augment_system("", raw_input)
|
||||||
|
state_set("layered_cycle_safety_system_addendum", augmented_addendum)
|
||||||
|
|
||||||
// L3: imprint responds
|
// L3: imprint responds
|
||||||
let output: String = imprint_respond(aligned, imprint_id)
|
let output: String = imprint_respond(aligned, imprint_id)
|
||||||
|
|
||||||
@@ -351,11 +370,28 @@ let snapshot_usable: Bool = local_node_count > 50
|
|||||||
|
|
||||||
if using_http_engram && !snapshot_usable {
|
if using_http_engram && !snapshot_usable {
|
||||||
// First boot or empty/corrupt snapshot: seed from HTTP Engram.
|
// First boot or empty/corrupt snapshot: seed from HTTP Engram.
|
||||||
|
// Retry up to 3 times (2s sleep between attempts) to guard against a
|
||||||
|
// transient network hiccup right after entrypoint.sh health check passes.
|
||||||
|
// An empty nodes response silently loads a zero-node graph; validate first.
|
||||||
|
// TODO(reliability): replace sleep_ms retry with non-blocking backoff.
|
||||||
println("[soul] engram -> HTTP " + engram_url_raw + " (no local snapshot, first boot)")
|
println("[soul] engram -> HTTP " + engram_url_raw + " (no local snapshot, first boot)")
|
||||||
let nodes_json: String = http_get(engram_url_raw + "/api/nodes?limit=10000")
|
let fetch_attempt: Int = 0
|
||||||
let edges_json: String = http_get(engram_url_raw + "/api/edges")
|
while fetch_attempt < 3 {
|
||||||
let nodes_part: String = if str_eq(nodes_json, "") { "[]" } else { nodes_json }
|
let fetch_attempt = fetch_attempt + 1
|
||||||
let edges_part: String = if str_eq(edges_json, "") { "[]" } else { edges_json }
|
let n: String = http_get(engram_url_raw + "/api/nodes?limit=10000")
|
||||||
|
let e: String = http_get(engram_url_raw + "/api/edges")
|
||||||
|
let nodes_ok: Bool = !str_eq(n, "") && str_starts_with(n, "[") && str_len(n) > 2
|
||||||
|
if nodes_ok {
|
||||||
|
state_set("_boot_nodes_json", n)
|
||||||
|
state_set("_boot_edges_json", e)
|
||||||
|
let fetch_attempt = 3
|
||||||
|
} else {
|
||||||
|
println("[soul] boot HTTP fetch attempt " + int_to_str(fetch_attempt) + " failed --- retrying in 2s")
|
||||||
|
sleep_ms(2000)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let nodes_json: String = state_get("_boot_nodes_json")
|
||||||
|
let edges_json: String = state_get("_boot_edges_json")
|
||||||
let snapshot_data: String = "{\"nodes\":" + nodes_part + ",\"edges\":" + edges_part + "}"
|
let snapshot_data: String = "{\"nodes\":" + nodes_part + ",\"edges\":" + edges_part + "}"
|
||||||
let tmp_path: String = "/tmp/soul-engram-" + soul_cgi_id + ".json"
|
let tmp_path: String = "/tmp/soul-engram-" + soul_cgi_id + ".json"
|
||||||
fs_write(tmp_path, snapshot_data)
|
fs_write(tmp_path, snapshot_data)
|
||||||
|
|||||||
Reference in New Issue
Block a user