Skip to content

fix(ui): show worktree setup in new sessions - #125100

Closed
vyctorbrzezowski wants to merge 5 commits into
mainfrom
fix/124966-optimistic-worktree-sessions
Closed

vyctorbrzezowski wants to merge 5 commits into
mainfrom
fix/124966-optimistic-worktree-sessions

Conversation

@vyctorbrzezowski

@vyctorbrzezowski vyctorbrzezowski commented Aug 17, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Closes #124966.

Starting a Control UI session with Worktree selected previously kept the operator on the New Session page while checkout and repository setup ran. The Enter action appeared inert, and the accepted first turn had no visible session identity or progress.

Why This Change Was Made

The Gateway now commits the session and a bounded projection of the first user turn before managed-worktree preparation begins, then returns the real session key immediately. Worktree preparation remains owned by one durable startup lifecycle with exact generation, delegated-authority, cancellation, cleanup, restart-recovery, and first-turn admission fences.

The Control UI navigates immediately, renders the submitted turn and bounded setup tail in the transcript, and keeps participation blocked until the initial turn is admitted. Cancel and Work locally are available during setup. A completed worktree has an explicit recovery action if the Gateway restarts before the first turn starts.

The closeout also:

  • splits the startup lifecycle out of sessions-create.ts into focused owners;
  • rolls back provisioned worktrees when cancellation, authority loss, or lifecycle replacement wins;
  • keeps attachment bytes out of session rows while preserving display metadata;
  • coalesces bounded-tail process output and decodes UTF-8 across process chunks;
  • preserves the existing unbounded public sessions.create.message request contract.

User Impact

After pressing Enter, operators immediately arrive in the new session, see their message, and can follow Checking out files… through Workspace ready. The composer does not show a separate “Preparing workspace…” status and remains blocked only while startup owns the first turn. Failure, cancellation, restart, and work-local choices all produce visible outcomes without duplicate sessions or leaked checkouts.

Evidence

Exact closeout commit: 076bf9eb86b9f120b688b4ff1a1afad91da20182

Full flow

The recording asserts: new-session submit → immediate transcript/session → checkout progress with Cancel / Work locally → Workspace ready → startup card removal before first stream → final assistant response.

pr-125100-full-flow.mp4

Before

Before: submit waits on the New Session page

Desktop

Dark progress Dark ready
Dark desktop progress Dark desktop ready
Light progress Light ready
Light desktop progress Light desktop ready

Mobile

Dark progress Dark ready
Dark mobile progress Dark mobile ready
Light progress Light ready
Light mobile progress Light mobile ready

All captures were inspected after recording. The progress states show the first turn, setup tail, both recovery actions, and no “Preparing workspace…” composer copy. Ready states show the completed checkout and explicit recovery action across desktop/mobile and dark/light.

Validation

  • OPENCLAW_VITEST_MAX_WORKERS=2 node scripts/run-vitest.mjs src/gateway/server.sessions.create.test.ts — 242 passed across both Gateway shards.
  • OPENCLAW_VITEST_MAX_WORKERS=2 node scripts/run-vitest.mjs run --config test/vitest/vitest.ui-e2e.config.ts --configLoader runner ui/src/e2e/new-session-page.worktree-startup.e2e.test.ts — passed.
  • OPENCLAW_VITEST_MAX_WORKERS=2 node scripts/check-changed.mjs — passed; SwiftLint was unavailable on Linux and remains owned by macOS CI.
  • pnpm build — passed, including Control UI performance budgets and published-surface checks.
  • codex --dangerously-bypass-approvals-and-sandbox review --base origin/main — final codex-review-19.log: no actionable correctness defects.

New/changed behavioral tests: 8 focused startup cases plus the Control UI E2E and metadata attachment assertion. Each protects behavior absent from the pre-fix flow: optimistic session visibility, authority retention, post-provision rollback, restart recovery, first-turn ordering, bounded metadata, UTF-8 streaming output, and completed-state participation blocking.

Closeout production delta: +1152/-735; test and test-support delta: +406/-48. The production increase is the durable startup protocol/lifecycle capability; sessions-create.ts itself is reduced by 548 lines and the lifecycle is split into its owning modules.

@vyctorbrzezowski vyctorbrzezowski self-assigned this Aug 17, 2026
@clawsweeper

clawsweeper Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui gateway Gateway runtime agents Agent runtime and tooling size: L maintainer Maintainer-authored PR labels Aug 17, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. 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. labels Aug 17, 2026
@clawsweeper

