Skip to content

feat: automatic managed git worktrees for agent tasks (create, snapshot, restore, GC)#100535

Merged
steipete merged 1 commit into
mainfrom
claude/blissful-heisenberg-98c99c
Jul 6, 2026
Merged

feat: automatic managed git worktrees for agent tasks (create, snapshot, restore, GC)#100535
steipete merged 1 commit into
mainfrom
claude/blissful-heisenberg-98c99c

Conversation

@steipete

@steipete steipete commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Closes #100534

What Problem This Solves

Agent tasks and operators have no isolated, managed place to work on a git repo. Parallel tasks collide in the user's checkout, hand-made temporary checkouts leak forever, and Workboard cards that declare workspace.kind: "worktree" silently do nothing because nothing materializes them. Automatic worktree management is the industry-standard answer (Claude Code, Codex, Cursor, Copilot, Hermes all ship it).

Why This Change Was Made

Adds a core managed-worktree service with the convergent industry lifecycle — create → provision → work → snapshot → cleanup/restore — built on OpenClaw's canonical seams: SQLite registry in the shared state DB, additive worktrees.* gateway methods (mutations require operator.admin), a narrow plugin-SDK facade, and hourly GC owned by gateway maintenance. Worktrees live centrally under <state-dir>/worktrees/<repo-fingerprint>/<name> on branch openclaw/<name>. Removal always snapshots the tree (untracked files included, gitignored files excluded) to refs/openclaw/snapshots/<id> in the source repo, so even automatic cleanup is restorable; restore rebuilds the branch at the original commit and returns the snapshot content as uncommitted working state, so snapshot commits can never leak into pushed history. Provisioning follows the cross-vendor .worktreeinclude convention plus an optional .openclaw/worktree-setup.sh repo hook (no new config keys). Manual worktrees are never auto-swept; workboard/session-owned ones GC after 7 idle days; snapshots are retained 30 days.

Non-goals: foreign worktree management (~/.codex/worktrees, .claude/worktrees), apply-to-main merge-back, port/env isolation, session-spawn trigger (follow-up).

User Impact

  • Workboard cards with workspace.kind: "worktree" now get a real isolated checkout per card, reused across retries, cleaned up losslessly when the run ends.
  • openclaw worktrees list|create|remove|restore|gc manages worktrees from the CLI; a new Control UI "Worktrees" page lists, deletes, and restores them.
  • .worktreeinclude brings .env-style gitignored files into fresh worktrees; .openclaw/worktree-setup.sh runs repo-specific setup (fail-closed).
  • Deleting a worktree is never lossy: work is snapshotted first and restorable from the UI/CLI for 30 days.
  • Known limitation (documented): sandboxed Workboard runs cannot yet use a managed-worktree cwd; the sandbox runner pins cwd to the agent workspace. Follow-up needs an SDK mount seam.

Evidence

End-to-end lifecycle proof on Blacksmith Testbox (Linux, Node 24) via the real CLI against a real repo with a bare origin:

  • create: worktree under the centralized root, openclaw/e2e-demo checked out, .env provisioned via .worktreeinclude, setup script ran, node_modules not copied
  • remove: snapshot commit OpenClaw worktree snapshot: manual-delete at refs/openclaw/snapshots/<id>; untracked file captured; .env and node_modules excluded; snapshot parent == worktree HEAD; dir and branch gone
  • restore: branch tip == pre-removal HEAD, no snapshot commit in branch history, untracked file back as untracked, uncommitted modification back unstaged, .env re-provisioned
  • gc: 8-day-idle workboard worktree swept (with snapshot), 8-day-idle manual worktree kept, orphan directory reconciled

