feat: add workspace lifecycle controls
Summary
- add
DELETE /v1/workspaces/{id}, authenticated by the exact workspace's own key (204success,401missing/invalid key,404valid key for a different id); retainDELETE /v1/workspace - add optional
expires_in_seconds(60 seconds to 30 days) at creation, persist the resulting nullableexpires_at, and reap expired workspaces in bounded D1-safe batches - run expiry maintenance on the Node adapter's maintenance cadence and opportunistically after workspace creation; export the reaper for scheduled hosts
- expose expiry through shared types and both TypeScript workspace-creation surfaces; make repository E2E workspaces expire after 24 hours
- document the API, response codes, operational limits, and migration in README/OpenAPI/changelogs
The safety predicate
A workspace is eligible for automatic deletion only when its creator explicitly supplied expires_in_seconds and the persisted, non-null expires_at deadline has passed.
Names, age, absence of agents, and absence of messages never participate in the predicate. Therefore a new or dormant real workspace cannot be mistaken for test debris. Setting a TTL is explicit consent to delete that workspace and all of its data at the deadline. Existing workspaces migrate with expires_at = NULL and are never selected automatically.
This PR does not delete production data and does not add any data-dropping migration. Reclaiming the existing production candidates remains a separate, reviewed operation owned by Khaliq.
D1 findings
Cloudflare documents that D1 enforces foreign keys equivalently to SQLite PRAGMA foreign_keys = ON, including ON DELETE CASCADE: https://developers.cloudflare.com/d1/sql-api/foreign-keys/
The lifecycle test inspects every applied migration-level foreign key that directly references workspaces and requires ON DELETE CASCADE, then deletes a populated workspace through the API and verifies workspace, channel, agent, and message rows are gone.
Cloudflare's current D1 SQL statement documentation does not document VACUUM as a supported operation: https://developers.cloudflare.com/d1/sql-api/sql-statements/
Accordingly, this change promises lower row count and less insert/index work, not a smaller D1 file. Deleted pages may remain allocated.
Verification
npx turbo test— exit 0 (18/18 tasks; engine 594 tests, SDK 423 tests, types 163 tests)npx turbo build— exit 0 (9/9 tasks)npx turbo lint— exit 0 (13/13 tasks)- OpenAPI YAML parse — exit 0
git diff --check— exit 0
Closes #336