Make app deletion mark-and-sweep, and stop deriving app ids from names
App deletion today happens all at once. DeleteAppTransitive finds every entity that points at the app and deletes them right then, while other writes on the app's behalf are still allowed. App ids also come from the app's name (app/<name>), so a new app with the same name gets the same id.
Those two things together cause a couple of problems that showed up while giving secrets an owning app (MIR-2235):
- Anything left behind is inherited by the next app with that name. Since ids repeat, any leftover entity that refers to the deleted app looks like it belongs to the new one. MIR-2235 handles this by deleting an app's owned secrets along with it, but that's a patch over the id scheme, not a fix.
- Deletion races with concurrent writes. If a secret write for the app lands while the delete is sweeping, the new secret version survives. The secret's entity id also comes from its path, so if that path is created again, the orphaned version attaches to the new secret and can be resolved by its pinned short id. That needs a well-timed write plus knowledge of the version's id, so the risk is low, but nothing structural stops it.
The proposal:
- Mark, then sweep. Deleting an app first marks it as deleting. Writes on behalf of a deleting app (secret writes, config pins, deploys) are refused. The sweep then works through a set that can no longer grow.
- Leave a tombstone. The deleted app's record stays behind as a tombstone instead of disappearing. That also leaves room for deletion to stop being so immediate.
- Decouple app ids from names. Give apps an id that isn't their name, so a new
shopnever shares an id with an old one. With that in place, a leftover reference points at a dead id instead of being inherited, and the secret cascade in MIR-2235 could become ordinary cleanup instead of a safety measure.
+++ Agent notes
- Current delete:
servers/app/delete.go,DeleteAppTransitive. It deletes every entity whose indexed attribute taggeddev.miren.app_refpoints at the app. MIR-2235 adds a cascade for ownedsecretentities and theirsecret_versionchildren (deleteSecretVersions). - Name-derived ids: apps are created via
EnsureAppwith idapp/<name>. The servers/secret ownership code also looks apps up by"app/"+name, so it will need updating if ids change. - Secret entity ids come from the path (
entityName(path)inpkg/secret/cluster), andloadVersiononly checks that a version's parent matches the secret's id. That's why an orphaned version reattaches when its path is recreated. - The write-side fence would need to cover at least
PutOwned(ownership) andsecret.Pin/coreutil.PinSecrets(references), plus deploy and config writes in general.
+++