session: /rm removes the embedding index too

sp_session_delete() unlinked the .jsonl, meta, agent, model and the logs, but
not emb/<id>.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.
This commit is contained in:
lotherk committed 2026-11-23 00:13:49 +00:00
1 parent ea772e1851
commit 6240f3f72a
2 files changed
+34

No files matched your search

+8
View File
@@ -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);
+26
View File
@@ -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/<id>.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];