Compare commits

..

1 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
2 changed files with 33 additions and 28 deletions
+2 -26
View File
@@ -1706,17 +1706,7 @@ fn dispatch_tool(tool_name: String, tool_input: String) -> String {
if !path_within_root(path, root) {
return json_safe("denied: path is outside the agent workspace root")
}
// BUG-29 (Receipt Contract rule 1): fs_write's result was ignored, so a
// failed write (missing/unwritable dir, disk full) still returned
// {"ok":true} a false receipt fed straight to the model. Check the
// return (1 = all bytes written, 0 = fail), the same honest-write pattern
// as the safety-contact fix. A read-back via fs_read is deliberately NOT
// used here: fs_read arms the runtime's one-shot binary send length,
// which truncated longer HTTP responses (the #96 failure mode).
let write_ok: Int = fs_write(resolve_in_root(path, root), content)
if write_ok == 0 {
return json_safe("{\"error\":\"write failed\"}")
}
fs_write(resolve_in_root(path, root), content)
return json_safe("{\"ok\":true}")
}
if str_eq(tool_name, "web_get") {
@@ -1794,22 +1784,8 @@ fn dispatch_tool(tool_name: String, tool_input: String) -> String {
if str_eq(content, "") {
return json_safe("{\"error\":\"file not found\"}")
}
// BUG-29 (Receipt Contract rule 1): when old_text was absent (or empty),
// str_replace was a silent no-op and the handler still claimed ok:true
// a false receipt. Verify the text is actually present before replacing.
if str_eq(old_text, "") {
return json_safe("{\"error\":\"old_text is required\"}")
}
if !str_contains(content, old_text) {
return json_safe("{\"error\":\"old_text not found in file\"}")
}
let updated: String = str_replace(content, old_text, new_text)
// BUG-29: the fs_write result was also unchecked a failed write still
// returned ok:true. Same honest-write check as write_file above.
let write_ok: Int = fs_write(resolved, updated)
if write_ok == 0 {
return json_safe("{\"error\":\"write failed\"}")
}
fs_write(resolved, updated)
return json_safe("{\"ok\":true}")
}
if str_eq(tool_name, "remember") {
+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)
}