Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): clean up child worktrees after their parent settles #30026

Mergedvoltcrash(GitHub profile, opens in a new tab)merged 2 commits intomain fromrefs/pull/30026/headmerged by maria-rcks View on GitHub

With only Delete settled worktrees enabled, a finished subagent's isolated worktree is retained forever when its parent settles: cleanup checks the child's own settledAt, which remains null.

Cleanup now uses the nearest settled ancestor reached through subagent lineage for the settled-age rule. Every traversed ancestor must be idle, both initially and when reloaded before removal. Child activity and the settle-script grace period still delay removal; explicit active/pinned overrides stop inheritance. Parent settlement is rechecked before removal, so reopening a parent or child during cleanup preserves the worktree. This also handles worktrees left behind before the fix.

Fixes #29999. This is a focused eligibility fix for an existing cleanup setting, confined to the server service and its tests. Thread settlement state and client contracts stay unchanged.

Verification on Linux with Git 2.56.0:

  • Added regression cases first: unchanged production failed five cases, including isolated child/grandchild removal. All 21 new cases now pass, covering immediate/aged cleanup, recent activity and settlement, busy children, explicit overrides, lineage boundaries, and reactivation during measurement.

  • Four additional regressions reproduced removal while an intermediate ancestor was running or had pending background work, including changes during measurement; all four pass with the guard.

  • vp test run apps/server/src/storageCleanup.test.ts: 174 passed, one existing failure. compares the checked-out branch without a full status expects a broken .git file to produce a kept entry, but Git returns an invalid-repository error. The same failure was reproduced with unchanged upstream production code.

  • vp run check:changed upstream/main: format, lint, both knip checks, generated GraphQL, and affected-package typechecks passed. Tests: 175 passed and the same existing failure.

  • Runtime transcript from the service fixture, using a real temporary Git repository, isolated worktree, and filesystem; projection/session boundaries use test fixtures:

    worktreeSettledAfterDays: 0
    parentSettled: true
    childSettledAt: null
    childStatus: completed
    cleanup outcome: removed
    cleanup reason: Settled for 0 days
    worktreeExistsAfter: false

No live-provider or multi-environment session was launched. The shared server cleanup path applies to web, desktop, and mobile.

Reviewed with review-loop: 2 rounds with GPT-6.1-Sol on xhigh. Reviewer verdict: approved. The final review confirmed the ancestor-activity finding was resolved with no new findings. All 50 focused subagent ownership tests pass.

