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 Multica Cloud (#7303)
Bohan Jiange41774327915
diff --git a/CLI_AND_DAEMON.md b/CLI_AND_DAEMON.mdindex 1332ec2d28..2b9e8c9676 100644--- a/CLI_AND_DAEMON.md+++ b/CLI_AND_DAEMON.md@@ -258,7 +258,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` | `0` (disabled) |+| GC completed-task TTL (issue tasks) | — | `MULTICA_GC_COMPLETED_TASK_TTL` | `14d` on Multica Cloud, `0` (disabled) elsewhere || 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` |@@ -272,7 +272,9 @@ Daemon behavior is configured via flags or environment variables:The daemon periodically scans `MULTICA_WORKSPACES_ROOT` and applies several disk-reclamation policies:- **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** — set `MULTICA_GC_COMPLETED_TASK_TTL` to fully remove an inactive issue task once its `.gc_meta.json` `completed_at` age exceeds the configured duration, even while the parent issue remains open. The default `0` disables this opt-in policy. 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.+- **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.+ - 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.- **Managed-cache reclamation** — the exact managed path above is reclaimed for *every* task kind once the task has been completed for `MULTICA_GC_ARTIFACT_TTL`, not just for issue tasks whose issue is still open. It applies even while the parent record says the directory itself must stay — an active chat session, a still-running autopilot run — and even when the parent record could not be reached this cycle, because the contents are regenerable and the next run re-provisions them on demand. A task currently running on the directory is never touched. Set `MULTICA_GC_ARTIFACT_TTL=0` to disable this along with the rest of artifact cleanup.diff --git a/server/internal/daemon/config.go b/server/internal/daemon/config.goindex eb4972c99b..fe33ab6e61 100644--- a/server/internal/daemon/config.go+++ b/server/internal/daemon/config.go@@ -68,7 +68,8 @@ const (DefaultMaxConcurrentTasks = 20DefaultGCInterval = 2 * time.HourDefaultGCTTL = 24 * time.Hour // 1 day — AI-coding issues rarely stay open long- DefaultGCCompletedTaskTTL = 0 // disabled — operators may bound completed issue-task env retention independently of issue status+ 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 inDefaultGCOrphanTTL = 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@@ -104,7 +105,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: 0, disabled; 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 on Multica Cloud, 0/disabled elsewhere; 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)@@ -454,7 +455,7 @@ func LoadConfig(overrides Overrides) (Config, error) {if err != nil {return Config{}, err}- gcCompletedTaskTTL, err := durationFromEnv("MULTICA_GC_COMPLETED_TASK_TTL", DefaultGCCompletedTaskTTL)+ gcCompletedTaskTTL, err := durationFromEnv("MULTICA_GC_COMPLETED_TASK_TTL", defaultGCCompletedTaskTTL(serverBaseURL))if err != nil {return Config{}, err}@@ -569,11 +570,13 @@ func LoadConfig(overrides Overrides) (Config, error) {const officialCloudHost = "api.multica.ai"// isOfficialCloudServer reports whether the resolved server base URL points-// at Multica's hosted cloud. Used to pick the auto-update default: cloud+// at Multica's hosted cloud. Used to pick defaults that are safe on+// 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; self-host users may run a fork or pin to an older-// server, so the default flips to off. Matching is host-only and-// case-insensitive — port and path are ignored.+// 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.func isOfficialCloudServer(baseURL string) bool {u, err := url.Parse(strings.TrimSpace(baseURL))if err != nil {@@ -582,6 +585,29 @@ 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 b17d5520ad..6ae8b13b1d 100644--- a/server/internal/daemon/config_test.go+++ b/server/internal/daemon/config_test.go@@ -112,7 +112,10 @@ func TestDefaultGCIntervalIsTwoHours(t *testing.T) {}}-func TestLoadConfig_CompletedTaskTTLDefaultsDisabledAndReadsEnv(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)t.Setenv("HOME", t.TempDir())t.Setenv("SHELL", filepath.Join(t.TempDir(), "missing-shell"))@@ -145,6 +148,71 @@ func TestLoadConfig_CompletedTaskTTLDefaultsDisabledAndReadsEnv(t *testing.T) {}}+func TestLoadConfig_CompletedTaskTTLDefaultsBoundedOnOfficialCloud(t *testing.T) {+ stageFakeAgent(t)+ t.Setenv("HOME", 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)+ }++ // 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", "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)+ }+}++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)+ }+ })+ }+}+func TestRepoMaintenanceKillSwitchDefaultsOnAndCanDisable(t *testing.T) {t.Setenv("MULTICA_GC_REPO_MAINTENANCE_ENABLED", "")if !boolFromEnv("MULTICA_GC_REPO_MAINTENANCE_ENABLED", true) {