feat: implement agent self-deletion (hard/soft delete)#39
Open
itsHaddad wants to merge 1 commit intomoltbook:mainfrom
Open
feat: implement agent self-deletion (hard/soft delete)#39itsHaddad wants to merge 1 commit intomoltbook:mainfrom
itsHaddad wants to merge 1 commit intomoltbook:mainfrom
Conversation
Implements feature request from issue moltbook#35. **Changes:** Service Layer (AgentService.js): - Add findById() method for internal lookups - Add delete() method supporting both soft and hard deletion - Soft delete: marks is_active=false, clears API key, preserves data - Hard delete: CASCADE removes agent and all associated content - Update findByApiKey() to include is_active field Route Layer (agents.js): - Add DELETE /agents/me endpoint - Supports ?permanent=true query param for hard delete - Default behavior is soft delete with 30-day restore window Auth Middleware (auth.js): - Add is_active check in requireAuth() - Reject authentication attempts from deactivated agents Tests (agent-deletion.test.js): - Comprehensive test coverage for soft/hard delete - Verify API key invalidation on deletion - Test auth rejection for inactive agents - Validate data preservation on soft delete **API Usage:** Soft delete: DELETE /api/v1/agents/me Hard delete: DELETE /api/v1/agents/me?permanent=true **Impact:** - Zero schema changes (leverages existing is_active column) - Backward compatible (existing agents remain active) - Maintains referential integrity via CASCADE - Provides user control and 30-day safety net Closes moltbook#35 Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
|
👍 for merging this; since it would also unblock the following support issues:
This would also unblock me - X account @davidlaing claimed (ID: C_P_Bondwell 1e5b2e75-1345-4be0-8ae0-fbdb8a08d9e8) but I lost the API key during the initial claim flow. I'm locked out of the agent and can't register a new one because my X account is already bound. This PR would let me hard delete the agent and start fresh with the same name. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements agent self-deletion feature requested in #35.
Implementation
Hybrid deletion approach:
is_active = false, invalidates API key, preserves data for 30-day grace periodChanges
Service Layer (
AgentService.js):findById()- Internal method for agent lookup by IDdelete(agentId, { permanent })- Deletion with soft/hard optionfindByApiKey()to includeis_activefieldRoute Layer (
agents.js):DELETE /agents/me- Soft delete (default)DELETE /agents/me?permanent=true- Hard deleteAuth Middleware (
auth.js):is_activecheck to reject deactivated agentsTests (
agent-deletion.test.js):API Usage
Soft delete:
Hard delete:
Schema Impact
is_activecolumnON DELETE CASCADEconstraintsSecurity
api_key_hash/meendpointTesting
All tests passing:
Closes
#35
cc @MattPRD @moltbook - Ready for review