Skip to content

fix: explain how to recover removed session worktrees - #200691

Merged
steipete merged 1 commit into
mainfrom
codex/dashboard-workspace-owner
Nov 17, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/dashboard-workspace-owner

Conversation

@steipete

@steipete steipete commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

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:29 intentionally skips unarchived sessions. Removal retains recovery metadata, but the projection guard at src/gateway/worker-environments/local-workspace-projection.ts:635 rejects removedAt using the generic ownership error.

The shared native/plugin workspace preparation boundary now reads the existing session binding and worktree record and throws the existing SessionWorkStartInvalidatedError for 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 with Received: "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 realpath call 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).
  • The workspace/runner consumer run passed 7 workspace tests and 19 setup/startup tests. After correcting the forged-binding fixture, pnpm test src/agents/sandbox/registry-authority.test.ts --maxWorkers=1 passed all 10 tests. The earlier failures and fixture corrections are described above.
  • Core and targeted Gateway/agent test typechecks; targeted lint and format; git diff --check; pnpm build.
  • All focused checks above passed on the final change (37 tests in total). Codex autoreview returned scoped-clean with 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.

@clawsweeper

clawsweeper Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-17T16:40:01.213847Z 45ca854 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: S labels Nov 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: 45ca8543bafd4746f6a9341734b9297c672d7ade
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/agents/workspace-sandbox.ts: Controls sandbox containment or tool execution authority. Check filesystem and network isolation, approval scope, and command allowlists.

Carefully review these changes before merging.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 17, 2026
@clawsweeper

clawsweeper Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This 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.

  • Before: Chat reports “Local sandbox managed workspace owner changed.”
  • After: Chat explains that the worktree was removed and offers restoration or a new session.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The implementation is focused, but the recovery destination is incorrect and the supplied evidence remains test-only.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Continuing an unarchived session whose checkout was removed produces an ownership error with no useful recovery instructions.
Reason: The maintainer-authored direction improves a real failure message without changing removal policy, restore authority, configuration, or stored formats.

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
Reviewed head: 45ca8543bafd4746f6a9341734b9297c672d7ade

Before merge

  • Point recovery instructions to Sessions > Worktrees (P2) - After a checkout is removed, the new error tells users to open Settings > Worktrees, but Worktrees is a tab of the Sessions hub and is absent from SETTINGS_NAVIGATION_GROUPS. The retained /settings/worktrees URL alias does not provide that menu path. Users following the advertised recovery steps therefore look in the wrong section. Change the message, matching documentation, and regression expectation to Sessions > Worktrees.

Findings

  • [P2] Point recovery instructions to Sessions > Worktrees — src/agents/workspace-sandbox.ts:155

Tests

  • Missing end-to-end proof: Provide a redacted live Gateway or chat capture showing the removed-worktree message and the correct in-product recovery destination; the body currently supplies test results only.
Agent review details

How this fits together

Shared 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]
Loading

Technical review

Best 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:

  • [P2] Point recovery instructions to Sessions > Worktrees — src/agents/workspace-sandbox.ts:155
    After a checkout is removed, the new error tells users to open Settings > Worktrees, but Worktrees is a tab of the Sessions hub and is absent from SETTINGS_NAVIGATION_GROUPS. The retained /settings/worktrees URL alias does not provide that menu path. Users following the advertised recovery steps therefore look in the wrong section. Change the message, matching documentation, and regression expectation to Sessions > Worktrees.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 64e2ad20c6ef.

Provenance checked

  • Shared workspace preparation keeps the original intent (3a08c3d: The shared preparation boundary supports native and plugin harness workspace containment; later worker-read and cold-import changes preserve that ownership.)
  • Archive restoration and removed-worktree lifecycle keeps the original intent (8e4eb78: Archived checkout reclamation retains recovery snapshots and restores authorized reopened sessions; the new diagnostic deliberately leaves unarchived removal recovery explicit.)
  • Existing cancellation test keeps the original intent (d73bc54: Workspace preparation rejects lost run authority at asynchronous filesystem boundaries; the fixture adjustment keeps cancellation attached to the intended workspace realpath.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test src/gateway/server.chat-removed-worktree.product.test.ts --maxWorkers=1
  • git diff --check

What I checked:

  • Introduced diagnostic: The pinned introduced diff adds a read-only preflight and uses the existing SessionWorkStartInvalidatedError; it leaves restoration and projection authorization unchanged. (src/agents/workspace-sandbox.ts:137, 45ca8543bafd)
  • Current main still has the underlying diagnostic problem: Current main retains the generic ownership error for removed worktrees, while restoreArchivedSession intentionally returns immediately for an unarchived session; the shared preparation file has no intervening main change from the pinned base. (src/gateway/worker-environments/local-workspace-projection.ts:635, 64e2ad20c6ef)
  • Recovery navigation mismatch: Worktrees is a Sessions hub tab and is excluded from Settings navigation; /settings/worktrees remains an address alias, not the advertised menu path. (ui/src/app-navigation.ts:175, 45ca8543bafd)
  • Existing explicit restore owner: The existing Restore button invokes worktrees.restore, whose service restores the snapshot and clears removedAt; the PR needs no new restoration mechanism. (src/agents/worktrees/service.ts:750, 45ca8543bafd)
  • Supplied behavioral evidence: The full PR body reports base-red/head-green Gateway testing; the added test exercises sessions.create, worktrees.remove and chat.send in a Vitest process, with a fixture provider and a sandbox spy, rather than supplying an independent live capture. (src/gateway/server.chat-removed-worktree.product.test.ts:14, 45ca8543bafd)
  • Failed shards did not execute tests: Jobs 134198058705, 134198058661 and 134198058655 failed at Setup Node environment and skipped Run Node test shard; no test failure is attributable to this patch from those jobs. (45ca8543bafd)

Likely related people:

  • Peter Steinberger: Raw commit 3a08c3d adds src/agents/workspace-sandbox.ts:28 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 3a08c3d9ee79; files: src/agents/workspace-sandbox.ts)
  • Vincent Koc: Raw commit 625945b adds src/agents/workspace-sandbox.ts:146 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 625945b7ae01; files: src/agents/workspace-sandbox.ts)

PR surface

Source +28, Tests +92, Docs +5. Total +125 across 5 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 1 28 0 +28
Tests 3 95 3 +92
Docs 1 5 0 +5
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 128 3 +125

Preflight source

Source 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

Metric Value Why it matters
Production versus test growth Production +28; tests +92 net The growth adds one shared diagnostic preflight and covers chat delivery, preserved ownership rejection, and the adjusted cancellation boundary without introducing another state owner.

Labels

Label changes:

  • add P2: Removed-worktree sessions receive misleading recovery guidance, but an existing in-product Restore action limits the impact.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: Removed-worktree sessions receive misleading recovery guidance, but an existing in-product Restore action limits the impact.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 17, 2026, 11:53 AM ET / 16:53 UTC.

@steipete
steipete merged commit 7244ad2 into main Nov 17, 2026
218 of 225 checks passed
@steipete
steipete deleted the codex/dashboard-workspace-owner branch November 17, 2026 17:11
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 18, 2026
tideclaw-bot pushed a commit that referenced this pull request Nov 24, 2026
* 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. security-sensitive-changed size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant