fix(daemon): reclaim idle task clones hourly, not only on a full volume (#1814)

This commit is contained in:
sam committed 2026-11-14 15:05:53 +11:00
1 parent f5c566bcab
commit 1d329bad35
1 file changed
+24
+24
View File
@@ -29,6 +29,7 @@ const mirrorIdle = 7 * 24 * time.Hour
func (d *Daemon) BuiltinJobs() []BuiltinJob {
return []BuiltinJob{
{ID: "volume-cleanup", Name: "Remove expired volumes", DefaultInterval: time.Hour, Run: d.cleanupExpiredStorage},
{ID: "clone-reclaim", Name: "Remove idle task clones", DefaultInterval: time.Hour, Run: d.reclaimIdleClones},
{ID: "issue-discovery", Name: "Discover forge issues", DefaultInterval: time.Minute, Run: d.IssuePoller.poll},
{ID: "pr-reconcile", Name: "Reconcile pull requests", DefaultInterval: time.Minute, Run: d.ReviewScanner.reconcilePRs},
{ID: "pr-review-scan", Name: "Scan pull request reviews", DefaultInterval: time.Minute, Run: d.ReviewScanner.scanPRReviews},
@@ -43,3 +44,26 @@ func (d *Daemon) pruneMirrors(ctx context.Context) error {
}
return err
}
// reclaimIdleClones removes every task clone idle for cloneRetention, so
// parked and finished tasks without a PR do not hold disk until the volume is
// full. A clone with uncommitted or unpushed work is kept and logged for the
// operator.
func (d *Daemon) reclaimIdleClones(ctx context.Context) error {
if d.Trees == nil {
return nil
}
noFloor := func() (uint64, error) { return 0, nil }
holdsWork := func(dir string) bool {
held := d.Trees.HoldsUnsharedWork(ctx, dir)
if held {
d.Log.WarnContext(ctx, "idle task clone kept: it holds uncommitted or unpushed work; archive the task to remove it", "dir", dir)
}
return held
}
n, err := worktree.ReclaimStale(d.Cfg.Get().WorkDir, "", cloneRetention, noFloor, 1, holdsWork)
if n > 0 {
d.Log.InfoContext(ctx, "idle task clones removed", "clones", n)
}
return err
}