Repository navigation
fix: explain how to recover removed session worktrees - #200691
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
|
Codex review: needs changes before merge. What this changesThis PR detects removed session worktrees before sandbox preparation and explains how to restore them. Example: Send “Continue the task” to agent:main:removed-worktree after worktrees.remove removes its checkout.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 1 item remains Keep open: this PR addresses a current recovery diagnostic bug, but the new instructions send users to the wrong navigation section. Priority: P2 Before merge
Findings
Tests
Agent review detailsHow this fits togetherShared workspace preparation reads session and worktree metadata before preparing native or plugin harness execution, returning workspace policy or an error delivered to chat. flowchart TD
A[Chat turn] --> B[Shared workspace preparation]
B --> C[Session and worktree readers]
C --> D[Removed worktree diagnostic]
C --> E[Sandbox preparation]
E --> F[Existing ownership guard]
D --> G[Chat error]
Technical reviewBest possible solution: Keep the shared preflight and explicit restore owner, but direct users to Sessions > Worktrees. Do we have a high-confidence way to reproduce the issue? Current source shows that unarchived sessions skip automatic archive restoration and removed worktrees reach the generic projection rejection; the supplied regression reports this exact failure, but this read-only review did not execute it. Is this the best way to solve the issue? The preflight is a focused use of existing metadata readers and error classification, and preserving explicit restoration respects deletion intent; its recovery destination needs the correction below. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 64e2ad20c6ef. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceSource +28, Tests +92, Docs +5. Total +125 across 5 files. Added test files: 1. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 17, 2026, 11:53 AM ET / 16:53 UTC. |
|
Merged via squash.
|
* fix(worktrees): retain recently used session checkouts * test(agents): decouple admission proof from workspace creation (cherry picked from commit f5d35bc) Release adaptation: reuse the beta.3 adaptation aef0b19dc08b for the stable workspace owner: add existing reader/error imports and the minimal #200691 removed-checkout preflight so activity marking never recreates a removed checkout. Omit only the changed assertion in the Gateway test file absent on this branch; retain existing Gateway readiness and owner coverage. Companions: #202074 is selected next. #202068 is present-equivalent (5631d96); #202204 changes later main-only GC owner-census behavior; #203057 is an independent probe optimization. Other later overlap concerns unrelated worktree refresh/reclamation, policy, restore UX, or the later absent removed-checkout fixture; not prerequisites (enumerated in lane audit). Release adaptation: reuse the sibling path-specific realpath spy and no-recreation regression (abce9babd5cab). The original one-shot spy closed authority at the preflight read instead of the target workspace boundary. Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit e3495dac6afc80bd3fe36110008dec96013d2514)
What Problem This Solves
Continuing an active session after its managed worktree was cleaned up or deleted fails every turn with the misleading message “Local sandbox managed workspace owner changed.” Retrying gives no recovery instructions.
User Impact
The chat now explains that the worktree was removed and directs the user to Restore in Settings > Worktrees (
worktrees.restore), or to start a new session. The failure happens before sandbox preparation.Why This Change Was Made
src/sessions/session-archive-restore.ts:29intentionally skips unarchived sessions. Removal retains recovery metadata, but the projection guard atsrc/gateway/worker-environments/local-workspace-projection.ts:635rejectsremovedAtusing the generic ownership error.The shared native/plugin workspace preparation boundary now reads the existing session binding and worktree record and throws the existing
SessionWorkStartInvalidatedErrorfor a removed, unarchived session. Its existing classification carries the actionable message to chat without treating it as a model-provider failure. The projection guard remains unchanged and still rejects removed or forged owners.Removal records do not distinguish idle cleanup from intentional deletion. This change therefore grants no restore authority: it leaves restoration to the existing explicit action. There is no schema, GC, removal, or automatic restoration change.
Evidence
A real isolated Gateway creates an unarchived worktree session, removes its checkout through
worktrees.remove, and sends a chat turn. On the base, the regression fails withReceived: "Local sandbox managed workspace owner changed". With the fix, it receives the actionable removal message and proves sandbox preparation was not called. The same test checks that bypassing this preflight still hits the original projection guard; a second test verifies a forged session owner is rejected there.The existing workspace cancellation test now targets the workspace's
realpathcall so the added metadata read cannot trigger its cancellation hook early. Two new tests, plus that adjustment, add 92 net test lines; production code adds 28 lines. The simplification pass retained the existing readers and error owner and introduced no helper, cache, or state owner.Validation:
pnpm test src/gateway/server.chat-removed-worktree.product.test.ts --maxWorkers=1: red on base (1 failed, old ownership error); green with fix (1 passed).pnpm test src/agents/sandbox/registry-authority.test.ts --maxWorkers=1passed all 10 tests. The earlier failures and fixture corrections are described above.git diff --check;pnpm build.scoped-cleanwith no actionable P0–P2 findings.Local timing: the product regression took 50.58 seconds wall time (9.81 seconds in the test), the workspace suite took 7.07 seconds, the setup/startup suites took 15.02 seconds together, and the registry suite took 51.79 seconds wall time (about 17 seconds in tests). The longer wall times include compiled worker preparation. The Gateway test is necessary to prove the actual chat error delivery and ordering before sandbox preparation; a helper test cannot establish that boundary.
CI run 44127948897 is green at
45ca8543bafd4746f6a9341734b9297c672d7ade. Attempt 1 took 1,009 elapsed seconds and failed three shards during Git package setup because the package repository returned HTTP 503; no tests ran in those failed jobs. After diagnosing those logs, a failed-jobs-only retry passed in 606 elapsed seconds (attempt 2), reusing successful jobs. No code change or unrelated test rerun was needed.