clawsweeper Bot commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed August 23, 2026, 2:56 PM ET / 18:56 UTC.

ClawSweeper review

What this changes

This PR creates a managed-worktree session immediately, shows setup progress in Control UI, and defers the first agent turn until workspace preparation finishes.

Merge readiness

⛔ Blocked until stronger real behavior proof is added - 7 items remain

Keep open: the revised lifecycle still permits revoked delegated authority to reach Git work before its first authority check, so the prior P1 remains unresolved.

Priority: P1
Reviewed head: 076bf9eb86b9f120b688b4ff1a1afad91da20182

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The PR has strong visible-flow evidence, but the unresolved P1 authority path blocks merge readiness.
Proof confidence 🦪 silver shellfish (2/6) Needs stronger real behavior proof before merge: Authority-chain proof required: the supplied recording demonstrates the allowed UI flow, but not that the nearest revoked delegated runtime is rejected before Git fetch, checkout, provisioning, or setup; add redacted final-effect evidence for that case. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🦪 silver shellfish (2/6) Security review found an item that needs attention.

Verification

Check Result Evidence
Real behavior Needs proof Needs stronger real behavior proof before merge: Authority-chain proof required: the supplied recording demonstrates the allowed UI flow, but not that the nearest revoked delegated runtime is rejected before Git fetch, checkout, provisioning, or setup; add redacted final-effect evidence for that case. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 5 items Authority gap: The worktree service calls the revocable commit guard only after resolving the base; resolving an unspecified base calls Git fetch first, so authority revocation can still reach repository I/O.
Caller chain: The deferred startup passes the original session-create guard into managed-worktree creation, but the callee does not invoke it before its fetch path.
Existing test misses early revocation: The authority test flips authority only after managedWorktrees.create has returned, so it proves rollback at the later writer boundary rather than preventing fetch or checkout after revocation.
Findings 1 actionable finding [P1] Revalidate authority before starting Git work
Security Needs attention Revoked authority can reach Git fetch: The deferred managed-worktree path validates its delegated authority after base resolution, allowing the unspecified-base fetch path to execute after revocation.

Live Verification

Command: node scripts/run-vitest.mjs src/gateway/server.sessions.create.test.ts -t "sessions.create keeps delegated authority attached to deferred worktree setup"

Result: PASS (completed)

node scripts/run-vitest.mjs src/gateway/server.sessions.create.test.ts -t "sessions.create keeps delegated authority attached to deferred worktree setup"
runner@runnervm76f27:/tmp/clawsweeper-live-proof-125100-oHy4PP/target$ node scripts/run-vitest.mjs src/gateway/server.sessions.create.test.ts -t "sessions.creat
e keeps delegated authority attached to deferred worktree setup"
node scripts/run-vitest.mjs src/gateway/server.sessions.create.test.ts -t "sessions.create keeps delegated authority attached to deferred worktree setup"
[test] starting test/vitest/vitest.gateway.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-125100-oHy4PP/target

 ✓  gateway-server-isolated  ../../src/gateway/server.sessions.create.test.ts (121 tests | 120 skipped) 17121ms
   ✓ sessions.create keeps delegated authority attached to deferred worktree setup  2315ms









































Assertions:

  • PASS expect_output: sessions.create keeps delegated authority attached to deferred worktree setup

How this fits together

Control UI submits a new session to the Gateway, which allocates its durable identity and prepares a managed Git worktree before admitting the first turn. The new startup state is persisted through Gateway session rows and rendered as a transcript card with recovery actions.

flowchart LR
  A[Control UI submission] --> B[Gateway session identity]
  B --> C[Durable startup state]
  C --> D[Managed Git worktree]
  D --> E[First-turn admission]
  C --> F[Transcript progress card]
  E --> F
Loading

Before merge

  • Add real behavior proof - Needs stronger real behavior proof before merge: Authority-chain proof required: the supplied recording demonstrates the allowed UI flow, but not that the nearest revoked delegated runtime is rejected before Git fetch, checkout, provisioning, or setup; add redacted final-effect evidence for that case. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Revalidate authority before starting Git work (P1) - commitGuard runs only after resolveWorktreeBase, whose unspecified-base path emits progress and runs git fetch origin. Revoking the delegated runtime after session creation can therefore still trigger repository I/O before rejection; guard stage writes and every Git/provisioning boundary, and cover revocation before fetch.
  • Resolve security concern: Revoked authority can reach Git fetch - The deferred managed-worktree path validates its delegated authority after base resolution, allowing the unspecified-base fetch path to execute after revocation.
  • Resolve merge risk (P1) - A revoked delegated runtime can still trigger git fetch origin and progress-state writes before the deferred startup detects the revoked authority; this is a security-boundary and workspace-side-effect risk.
  • Complete next step (P2) - The remaining P1 is mechanically clear, but this maintainer-authored, protected PR needs its authority boundary corrected and re-reviewed rather than automated cleanup.
  • Improve patch quality - Add final-effect proof for the nearest unauthorized principal and prove revocation prevents Git I/O before any fetch, checkout, provisioning, or setup.
  • Improve patch quality - Extend the Gateway regression so revocation occurs before base resolution, not after worktree creation returns.

Findings

  • [P1] Revalidate authority before starting Git work — src/agents/worktrees/service.ts:721-727
  • [high] Revoked authority can reach Git fetch — src/agents/worktrees/service.ts:721
Agent review details

Security

Needs attention: The deferred startup still permits a revoked authority to reach repository-side effects before its guard runs.

PR surface

Source +1573, Tests +638, Docs +2, Other +44. Total +2257 across 55 files.

View PR surface stats
Area Files Added Removed Net
Source 46 1689 116 +1573
Tests 5 663 25 +638
Docs 1 2 0 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 3 46 2 +44
Total 55 2400 143 +2257

Review metrics

Metric Value Why it matters
Production versus test delta production +1,152/-735; tests/test-support +406/-48 The durable startup lifecycle adds net production code for a bug fix, so the remaining authority boundary must be resolved before accepting that growth.
Gateway startup surface 1 RPC added; 2 startup types exported The additive startup-resolution API and persisted state cross Gateway, Control UI, and native client contracts.

Stored data model

Persistent data-model change detected: serialized state: packages/gateway-protocol/src/schema/sessions-row.ts, serialized state: packages/gateway-protocol/src/schema/sessions-startup.ts, serialized state: packages/gateway-protocol/src/schema/sessions.ts, serialized state: src/config/sessions/store-entry-shape.ts, serialized state: src/config/sessions/types.ts, serialized state: src/gateway/server-methods/session-create-initial-dispatch.ts, and 21 more. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #124966
Summary: This PR is the active candidate fix for the linked optimistic managed-worktree startup issue.

Members:

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

Merge-risk options

Maintainer options:

  1. Fence worktree effects before merge (recommended)
    Compose the delegated-authority guard at every pre-I/O and post-await worktree boundary, then prove revocation prevents Git activity before any repository effect.

Technical review

Best possible solution:

Revalidate the original delegated-authority guard before every startup effect, including stage persistence, fetch, checkout, provisioning, setup, terminal state, and first-turn admission; add a revocation-before-fetch regression test.

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

Yes, source-reproducible: revoke the delegated runtime after the pending session is created but before base resolution, then observe that the current path can still enter git fetch origin.

Is this the best way to solve the issue?

No; the durable session and UI projection are the right owner boundary, but the guard must fence worktree effects before fetch rather than only later commits.

Full review comments:

  • [P1] Revalidate authority before starting Git work — src/agents/worktrees/service.ts:721-727
    commitGuard runs only after resolveWorktreeBase, whose unspecified-base path emits progress and runs git fetch origin. Revoking the delegated runtime after session creation can therefore still trigger repository I/O before rejection; guard stage writes and every Git/provisioning boundary, and cover revocation before fetch.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 7c7e10ab853e.

Labels

Label justifications:

  • P1: A revoked delegated runtime can still perform managed-worktree Git work during a first-turn startup.
  • merge-risk: 🚨 session-state: The PR persists and transitions a new session startup lifecycle before first-turn dispatch.
  • merge-risk: 🚨 security-boundary: Deferred worktree preparation can outlive the authority that admitted it and can reach repository side effects.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦪 silver shellfish.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: Authority-chain proof required: the supplied recording demonstrates the allowed UI flow, but not that the nearest revoked delegated runtime is rejected before Git fetch, checkout, provisioning, or setup; add redacted final-effect evidence for that case. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • proof: 🎥 video: Contributor real behavior proof includes video or recording evidence. Authority-chain proof required: the supplied recording demonstrates the allowed UI flow, but not that the nearest revoked delegated runtime is rejected before Git fetch, checkout, provisioning, or setup; add redacted final-effect evidence for that case.

Evidence

Security concerns:

  • [high] Revoked authority can reach Git fetch — src/agents/worktrees/service.ts:721
    The deferred managed-worktree path validates its delegated authority after base resolution, allowing the unspecified-base fetch path to execute after revocation.
    Confidence: 0.98

What I checked:

Likely related people:

  • Vincent Koc: Current-main blame attributes the managed-worktree session creation caller to this commit. (role: recent area contributor; confidence: high; commits: c4e0c003a406; files: src/gateway/server-methods/sessions-create.ts)
  • steipete: Feature history shows sustained work across the session-creation and managed-worktree surfaces. (role: historical contributor; confidence: medium; files: src/gateway/server-methods/sessions-create.ts, src/agents/worktrees/service.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

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

History

Review history (4 earlier review cycles)
  • reviewed 2026-08-17T06:20:04.826Z sha 5f028a4 :: found issues before merge. :: [P1] Preserve delegated authority during deferred setup | [P1] Keep worktree startup cancellable | [P1] Record deferred initial-turn failures | [P2] Persist initial attachments for reconnect recovery
  • reviewed 2026-08-20T00:24:32.726Z sha 5f028a4 :: found issues before merge. :: [P1] Preserve delegated authority during deferred setup | [P1] Make workspace startup cancellable | [P1] Record an initial-turn dispatch failure | [P2] Persist initial attachments in startup state
  • reviewed 2026-08-20T13:34:41.677Z sha 5f028a4 :: found issues before merge. :: [P1] Revalidate authority throughout deferred setup | [P1] Make deferred worktree setup cancellable | [P1] Record a failed initial-turn dispatch | [P2] Persist initial attachments in startup state
  • reviewed 2026-08-23T10:59:59.766Z sha ac2b004 :: found issues before merge. :: [P1] Compose the original authority guard with startup ownership | [P2] Rollback a worktree when cancellation wins after provisioning

@clawsweeper clawsweeper Bot added the proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. label Aug 20, 2026
@vyctorbrzezowski
vyctorbrzezowski marked this pull request as ready for review August 20, 2026 13:29
@clawsweeper

clawsweeper Bot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@vyctorbrzezowski
vyctorbrzezowski force-pushed the fix/124966-optimistic-worktree-sessions branch from 5f028a4 to ac2b004 Compare August 23, 2026 10:53
@openclaw openclaw deleted a comment from clawsweeper Aug 23, 2026
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: android App: android labels Aug 23, 2026
@clawsweeper clawsweeper Bot removed 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. labels Aug 23, 2026
@clawsweeper clawsweeper Bot added proof: 🎥 video Contributor real behavior proof includes video or recording evidence. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. labels Aug 23, 2026
@steipete

Copy link
Copy Markdown
Contributor

Heads-up for the next rebase: #130192 landed the preceding unregistered remote-project materialization path as b6662bf157e5e32cb08f5d558d4e6d5cf3a97cde.

The landed contract is deliberately split:

  • non-Worktree remote first turns create the session immediately, then prepare and bind the project inside the admitted run;
  • remote Worktree starts retain projects.add → projectId before the managed-Worktree lifecycle begins;
  • empty remote sessions also retain pre-materialization.

This does not replace the managed-Worktree startup lifecycle in this PR, but it will overlap draft-submission-flow.ts, sessions-create.ts, dispatch, session-entry state, and generated protocol clients. Please preserve the split above when rebasing rather than reintroducing the clone-before-session delay for ordinary non-Worktree remote starts.

@steipete

Copy link
Copy Markdown
Contributor

The startup-latency goal is now implemented on main by #131559, merged as 54a5358, which also closes #124966.

The landed path extends the admitted-run workspace preparation owner introduced by #130192: create/open the real session before naming, checkout, and setup; restore progress after reload; keep failures and retries in that session; bind the checkout before agent/terminal execution. The PR includes an inspected real-Gateway/Codex recording and green exact-head CI, plus retry/authority and lifecycle regressions.

Closing this earlier implementation as superseded so there is one canonical startup lifecycle. This does not claim to include its additional Work locally/setup-output-tail UI; those would be separate UX proposals rather than a reason to retain a second initialization state machine. Thanks for the earlier investigation and proposal, which are linked from the landed PR.

@steipete steipete closed this Aug 28, 2026
@RomneyDa
RomneyDa deleted the fix/124966-optimistic-worktree-sessions branch October 22, 2026 00:19
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: android App: android app: web-ui App: web-ui docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. proof: 🎥 video Contributor real behavior proof includes video or recording evidence. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: XL status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Control UI: create worktree sessions optimistically and show setup progress

2 participants