Relationships
#2515 definitions: delete() silently leaves an auto-definition file unless an earlier lookup cached its path
Opened by stack72 · 9/25/2026· Shipped 9/29/2026
Description
YamlDefinitionRepository.delete(type, id) (src/infrastructure/persistence/yaml_definition_repository.ts) silently does nothing for a definition in the secondary auto-definitions directory unless an earlier lookup cached that file's path in idToActualPath.
delete() tries three paths: the primary directory's id-based path, the primary directory's name-based path, and idToActualPath.get(id). It swallows NotFound for each. Lookups differ in whether they cache a secondary file's path:
findByNameGlobal(viasearchDefinitionByName) recordsidToActualPathfor secondary matches, soswamp model delete <name>works on an auto-definition.- The type-scoped
findByNamesecondary branch only records anameToActualPathhint, notidToActualPath, and neither does its hinted-secondary branch. findById's secondary fallback (findByIdInDir), whichdelete()itself calls first, records nothing either.
So findByName(type, name) followed by delete(type, definition.id) on the shared repository (secondary search enabled, the default) reports success and leaves the auto-definition file on disk. Whether it works depends on what else touched that id earlier in the process: a model method run on the same definition happens to cache the path.
This surfaced while fixing swamp-club#2413. The server token GC first looked tokens up with the type-scoped findByName and then deleted through the shared repository. The token's data and secret were removed, but .swamp/auto-definitions/swamp/server-token/<name>.yaml stayed behind unless the token had been revoked in the same process. The #2413 fix works around it the way the admin grant store and access.reload already do: it looks up and deletes through a repository rooted at repoContext.autoDefinitionsDir with secondary search off.
Steps to reproduce
- Save a definition into the auto-definitions directory through an auto-definitions-rooted repository (as the token mint does).
- In a fresh
YamlDefinitionRepository(repoDir)(secondary search on), callfindByName(type, name)and thendelete(type, definition.id). - The file is still in
.swamp/auto-definitions/..., and no error is raised.
Expected
delete() removes the definition wherever it lives, primary or secondary, independent of cache state. That could mean findByIdInDir and the secondary branches of findByName recording idToActualPath as searchDefinitionByName already does, or delete() trying the secondary directory's id and name paths itself. Either way a delete that removed nothing arguably should not report success silently.
Shipped
Click a lifecycle step above to view its details.
Sign in to post a ripple.