Merge pull request 'fix(routes): /api/graph/edges must not write the canonical snapshot' (#161) from fix/graph-edges-no-canonical-clobber into main
This commit was merged in pull request #161.
This commit is contained in:
@@ -420,14 +420,23 @@ fn r_api_graph_nodes(method: String, path: String, body: String) -> String {
|
||||
|
||||
@route("/api/graph/edges", "GET", "exact") @manager
|
||||
fn r_api_graph_edges(method: String, path: String, body: String) -> String {
|
||||
// TODO(reliability #8): engram_save races with awareness loop mem_save().
|
||||
// Both now use atomic write-to-temp+rename (el_runtime.c). Serialised
|
||||
// by engram_global_mu. Future: add engram_edges_json() builtin.
|
||||
let snap_path: String = env("HOME") + "/.neuron/engram/snapshot.json"
|
||||
engram_save(snap_path)
|
||||
let snap: String = fs_read(snap_path)
|
||||
let edges_raw: String = json_get_raw(snap, "edges")
|
||||
return if str_eq(edges_raw, "") { "[]" } else { edges_raw }
|
||||
// Reads edges straight from the store. No file is written or read.
|
||||
//
|
||||
// This route used to engram_save() the ENTIRE graph over
|
||||
// ~/.neuron/engram/snapshot.json — the engram server's CANONICAL store —
|
||||
// and then fs_read it back, just to answer a read query. Two defects in
|
||||
// one line: a READ route clobbering the persistence owner's canonical
|
||||
// file (the defect fixed once already, then reintroduced when the
|
||||
// hand-written dispatch block was replaced by @route dispatch and the
|
||||
// unfixed copy is the one that survived), and a 128 MB serialize +
|
||||
// reread + parse per request. Calling it on 2026-08-15 overwrote the
|
||||
// canonical snapshot and preceded an engram crash loop.
|
||||
//
|
||||
// engram_edges_json is the builtin the old TODO here asked for. Bounded
|
||||
// by default (1000) — the unbounded whole-graph read is what fell over.
|
||||
let lim: Int = api_query_int(path, "limit", 1000)
|
||||
let off: Int = api_query_int(path, "offset", 0)
|
||||
return engram_edges_json(lim, off)
|
||||
}
|
||||
|
||||
// ── GET /api/chat — legacy probe interface; body may be empty ───────────────
|
||||
|
||||
Reference in New Issue
Block a user