Created with GPT-6.1-Sol in Codex through T3 Code.

    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    2. Approvability

      Verdict: Needs Human Approval

      Macroscope's review found this PR requires human approval — Cleanup now treats eligible child worktrees as settled when an ancestor settles, including previously retained worktrees. Human confirmation is needed for this retroactive deletion scope, particularly where existing settings allow untracked and ignored files to be discarded.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      No actionable comments were generated in the recent review.

      Walkthrough

      Worktree cleanup now evaluates non-deleted subagent worktrees using eligible settled ancestors. Before removal, cleanup checks whether the terminal settled thread changed during measurement.

      Changes: Subagent worktree cleanup

      Layer / File(s)Summary
      Settlement-chain eligibility
      apps/server/src/storageCleanup.ts, apps/server/src/storageCleanup.test.ts
      Cleanup follows eligible unsettled subagent ancestors to a terminal settled thread. It uses that thread for settlement-age checks and includes chain members in the grace-period check. Tests cover removal and retention scenarios.
      Settlement revalidation
      apps/server/src/storageCleanup.ts, apps/server/src/storageCleanup.test.ts
      Before removal, cleanup reloads the chain and retains the worktree if the terminal settled thread’s identity, settlement time, or update time changed. Tests cover settlement and activity changes during measurement.

      Estimated code review effort: 3 (Moderate) | ~20 minutes

      Change: Bug fix · Severity of issue fixed: Medium

      Suggested labels: bugfix

      Suggested reviewers: maria-rcks

      Merge Risk: Minimal · up to 2d2cb

      Eligible idle child worktrees can inherit ancestor settlement. No material merge-blocking risk was identified.

      Pre-merge checks: Passed 4
      Check nameStatusExplanation
      Title checkPassedThe title clearly identifies the server cleanup fix for child worktrees after parent settlement.
      Description checkPassedThe description explains the problem, implementation, scope, linked issue, verification results, known existing test failure, limitations, and agent details. Although it does not use the template head…
      Linked Issues checkPassedIssue #29999 requires cleanup to remove finished child worktrees when the parent is settled and only settled-age cleanup is enabled. worktreeSettlementChain follows unsettled subagent ancestors to t…
      Out of Scope Changes checkPassedThe whole pull request changes apps/server/src/storageCleanup.ts and its focused apps/server/src/storageCleanup.test.ts. The production changes implement issue #29999 cleanup eligibility and remov…
      Full details: Description check

      Explanation

      The description explains the problem, implementation, scope, linked issue, verification results, known existing test failure, limitations, and agent details. Although it does not use the template headings verbatim, it provides the required information in a complete and focused form.

      Full details: Linked Issues check

      Explanation

      Issue #29999 requires cleanup to remove finished child worktrees when the parent is settled and only settled-age cleanup is enabled. worktreeSettlementChain follows unsettled subagent ancestors to the nearest settled ancestor and requires each traversed ancestor to be idle. Cleanup uses that ancestor for settled-age and grace-period checks. The removal path rechecks ancestor settlement and activity before deletion. Tests cover child and grandchild cleanup, activity and pending work, overrides, lineage boundaries, and reactivation during measurement. This implements the issue's storage-cleanup alternative without changing thread settlement state.

      Full details: Out of Scope Changes check

      Explanation

      The whole pull request changes apps/server/src/storageCleanup.ts and its focused apps/server/src/storageCleanup.test.ts. The production changes implement issue #29999 cleanup eligibility and removal revalidation. The tests verify those requirements. No unrelated thread settlement behavior or client contract changes are present.

      Finishing Touches
      Generate unit tests (beta)
      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

      CodeRabbit Verify

      • Run CodeRabbit Verify to test the changes in this pull request.
      Recent review info
      Run configuration
      Commits

      Reviewing files that changed from the base of the PR and between cfac8f202ff2d3308a786d745e0e1764ba4d248e and 2d2cb13d4493edcb35e7b114b8d231dde53fbf6e.

      Files selected for processing: 2
      • apps/server/src/storageCleanup.test.ts
      • apps/server/src/storageCleanup.ts

      Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.

      • Fix comments: Fix CodeRabbit comments on this PR
    4. maria-rckscommented

      Note

      Written by gpt-6.1-sol on behalf of Maria

      Verified in a real dev environment

      Verified head 2d2cb13d4493edcb35e7b114b8d231dde53fbf6e as-is on Linux, using the real dev web app in Google Chrome driven by repository Playwright. Created a real Git project through the app and ran Codex gpt-6.1-sol parent and isolated child turns. No mocks, fixtures, or demo data.

      • Reproduced on github/main (cefb544af3): with only "Delete settled worktrees" enabled at 0 days, a completed child's worktree remained "Not settled" after its parent settled and the 60-second grace elapsed.
      • Started the exact PR head with the same task-owned dev state. Startup cleanup removed that existing child worktree as "Settled for 0 days".
      • Ran another real Codex parent/child turn on the PR. Cleanup preserved the child while its parent was active, and preserved a pinned child after parent settlement.
      • Repeated main versus PR on the same fresh child: main retained it; after unpinning, the PR's web "Delete now" removed it. Confirmed the directory disappeared from disk and git worktree list; its branch and conversation remained available.
      • Blacksmith: all 175 storageCleanup.test.ts tests passed. vp run check:changed cefb544af3c98224874419198c0359b652ca3c94 passed format, lint, both knip checks, generated GraphQL, affected-package typechecks, and tests. No source changes were needed.

      Before, main retaining the fresh child:

      main retains the completed child after parent settlement

      After, PR removing the same child:

      pr removes the same child after parent settlement

      8-second cleanup recording (playback and seeking verified in T3; GitHub does not embed this external video host).

      Runtime transcript

      Not verified

      Native desktop, iOS, and Android clients; macOS/Windows filesystem behavior; remote/relay and tunnel connections; other providers. Ancestor-reactivation races and deeper ancestry were covered by existing automated tests, not manually forced during a live cleanup.

    5. maria-rcks merged thisb6307ee

    6. maria-rcks closed this

Sign in to join this conversation.