Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(daemon): default completed-task TTL to 14d on every server (#10458)
Bohan Jiang606ed4b4ed70
diff --git a/CLI_AND_DAEMON.md b/CLI_AND_DAEMON.mdindex a91a668d1d..83e58497e4 100644--- a/CLI_AND_DAEMON.md+++ b/CLI_AND_DAEMON.md@@ -391,7 +391,7 @@ Daemon behavior is configured via flags or environment variables:| GC enabled | — | `MULTICA_GC_ENABLED` | `true` (set `false`/`0` to disable) || GC scan interval | — | `MULTICA_GC_INTERVAL` | `2h` || GC TTL (done/cancelled issues) | — | `MULTICA_GC_TTL` | `24h` |-| GC completed-task TTL (issue tasks) | — | `MULTICA_GC_COMPLETED_TASK_TTL` | `14d` on Multica Cloud, `0` (disabled) elsewhere |+| GC completed-task TTL (issue tasks) | — | `MULTICA_GC_COMPLETED_TASK_TTL` | `14d` (set `0` to disable) || GC orphan TTL (no `.gc_meta.json`) | — | `MULTICA_GC_ORPHAN_TTL` | `72h` || GC artifact TTL (completed tasks) | — | `MULTICA_GC_ARTIFACT_TTL` | `12h` (set `0` to disable) || GC artifact patterns | — | `MULTICA_GC_ARTIFACT_PATTERNS` | `node_modules,.next,.turbo` |@@ -407,7 +407,7 @@ The daemon periodically scans `MULTICA_WORKSPACES_ROOT` for cleanup. The active-- **Full task cleanup** — when an issue's status is `done` or `cancelled` and has been idle for `MULTICA_GC_TTL`, the entire task directory is removed.- **Completed-task retention bound** — `MULTICA_GC_COMPLETED_TASK_TTL` fully removes an inactive issue task once its `.gc_meta.json` `completed_at` age exceeds the configured duration, even while the parent issue remains open. Cleanup waits for a successful parent-issue status check, never removes an active environment, and never fully removes a `local_directory` environment. A later rerun provisions a fresh environment instead of resuming the removed checkout.- - The default depends on where the daemon points: `14d` against Multica Cloud, and `0` (disabled, retain indefinitely) for self-host and every other origin — including cloud staging and previews. Set the variable to opt in or out on either side; an explicit `0` disables the policy on Cloud too.+ - The default is `14d` on every server, Multica Cloud and self-host alike. Set the variable to change it; an explicit `0` disables the policy and keeps every completed environment until its issue becomes `done` or `cancelled`.- Removing an environment discards work an agent left uncommitted or unpushed on its branch, along with that task's `output/` and `logs/`. The per-issue Codex session store lives outside `MULTICA_WORKSPACES_ROOT` under its own TTL, so a later rerun still resumes the agent's prior session — it just starts from a fresh checkout. Size the TTL against that trade, and keep it comfortably above `MULTICA_GC_INTERVAL`: the active-root guard protects a task that is currently running, not one whose follow-up run is queued but unclaimed.- **Orphan cleanup** — task directories with no `.gc_meta.json` (e.g. left over from a daemon crash) are removed once they exceed `MULTICA_GC_ORPHAN_TTL`.- **Artifact-only cleanup** — when a task has been completed for at least `MULTICA_GC_ARTIFACT_TTL` but the issue is still open, regenerable build outputs whose directory basename matches `MULTICA_GC_ARTIFACT_PATTERNS` are removed. The daemon also reclaims the exact managed path `codex-home/.sandbox-bin`; old task metadata without `completed_at` becomes eligible for this managed-only cleanup after its `.gc_meta.json` file has been idle for `MULTICA_GC_ORPHAN_TTL`. The rest of the task (source, `.git`, `output/`, `logs/`, `.gc_meta.json`, Codex auth/config/session state) is preserved so the agent can resume it. The same basename patterns apply to unarchived chats that use a daemon-managed work directory once the chat status check succeeds and the last run has been complete for `MULTICA_GC_ARTIFACT_TTL`. After a successful cleanup, the daemon skips repeat scans for that run. A later completed run becomes eligible again after the same delay.diff --git a/apps/docs/content/docs/environment-variables.fr.mdx b/apps/docs/content/docs/environment-variables.fr.mdxindex 5ada9e956a..2e79c5b3df 100644--- a/apps/docs/content/docs/environment-variables.fr.mdx+++ b/apps/docs/content/docs/environment-variables.fr.mdx@@ -273,7 +273,7 @@ Le daemon nettoie régulièrement les répertoires des exécutions, les caches d| `MULTICA_GC_ENABLED` | `true` | `false` ou `0` désactive toute la boucle de nettoyage || `MULTICA_GC_INTERVAL` | `2h` | Intervalle entre deux passes ; la première a lieu environ 30 secondes après le démarrage du daemon || `MULTICA_GC_TTL` | `24h` | Délai après lequel les répertoires d'exécution sont supprimés une fois la tâche passée dans la catégorie `done` ou `closed`, ou la session de chat archivée |-| `MULTICA_GC_COMPLETED_TASK_TTL` | Multica Cloud `14d` ; auto-hébergé `0` | Délai après la fin d'une exécution de tâche au bout duquel tout son répertoire est supprimé, que la tâche soit fermée ou non ; `0` désactive. Ne s'applique pas aux exécutions sur le répertoire local d'un projet |+| `MULTICA_GC_COMPLETED_TASK_TTL` | `14d` | Délai après la fin d'une exécution de tâche au bout duquel tout son répertoire est supprimé, que la tâche soit fermée ou non ; `0` désactive. Ne s'applique pas aux exécutions sur le répertoire local d'un projet || `MULTICA_GC_ORPHAN_TTL` | `72h` | Durée sans modification après laquelle un répertoire sans propriétaire identifié est supprimé || `MULTICA_GC_ARTIFACT_TTL` | `12h` | Délai entre la fin d'une exécution et le nettoyage du contenu régénérable. Les règles de la ligne suivante s'appliquent aux tâches ouvertes et aux chats non archivés qui utilisent un répertoire de travail géré. Le même délai s'applique au cache Codex géré par le daemon. `0` conserve ces caches || `MULTICA_GC_ARTIFACT_PATTERNS` | `node_modules,.next,.turbo` | Noms de répertoires considérés comme régénérables, séparés par des virgules. La définir **remplace** la liste par défaut : ajoutez les valeurs par défaut si vous voulez les garder. Les entrées contenant `/` ou `\` sont ignorées |diff --git a/apps/docs/content/docs/environment-variables.ja.mdx b/apps/docs/content/docs/environment-variables.ja.mdxindex 0a4371c761..98239eec2d 100644--- a/apps/docs/content/docs/environment-variables.ja.mdx+++ b/apps/docs/content/docs/environment-variables.ja.mdx@@ -276,7 +276,7 @@ API key と base URL の両方が空の場合、このレイヤーは無効に| `MULTICA_GC_ENABLED` | `true` | `false` または `0` でクリーンアップ全体を止める || `MULTICA_GC_INTERVAL` | `2h` | クリーンアップの間隔。デーモン起動の約 30 秒後に最初の 1 回を実行 || `MULTICA_GC_TTL` | `24h` | タスクが `done` または `closed` カテゴリに入ってから、またはチャットセッションがアーカイブされてから、実行ディレクトリを削除するまでの時間 |-| `MULTICA_GC_COMPLETED_TASK_TTL` | Multica Cloud は `14d`、セルフホストは `0` | タスクの実行が完了してからディレクトリ全体を削除するまでの時間。タスクが閉じているかどうかは問わない。`0` で無効。プロジェクトのローカルディレクトリでの実行には適用されない |+| `MULTICA_GC_COMPLETED_TASK_TTL` | `14d` | タスクの実行が完了してからディレクトリ全体を削除するまでの時間。タスクが閉じているかどうかは問わない。`0` で無効。プロジェクトのローカルディレクトリでの実行には適用されない || `MULTICA_GC_ORPHAN_TTL` | `72h` | 持ち主が見つからないディレクトリを、変更がないまま何時間経ったら削除するか || `MULTICA_GC_ARTIFACT_TTL` | `12h` | 実行終了からデーモンが再生成できる内容を削除するまでの時間。次の行のパターンは、まだ閉じていないタスクと、管理対象の作業ディレクトリを使う未アーカイブのチャットに適用される。デーモンが管理する Codex キャッシュにも同じ時間が適用される。`0` でこれらのキャッシュを保持する || `MULTICA_GC_ARTIFACT_PATTERNS` | `node_modules,.next,.turbo` | 再生成できるとみなすディレクトリ名(カンマ区切り)。設定するとデフォルトの一覧を**置き換える**ため、デフォルトも残したいなら一緒に書く。`/` や `\` を含む項目は無視される |diff --git a/apps/docs/content/docs/environment-variables.ko.mdx b/apps/docs/content/docs/environment-variables.ko.mdxindex cf7ba7af41..06c43adae3 100644--- a/apps/docs/content/docs/environment-variables.ko.mdx+++ b/apps/docs/content/docs/environment-variables.ko.mdx@@ -276,7 +276,7 @@ API key와 base URL이 모두 비어 있으면 이 레이어가 꺼지고 업스| `MULTICA_GC_ENABLED` | `true` | `false` 또는 `0`이면 정리 전체를 끕니다 || `MULTICA_GC_INTERVAL` | `2h` | 정리 간격. 데몬 시작 약 30초 뒤에 첫 정리를 합니다 || `MULTICA_GC_TTL` | `24h` | 태스크가 `done` 또는 `closed` 분류에 들어가거나 채팅 세션이 보관된 뒤, 실행 디렉터리를 삭제하기까지의 시간 |-| `MULTICA_GC_COMPLETED_TASK_TTL` | Multica Cloud `14d`, 셀프 호스팅 `0` | 태스크 실행이 완료된 뒤 디렉터리 전체를 삭제하기까지의 시간. 태스크가 닫혔는지와 관계없음. `0`이면 끔. 프로젝트 로컬 디렉터리에서의 실행에는 적용되지 않음 |+| `MULTICA_GC_COMPLETED_TASK_TTL` | `14d` | 태스크 실행이 완료된 뒤 디렉터리 전체를 삭제하기까지의 시간. 태스크가 닫혔는지와 관계없음. `0`이면 끔. 프로젝트 로컬 디렉터리에서의 실행에는 적용되지 않음 || `MULTICA_GC_ORPHAN_TTL` | `72h` | 소속을 찾을 수 없는 디렉터리가 변경 없이 얼마나 지나면 삭제할지 || `MULTICA_GC_ARTIFACT_TTL` | `12h` | 실행이 끝난 뒤 데몬이 다시 만들 수 있는 내용을 정리하기까지의 시간. 다음 행의 패턴은 열린 태스크와 관리되는 작업 디렉터리를 쓰는 미보관 채팅에 적용됨. 데몬이 관리하는 Codex 캐시에도 같은 시간이 적용됨. `0`이면 이 캐시를 유지함 || `MULTICA_GC_ARTIFACT_PATTERNS` | `node_modules,.next,.turbo` | 다시 만들 수 있다고 보는 디렉터리 이름(쉼표로 구분). 설정하면 기본 목록을 **대체**하므로 기본 항목도 유지하려면 함께 적어야 함. `/`나 `\`가 들어간 항목은 무시됨 |diff --git a/apps/docs/content/docs/environment-variables.mdx b/apps/docs/content/docs/environment-variables.mdxindex 78831bdc6b..892e5181ac 100644--- a/apps/docs/content/docs/environment-variables.mdx+++ b/apps/docs/content/docs/environment-variables.mdx@@ -282,7 +282,7 @@ The daemon periodically cleans up run directories, repository caches, session re| `MULTICA_GC_ENABLED` | `true` | Set to `false` or `0` to turn the whole cleanup loop off || `MULTICA_GC_INTERVAL` | `2h` | Time between cleanup passes; the first pass runs about 30 seconds after the daemon starts || `MULTICA_GC_TTL` | `24h` | How long after an issue enters the `done` or `closed` category, or a chat session is archived, its run directories are removed |-| `MULTICA_GC_COMPLETED_TASK_TTL` | Multica Cloud `14d`; self-hosted `0` | How long after an issue run completes its whole directory is removed, whether or not the issue is closed; `0` turns this off. Does not apply to runs on a project's local directory |+| `MULTICA_GC_COMPLETED_TASK_TTL` | `14d` | How long after an issue run completes its whole directory is removed, whether or not the issue is closed; `0` turns this off. Does not apply to runs on a project's local directory || `MULTICA_GC_ORPHAN_TTL` | `72h` | How long a directory with no owner found must go unchanged before it is removed || `MULTICA_GC_ARTIFACT_TTL` | `12h` | How long after a run ends before the daemon cleans regenerable content. The patterns in the next row apply to open issues and to unarchived chats with managed work directories. The same duration applies to the daemon-managed Codex cache. `0` keeps these caches || `MULTICA_GC_ARTIFACT_PATTERNS` | `node_modules,.next,.turbo` | Directory names treated as regenerable, comma-separated. Setting it **replaces** the default list, so include the defaults if you still want them; entries containing `/` or `\` are ignored |diff --git a/apps/docs/content/docs/environment-variables.zh-Hant.mdx b/apps/docs/content/docs/environment-variables.zh-Hant.mdxindex 14a1085d0b..6f1f45c35a 100644--- a/apps/docs/content/docs/environment-variables.zh-Hant.mdx+++ b/apps/docs/content/docs/environment-variables.zh-Hant.mdx@@ -272,7 +272,7 @@ API key 與 base URL 都為空時,這一層關閉,不會發出任何上游| `MULTICA_GC_ENABLED` | `true` | 設為 `false` 或 `0` 關閉整個清理迴圈 || `MULTICA_GC_INTERVAL` | `2h` | 兩輪清理之間的間隔;守護程序啟動約 30 秒後先清理一次 || `MULTICA_GC_TTL` | `24h` | 任務進入 `done` 或 `closed` 分類、或聊天會話歸檔後,再過多久刪除對應執行目錄 |-| `MULTICA_GC_COMPLETED_TASK_TTL` | Multica Cloud `14d`;自託管 `0` | 任務執行完成多久後刪除整個目錄,不論任務是否關閉;`0` 表示關閉。不作用於專案本地目錄上的執行 |+| `MULTICA_GC_COMPLETED_TASK_TTL` | `14d` | 任務執行完成多久後刪除整個目錄,不論任務是否關閉;`0` 表示關閉。不作用於專案本地目錄上的執行 || `MULTICA_GC_ORPHAN_TTL` | `72h` | 找不到歸屬的目錄多久沒有改動後刪除 || `MULTICA_GC_ARTIFACT_TTL` | `12h` | 從執行結束到守護程序清理可重新生成內容的時間。下一行的目錄名稱規則適用於未關閉的任務,以及使用受管理工作目錄的未歸檔聊天。守護程序管理的 Codex 快取也適用相同時長。設為 `0` 可保留這些快取 || `MULTICA_GC_ARTIFACT_PATTERNS` | `node_modules,.next,.turbo` | 按目錄名匹配的可再生成內容,逗號分隔。設定後**替換**預設列表,要保留預設項就一併寫上;含 `/` 或 `\` 的項會被忽略 |diff --git a/apps/docs/content/docs/environment-variables.zh.mdx b/apps/docs/content/docs/environment-variables.zh.mdxindex ef6b53a803..8c63788f12 100644--- a/apps/docs/content/docs/environment-variables.zh.mdx+++ b/apps/docs/content/docs/environment-variables.zh.mdx@@ -276,7 +276,7 @@ API key 与 base URL 都为空时,这一层关闭,不会发出任何上游| `MULTICA_GC_ENABLED` | `true` | 设为 `false` 或 `0` 关闭整个清理循环 || `MULTICA_GC_INTERVAL` | `2h` | 两轮清理之间的间隔;守护进程启动约 30 秒后先清理一次 || `MULTICA_GC_TTL` | `24h` | 任务进入 `done` 或 `closed` 分类、或聊天会话归档后,再过多久删除对应运行目录 |-| `MULTICA_GC_COMPLETED_TASK_TTL` | Multica Cloud `14d`;自托管 `0` | 任务运行完成多久后删除整个目录,不论任务是否关闭;`0` 表示关闭。不作用于项目本地目录上的运行 |+| `MULTICA_GC_COMPLETED_TASK_TTL` | `14d` | 任务运行完成多久后删除整个目录,不论任务是否关闭;`0` 表示关闭。不作用于项目本地目录上的运行 || `MULTICA_GC_ORPHAN_TTL` | `72h` | 找不到归属的目录多久没有改动后删除 || `MULTICA_GC_ARTIFACT_TTL` | `12h` | 从运行结束到守护进程清理可重新生成内容的时间。下一行的目录名规则适用于未关闭的任务,以及使用托管工作目录的未归档聊天。守护进程管理的 Codex 缓存也适用相同时长。设为 `0` 可保留这些缓存 || `MULTICA_GC_ARTIFACT_PATTERNS` | `node_modules,.next,.turbo` | 按目录名匹配的可再生成内容,逗号分隔。设置后**替换**默认列表,要保留默认项就一并写上;含 `/` 或 `\` 的项会被忽略 |diff --git a/server/internal/daemon/config.go b/server/internal/daemon/config.goindex b246194757..4369c21f0a 100644--- a/server/internal/daemon/config.go+++ b/server/internal/daemon/config.go@@ -72,8 +72,7 @@ const (DefaultMaxConcurrentTasks = 20DefaultGCInterval = 2 * time.HourDefaultGCTTL = 24 * time.Hour // 1 day — AI-coding issues rarely stay open long- DefaultGCCompletedTaskTTLCloud = 14 * 24 * time.Hour // 14 days — Multica Cloud bounds completed issue-task env retention by default; see defaultGCCompletedTaskTTL- DefaultGCCompletedTaskTTLSelfHost = 0 // disabled — self-host keeps every completed env until its issue goes terminal, unless an operator opts in+ DefaultGCCompletedTaskTTL = 14 * 24 * time.Hour // 14 days — bound completed issue-task env retention on every server; see the MULTICA_GC_COMPLETED_TASK_TTL comment in LoadConfigDefaultGCOrphanTTL = 72 * time.Hour // 3 days — orphans with no meta (crashes, pre-GC leftovers)DefaultGCArtifactTTL = 12 * time.Hour // 12h — drop regenerable artifacts once a task has been completed this longDefaultGCCodexSessionTTL = 14 * 24 * time.Hour // 14 days — reclaim per-issue Codex session stores untouched this long@@ -118,7 +117,7 @@ type Config struct {GCEnabled bool // enable periodic workspace garbage collection (default: true)GCInterval time.Duration // how often the GC loop runs (default: 2h)GCTTL time.Duration // clean dirs whose issue is done/cancelled and updated_at < now()-TTL (default: 24h)- GCCompletedTaskTTL time.Duration // fully clean inactive issue-task envs completed at least this long ago, regardless of parent issue status (default: 14d on Multica Cloud, 0/disabled elsewhere; local_directory envs are never fully removed)+ GCCompletedTaskTTL time.Duration // fully clean inactive issue-task envs completed at least this long ago, regardless of parent issue status (default: 14d; 0 disables; local_directory envs are never fully removed)GCOrphanTTL time.Duration // clean orphan dirs with no meta, or dirs whose issue gc-check returns 404, once they exceed this age (default: 72h). The 404 path uses the same TTL — a scoped-down token can't instantly wipe live workspaces.GCArtifactTTL time.Duration // once a task has been completed for at least this long, drop regenerable artifacts: pattern-matched build outputs when the parent record keeps the directory (an open issue), and the exact daemon-managed Codex cache for every task kind (default: 12h, set 0 to disable both)GCArtifactPatterns []string // basename patterns whose subtrees are removed during artifact cleanup (default: node_modules, .next, .turbo)@@ -560,7 +559,16 @@ func LoadConfig(overrides Overrides) (Config, error) {if err != nil {return Config{}, err}- gcCompletedTaskTTL, err := durationFromEnv("MULTICA_GC_COMPLETED_TASK_TTL", defaultGCCompletedTaskTTL(serverBaseURL))+ // Full removal of a completed task environment is irreversible: it takes+ // the checkout, .git (including work an agent left uncommitted), output/+ // and logs/ with it. The default is bounded on every server, self-host+ // included, because unbounded retention fills the disk of any long-lived+ // daemon whose issues sit open (in review, awaiting response, backlog) and+ // nobody is watching it. 14d is deliberately generous: past that much idle+ // time main has usually moved far enough that a fresh checkout beats a+ // stale worktree. Operators who want the old keep-until-terminal behavior+ // set MULTICA_GC_COMPLETED_TASK_TTL=0.+ gcCompletedTaskTTL, err := durationFromEnv("MULTICA_GC_COMPLETED_TASK_TTL", DefaultGCCompletedTaskTTL)if err != nil {return Config{}, err}@@ -686,9 +694,8 @@ const officialCloudHost = "api.multica.ai"// infrastructure we operate but not on someone else's: auto-update (cloud// users run a server that publishes the matching CLI release, so opt-in// self-update is safe, while self-host users may run a fork or pin to an-// older server) and the completed-task retention TTL (see-// defaultGCCompletedTaskTTL). Matching is host-only and case-insensitive —-// port and path are ignored.+// older server). Matching is host-only and case-insensitive — port and path+// are ignored.func isOfficialCloudServer(baseURL string) bool {u, err := url.Parse(strings.TrimSpace(baseURL))if err != nil {@@ -697,29 +704,6 @@ func isOfficialCloudServer(baseURL string) bool {return strings.EqualFold(u.Hostname(), officialCloudHost)}-// defaultGCCompletedTaskTTL picks the completed-task retention default from the-// deployment kind, the same way the auto-update default is picked.-//-// Full removal of a completed task environment is irreversible: it takes the-// checkout, .git (including work an agent left uncommitted), output/ and logs/-// with it. On Multica Cloud that trade is ours to make — we operate the nodes,-// a full disk is our incident rather than a user's, and unbounded retention has-// no operator watching it. On self-host the same default would turn a routine-// daemon upgrade into a silent deletion of data the operator never agreed to-// give up, so it stays disabled until they set MULTICA_GC_COMPLETED_TASK_TTL-// themselves. Either side can override in either direction; cloud disables it-// again with an explicit 0.-//-// Non-production cloud origins (staging, previews) fall to the self-host value-// along with everything else officialCloudHost excludes, and opt in explicitly-// if they want the bound.-func defaultGCCompletedTaskTTL(serverBaseURL string) time.Duration {- if isOfficialCloudServer(serverBaseURL) {- return DefaultGCCompletedTaskTTLCloud- }- return DefaultGCCompletedTaskTTLSelfHost-}-// NormalizeServerBaseURL converts a WebSocket or HTTP URL to a base HTTP URL.func NormalizeServerBaseURL(raw string) (string, error) {u, err := url.Parse(strings.TrimSpace(raw))diff --git a/server/internal/daemon/config_test.go b/server/internal/daemon/config_test.goindex 3ab419d632..5b0c02350f 100644--- a/server/internal/daemon/config_test.go+++ b/server/internal/daemon/config_test.go@@ -106,42 +106,6 @@ func TestPatternsFromEnv_DefaultsWhenUnset(t *testing.T) {}}-// A localhost server URL is not the official cloud host, so this exercises the-// self-host branch of defaultGCCompletedTaskTTL: retention stays unbounded until-// an operator opts in, and a daemon upgrade never starts deleting on its own.-func TestLoadConfig_CompletedTaskTTLDefaultsDisabledOnSelfHostAndReadsEnv(t *testing.T) {- stageFakeAgent(t)- redirectTestHome(t, t.TempDir())- t.Setenv("SHELL", filepath.Join(t.TempDir(), "missing-shell"))- t.Setenv("MULTICA_GC_COMPLETED_TASK_TTL", "")-- overrides := Overrides{- ServerURL: "http://localhost:0",- WorkspacesRoot: t.TempDir(),- }- cfg, err := LoadConfig(overrides)- if err != nil {- t.Fatalf("LoadConfig with default completed-task TTL: %v", err)- }- if cfg.GCCompletedTaskTTL != 0 {- t.Fatalf("GCCompletedTaskTTL = %s, want disabled", cfg.GCCompletedTaskTTL)- }-- t.Setenv("MULTICA_GC_COMPLETED_TASK_TTL", "36h")- cfg, err = LoadConfig(overrides)- if err != nil {- t.Fatalf("LoadConfig with completed-task TTL: %v", err)- }- if cfg.GCCompletedTaskTTL != 36*time.Hour {- t.Fatalf("GCCompletedTaskTTL = %s, want 36h", cfg.GCCompletedTaskTTL)- }-- t.Setenv("MULTICA_GC_COMPLETED_TASK_TTL", "not-a-duration")- if _, err := LoadConfig(overrides); err == nil || !strings.Contains(err.Error(), "MULTICA_GC_COMPLETED_TASK_TTL") {- t.Fatalf("LoadConfig invalid completed-task TTL error = %v, want named validation error", err)- }-}-func TestLoadConfig_WSClaimPollIntervalPrecedence(t *testing.T) {stageFakeAgent(t)redirectTestHome(t, t.TempDir())@@ -182,66 +146,57 @@ func TestLoadConfig_WSClaimPollIntervalPrecedence(t *testing.T) {}}-func TestLoadConfig_CompletedTaskTTLDefaultsBoundedOnOfficialCloud(t *testing.T) {+// The completed-task retention bound is on by default for every server, not+// just Multica Cloud: a self-hosted or team-hosted daemon whose issues sit open+// fills its disk just as fast. The env var still overrides in both directions.+func TestLoadConfig_CompletedTaskTTLDefaultsBoundedOnEveryServer(t *testing.T) {stageFakeAgent(t)redirectTestHome(t, t.TempDir())t.Setenv("SHELL", filepath.Join(t.TempDir(), "missing-shell"))- t.Setenv("MULTICA_GC_COMPLETED_TASK_TTL", "")- overrides := Overrides{- ServerURL: "https://" + officialCloudHost,- WorkspacesRoot: t.TempDir(),- }- cfg, err := LoadConfig(overrides)- if err != nil {- t.Fatalf("LoadConfig on official cloud: %v", err)- }- if cfg.GCCompletedTaskTTL != 14*24*time.Hour {- t.Fatalf("GCCompletedTaskTTL = %s, want 14d on official cloud", cfg.GCCompletedTaskTTL)- }+ for _, serverURL := range []string{+ "https://" + officialCloudHost,+ "https://api-staging.multica.ai",+ "https://multica.example.com",+ "http://localhost:0",+ } {+ t.Run(serverURL, func(t *testing.T) {+ overrides := Overrides{+ ServerURL: serverURL,+ WorkspacesRoot: t.TempDir(),+ }- // An explicit 0 has to win on cloud too — otherwise the only way back to the- // previous retention behavior would be downgrading the daemon.- t.Setenv("MULTICA_GC_COMPLETED_TASK_TTL", "0")- cfg, err = LoadConfig(overrides)- if err != nil {- t.Fatalf("LoadConfig with cloud opt-out: %v", err)- }- if cfg.GCCompletedTaskTTL != 0 {- t.Fatalf("GCCompletedTaskTTL = %s, want an explicit 0 to disable the cloud default", cfg.GCCompletedTaskTTL)- }+ t.Setenv("MULTICA_GC_COMPLETED_TASK_TTL", "")+ cfg, err := LoadConfig(overrides)+ if err != nil {+ t.Fatalf("LoadConfig with default completed-task TTL: %v", err)+ }+ if cfg.GCCompletedTaskTTL != 14*24*time.Hour {+ t.Fatalf("GCCompletedTaskTTL = %s, want 14d", cfg.GCCompletedTaskTTL)+ }- t.Setenv("MULTICA_GC_COMPLETED_TASK_TTL", "36h")- cfg, err = LoadConfig(overrides)- if err != nil {- t.Fatalf("LoadConfig with cloud override: %v", err)- }- if cfg.GCCompletedTaskTTL != 36*time.Hour {- t.Fatalf("GCCompletedTaskTTL = %s, want the env override to win on cloud", cfg.GCCompletedTaskTTL)- }-}+ // An explicit 0 restores keep-until-terminal retention.+ t.Setenv("MULTICA_GC_COMPLETED_TASK_TTL", "0")+ cfg, err = LoadConfig(overrides)+ if err != nil {+ t.Fatalf("LoadConfig with completed-task TTL opt-out: %v", err)+ }+ if cfg.GCCompletedTaskTTL != 0 {+ t.Fatalf("GCCompletedTaskTTL = %s, want an explicit 0 to disable the default", cfg.GCCompletedTaskTTL)+ }-func TestDefaultGCCompletedTaskTTLOnlyBoundsOfficialCloudHost(t *testing.T) {- t.Parallel()- cases := []struct {- name string- serverURL string- want time.Duration- }{- {"official cloud", "https://api.multica.ai", DefaultGCCompletedTaskTTLCloud},- {"official cloud with port and path", "https://API.Multica.AI:443/api", DefaultGCCompletedTaskTTLCloud},- // Staging and previews inherit the self-host value for the same reason- // officialCloudHost excludes them from the auto-update default.- {"staging", "https://api-staging.multica.ai", DefaultGCCompletedTaskTTLSelfHost},- {"self-host", "https://multica.example.com", DefaultGCCompletedTaskTTLSelfHost},- {"localhost", "http://localhost:8080", DefaultGCCompletedTaskTTLSelfHost},- {"unparseable", "://nope", DefaultGCCompletedTaskTTLSelfHost},- }- for _, tc := range cases {- t.Run(tc.name, func(t *testing.T) {- t.Parallel()- if got := defaultGCCompletedTaskTTL(tc.serverURL); got != tc.want {- t.Fatalf("defaultGCCompletedTaskTTL(%q) = %s, want %s", tc.serverURL, got, tc.want)+ t.Setenv("MULTICA_GC_COMPLETED_TASK_TTL", "36h")+ cfg, err = LoadConfig(overrides)+ if err != nil {+ t.Fatalf("LoadConfig with completed-task TTL override: %v", err)+ }+ if cfg.GCCompletedTaskTTL != 36*time.Hour {+ t.Fatalf("GCCompletedTaskTTL = %s, want 36h", cfg.GCCompletedTaskTTL)+ }++ t.Setenv("MULTICA_GC_COMPLETED_TASK_TTL", "not-a-duration")+ if _, err := LoadConfig(overrides); err == nil || !strings.Contains(err.Error(), "MULTICA_GC_COMPLETED_TASK_TTL") {+ t.Fatalf("LoadConfig invalid completed-task TTL error = %v, want named validation error", err)}})}