Skip to content

fix(daemon): reclaim superseded open-issue workdirs - #6256

Draft
violinhost wants to merge 1 commit into
multica-ai:mainfrom
violinhost:codex/daemon-superseded-workdir-gc
Draft

fix(daemon): reclaim superseded open-issue workdirs#6256
violinhost wants to merge 1 commit into
multica-ai:mainfrom
violinhost:codex/daemon-superseded-workdir-gc

Conversation

@violinhost

Copy link
Copy Markdown

What does this PR do?

Bounds daemon-host disk growth for issues that stay open across many runs.

Today GC preserves every terminal task root while its issue is open, even though only the current healthy (agent, issue) resume candidate and workdirs referenced by non-terminal tasks can be reused. A single long-lived issue can therefore retain hundreds of full repository copies.

This change makes the server return an authoritative protected-workdir set and lets the daemon remove completed, TTL-expired task roots that are no longer protected. The daemon fails closed when the server is old or the protection lookup fails.

Thinking path:

  1. Field evidence showed GC running normally but skipping hundreds of terminal roots on open issues.
  2. A sampled open issue had 152 terminal runs and one workdir per historical run, while resume uses only the latest healthy session per (agent, issue).
  3. Resume authority belongs on the server because it owns poisoned/retired-session filtering, active tasks, and exact manual-rerun lineage.
  4. The daemon keeps deletion containment and active env-root reservations, and only adds a server-authorized superseded branch after MULTICA_GC_TTL.

Related Issue

Refs #1636

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Refactor / code improvement (no behavior change)
  • Documentation update
  • Tests (adding or improving test coverage)
  • CI / infrastructure

Changes Made

  • Add an additive workdir_protection_known / protected_work_dirs contract to both daemon issue-GC endpoints.
  • Protect the current healthy resume workdir per (agent, issue), workdirs pinned by non-terminal tasks (including deferred tasks), and exact sources of non-terminal manual reruns.
  • Reclaim only TTL-expired completed roots for explicitly open issue states when their <taskDir>/workdir is not protected.
  • Preserve rolling compatibility: new server + old daemon ignores additive fields; new daemon + old server keeps full roots.
  • Keep recently done/cancelled issues on their existing issue-updated-at TTL path.
  • Document the fourth workspace GC mode and deployment behavior.

No database migration is required.

How to Test

  1. go test -race ./internal/daemon
  2. go test -race ./internal/handler
  3. go vet ./internal/daemon ./internal/handler
  4. go build ./cmd/server ./cmd/multica
  5. go test ./...

The affected packages, race tests, vet, and builds pass. The full suite passed except the pre-existing internal/metrics pg_sleep assertion on this local Homebrew PostgreSQL setup: the driver returns context deadline exceeded instead of the test-required *pgconn.PgError. Temp-database backfill tests pass when the local test role has the required CREATEDB privilege; that privilege was removed again after verification.

Rollout / risk

Deploy server first, then daemons. Until both sides support the protection contract, open-issue full cleanup stays disabled. Deletion remains constrained to known task env roots and is rechecked against the daemon active-root reservation immediately before mutation. local_directory tasks retain the existing no-full-delete override.

A manual rerun of a terminal task older than the full-cleanup TTL remains best-effort: if its superseded workdir was reclaimed before the rerun was requested, the existing claim path starts fresh.

Checklist

  • I have included a thinking path that traces from project context to this change
  • I have run tests locally and they pass
  • I have added or updated tests where applicable
  • If this change affects the UI, I have included before/after screenshots (not applicable)
  • I have updated relevant documentation to reflect my changes
  • If I added a new runtime / coding tool / UI tab, I synced the change to landing copy and relevant docs (not applicable)
  • If this PR touches Chinese product copy, I checked it against the convention (not applicable)
  • I have considered and documented any risks above
  • I will address all reviewer comments before requesting merge

AI Disclosure

AI tool used: OpenAI Codex

Prompt / approach: Diagnosed production daemon-host disk growth from live GC logs and workspace samples, minimized the retention rule to resume-authoritative state, added red/green daemon and database-backed handler regressions, then ran package, race, vet, build, and compatibility checks.

Screenshots (optional)

Not applicable; no UI change.

@vercel

vercel Bot commented Aug 1, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the IndexLabs Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant