Skip to content

feat(core): add remote workspace lifecycle seam#37437

Draft
kitlangton wants to merge 4 commits into
v2from
remote-workspaces-plan
Draft

feat(core): add remote workspace lifecycle seam#37437
kitlangton wants to merge 4 commits into
v2from
remote-workspaces-plan

Conversation

@kitlangton

@kitlangton kitlangton commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

What

Introduce the provider-neutral lifecycle and environment seam for centrally executed V2 Sessions to address hosted Workspaces without touching the server host checkout.

  • Adds browser-safe Workspace.Info metadata.
  • Adds provider-neutral create, connect, suspend, reconcile, and delete contracts.
  • Adds a lazy, scoped, idle-expiring Workspace connection cache.
  • Fences lifecycle transitions against active file and process leases.
  • Resolves hosted Location project metadata from the Workspace record instead of host-local Project.resolve.
  • Keeps implicit-local Location behavior unchanged.
  • Includes the staged implementation plan in specs/v2/remote-workspace-execution.md.

How

  • packages/core/src/workspace.ts owns Workspace creation, connection, suspension, and removal; compensates failed initial persistence; persists replacement bindings before reconciliation; and keeps deletion retryable when the provider fails.
  • A keyed writer-preferring lifecycle gate closes admission, drains scoped borrows, runs one transition, and reopens admission on success, failure, or interruption.
  • packages/core/src/workspace.ts reads durable metadata independently from provider connection, shares concurrent connections through RcMap, and immediately evicts failed acquisitions.
  • packages/core/src/workspace/sandbox.ts requires a versioned kind: "sandbox" placement envelope before V2 can interpret legacy Workspace JSON. Providers own binding decoding and lifecycle operations.
  • packages/core/src/workspace/environment.ts binds separate local and hosted Location services. Hosted file operations borrow one connection, resolve provider-canonical paths, and reject direct or symlink escapes outside the Workspace root.
  • packages/core/src/location.ts selects local Project resolution or hosted Workspace metadata at node-binding time and lexically rejects working directories outside the durable Workspace root.
  • Local mutations share one keyed target lock, including ordinary writes, conditional writes, exclusive creates, and removal.

Scope

This PR establishes placement, lifecycle, and connection seams only.

  • No Vercel, Daytona, Modal, or E2B production adapter.
  • No public HTTP or product provisioning surface for hosted Workspaces.
  • No migration of existing file, shell, search, config, VCS, PTY, snapshot, or watcher consumers.
  • No claim that a complete hosted Session can execute tools yet.
  • Hosted Location lookup errors still follow the current infallible Location-layer boot contract; transport-level placement errors are deferred with the public Workspace API surface.

Testing

  • bun run test test/workspace.test.ts test/location.test.ts test/location-layer.test.ts: 20 passed.
  • bun run test --rerun-each 10 test/workspace.test.ts: 10 consecutive lifecycle runs passed.
  • Lifecycle coverage includes stable create identity, failed-persistence compensation, shared scoped connections, suspend draining and admission fencing, replacement-binding reconnection, retryable provider deletion, and final row removal.
  • Live Modal SDK 1.5.2 tracer verified Sandbox creation, reconnection by ID, direct file operations, foreground commands, timeout cleanup, filesystem snapshot and restoration, retained writable files, credential isolation, and Sandbox cleanup.
  • Modal timeout verification observed the command gone while the Python SDK resolved with -1; current Python and JavaScript process handles expose no direct per-process termination.
  • bun typecheck in packages/core, packages/schema, packages/protocol, packages/server, packages/sdk-next, and packages/opencode.
  • Push hook: bun turbo typecheck --concurrency=3, 32 configured tasks passed.
  • bun run migration --check in packages/core.
  • Prettier and git diff --check passed.
  • Simplify review completed with separate reuse, quality, and efficiency passes, followed by a focused Effect lifecycle review.
  • Full Core run: 1,323 passed, 6 skipped, 10 failed. The failures are 9 existing provider-opencode five-second timeouts and 1 provider-openai polling timeout; both reproduce independently and do not touch Workspace or Location code.

Flow

sequenceDiagram
  participant L as Location graph
  participant W as Workspace lifecycle
  participant G as Lifecycle gate
  participant C as Connection cache
  participant P as Sandbox provider

  L->>W: get(workspaceID)
  W-->>L: project and root metadata
  Note over L,P: No provider connection during Location boot
  L->>G: borrow read lease
  G->>C: acquire shared connection
  C->>P: decode and connect on cache miss
  P-->>C: environment and replacement binding
  C->>P: reconcile(binding)
  C-->>L: hosted environment
  W->>G: suspend or remove
  G-->>W: wait for active leases, block new leases
  W->>P: transition provider state
  W->>W: persist replacement binding
  W->>G: reopen admission
Loading

@kitlangton
kitlangton marked this pull request as draft July 18, 2026 02:25
@kitlangton kitlangton changed the title feat(core): add remote workspace environment seam feat(core): add remote workspace lifecycle seam Jul 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant