zachzhao1984 on Discord: some agents' sessions can't be deleted on the Sessions page. Droid was one of them. What changed (internal/sessions/manage.go): "droid" is Deletable. A Droid session goes to the trash whole: its transcript, its .settings.json beside it, and a subagent's two files. Nothing of another session goes with it, and Restore puts them all back. A session written to just now is left alone (ErrActive), as for every other agent. The package comment now also says why OpenCode, ZCode, Grok Build, Kimi Code and Claude Desktop (Cowork) sessions stay list-only. Guarded by internal/sessions/droid_manage_test.go (TestDroidDeleteRestore). Broken by hand: - "droid" taken out of Deletable: FAIL "droid not deletable". - The .settings.json no longer added to the session's paths: FAIL "a session just written: <nil>". The settings file isn't counted as the session's, so a write to it no longer holds the delete back. Record for this push: 13 commits on origin/mainca4a1cde0, head tree539c84e92. Go 1.26.8, sandbox HOME, GOMODCACHE/GOCACHE pinned. The full Go run and vet were at tree d6393dfc8, the same Go code as this head: only app.js comments (cut under the core script budget) and one ja string changed after it. - gofmt -l: nothing. go build ./...; go vet ./... (darwin), GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet ./...: clean. - go test -timeout 45m ./..., through tee, one suite on the machine: 68 packages ok. The one red was internal/gui's TestCoreScriptBudget: app.js 1,335,314 > 1,335,000, since main grew app.js under the stack. The autoscroll commit's own comments were cut (to 1,334,629) rather than the budget raised, and go test -count=1 ./internal/gui is ok at this head (113s). Packages the run took from Go's test cache had the same inputs. - GUI: the 18 files this stack touches or names, both engines, 202 of 204 pass (tree068acf128, this push less the last commit). The two reds: gui-ja, red on main sincec2636b7b5and fixed by this push's last commit (gui-ja and i18n-keys 6 of 6 there), and usage-fold's chromium "several accounts" (#2163, red on main the same way). - internal/sessions ok, TestDroidDeleteRestore with it. - sessions-manage and sessions-folder-delete, red in the whole run under load, pass alone at the stack and on main (#3294, #2218). The whole GUI suite ran at 1c1fc7183 (this stack's first 12 commits on0ddcf28a1): 11713 of 11769 pass. Each of the 21 red files was then run alone at the stack and at origin/main8278fd9b0. Eight are red the same way on main: plugin-card-update (#3079), quota-count-wrap and quota-name-translated (#2228), s3-sync (#2448), usage-agents-hide (#2276), usage-checkin (#3091), usage-fold's chromium "several accounts" (#2163), usage-ledger (#3104). The other 13 pass alone on both and were red only under that run's load (50 to 335): currency #3101, plugin-github #3218, provider-fetch-again #3292, rest-try-now #2564, routing-auto-reset #3293, routing-keys-fold #1612, routing-steady #1804, routing-wb-restricted #1905, sessions-folder-delete #2218, sessions-manage #3294, switch-only #3295, text-size #1866, usage-pack #3296. Not tried: deleting a real Droid session and then opening Droid. No sessions are in this machine's ~/.factory. The installed droid 0.231.0 binary names no sessions index (grep for session(s)-index, sessionIndex, session(s)_index found nothing), so nothing is known to be left pointing at a deleted session. Not tried on Windows or WSL.
94 lines
2.7 KiB
Go
94 lines
2.7 KiB
Go
package sessions
|
|
|
|
import (
|
|
"errors"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func ageTree(root string) {
|
|
old := time.Now().Add(-24 * time.Hour)
|
|
filepath.WalkDir(root, func(p string, d os.DirEntry, err error) error {
|
|
if err == nil {
|
|
os.Chtimes(p, old, old)
|
|
}
|
|
return nil
|
|
})
|
|
}
|
|
|
|
// zachzhao1984 on Discord: some agents' sessions can't be deleted on the
|
|
// Sessions page. Droid's are files of its own (a transcript and its
|
|
// .settings.json, a subagent's beside them; the session index Droid keeps
|
|
// is a cache it rebuilds from them), so one goes to the trash whole: its
|
|
// transcript, its settings, its subagent's two, and nothing of another
|
|
// session's. Restore puts them back.
|
|
func TestDroidDeleteRestore(t *testing.T) {
|
|
manageSetup(t)
|
|
home := filepath.Join(t.TempDir(), "droid-home")
|
|
t.Setenv("FACTORY_HOME_OVERRIDE", home)
|
|
putDroid(t, home)
|
|
ageTree(home)
|
|
Reset()
|
|
|
|
if !Deletable("droid") {
|
|
t.Fatal("droid not deletable")
|
|
}
|
|
m, ok := findManaged(ListAgent("droid"), droidMain)
|
|
if !ok || !m.Deletable || m.Files != 2 {
|
|
t.Fatalf("listed as %+v", m)
|
|
}
|
|
dir := filepath.Join(home, ".factory", "sessions", "-work-droid")
|
|
mine := []string{
|
|
filepath.Join(dir, droidMain+".jsonl"), filepath.Join(dir, droidMain+".settings.json"),
|
|
filepath.Join(dir, droidSub+".jsonl"), filepath.Join(dir, droidSub+".settings.json"),
|
|
}
|
|
others := []string{
|
|
filepath.Join(dir, droidFork+".jsonl"), filepath.Join(dir, droidFork+".settings.json"),
|
|
filepath.Join(home, ".factory", "sessions", droidOld+".jsonl"), filepath.Join(home, ".factory", "settings.json"),
|
|
}
|
|
|
|
// one being written to is left alone
|
|
now := time.Now()
|
|
os.Chtimes(mine[3], now, now)
|
|
if _, err := Delete("droid", droidMain); !errors.Is(err, ErrActive) {
|
|
t.Fatalf("a session just written: %v", err)
|
|
}
|
|
ageTree(home)
|
|
|
|
tr, err := Delete("droid", droidMain)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(tr.Items) != 4 || tr.Cwd != "/work/droid" || tr.Title != "Login bug" {
|
|
t.Fatalf("trashed %+v, want its transcript and settings and its subagent's", tr)
|
|
}
|
|
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)
|
|
}
|
|
}
|
|
if _, ok := findManaged(ListAgent("droid"), droidMain); 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 m, ok := findManaged(ListAgent("droid"), droidMain); !ok || m.Title != "Login bug" || m.Files != 2 {
|
|
t.Fatalf("the restored session: %+v", m)
|
|
}
|
|
}
|