Self-hosted workflows for coding-agent delivery. Orchestrate CodeBuddy, Codex and Claude Code with scripts and human approval gates. Includes Local workflows for coding assistants.
JavaScript agent-orchestrationagentic-workflowai-agentsai-codingclaude-codecode-reviewcodebuddycodexcoding-agentscursordeveloper-toolshuman-on-the-loopllmmcpmulti-agentsdlcself-hostedsopworkflow-automationworkflow-engine
fix(chat): remove a conversation's shared native root when it is deleted (#601)
Robert0622132698262ba6
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 111bd8ce..6adb3baa 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -10,6 +10,7 @@ Platform releases use `vX.Y.Z` tags and publish `ghcr.io/tencent/loopforge`. Loo- SOP sandboxes of the published image install OpenCode, Kimi Code and Pi on first use, as they already did for Claude Code. An SOP role on one of these CLIs used to fail with `exec: <cli>: not found` (exit 127) even after a conversation installed it.- Run logs and telemetry redact every environment variable ending in `_API_KEY`, `_TOKEN`, `_SECRET` or `_PASSWORD`. Agent CLI keys such as `DEEPSEEK_API_KEY`, and `AGENTFLOW_CLI_API_KEY` used with a custom Base URL, used to appear in clear text in the `docker exec` line of an SOP run log, readable by project members. Rotate a key that ran an SOP role before this release.- Upgrading with `./start.sh pull` now re-applies the schema pieces gorm AutoMigrate cannot create: the `run_telemetry.adapter` and `run_logs.level` generated columns from `migrations/001_run_obs_generated_columns.sql`, and the `INSERT IGNORE` starter catalog. A data volume from an older release no longer fails with `Error 1054 Unknown column 'adapter'` the first time someone opens a run detail. The installer and the upgrade command share one script, `scripts/install-schema-extensions.sh`, and a failed step stops the command with the migration file an operator has to run by hand.+- Deleting a conversation removes its shared native root (`shared/<hash>`). It used to stay on disk, about 73 MB each because every root holds its own CLI home with the CodeBuddy plugin marketplace, so a scheduled task that replaces its previous run on every cycle grew the disk by one root per run. The daily session janitor also removes roots left behind earlier once their conversation is gone and they have not changed for a day.- Native conversation roots move to `AGENTFLOW_CONVERSATION_DIR`, which `compose.yaml` sets to `${LOOPFORGE_DATA_DIR}/conversations`. They used to sit in the `platform-data` volume under `/data/assistant`, a path the host Docker daemon does not have, so opening a conversation workspace on a Compose installation failed with `mkdirat ... read-only file system`. Attachments and other per-user assistant data stay in `/data/assistant`; nothing needs moving. A customised `compose.yaml` needs the same setting. `docs/deployment.md` now spells out the upgrade steps: update the checkout, then `./start.sh pull`.- The built-in `generic-backend` Dockerfile includes `openssh-client` again, matching the platform image, so a `generic-docker` workspace or SOP sandbox starts on the platform image instead of building `agentflow-img-*` on first use. #207 added the package to the platform image but not to the starter catalog. The installer and `./start.sh pull` run `migrations/031_generic_backend_openssh.sql`, which updates the row only while it still holds the unedited previous default.- `docs/deployment.md` splits `migrations/` into scripts the installer already covers, scripts an upgrade must run once, and scripts that only backfill existing rows.diff --git a/internal/httpapi/assistant_session.go b/internal/httpapi/assistant_session.goindex 0671fa67..73393aea 100644--- a/internal/httpapi/assistant_session.go+++ b/internal/httpapi/assistant_session.go@@ -547,6 +547,9 @@ func deleteAssistantConversation(st *repo.Store, userID int64, id string) errorif err != nil {return os.ErrNotExist}+ // Session ids are unique across owners, so once the owner's row is gone no+ // participant can open the shared root again.+ _ = os.RemoveAll(assistantSharedSessionRoot(id))return nil}diff --git a/internal/httpapi/assistant_session_cleanup.go b/internal/httpapi/assistant_session_cleanup.goindex 8d202b8f..32823611 100644--- a/internal/httpapi/assistant_session_cleanup.go+++ b/internal/httpapi/assistant_session_cleanup.go@@ -2,10 +2,12 @@ package httpapiimport ("context"+ "encoding/hex""flag""fmt""log""os"+ "path/filepath""sort""strings""time"@@ -45,6 +47,9 @@ func (h *assistantHandlers) startSessionJanitor(ctx context.Context) {if n := h.pruneScheduledAssistantSessions(time.Now().UTC()); n > 0 {log.Printf("assistant session cleanup: removed %d scheduled conversations", n)}+ if n := h.pruneOrphanSharedRoots(time.Now()); n > 0 {+ log.Printf("assistant session cleanup: removed %d orphaned shared conversation roots", n)+ }timer.Reset(assistantSessionJanitorEvery)}}@@ -95,6 +100,55 @@ func (h *assistantHandlers) pruneScheduledAssistantSessions(now time.Time) int {return removed}+// sharedRootOrphanAge leaves a root alone while the conversation that owns it+// may still be in the middle of being saved.+const sharedRootOrphanAge = 24 * time.Hour++// pruneOrphanSharedRoots removes shared native roots whose conversation no+// longer exists. Deleting a conversation used to leave its shared root behind,+// and each one holds a full CLI home. An unreadable session list skips the run.+func (h *assistantHandlers) pruneOrphanSharedRoots(now time.Time) int {+ if h == nil || h.repo == nil {+ return 0+ }+ base := filepath.Dir(assistantSharedSessionRoot("-"))+ entries, err := os.ReadDir(base)+ if err != nil {+ return 0+ }+ ids, err := h.repo.AssistantSessionIDs()+ if err != nil {+ log.Printf("assistant shared root cleanup skipped: %v", err)+ return 0+ }+ live := make(map[string]bool, len(ids))+ for _, id := range ids {+ live[filepath.Base(assistantSharedSessionRoot(id))] = true+ }+ removed := 0+ for _, entry := range entries {+ name := entry.Name()+ if !entry.IsDir() || live[name] || !sharedRootName(name) {+ continue+ }+ info, err := entry.Info()+ if err != nil || now.Sub(info.ModTime()) < sharedRootOrphanAge {+ continue+ }+ if err := os.RemoveAll(filepath.Join(base, name)); err != nil {+ log.Printf("assistant shared root cleanup %s: %v", name, err)+ continue+ }+ removed+++ }+ return removed+}++func sharedRootName(name string) bool {+ _, err := hex.DecodeString(name)+ return err == nil && len(name) == 64 && strings.ToLower(name) == name+}+// deleteScheduledSessions removes every conversation a deleted scheduled task// left behind; keepID preserves the run that is being written right now.func (h *assistantHandlers) deleteScheduledSessions(taskID, keepID string) {diff --git a/internal/httpapi/assistant_session_source_test.go b/internal/httpapi/assistant_session_source_test.goindex 59a2901b..7c05fc50 100644--- a/internal/httpapi/assistant_session_source_test.go+++ b/internal/httpapi/assistant_session_source_test.go@@ -2,6 +2,8 @@ package httpapiimport ("context"+ "os"+ "path/filepath""testing""time"@@ -159,3 +161,100 @@ func TestPruneScheduledSessionsKeepsLatestAndLeavesSOPAlone(t *testing.T) {}}}++func writeSharedRoot(t *testing.T, id string, modified time.Time) string {+ t.Helper()+ root := assistantSharedSessionRoot(id)+ file := filepath.Join(root, "home", ".codebuddy", "plugins", "marketplace.json")+ if err := os.MkdirAll(filepath.Dir(file), 0o700); err != nil {+ t.Fatal(err)+ }+ if err := os.WriteFile(file, []byte("{}"), 0o600); err != nil {+ t.Fatal(err)+ }+ if err := os.Chtimes(root, modified, modified); err != nil {+ t.Fatal(err)+ }+ return root+}++// A scheduled task deletes its previous run every time, so a shared root left+// behind by each deletion grows the disk by a whole CLI home per run.+func TestDeletingConversationRemovesItsSharedRoot(t *testing.T) {+ t.Setenv("AGENTFLOW_ASSISTANT_SESSION_DIR", t.TempDir())+ st, err := repo.OpenTest()+ if err != nil {+ t.Fatal(err)+ }+ t.Cleanup(st.Close)+ for _, login := range []string{"shared-owner", "shared-other"} {+ if err := st.PutUser(domain.User{LoginName: login, CodeBuddyAPIKey: "test-key"}); err != nil {+ t.Fatal(err)+ }+ }+ owner, _ := st.UserByLoginName("shared-owner")+ other, _ := st.UserByLoginName("shared-other")+ now := time.Now()+ for _, id := range []string{"run-1", "run-2"} {+ if err := st.PutAssistantSession(owner.ID, domain.AssistantSession{ID: id, Source: domain.AssistantSourceScheduled, TaskID: "job-1", CreatedAt: now, UpdatedAt: now}); err != nil {+ t.Fatal(err)+ }+ }+ first, second := writeSharedRoot(t, "run-1", now), writeSharedRoot(t, "run-2", now)+ h := &assistantHandlers{deps: &deps{repo: st}}++ if err := h.deleteConversation(other.ID, "run-1"); err == nil {+ t.Fatal("a user who does not own the conversation deleted it")+ }+ if _, err := os.Stat(first); err != nil {+ t.Fatalf("a refused deletion removed the shared root: %v", err)+ }+ h.deleteScheduledSessionsExcept("job-1", "run-2")+ if _, err := os.Stat(first); !os.IsNotExist(err) {+ t.Fatalf("the deleted run left its shared root: %v", err)+ }+ if _, err := os.Stat(second); err != nil {+ t.Fatalf("the kept run lost its shared root: %v", err)+ }+}++func TestPruneOrphanSharedRootsKeepsLiveAndRecentRoots(t *testing.T) {+ t.Setenv("AGENTFLOW_ASSISTANT_SESSION_DIR", t.TempDir())+ st, err := repo.OpenTest()+ if err != nil {+ t.Fatal(err)+ }+ t.Cleanup(st.Close)+ if err := st.PutUser(domain.User{LoginName: "orphan-owner", CodeBuddyAPIKey: "test-key"}); err != nil {+ t.Fatal(err)+ }+ owner, _ := st.UserByLoginName("orphan-owner")+ now := time.Now()+ old := now.Add(-2 * sharedRootOrphanAge)+ if err := st.PutAssistantSession(owner.ID, domain.AssistantSession{ID: "live", CreatedAt: old, UpdatedAt: old}); err != nil {+ t.Fatal(err)+ }+ live := writeSharedRoot(t, "live", old)+ orphan := writeSharedRoot(t, "deleted-long-ago", old)+ recent := writeSharedRoot(t, "being-saved", now)+ foreign := filepath.Join(filepath.Dir(live), "not-a-root")+ if err := os.MkdirAll(foreign, 0o700); err != nil {+ t.Fatal(err)+ }+ if err := os.Chtimes(foreign, old, old); err != nil {+ t.Fatal(err)+ }++ h := &assistantHandlers{deps: &deps{repo: st}}+ if removed := h.pruneOrphanSharedRoots(now); removed != 1 {+ t.Fatalf("removed = %d, want 1", removed)+ }+ if _, err := os.Stat(orphan); !os.IsNotExist(err) {+ t.Fatalf("orphaned root kept: %v", err)+ }+ for _, path := range []string{live, recent, foreign} {+ if _, err := os.Stat(path); err != nil {+ t.Fatalf("%s removed: %v", path, err)+ }+ }+}diff --git a/internal/repo/assistant_session_cleanup.go b/internal/repo/assistant_session_cleanup.goindex 018130a9..4245c9a7 100644--- a/internal/repo/assistant_session_cleanup.go+++ b/internal/repo/assistant_session_cleanup.go@@ -21,6 +21,13 @@ func (r *AssistantRepo) ListAssistantSessionsBySource(source string) []domain.Asreturn r.assistantSessionsBy("source = ?", source)}+// AssistantSessionIDs lists every stored conversation id.+func (r *AssistantRepo) AssistantSessionIDs() ([]string, error) {+ var ids []string+ err := r.DB.Table("assistant_sessions").Pluck("id", &ids).Error+ return ids, err+}+// ListAssistantSessionsByTask returns the conversations a scheduled task or// assistant task produced, so a new run can keep only its own.func (r *AssistantRepo) ListAssistantSessionsByTask(source, taskID string) []domain.AssistantSession {