Skip to content

feat(sandbox): confirm before auto-starting on another member's thread - #5086

Merged
guitavano merged 2 commits into
mainfrom
guitavano/sandbox-branch-leak
Jul 23, 2026
Merged

guitavano merged 2 commits into
mainfrom
guitavano/sandbox-branch-leak

Conversation

@guitavano

@guitavano guitavano commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Opening another org member's thread by URL (/<org>/<threadId>) silently auto-started a sandbox on the creator's branch. The existing "read-only" guard only replaced the chat composer — the sandbox/CMS preview kept booting and stayed fully editable, so a user could edit (and commit to) someone else's branch without ever choosing to.

This adds a confirmation gate: when the active thread belongs to someone else, the sandbox does not auto-start. The preview shows a card identifying the thread with two actions:

  • Continue anyway → releases the gate and boots the sandbox on that branch (the old behavior, now deliberate).
  • Start new chat → navigates to a fresh thread with no branch, so the server scopes it to the user's own warm branch (or a new one) — never the creator's.

On your own thread nothing changes.

How it works

  • shouldAutoStart gains an autoStartBlocked flag.
  • computePreviewState gains an othersThread state that wins before starting (but yields to a live previewUrl, i.e. once acknowledged).
  • SandboxLifecycleProvider takes an othersThreadLabel prop (branch, or title fallback) and an acknowledgeOthersThread() action; the acknowledgement is keyed by branch so switching threads re-arms the gate.
  • VmEventsBridge computes othersThreadLabel from activeTask.created_by !== userId — the same signal the chat composer's read-only banner already uses.
  • content-browser narrows out the new state (the Content tab is gated behind phase === "running" and never passes the gate).

Scope

This is a client-side mitigation, matching the existing read-only banner. The authoritative fixes are follow-ups:

  • COLLECTION_THREADS_GET (storage/threads.ts) scopes only by org, not owner — any member can open any thread id by URL.
  • "Continue anyway" still yields an editable sandbox on the creator's branch.

Testing

  • bun run --cwd=apps/mesh check ✅
  • bun test apps/mesh/src/web/components/sandbox/ → 385 pass ✅ (added cases for shouldAutoStart blocked, computeDrawerStatus othersThread→idle, and computePreviewState gate precedence)
  • bun run lint — no new warnings ✅
  • bun run fmt applied ✅

🤖 Generated with Claude Code


Summary by cubic

Add a confirmation gate before auto-starting the sandbox when opening another member’s thread to prevent silent boot/edits on their branch. Users can continue on that branch or start a new thread on their own.

  • New Features

    • Block auto-start on others’ threads via autoStartBlocked; Preview shows a card with the thread label and actions: “Continue anyway” or “Start new chat”.
    • Preview adds an othersThread gate that wins before starting; Content remains gated by phase === "running".
    • SandboxLifecycleProvider now takes othersThreadLabel + othersThreadId and exposes acknowledgeOthersThread(); VmEventsBridge derives the label with deriveOthersThreadLabel.
    • Added en/pt-br strings and tests. Client-side mitigation; server scoping follow-up remains.
  • Bug Fixes

    • Self-heal also honors the gate (shouldSelfHeal), preventing silent reprovision on another member’s branch.
    • Acknowledgement keyed by thread id (not branch), fixing the null-branch re-prompt/double-start and avoiding cross-thread collisions on identical branch names.

Written for commit 52f9507. Summary will update on new commits.

Review in cubic

guitavano and others added 2 commits July 22, 2026 23:56
Opening another org member's thread by URL silently auto-started a
sandbox on the creator's branch (the read-only gate only covered the
chat composer, not the sandbox/CMS). Hold auto-start behind a
confirmation gate for threads owned by someone else: the preview shows a
card identifying the thread with "Continue anyway" / "Start new chat"
instead of booting.

- shouldAutoStart: new autoStartBlocked flag
- computePreviewState: new "othersThread" gate state (wins before starting)
- SandboxLifecycleProvider: othersThreadLabel prop + acknowledge action,
  gate keyed by branch so switching threads re-arms it
- "Start new chat" navigates to a fresh thread with no branch, so the
  server scopes it to the user's own warm branch (never the creator's)
- i18n (en + pt-br), tests for the gate

Client-side mitigation; the authoritative server-side ownership scope on
COLLECTION_THREADS_GET is a follow-up.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Addresses correctness + testing findings from PR review:

