---
title: Space storage setup
description: Durable storage requests, verified native buckets, and automatic Space resource cleanup.
owner: engineering
sourceFiles:
  - packages/db/src/schema/space-storage.ts
  - packages/config/src/env.ts
  - apps/server/src/domain/organizations/data/spaces.ts
  - apps/server/src/domain/organizations/spaces.ts
  - apps/server/src/domain/space-storage/service.ts
  - apps/server/src/runtime/space-storage.ts
  - apps/server/src/runtime/space-cleanup.ts
  - apps/server/src/domain/space-storage/cleanup.ts
  - apps/web/src/features/spaces/components/delete-space.tsx
  - infra/storage/deleted-spaces.ts
  - packages/contracts/src/server/space-storage.ts
  - packages/contracts/src/space-storage.ts
  - infra/storage/space-buckets.ts
  - infra/alchemy.run.ts
  - infra/server.ts
  - .env.production
  - apps/web/src/features/conversation/components/space-files.tsx
  - apps/web/src/features/conversation/components/storage-notice.tsx
---

New spaces use one private R2 evidence bucket per environment. Alchemy provisions and binds that bucket during normal deployment. Creating another space needs no Cloudflare resource creation, manifest edit, or Worker deployment. Postgres owns metadata and authorization; SQLite-backed Computer storage remains the agent's working filesystem.

Creating a space saves a pending shared storage location in the same database transaction. The location records its creator, owning organization, environment, immutable space identity, backend, and generation. A failed insert rolls back space creation. After commit, the server automatically verifies the location against the existing shared binding. If storage is unavailable, the space still exists with pending storage; its next authorized upload retries verification. Existing spaces without a location record are not automatically backfilled.

## Status and verification

Authenticated callers with current space read permission can read `GET /spaces/:spaceId/storage`. The response contains space ID, generation, status and verification time. Physical bucket names, binding names, backend and location coordinates stay internal.

Automatic verification writes a server-generated receipt under `_provisioning/<location-id>/<generation>/` and checks an exact readback, with a five-second timeout. Completion requires the same live location, backend and generation. An upload rechecks its conversation write authority when reserving and finishing the file; successful storage verification does not grant file access.

An owning firm manager with current space update permission can also call `POST /spaces/:spaceId/storage/verify` with the expected generation. Finance verification also requires the current client business relationship. This explicit check rechecks authority after storage I/O. Apps & Files exposes it as **Check storage** for recovery, rather than a required step for new spaces.

| Status | Meaning |
| --- | --- |
| `pending` | A location exists; usable storage has not been verified |
| `unavailable` | A verified binding is absent, or its coordinates no longer match the location |
| `ready` | A native write/readback receipt matches the binding and location generation |

A missing or failing binding returns 503 for uploads and verification. An explicit check with a stale generation returns 409. Hidden or revoked scope returns 404. Storage readiness does not change the [Finance setup request](/architecture/finance-setup) or prove agent, Computer, Executor or financial-data readiness.

## Buckets and object keys

Alchemy owns the shared `Evidence` binding and `wb-<environment>-evidence` bucket. Saved objects use `spaces/<organization-id>/<space-id>/evidence/<file-id>/<version-id>`. These prefixes organize storage; current conversation and file grants enforce access. A shared bucket does not share Team or private history with Client recipients.

The shared layout has a stable revision independent of the legacy enrollment manifest. Creating another space or changing that manifest does not invalidate shared-location readiness. File versions remain pinned to immutable location IDs; reads do not fall back to a different bucket.

This follows Executor's shared `AppBuilds` bucket with keyed app workspaces and Alchemy's native R2 bindings. Workbench retains its own conversation authorization and immutable-file policy. See [Executor's blob implementation](https://github.com/UsefulSoftwareCo/executor/blob/dff3b77ca221aabd2f08ddc4b2b2a6706750e837/apps/hosted/cloud/src/infrastructure/blobs.ts) and [Alchemy R2](https://alchemy.run/cloudflare/data/r2/).

## Legacy locations and migration

Previously enrolled spaces retain their dedicated `SpaceFiles-<space-id>` resources, `wb-<environment>-<space-id>` buckets, and `evidence/<file-id>/<version-id>` keys. The additive backend migration defaults existing locations to `space`. Only live, pending locations with no file records switch to `shared`; their generation increments to reject a stale in-flight verification. Locations referenced by any file, including a pending upload, are never redirected. No saved bytes move or disappear.

The legacy enrollment settings remain solely to preserve those existing buckets. Production's reviewed Proton manifest continues declaring every managed legacy location, including retained ones. Validation still rejects missing resources without a completed deletion tombstone, stage mismatches, duplicate identities, inconsistent counts, and admission above the configured cap (16 by default). That cap applies to legacy dedicated buckets, not new shared locations. Disabling enrollment after legacy buckets exist fails closed. Manifest revisions still require fresh verification for their legacy locations.

Local HTTP tests replace the R2 boundary and exercise the same file adapter and API used in production. A read-only Alchemy plan must preserve existing resource identities before deployment. The API never receives deployment credentials or runs Alchemy provisioning.

## Deletion and retention

Owning firm administrators and leads can select **Delete space** in the Space’s settings, under **About**. The confirmation names the Space and explains that deletion affects everyone and cannot be undone. Client members and shared recipients cannot delete a firm-owned Space. This panel reads persisted Space details directly from the authorized client directory; unfinished settings and settings-conversation services do not block its About panel or deletion control.

Deleting a space removes its product records and grants and atomically marks its location `deleting`. Historical location identity remains as a cleanup tombstone; product access requires a live authorized parent. A five-minute Worker sweep stops agent work and schedules, clears agent/Computer state, and removes that location's objects. Failures stay pending for later sweeps.

For a shared location, cleanup is restricted to `spaces/<organization-id>/<space-id>/` and `_provisioning/<location-id>/`. It never deletes the shared bucket or another space's files. For a dedicated legacy location, cleanup empties and deletes only its exact bucket. The reviewed legacy manifest excludes completed deletion tombstones so deployments cannot recreate those buckets. Historical `retained` locations remain untouched.

Production and personal-stage shared evidence buckets are private and retained during infrastructure removal, with no automatic object expiry or force-destroy behavior. PR-preview shared buckets belong only to their isolated preview stage; authorized PR cleanup removes their bytes and bucket when the PR closes. Production and personal-stage buckets are unaffected.

Legacy bucket deletion uses the dedicated `SPACE_CLEANUP_R2_TOKEN`, stored as a hidden environment field in the production Proton item, with account R2 storage-write permission. The Worker constructs bucket coordinates from persisted tombstones. Shared-prefix cleanup uses its existing native binding and does not need bucket-management credentials. See [credentials](/operations/credentials) for the shared secret workflow.

Enrolled environments require the legacy cleanup token before the Worker can initialize or deploy. An invalid or revoked token leaves legacy cleanup pending. Local HTTP tests replace R2 and management HTTP boundaries; native workerd tests verify durable state and alarm cleanup. Live teardown still requires verification after an authorized deployment.
