ysm119 (#help) could delete Codex sessions on the Sessions page but not agy's, and wanted to clear out empty ones. A delete now moves a conversation to magpie's trash the way agy's own /resume delete (F4) removes it: brain/<id>/, conversations/<id>.db with the -wal, -shm and -journal SQLite leaves beside it, and annotations/<id>.pbtxt. Restore puts them back. What agy keeps of a conversation, read from real agy 1.4.12 in a sandbox HOME against a fake Gemini endpoint (the live ~/.gemini was only read): the files above, presence/<id>.lock, a row in conversation_summaries.db, an entry in jetbox_summaries_proto.pb, and cache/last_conversations.json. agy's own delete removes the files, the row and the jetbox entry. It leaves the lock and last_conversations.json. magpie leaves the row and jetbox entry too, because agy keeps both files open and jetbox is an unknown protobuf. agy's /resume list leaves out a row whose files are gone, so it never lists a deleted conversation. A conversation agy has open is not deleted: agy flocks presence/<id>.lock for as long as it has it open, idle too, and a held lock (or one that can't be tried) is ErrActive. On Windows how agy locks it hasn't been seen, so the minute since a write decides there alone. Siblings: Hermes, Alma, OpenCode, ZCode, Cline, Grok Build, Kimi Code and Claude Desktop (Cowork) sessions still can't be deleted. Each keeps an index magpie would have to edit or leave stale; filed as #4595 with what each needs. Run at d018b9302 (on origin/mainc30d3b7b6), then rebased onto2cca11176, which changes internal/gateway only; go test ./internal/sessions passed again at the pushed head: - mote: gofmt -l internal/sessions clean; go vet ./internal/sessions (darwin, GOOS=linux -tags nogui, GOOS=windows -tags nogui); go build ./... and the linux/windows nogui builds: ok. - mote: go test -tags nogui -count=1 -timeout 45m ./...: 82 packages ok, internal/gui red only on TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and TestColdTurnsTaken (#4510), both filed before and untouched here. go test ./internal/gui alone also showed TestMainWindowCorners (#3949). - Windows (win-run): go test -run Agy ./internal/sessions: both new tests pass. TestAgySessions and TestAgyRowOnly are red there already (#4115, a /work cwd read as \work). - Real agy 1.4.12 in a sandbox HOME, with a test binary built from this tree: Delete of one of three conversations moved its brain folder, .db and .pbtxt. agy's /resume then listed 2 of 3 and Other "No conversations available". Restore brought it back, and /resume listed 3. Before this, with the files moved by hand, `agy --conversation <id>` resumed a restored conversation and appended to it. Broken by hand (each red in TestAgyDeleteRestore/TestAgyDeleteRowOnly): agy taken out of Deletable; the presence-lock check turned off (a conversation agy has open was deleted); only <id>.db moved, not its -wal/-shm (a fresh -wal wasn't seen as recent, and they'd be left behind). Not tried: agy on Windows or Linux for real; the GUI suite (no GUI file changed: the Sessions page shows Delete from /api/sessions/manage's deletable flag).
163 lines
4.9 KiB
Go
163 lines
4.9 KiB
Go
package sessions
|
|
|
|
import (
|
|
"database/sql"
|
|
"errors"
|
|
"os"
|
|
"path/filepath"
|
|
"runtime"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// agyConversation writes the files agy keeps of conversation id beside its
|
|
// brain folder, shaped as a real agy 1.4.12 left them: its trajectory
|
|
// database (SQLite, with the -wal and -shm agy leaves while it has it
|
|
// open), its annotations (title:"…" text), and its presence lock (empty).
|
|
func agyConversation(t *testing.T, dir, id string) []string {
|
|
t.Helper()
|
|
files := map[string]string{
|
|
filepath.Join("conversations", id+".db"): "SQLite format 3\x00",
|
|
filepath.Join("conversations", id+".db-wal"): "",
|
|
filepath.Join("conversations", id+".db-shm"): "\x00\x00",
|
|
filepath.Join("annotations", id+".pbtxt"): `title:"Hello there."`,
|
|
filepath.Join("presence", id+".lock"): "",
|
|
}
|
|
var out []string
|
|
for rel, body := range files {
|
|
p := filepath.Join(dir, rel)
|
|
os.MkdirAll(filepath.Dir(p), 0o755)
|
|
if err := os.WriteFile(p, []byte(body), 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
out = append(out, p)
|
|
}
|
|
return out
|
|
}
|
|
|
|
// ysm119 on Discord: agy's sessions couldn't be deleted on the Sessions
|
|
// page, Codex's could. A conversation goes to the trash as agy's own
|
|
// delete (its /resume picker's) removes it: its brain folder, its
|
|
// conversations/<id>.db with SQLite's files beside it, and its
|
|
// annotations; nothing of another conversation's, and not the summaries
|
|
// agy keeps open, whose row agy doesn't list once the files are gone.
|
|
// Restore puts them back.
|
|
func TestAgyDeleteRestore(t *testing.T) {
|
|
dir := putAgy(t)
|
|
t.Setenv("XDG_CONFIG_HOME", filepath.Join(t.TempDir(), "config"))
|
|
agyConversation(t, dir, agyTwoTurns)
|
|
others := agyConversation(t, dir, agyRead)
|
|
others = append(others, filepath.Join(dir, "brain", agyRead), filepath.Join(dir, "conversation_summaries.db"))
|
|
ageTree(dir)
|
|
Reset()
|
|
|
|
if !Deletable("agy") {
|
|
t.Fatal("agy not deletable")
|
|
}
|
|
m, ok := findManaged(ListAgent("agy"), agyTwoTurns)
|
|
if !ok || !m.Deletable {
|
|
t.Fatalf("listed as %+v", m)
|
|
}
|
|
conv := filepath.Join(dir, "conversations", agyTwoTurns+".db")
|
|
mine := []string{
|
|
filepath.Join(dir, "brain", agyTwoTurns), conv, conv + "-wal", conv + "-shm",
|
|
filepath.Join(dir, "annotations", agyTwoTurns+".pbtxt"),
|
|
}
|
|
|
|
// one being written to is left alone
|
|
now := time.Now()
|
|
os.Chtimes(conv+"-wal", now, now)
|
|
if _, err := Delete("agy", agyTwoTurns); !errors.Is(err, ErrActive) {
|
|
t.Fatalf("a conversation just written: %v", err)
|
|
}
|
|
ageTree(dir)
|
|
|
|
// and so is one a running agy has open, however long since it wrote
|
|
if runtime.GOOS != "windows" {
|
|
lock, err := os.Open(filepath.Join(dir, "presence", agyTwoTurns+".lock"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := syscallFlock(lock); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
_, err = Delete("agy", agyTwoTurns)
|
|
lock.Close()
|
|
if !errors.Is(err, ErrActive) {
|
|
t.Fatalf("a conversation agy has open: %v", err)
|
|
}
|
|
}
|
|
|
|
tr, err := Delete("agy", agyTwoTurns)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(tr.Items) != len(mine) {
|
|
t.Fatalf("trashed %+v, want %d items", tr.Items, len(mine))
|
|
}
|
|
for _, p := range mine {
|
|
if _, err := os.Lstat(p); err == nil {
|
|
t.Fatalf("%s is still there", p)
|
|
}
|
|
}
|
|
for _, p := range others {
|
|
if _, err := os.Stat(p); err != nil {
|
|
t.Fatalf("another's %s: %v", p, err)
|
|
}
|
|
}
|
|
Reset()
|
|
if _, ok := findManaged(ListAgent("agy"), agyTwoTurns); ok {
|
|
t.Fatal("still listed after the delete")
|
|
}
|
|
|
|
if _, err := Restore(tr.Key); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for _, p := range mine {
|
|
if _, err := os.Stat(p); err != nil {
|
|
t.Fatalf("%s isn't back: %v", p, err)
|
|
}
|
|
}
|
|
Reset()
|
|
if back, ok := findManaged(ListAgent("agy"), agyTwoTurns); !ok || back.Title != m.Title {
|
|
t.Fatalf("the restored conversation: %+v", back)
|
|
}
|
|
}
|
|
|
|
// A conversation listed from its row alone (no transcript, #1718) is
|
|
// deleted by its conversations/<id>.db, and its row then lists nothing.
|
|
func TestAgyDeleteRowOnly(t *testing.T) {
|
|
dir := putAgy(t)
|
|
t.Setenv("XDG_CONFIG_HOME", filepath.Join(t.TempDir(), "config"))
|
|
const id = "7d1e2f3a-4b5c-4d6e-8f90-a1b2c3d4e5f6"
|
|
db, err := sql.Open("sqlite", filepath.Join(dir, "conversation_summaries.db"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := db.Exec(`INSERT INTO conversation_summaries (conversation_id, title, last_modified_time, workspace_uris, last_user_input_time) VALUES (?, 'Older talk', '2026-10-12 04:41:53.5+00:00', '["file:///work/old"]', '2026-10-12 04:41:53.5+00:00')`, id); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
db.Close()
|
|
agyConversation(t, dir, id)
|
|
ageTree(dir)
|
|
Reset()
|
|
|
|
if m, ok := findManaged(ListAgent("agy"), id); !ok || !m.Deletable {
|
|
t.Fatalf("listed as %+v", m)
|
|
}
|
|
tr, err := Delete("agy", id)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(tr.Items) != 4 {
|
|
t.Fatalf("trashed %+v, want its database, -wal, -shm and annotations", tr.Items)
|
|
}
|
|
Reset()
|
|
if _, ok := findManaged(ListAgent("agy"), id); ok {
|
|
t.Fatal("its row is still listed")
|
|
}
|
|
if _, ok := findManaged(ListAgent("agy"), agyTwoTurns); !ok {
|
|
t.Fatal("another conversation went with it")
|
|
}
|
|
}
|