Skip to content

Add DeleteOrganizationResources - #107

Open
vitramir wants to merge 1 commit into
mainfrom
delete-organization-resources
Open

vitramir wants to merge 1 commit into
mainfrom
delete-organization-resources

Conversation

@vitramir

@vitramir vitramir commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Step 1 of the organization teardown: the organization's sandboxes, agent instances, agents and their sub-resources, and environments. First in the order, because almost everything else in the organization is either referenced by these or refuses to be deleted while they exist.

This is the one service where the per-resource delete paths do not compose into an org-wide sweep. envs, init_scripts, mcps and skills reference agents with NO ACTION, and agents and sandboxes reference environments the same way — so deleting either parent while a child remains is a foreign key violation, and walking the existing per-resource paths would hit that on almost every row. The store orders the whole set once, in one transaction. The invariants the individual paths enforce — an agent with no live instances, an environment nothing references — hold here because the order satisfies them, not because each row is re-checked. Flagging this as the deliberate deviation from "reuse the paths that already exist"; everything else in this change set does reuse them.

The order is derived from the live schema, not the migration history. Reading the migrations suggested tables — hooks, volume_attachments, image_pull_secret_attachments, and the old entity model's memory_buckets / tools / variables / workspace_configurations / attachments — that later migrations had dropped. My first draft deleted from volume_attachments and failed at runtime with relation does not exist. The final order comes from pg_constraint on a migrated database.

Tuples come off before the rows, batched at OpenFGA's per-Write limit of 100. Nicknames are given back best-effort — one that outlives its agent is a stale row Identity's own step reaches at step 8, not a reason to stall step 1.

Tested against a real database. Server.store is a concrete *store.Store with no interface seam, and more importantly the foreign keys are the thing being ordered against, so a fake store would prove nothing. The test follows the existing AGENTS_TEST_DATABASE_URL pattern and seeds a skill and a sandbox specifically so the ordering is exercised. Note that it skips silently when the variable is unset — I ran it against a live postgres, and it is worth doing the same when reviewing.

New rule on the existing AuthorizationPolicy admitting only the organizations ServiceAccount. Chart bumped to 0.2.0.

The two .gen/go/agynio/api/identity/v1/*.pb.go files are tracked here despite .gen being gitignored; they were stale relative to the BSR and this regenerates them.

Part of organization settings and deletion.

Step 1 of the organization teardown: the organization's sandboxes, agent
instances, agents and their sub-resources, and environments. First, because
almost everything else in the organization is either referenced by these or
refuses to be deleted while they exist.

The per-resource delete paths do not compose into an org-wide sweep here.
envs, init_scripts, mcps and skills reference agents with NO ACTION, and
agents and sandboxes reference environments the same way, so deleting either
parent while a child remains is a foreign key violation. The store orders the
whole set once, in one transaction; the invariants the individual paths
enforce hold because the order satisfies them rather than because each row is
checked.

The order is derived from the live schema rather than from the migration
history -- hooks, volume_attachments, image_pull_secret_attachments and the
old entity model's tables were dropped by later migrations and no longer
exist.

Tuples come off before the rows, batched at OpenFGA's per-Write limit of 100.
Nicknames are given back best-effort: one that outlives its agent is a stale
row Identity's own step reaches at step 8, not a reason to stall step 1.

Exercised against a real database (AGENTS_TEST_DATABASE_URL) rather than a
fake store, because the foreign keys are the thing being ordered against.
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