feat(environments): archive grace period + Restore environment#242
Draft
ymichael wants to merge 1 commit into
Draft
feat(environments): archive grace period + Restore environment#242ymichael wants to merge 1 commit into
ymichael wants to merge 1 commit into
Conversation
Archiving the last live thread in a managed environment no longer destroys its worktree immediately. The environment stays `retiring` for a configurable grace window (default 10s via MANAGED_ENVIRONMENT_RETIRE_GRACE_MS), during which: - un-archiving revives it in place (retire.cancelled) — a lossless undo that preserves the worktree and uncommitted work, and - an "Undo" toast on archive offers the same one click. After the window the worktree is reclaimed by the existing recovery sweep (the grace gate lives in advanceEnvironmentCleanup and is durable across restart via the row's updatedAt clock; no in-memory timer). The gate applies only when a revivable archived thread remains, so a deleted thread's orphaned environment is still cleaned up immediately. A new "Restore environment" action (POST /threads/:id/restore-environment) reprovisions a fresh environment for a thread whose environment is gone. The daemon's createWorktree now checks out an existing branch in place instead of `-B`-resetting it, so committed work (which survives `git worktree remove`) is recovered; the thread is re-seeded into idle without an automatic turn. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
52cc265 to
0943c24
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Two gaps around a thread losing its environment:
destroying/destroyedshowed a dead-end "Environment is no longer available" banner.What this does
Archive grace period (the brick fix). Archiving the last live thread now leaves the environment
retiringfor a configurable window (managedEnvironmentRetireGraceMs, default 10s) before the worktree is destroyed. The gate lives inadvanceEnvironmentCleanupand is durable across restart (keyed on the row'supdatedAt; no in-memory timer). It only applies when a revivable archived thread remains, so a deleted thread's orphaned environment is still cleaned up immediately.Lossless undo. Within the window:
retire.cancelled→ environment back toready, worktree (and uncommitted work) intact.Restore environment.
POST /threads/:id/restore-environmentreprovisions a fresh environment for a thread whose environment is gone:createWorktreenow checks out an existing branch in place instead of-B-resetting it, so committed work (which survivesgit worktree remove) is recovered.idle(no automatic turn); routing handlesretiring(revive in place),destroying(409, retry),unmanaged(409), and pruned envs (409).T3-style per-turn checkpointing was evaluated and left out of scope (rationale in the plan): the grace period makes accidental archive lossless without new storage, and it conflicts with T3's own delete-refs-on-archive hygiene.
Design notes and exit criteria:
plans/environment-restore-and-archive-grace-period.md.Testing
Follow-ups (not blocking)
Not needed:
SideChatTabContent's "no longer available" copy is a not-found thread label, not an environment-gone surface — there is nothing to restore there.🤖 Generated with Claude Code