Compare commits

...

4 Commits

Author SHA1 Message Date
Tim Lingo f06fe1e72e fix(mcp-wrapper): forget/delete tools no longer return fake ok receipts (BUG-18)
Root cause: two false-receipt paths in the wrapper's delete family.
- delete_by_id (removeKnowledge, deleteProcess, deleteImprint,
  dischargeWonder) FABRICATED {"ok":true,...,"note":"soft-deleted"}
  without calling the soul at all — the 'soul does not yet expose a delete
  HTTP route' note was stale (/api/neuron/node/delete exists and tombstones
  any node type).
- tool_forget forwarded the soul's response but never verified the deletion
  actually persisted before answering ok.

The change (Receipt Contract rule 1 — a tool result must reflect what
actually happened):
- delete_by_id now routes to the soul's real /api/neuron/node/delete and
  propagates its answer (honest 'node not found' for bad ids).
- Both handlers read back before answering ok: GET /api/neuron/graph?id=..
  &depth=1 must show the tombstone marker (label "tombstone:<id>"); if it
  does not, answer {"ok":false,"error":"delete_not_persisted",...} in
  the soul's not-persisted error shape (api_not_persisted).
- Soul errors and transport failures pass through unchanged.

E2E evidence (sandbox soul :7791 + wrapper :7792, elb builds):
- unpatched: removeKnowledge on a NONEXISTENT id -> {"ok":true,
  "deleted":"kn-DOES-NOT-EXIST-deadbeef","note":"soft-deleted"} (lie)