Gates on Testbox (post-rebase on latest main): tsgo:prod + tsgo:test green, oxlint 0 warnings/0 errors on all touched paths, focused suites green (worktrees service 44 tests, gateway methods, gateway maintenance, protocol schema, workboard incl. dispatcher materialization, UI navigation), pnpm build clean, db:kysely:check clean, ui:i18n:check clean. Codex autoreview (gpt-5.5): no actionable findings.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui gateway Gateway runtime cli CLI command changes agents Agent runtime and tooling plugin: workboard size: XL maintainer Maintainer-authored PR labels Jul 6, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d841132008

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread ui/src/app-navigation.ts
export function sidebarMoreRoutes(pinned: readonly SidebarNavRoute[]): SidebarNavRoute[] {
return SIDEBAR_NAV_ROUTES.filter((routeId) => !pinned.includes(routeId));
}
export const SIDEBAR_SECTIONS = [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep sidebar exports until callers migrate

This replaces the old sidebar export surface with SIDEBAR_SECTIONS, but ui/src/components/app-sidebar.ts and ui/src/app/settings.ts still import DEFAULT_SIDEBAR_PINNED_ROUTES, SIDEBAR_NAV_ROUTES, SidebarNavRoute, sidebarMoreRoutes, and normalizeSidebarPinnedRoutes; at this commit those symbols no longer exist, so the Control UI build/tests fail before the Worktrees page can load. Either migrate those callers to the new section model or keep the compatibility exports.

Useful? React with 👍 / 👎.

@clawsweeper

clawsweeper Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed July 5, 2026, 9:59 PM ET / 01:59 UTC.

Summary
The PR adds a core managed git worktree service with SQLite registry/snapshots/GC, new gateway/CLI/plugin-runtime/UI/Workboard surfaces, docs, tests, and regenerated UI translations.

Reproducibility: yes. for the PR blockers: source inspection shows removed sidebar exports still have callers, node_modules symlinks are tracked in the diff, and setup hook execution inherits process.env through runCommandWithTimeout. I did not run the PR branch.

Review metrics: 3 noteworthy metrics.

  • Committed install artifacts: 9 node_modules symlinks added. Tracked install artifacts can change package resolution and should be removed before review continues.
  • New runtime/API surfaces: 5 gateway methods, 1 agent cwd param, 1 plugin runtime worktrees facade. These are compatibility- and security-sensitive surfaces that need maintainer approval and upgrade proof.
  • Stored state model: 1 shared-state table plus 2 indexes added. A new persisted registry requires migration/upgrade confidence before merge.

Stored data model
Persistent data-model change detected: database schema: packages/gateway-protocol/src/schema/worktrees.test.ts, persistent cache schema: ui/src/i18n/.i18n/pt-BR.tm.jsonl, persistent cache schema: ui/src/i18n/.i18n/ru.tm.jsonl, persistent cache schema: ui/src/i18n/.i18n/th.tm.jsonl, persistent cache schema: ui/src/i18n/.i18n/tr.tm.jsonl, persistent cache schema: ui/src/i18n/.i18n/uk.tm.jsonl, and 8 more. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #100534
Summary: This PR is the explicit implementation candidate for the open managed-worktrees issue it closes; the issue remains the canonical tracker until this PR lands or is rejected.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🧂 unranked krab
Proof: 🐚 platinum hermit
Patch quality: 🧂 unranked krab
Result: blocked by patch quality or review findings.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Sanitize or gate .openclaw/worktree-setup.sh so repository hooks do not inherit the gateway process environment by default.
  • Migrate remaining sidebar/settings/tests to the new navigation model or keep compatibility exports until they are removed.
  • Remove all tracked node_modules symlinks and rerun the affected type/build/package checks.

Risk before merge

  • [P1] Merging as-is would break Control UI TypeScript consumers because the PR removes sidebar exports that unchanged callers still import.
  • [P1] The branch commits 9 node_modules symlinks, which turns local install state into tracked package-resolution and supply-chain surface.
  • [P1] The new worktree setup hook runs repo-controlled code during worktree creation and currently inherits the gateway process environment, so the security boundary needs repair and maintainer approval before merge.

Maintainer options:

  1. Fix blockers before merge (recommended)
    Remove the committed node_modules symlinks, restore or migrate the sidebar callers, and sanitize setup-hook execution before any merge decision.
  2. Accept the core boundary intentionally
    Maintainers may still choose the broad core worktree/API direction after the security and upgrade implications are explicit and repaired.
  3. Pause and split the PR
    If the core boundary is not settled, pause this branch and request a smaller design or staged PR sequence.

Next step before merge

  • [P2] Maintainer review is needed before repair automation because the PR adds broad core/API/security surfaces and currently has blocking findings that should be fixed only if maintainers keep this direction.

Maintainer decision needed

  • Question: Should OpenClaw core own automatic managed worktree creation/restoration, including the plugin runtime facade and executable repo setup hook, after the current blockers are fixed?
  • Rationale: The feature spans core state, gateway RPC, CLI, plugin runtime, Workboard, Control UI, Git operations, and repo-controlled code execution, so automation cannot choose the permanent product/security boundary on its own.
  • Likely owner: steipete — He is the linked issue and PR author and the recent history owner for the Workboard/sidebar surfaces this feature extends.
  • Options:
    • Sponsor the core feature after fixes (recommended): Fix the build, artifact, and setup-hook security blockers, then continue reviewing this PR as the canonical core implementation candidate.
    • Split before accepting: Ask for a narrower staged design that separates core service, Workboard materialization, UI, and plugin SDK exposure before merge.
    • Pause core ownership: Close or pause this PR if maintainers decide managed worktrees should live outside core or behind a different extension API first.

Security
Needs attention: Needs attention: the PR introduces repo-controlled setup hook execution with inherited process environment and commits node_modules symlinks.

Review findings

  • [P1] Sanitize the setup hook environment — src/agents/worktrees/service.ts:267-274
  • [P1] Keep sidebar exports until callers migrate — ui/src/app-navigation.ts:17-34
  • [P1] Remove committed node_modules symlinks — packages/acp-core/node_modules/@openclaw/normalization-core:1
Review details

Best possible solution:

Keep this PR as the implementation candidate, but merge only after removing install artifacts, preserving or migrating sidebar API callers, sanitizing setup-hook execution, and getting maintainer approval for the core/API/security boundary.

Do we have a high-confidence way to reproduce the issue?

Yes for the PR blockers: source inspection shows removed sidebar exports still have callers, node_modules symlinks are tracked in the diff, and setup hook execution inherits process.env through runCommandWithTimeout. I did not run the PR branch.

Is this the best way to solve the issue?

No, not as-is. The managed-worktree direction is plausible, but the branch needs blocker fixes and maintainer approval for the new core, protocol, plugin SDK, state, and security surfaces.

Full review comments:

  • [P1] Sanitize the setup hook environment — src/agents/worktrees/service.ts:267-274
    runCommandWithTimeout merges the supplied env with process.env by default, so this repo-controlled .openclaw/worktree-setup.sh runs with the gateway's full environment, not only the two worktree path variables documented for the hook. That can expose tokens or operator environment to any repository whose worktree is created; pass an explicit sanitized baseEnv/allowlist or require a separate trusted-hook path before running it automatically.
    Confidence: 0.88
  • [P1] Keep sidebar exports until callers migrate — ui/src/app-navigation.ts:17-34
    This module no longer exports the old sidebar API, but ui/src/components/app-sidebar.ts, ui/src/app/settings.ts, and existing navigation tests still import those symbols. The Control UI build/typecheck will fail before the new Worktrees page can load; migrate those callers to SIDEBAR_SECTIONS or keep compatibility exports until they are gone.
    Confidence: 0.97
  • [P1] Remove committed node_modules symlinks — packages/acp-core/node_modules/@openclaw/normalization-core:1
    The PR tracks local package-manager symlinks under packages/*/node_modules and ui/node_modules. Those install artifacts are ignored by the repo and can change package resolution or shipped package contents on clean checkouts, so they need to be removed from the branch.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.94

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 4a5bdc6ae3a9.

Label changes

Label changes:

  • add P2: This is a significant feature PR with concrete merge blockers, but it is not a shipped emergency or active user regression.
  • add merge-risk: 🚨 compatibility: The PR changes gateway protocol, plugin runtime API, persisted state, agent cwd handling, and Control UI navigation/settings behavior.
  • add merge-risk: 🚨 security-boundary: The new worktree lifecycle can run repo-controlled setup scripts and manage host paths from gateway/admin/plugin surfaces.
  • add merge-risk: 🚨 availability: The current head removes exports still used by Control UI callers, so merging as-is would break the UI build/runtime surface.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body gives Testbox CLI lifecycle proof for create, remove, restore, and GC against a real repository, but code/security findings still block merge.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🐚 platinum hermit and patch quality is 🧂 unranked krab.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (terminal): The PR body gives Testbox CLI lifecycle proof for create, remove, restore, and GC against a real repository, but code/security findings still block merge.

Label justifications:

  • P2: This is a significant feature PR with concrete merge blockers, but it is not a shipped emergency or active user regression.
  • merge-risk: 🚨 compatibility: The PR changes gateway protocol, plugin runtime API, persisted state, agent cwd handling, and Control UI navigation/settings behavior.
  • merge-risk: 🚨 security-boundary: The new worktree lifecycle can run repo-controlled setup scripts and manage host paths from gateway/admin/plugin surfaces.
  • merge-risk: 🚨 availability: The current head removes exports still used by Control UI callers, so merging as-is would break the UI build/runtime surface.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🐚 platinum hermit and patch quality is 🧂 unranked krab.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (terminal): The PR body gives Testbox CLI lifecycle proof for create, remove, restore, and GC against a real repository, but code/security findings still block merge.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body gives Testbox CLI lifecycle proof for create, remove, restore, and GC against a real repository, but code/security findings still block merge.
Evidence reviewed

Security concerns:

  • [high] Setup hook inherits gateway environment — src/agents/worktrees/service.ts:267
    The worktree setup script runs from the source repository and the spawn helper merges its env overlay with process.env, so secrets or operator environment variables can be exposed to repository code during worktree creation.
    Confidence: 0.88
  • [medium] node_modules symlinks committed — packages/acp-core/node_modules/@openclaw/normalization-core:1
    Tracked node_modules symlinks are local install artifacts and create a package-resolution/supply-chain surface unrelated to the feature implementation.
    Confidence: 0.99

What I checked:

  • Sidebar export regression: The PR replaces the old sidebar export surface with SIDEBAR_SECTIONS, while app-sidebar, app settings, and existing navigation tests still import DEFAULT_SIDEBAR_PINNED_ROUTES, SIDEBAR_NAV_ROUTES, SidebarNavRoute, sidebarMoreRoutes, or normalizeSidebarPinnedRoutes from the same module. (ui/src/app-navigation.ts:17, d84113200885)
  • Committed install artifacts: The diff adds 9 symlinks under package and UI node_modules directories; these are local package-manager artifacts and a package/supply-chain surface, not source files. (packages/acp-core/node_modules/@openclaw/normalization-core:1, d84113200885)
  • Setup hook inherits process environment: The new worktree setup hook is executed with runCommandWithTimeout and an env overlay; that helper merges overlays with process.env by default, so repo-controlled setup scripts inherit the gateway process environment unless the call supplies a sanitized baseEnv. (src/agents/worktrees/service.ts:267, d84113200885)
  • Linked canonical issue: Live issue data shows Automatic git worktree management for agent tasks #100534 is open, has a maintainer label, and this PR is its explicit closing implementation candidate.
  • Feature history routing: Current-main blame and log point the Workboard dispatcher and Control UI sidebar/navigation surface to recent work by steipete, making him the best available routing owner for this feature boundary. (extensions/workboard/src/dispatcher.ts:1, aaf5ab910cbe)

Likely related people:

  • steipete: Current-main blame attributes the Workboard dispatcher and Control UI sidebar/navigation surface to recent commits by Peter Steinberger, and the linked issue/PR are authored by the same account. (role: recent feature-area contributor and likely follow-up owner; confidence: high; commits: aaf5ab910cbe, 60cf7eaa005; files: extensions/workboard/src/dispatcher.ts, ui/src/app-navigation.ts, ui/src/components/app-sidebar.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Jul 6, 2026
…apshot/restore/GC)

Centralized managed worktrees under <state-dir>/worktrees/<repo-fingerprint>/<name>
with branch-per-task (openclaw/<name>), .worktreeinclude provisioning, an optional
.openclaw/worktree-setup.sh repo hook, and a SQLite registry in the shared state DB.
Removal always snapshots the tree (untracked included, gitignored excluded) to
refs/openclaw/snapshots/<id>; restore rebuilds the branch at the original commit with
the snapshot content as uncommitted state. Lossless run-end cleanup, 7-day idle GC for
run-owned worktrees (manual exempt), orphan reconciliation, 30-day snapshot retention.
Surfaces: worktrees.* gateway RPC (operator.admin mutations), openclaw worktrees CLI,
Control UI page, plugin-SDK facade + Workboard kind:"worktree" materialization.

E2E-verified on Testbox: full create->work->remove->restore->gc lifecycle.
@steipete
steipete force-pushed the claude/blissful-heisenberg-98c99c branch from d841132 to 4150d98 Compare July 6, 2026 04:24
@steipete
steipete merged commit 0acd851 into main Jul 6, 2026
45 checks passed
@steipete
steipete deleted the claude/blissful-heisenberg-98c99c branch July 6, 2026 04:25

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4150d98e2f

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@@ -0,0 +1 @@
../../../normalization-core No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Remove committed node_modules symlinks

This commit starts tracking pnpm-generated node_modules symlinks here and in the other added packages/*/node_modules / ui/node_modules paths. In a clean checkout these local install artifacts will be materialized by Git and then package-manager installs can rewrite or remove them, leaving dirty worktrees and making the dependency layout depend on tracked node_modules entries instead of the lockfile; please drop these generated links from the commit.

Useful? React with 👍 / 👎.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 6, 2026
…apshot/restore/GC) (openclaw#100535)

Centralized managed worktrees under <state-dir>/worktrees/<repo-fingerprint>/<name>
with branch-per-task (openclaw/<name>), .worktreeinclude provisioning, an optional
.openclaw/worktree-setup.sh repo hook, and a SQLite registry in the shared state DB.
Removal always snapshots the tree (untracked included, gitignored excluded) to
refs/openclaw/snapshots/<id>; restore rebuilds the branch at the original commit with
the snapshot content as uncommitted state. Lossless run-end cleanup, 7-day idle GC for
run-owned worktrees (manual exempt), orphan reconciliation, 30-day snapshot retention.
Surfaces: worktrees.* gateway RPC (operator.admin mutations), openclaw worktrees CLI,
Control UI page, plugin-SDK facade + Workboard kind:"worktree" materialization.

E2E-verified on Testbox: full create->work->remove->restore->gc lifecycle.
steipete added a commit that referenced this pull request Jul 6, 2026
Adds an additive worktree flag to sessions.create so any new chat can run in an
isolated managed worktree of the agent's git workspace, with the branch checked
out and .worktreeinclude provisioning applied. The session's spawnedCwd points at
the matching subdirectory inside the worktree so chat runs, CLI, and the file
browser execute there. agents.list gains workspaceGit (workspace or an ancestor
is a git checkout) to gate the affordance; web sidebar, iOS, and Android expose a
New-Chat-in-worktree action. Uses the method's operator.write scope, but the
.openclaw/worktree-setup.sh step runs only for operator.admin callers since it
executes repo code. Deleting the session, or leaving via a plain New Chat, clears
the cwd and lossless-removes the worktree; idle GC treats recent session activity
as worktree activity so an active session's checkout is never swept.

Live-verified end-to-end on a real gateway; follow-up to #100535 (issue #100534).
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 7, 2026
…aw#100788)

Adds an additive worktree flag to sessions.create so any new chat can run in an
isolated managed worktree of the agent's git workspace, with the branch checked
out and .worktreeinclude provisioning applied. The session's spawnedCwd points at
the matching subdirectory inside the worktree so chat runs, CLI, and the file
browser execute there. agents.list gains workspaceGit (workspace or an ancestor
is a git checkout) to gate the affordance; web sidebar, iOS, and Android expose a
New-Chat-in-worktree action. Uses the method's operator.write scope, but the
.openclaw/worktree-setup.sh step runs only for operator.admin callers since it
executes repo code. Deleting the session, or leaving via a plain New Chat, clears
the cwd and lossless-removes the worktree; idle GC treats recent session activity
as worktree activity so an active session's checkout is never swept.

Live-verified end-to-end on a real gateway; follow-up to openclaw#100535 (issue openclaw#100534).
giodl73-repo pushed a commit to giodl73-repo/openclaw that referenced this pull request Jul 8, 2026
…apshot/restore/GC) (openclaw#100535)

Centralized managed worktrees under <state-dir>/worktrees/<repo-fingerprint>/<name>
with branch-per-task (openclaw/<name>), .worktreeinclude provisioning, an optional
.openclaw/worktree-setup.sh repo hook, and a SQLite registry in the shared state DB.
Removal always snapshots the tree (untracked included, gitignored excluded) to
refs/openclaw/snapshots/<id>; restore rebuilds the branch at the original commit with
the snapshot content as uncommitted state. Lossless run-end cleanup, 7-day idle GC for
run-owned worktrees (manual exempt), orphan reconciliation, 30-day snapshot retention.
Surfaces: worktrees.* gateway RPC (operator.admin mutations), openclaw worktrees CLI,
Control UI page, plugin-SDK facade + Workboard kind:"worktree" materialization.

E2E-verified on Testbox: full create->work->remove->restore->gc lifecycle.
giodl73-repo pushed a commit to giodl73-repo/openclaw that referenced this pull request Jul 8, 2026
…aw#100788)

Adds an additive worktree flag to sessions.create so any new chat can run in an
isolated managed worktree of the agent's git workspace, with the branch checked
out and .worktreeinclude provisioning applied. The session's spawnedCwd points at
the matching subdirectory inside the worktree so chat runs, CLI, and the file
browser execute there. agents.list gains workspaceGit (workspace or an ancestor
is a git checkout) to gate the affordance; web sidebar, iOS, and Android expose a
New-Chat-in-worktree action. Uses the method's operator.write scope, but the
.openclaw/worktree-setup.sh step runs only for operator.admin callers since it
executes repo code. Deleting the session, or leaving via a plain New Chat, clears
the cwd and lossless-removes the worktree; idle GC treats recent session activity
as worktree activity so an active session's checkout is never swept.

Live-verified end-to-end on a real gateway; follow-up to openclaw#100535 (issue openclaw#100534).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: web-ui App: web-ui cli CLI command changes docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. plugin: workboard proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XL 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.

Automatic git worktree management for agent tasks

1 participant