From 6240f3f72a571e31407b44825f4c467cebb909cb Mon Sep 17 00:00:00 2001 From: lotherk Date: Mon, 23 Nov 2026 00:13:49 +0000 Subject: [PATCH] session: /rm removes the embedding index too sp_session_delete() unlinked the .jsonl, meta, agent, model and the logs, but not emb/.emb. The index is derived data, yet it holds a copy of the conversation text and 42 MB had piled up in ~/.splinter: 41 orphaned files whose session was long gone. A delete that leaves a searchable copy of the deleted session behind is also the wrong promise. tests/test_session.c creates emb/s1.emb, removes the session and checks the file is gone: red before (access(F_OK) == 0), green after. make check: all tests passed, rc 0. --- src/backend/session.c | 8 ++++++++ tests/test_session.c | 26 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/backend/session.c b/src/backend/session.c index be24776..b01bc21 100644 --- a/src/backend/session.c +++ b/src/backend/session.c @@ -1475,6 +1475,14 @@ sp_session_delete(const char *dir, const char *id, struct sp_buf *err) (void)unlink(side); snprintf(side, sizeof(side), "%s/%s.model.tmp", dir, id); (void)unlink(side); + /* + * The embedding index is derived data, but it costs real space and + * nothing else ever removes it: 41 orphaned .emb files and 42 MB in + * ~/.splinter after a few weeks of /rm. A delete that leaves a copy of + * the conversation behind is also the wrong promise. + */ + snprintf(side, sizeof(side), "%s/emb/%s.emb", dir, id); + (void)unlink(side); /* logs are a convenience, not the record: a leftover must not fail this */ snprintf(logdir, sizeof(logdir), "%s/logs/%s", dir, id); (void)rm_tree(logdir); diff --git a/tests/test_session.c b/tests/test_session.c index 8d714b3..c5d5435 100644 --- a/tests/test_session.c +++ b/tests/test_session.c @@ -219,10 +219,36 @@ main(void) fclose(lf); } snprintf(path, sizeof(path), "%s/s1.jsonl", dir); + /* + * The embedding index is derived data, but it is written to + * emb/.emb and nothing ever removed it: 41 orphans and + * 42 MB in ~/.splinter after a few weeks of /rm. + */ + { + char edir[700], efile[800]; + FILE *ef; + + snprintf(edir, sizeof(edir), "%s/emb", dir); + (void)mkdir(edir, 0755); + snprintf(efile, sizeof(efile), "%s/s1.emb", edir); + ef = fopen(efile, "w"); + CHECK(ef != NULL); + if (ef != NULL) { + fputs("{\"sp_embed\":1}\n", ef); + fclose(ef); + } + CHECK(access(efile, F_OK) == 0); + } CHECK(sp_session_delete(dir, "s1", &err) == 0); CHECK(access(path, F_OK) != 0); CHECK(access(lpath, F_OK) != 0); CHECK(access(lfile, F_OK) != 0); + { + char efile[800]; + + snprintf(efile, sizeof(efile), "%s/emb/s1.emb", dir); + CHECK(access(efile, F_OK) != 0); + } { struct sp_session_brief v[4];