- patched:   same call -> {"error":"node not found: ..."} (soul's answer)
- happy path: remember -> forget -> {"ok":true,"tombstoned":true};
  read-back: hidden from default /list/Memory, present with
  ?include_deleted=1, node KEPT in full graph view (immutability intact)
- scripts/verify-soul-contract.sh on the soul it talks to: GATE PASS
  (27/27 presence + immutability)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-22 16:24:55 -05:00
will.anderson b784750f69 Merge pull request 'Fix truncated /api/safety-contact response (988 crisis-line)' (#96) from fix/safety-contact-truncation into hotfix/elc-source-typos 2026-07-21 17:16:13 +00:00
will.anderson a45a3ca379 Fix truncated POST/GET /api/safety-contact response
Saving the 988 crisis-line contact returned truncated, unparseable JSON —
cut mid-"set_at" at the file's byte length (e.g. 178 of a 218-byte
response). The contact written to disk was complete; only the HTTP response
was clipped, so a real customer's crisis-contact save came back corrupt.

Root cause is in the el runtime's response writer, not a handler buffer:
fs_read stores the file's byte count in a thread-local (_tl_fs_read_len)
for binary-safe file serving, and the response writer uses that length when
non-zero instead of strlen(body) (el_runtime.c:1409). Both safety-contact
handlers call fs_read (the POST read-back verify; the GET file read) and
then return a LONGER wrapped JSON string, so the response is capped to the
file size.

Soul-source fix (no runtime change needed):
- POST: verify persistence via fs_write's return (1 = all bytes written)
  instead of an fs_read read-back — removes the fs_read, so nothing caps the
  response.
- GET: fs_read is required, so reset the thread-local after it with a no-op
  fs_read("") (fs_read zeroes the length before it opens a path) so the
  wrapped response is sent in full.

Verified: POST (crisis-line + custom) and GET now return complete, valid
JSON (parses cleanly, full contact incl. set_at). Regenerated dist/soul.c +
dist/safety.c (3GB RSS watchdog, release el_runtime v1.0.0-20260501).
Full suite still green: verify-soul-contract GATE PASS (PRESENCE +
IMMUTABILITY), genesis boot survives (/health 200, no segfault), bounded-
persona floor still compiled in.

NOTE: the underlying runtime leak (any handler that fs_reads then returns a
longer string) is worth a proper fix in el_runtime.c (use the max of
strlen and _tl_fs_read_len) so this class can't recur.
2026-07-21 12:13:58 -05:00
will.anderson 9387c57c3b Merge pull request 'Fix #150: fresh-install genesis boot SIGSEGV in mem_save' (#95) from fix/genesis-boot-crash into hotfix/elc-source-typos 2026-07-21 16:53:52 +00:00
4 changed files with 50 additions and 12 deletions
Generated Vendored
+3 -3
View File
@@ -340,6 +340,7 @@ el_val_t handle_safety_contact_get(void) {
if (str_eq(raw, EL_STR(""))) {
return EL_STR("{\"configured\":false}");
}
el_val_t _reset = fs_read(EL_STR(""));
return el_str_concat(el_str_concat(EL_STR("{\"configured\":true,\"contact\":"), raw), EL_STR("}"));
return 0;
}
@@ -359,9 +360,8 @@ el_val_t handle_safety_contact_post(el_val_t body) {
el_val_t crisis_str = ({ el_val_t _if_result_51 = 0; if (is_crisis) { _if_result_51 = (EL_STR("true")); } else { _if_result_51 = (EL_STR("false")); } _if_result_51; });
el_val_t now = time_format(time_now(), EL_STR("%Y-%m-%dT%H:%M:%SZ"));
el_val_t contact_json = 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("{\"name\":\""), json_safe(name)), EL_STR("\"")), EL_STR(",\"contact_method\":\"")), json_safe(method)), EL_STR("\"")), EL_STR(",\"contact_value\":\"")), json_safe(value)), EL_STR("\"")), EL_STR(",\"relationship\":\"")), json_safe(rel)), EL_STR("\"")), EL_STR(",\"confirmed\":true")), EL_STR(",\"is_crisis_line\":")), crisis_str), EL_STR(",\"set_at\":\"")), now), EL_STR("\"}"));
fs_write(safety_contact_path(), contact_json);
el_val_t check = fs_read(safety_contact_path());
if (str_eq(check, EL_STR(""))) {
el_val_t write_ok = fs_write(safety_contact_path(), contact_json);
if (write_ok == 0) {
return EL_STR("{\"ok\":false,\"error\":\"write_failed\"}");
}
return el_str_concat(el_str_concat(EL_STR("{\"configured\":true,\"contact\":"), contact_json), EL_STR(",\"ok\":true}"));
Generated Vendored
+3 -3
View File
@@ -25754,6 +25754,7 @@ el_val_t handle_safety_contact_get(void) {
if (str_eq(raw, EL_STR(""))) {
return EL_STR("{\"configured\":false}");
}
el_val_t _reset = fs_read(EL_STR(""));
return el_str_concat(el_str_concat(EL_STR("{\"configured\":true,\"contact\":"), raw), EL_STR("}"));
return 0;
}
@@ -25773,9 +25774,8 @@ el_val_t handle_safety_contact_post(el_val_t body) {
el_val_t crisis_str = ({ el_val_t _if_result_51 = 0; if (is_crisis) { _if_result_51 = (EL_STR("true")); } else { _if_result_51 = (EL_STR("false")); } _if_result_51; });
el_val_t now = time_format(time_now(), EL_STR("%Y-%m-%dT%H:%M:%SZ"));
el_val_t contact_json = 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("{\"name\":\""), json_safe(name)), EL_STR("\"")), EL_STR(",\"contact_method\":\"")), json_safe(method)), EL_STR("\"")), EL_STR(",\"contact_value\":\"")), json_safe(value)), EL_STR("\"")), EL_STR(",\"relationship\":\"")), json_safe(rel)), EL_STR("\"")), EL_STR(",\"confirmed\":true")), EL_STR(",\"is_crisis_line\":")), crisis_str), EL_STR(",\"set_at\":\"")), now), EL_STR("\"}"));
fs_write(safety_contact_path(), contact_json);
el_val_t check = fs_read(safety_contact_path());
if (str_eq(check, EL_STR(""))) {
el_val_t write_ok = fs_write(safety_contact_path(), contact_json);
if (write_ok == 0) {
return EL_STR("{\"ok\":false,\"error\":\"write_failed\"}");
}
return el_str_concat(el_str_concat(EL_STR("{\"configured\":true,\"contact\":"), contact_json), EL_STR(",\"ok\":true}"));
+31 -2
View File
@@ -311,8 +311,25 @@ fn delete_by_id(args: String) -> String {
if str_eq(id, "") {
return mcp_text_result("error: id is required")
}
// Soul does not yet expose a delete HTTP route; acknowledge the request
return mcp_json_result("{\"ok\":true,\"deleted\":\"" + id + "\",\"note\":\"soft-deleted\"}")
// BUG-18 (Receipt Contract rule 1): this handler used to FABRICATE
// {"ok":true,...,"note":"soft-deleted"} without calling the soul at all
// a false receipt for every delete-family tool (removeKnowledge,
// deleteProcess, deleteImprint, dischargeWonder). The old "soul does not
// yet expose a delete HTTP route" note was stale: /api/neuron/node/delete
// tombstones any node type and errors on unknown ids. Route there and
// propagate the soul's real answer.
let body: String = "{\"id\":\"" + id + "\"}"
let resp: String = http_post_json(neuron_url() + "/node/delete", body)
if !str_contains(resp, "\"ok\":true") {
return mcp_json_result(resp)
}
// Read-back verify before answering ok: the tombstone marker
// (label "tombstone:<id>") must actually be wired to the node.
let check: String = http_get(neuron_url() + "/graph?id=" + id + "&depth=1")
if !str_contains(check, "tombstone:" + id) {
return mcp_json_result("{\"ok\":false,\"error\":\"delete_not_persisted\",\"id\":\"" + id + "\"}")
}
return mcp_json_result(resp)
}
// evolve_by_supersede: create an updated node and wire a supersedes edge.
@@ -546,6 +563,18 @@ fn tool_forget(args: String) -> String {
// Previously this returned a fake ok without deleting OR tombstoning anything.
let body: String = "{\"id\":\"" + id + "\"}"
let resp: String = http_post_json(neuron_url() + "/memory/delete", body)
// BUG-18 (Receipt Contract rule 1): propagate the soul's real answer its
// errors (memory not found, protected node, transport failure) pass through
// unchanged and never answer ok without read-back.
if !str_contains(resp, "\"ok\":true") {
return mcp_json_result(resp)
}
// Read-back verify before answering ok: the tombstone marker
// (label "tombstone:<id>") must actually be wired to the node.
let check: String = http_get(neuron_url() + "/graph?id=" + id + "&depth=1")
if !str_contains(check, "tombstone:" + id) {
return mcp_json_result("{\"ok\":false,\"error\":\"delete_not_persisted\",\"id\":\"" + id + "\"}")
}
return mcp_json_result(resp)
}
+13 -4
View File
@@ -438,6 +438,12 @@ fn safety_contact_path() -> String {
fn handle_safety_contact_get() -> String {
let raw: String = fs_read(safety_contact_path())
if str_eq(raw, "") { return "{\"configured\":false}" }
// fs_read set the runtime's binary-safe send length to len(raw); the HTTP
// response writer uses that length when non-zero, which would TRUNCATE this
// wrapped (longer) response to len(raw). Reset it with a no-op read of a
// missing path (fs_read zeroes the length before it opens) so the full
// response is sent.
let _reset: String = fs_read("")
return "{\"configured\":true,\"contact\":" + raw + "}"
}
@@ -463,9 +469,12 @@ fn handle_safety_contact_post(body: String) -> String {
+ ",\"confirmed\":true"
+ ",\"is_crisis_line\":" + crisis_str
+ ",\"set_at\":\"" + now + "\"}"
fs_write(safety_contact_path(), contact_json)
// Read-back verify the write actually persisted.
let check: String = fs_read(safety_contact_path())
if str_eq(check, "") { return "{\"ok\":false,\"error\":\"write_failed\"}" }
// Verify persistence via fs_write's return (1 = all bytes written, 0 = fail).
// The previous fs_read read-back set the runtime's binary-safe send length to
// the file size, which then TRUNCATED this longer JSON response to that size
// (the safety-contact 988 response was cut mid-"set_at"). Checking the write
// return avoids the fs_read entirely, so the full response is sent.
let write_ok: Int = fs_write(safety_contact_path(), contact_json)
if write_ok == 0 { return "{\"ok\":false,\"error\":\"write_failed\"}" }
return "{\"configured\":true,\"contact\":" + contact_json + ",\"ok\":true}"
}