Let people forget a conversation, and make retention actually expire things
CI / test (push) Successful in 1m38s

Two halves of keeping the promise that storing makes.

DELETE /v1/threads/{id} is a client endpoint, not an admin one: the person who
said the thing should be able to unsay it, and making them ask an operator
would mean the operator reads it first. Deleting a thread in another project
answers exactly as deleting one that never existed does — two answers would
let a caller map which ids are real in projects they cannot read, and this one
would do it by trying to destroy them.

And something now runs the pruner. Without it "we keep conversations for 24
hours" was a comment rather than a promise: the rows would accumulate and the
number a project chose would describe nothing. Hourly, and once at startup,
because a gateway that has been down for a week should not wait another hour
before honouring a window that expired while it was off.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ilker ManapandClaude Opus 5 committed 2026-09-18 11:52:06 +02:00
1 parent 9eb321ae3e
commit d26a30471e
4 files changed
+150

No files matched your search

+73
View File
@@ -223,3 +223,76 @@ func TestWithoutAThreadNothingIsStoredAtAll(t *testing.T) {
}
})
}
// forget calls the delete endpoint the way a client would.
func (h *harness) forget(t *testing.T, key, thread string) int {
t.Helper()
req, err := http.NewRequestWithContext(context.Background(), http.MethodDelete,
h.router.URL+"/v1/threads/"+thread, nil)
if err != nil {
t.Fatal(err)
}
req.Header.Set("Authorization", "Bearer "+key)
resp, err := http.DefaultClient.Do(req)
if err != nil {
t.Fatal(err)
}
defer resp.Body.Close()
_, _ = io.Copy(io.Discard, resp.Body)
return resp.StatusCode
}
func TestSomeoneCanUnsayWhatTheySaid(t *testing.T) {
path, mint := provision(t)
key := mint(t, "user")
enableThreads(t, path, 24)
h := start(t, 2, authConfig(path))
if code, _, msg := h.say(t, key, testModel, "th1", "please forget this"); code != http.StatusOK {
t.Fatalf("%d %s", code, msg)
}
if turns := storedTurns(t, path, "th1"); len(turns) == 0 {
t.Fatal("nothing was stored to delete")
}
if code := h.forget(t, key, "th1"); code != http.StatusNoContent {
t.Fatalf("deleting the thread returned %d", code)
}
withStore(t, path, func(s *store.SQLite) {
if _, err := s.Thread(context.Background(), "proj", "th1"); err == nil {
t.Error("the conversation survived being deleted")
}
})
}
func TestDeletingSomeoneElsesThreadLooksLikeDeletingNothing(t *testing.T) {
// The same answer as a thread that never existed. Two answers would let a
// caller map which ids are real in projects they cannot read — and this
// one would do it by trying to destroy them.
path, mint := provision(t)
mine := mint(t, "mine")
enableThreads(t, path, 24)
withStore(t, path, func(s *store.SQLite) {
if err := s.PutProject(context.Background(),
store.Project{ID: "other", TeamID: "team", Name: "Other"}); err != nil {
t.Fatal(err)
}
})
theirs := mint(t, "theirs", func(k *store.Key) { k.ProjectID = "other" })
h := start(t, 2, authConfig(path))
if code, _, msg := h.say(t, mine, testModel, "th1", "mine alone"); code != http.StatusOK {
t.Fatalf("%d %s", code, msg)
}
if code := h.forget(t, theirs, "th1"); code != http.StatusNotFound {
t.Errorf("deleting another project's thread returned %d", code)
}
if code := h.forget(t, theirs, "never-existed"); code != http.StatusNotFound {
t.Errorf("deleting a missing thread returned a different code: %d", code)
}
// And it is still there.
if turns := storedTurns(t, path, "th1"); len(turns) == 0 {
t.Error("another project destroyed a conversation it could not read")
}
}