- Gate self-heal too: shouldSelfHeal now honors autoStartBlocked, so a
  stale dead-handle can't silently reprovision a sandbox on another
  member's branch while the confirmation gate is up.
- Key the acknowledgement by thread id, not branch. Fixes the null-branch
  case where the server assigning a branch re-armed the gate mid-boot
  (re-prompt + a second SANDBOX_START), and stops two members' threads
  that collide on a branch name from sharing an acknowledgement.
- Extract deriveOthersThreadLabel + computeOthersThreadGate as pure,
  unit-tested helpers (the ownership rule and gate derivation were
  provider-internal before — an inverted comparison would have shipped
  green). 11 new helper cases + self-heal-blocked + gate-vs-suspended /
  gate-vs-errored precedence.
- Rename the card prop onStartNewChat → onStartNewThread (code = thread).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@guitavano

Copy link
Copy Markdown
Contributor Author

Self-review (parallel critics: correctness / security / architecture / testing)

Ran a multi-perspective review and pushed fixes for the substantive findings in 52f95070.

Fixed

  • Self-heal bypassed the gate (correctness). shouldSelfHeal didn't check autoStartBlocked, so a stale dead handle could silently reprovision a sandbox on another member's branch while the gate was up. Now gated + tested.
  • Null-branch re-prompt / double-start (correctness). The acknowledgement was keyed by branch; when the server assigned a branch to a null-branch thread, the gate re-armed mid-boot and a second SANDBOX_START could fire. Re-keyed the acknowledgement by thread id (also stops two members' threads colliding on a branch name from sharing an ack). Tested.
  • Untested gate logic / ownership wiring (testing). Extracted deriveOthersThreadLabel + computeOthersThreadGate as pure helpers and unit-tested them (an inverted created_by comparison would previously have shipped green). +14 unit cases incl. gate-vs-suspended/errored precedence. 399 pass.
  • Naming (architecture): onStartNewChat → onStartNewThread (code identifier = thread per CLAUDE.md).

Deferred (tracked, not in this PR)

  • This is a client-side UX speed bump, not the isolation fix. "Continue anyway" still yields an editable sandbox on the creator's branch. The real fix is server-side: scope COLLECTION_THREADS_GET / SANDBOX_START by owner (or an explicit collaborator grant), and enforce a true non-owner read-only mode across all mutation surfaces (not just the chat composer). This PR does not touch that and should not be read as closing the gap.
  • Content tab manual "Start" is not gated — it can boot on the creator's branch without the warning. Reachability is limited (the tab is gated behind phase === "running"), but it's an inconsistency that the server-side fix should subsume.
  • Two-member Playwright e2e for the land-on-others-thread flow — the extracted-helper unit tests now cover the decision logic; a full e2e (real invite + sandbox start) is a recommended follow-up.

@guitavano
guitavano merged commit 2c252aa into main Jul 23, 2026
14 checks passed
@guitavano
guitavano deleted the guitavano/sandbox-branch-leak branch July 23, 2026 03:18
decocms Bot pushed a commit that referenced this pull request Jul 23, 2026
PR: #5086 feat(sandbox): confirm before auto-starting on another member's thread
Bump type: minor

- decocms (apps/mesh/package.json): 4.100.2 -> 4.101.0

Deploy-Scope: web
rafavalls added a commit that referenced this pull request Jul 23, 2026
Only conflict was apps/mesh/src/web/components/sandbox/preview/preview.tsx,
where main's new preview "display model" (#5084 production fallback while the
dev server wakes, #5089 resilient path-param picker, #5086 confirm-before-
auto-start) collided with this branch's header-portal redesign of the same
toolbar.

Resolution: keep the redesign's structure (urlControls / moreMenu extracted and
portaled into the panel header via headerSlot) and adopt main's display model:
- showPreviewToolbar now follows main's visibility — shown once an iframe
  surface is active (sandbox when the daemon is up, or the production fallback
  while it wakes) instead of `daemonReady && previewState.kind === "iframe"`.
- canVisualEdit uses `display.mode === "sandbox"`.
- "Open in new tab" resolves the URL via `iframeSrc ?? display.iframeBase`
  (previewState.previewUrl no longer exists under the display model).
Main's toolbar-internal changes were pure re-indentation (verified against the
base diff), so the extracted urlControls/moreMenu already carry them; main's
other features (waking pill, confirm dialog) live outside the toolbar and
auto-merged.

Verified: tsc across all workspaces, oxlint (0), knip (clean), format.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant