fix(workspace): make agent removal sticky so removed agents can't reappear (#347)#560
Open
nolanchic wants to merge 1 commit into
Open
Conversation
…ppear /v1/remove hard-deleted the WorkspaceMember, but a still-running agent daemon reconnects and re-POSTs /v1/join, and _handle_agent_join blindly upserted the row back to status='online' — so a removed agent reappeared in /v1/discover (and thus the workspace sidebar). The discover list showed every member while the online count stayed correct, matching the reported "Agents (2/4)" symptom. Make removal a soft-delete (status='removed') and refuse self-resurrection: - _handle_agent_remove: mark status='removed' (keep the row) instead of deleting; exclude removed members when reassigning a channel master. - _handle_agent_join: raise EventRejected when a removed agent tries to re-join, so /v1/join 401s instead of resurrecting the membership. - _handle_ping: don't flip a removed member back to online; surface session_revoked so the daemon stops its adapter. - /v1/discover: hide removed members. Offline members are intentionally kept — mobile clients key the "connect an agent" prompt off membership, not online status. - POST /v1/cloud-agents: re-adding a previously-removed cloud agent reactivates it (refreshes its retained config) instead of rejecting with "already exists". Closes openagents-org#347
|
@nolanchic is attempting to deploy a commit to the Raphael's projects Team on Vercel. A member of the Team first needs to authorize it. |
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.
Fixes #347
A removed agent reappeared in the workspace sidebar. The online count was correct ("Agents (2/4)"), but the agent list kept showing every agent that had ever been added.
Root cause
POST /v1/removehard-deleted theWorkspaceMemberrow, but a still-running agent daemon reconnects and re-POSTs/v1/join, and_handle_agent_joinblindly upserted the row back tostatus='online'. So removal wasn't sticky — the daemon resurrected its own membership, and/v1/discover(which the sidebar renders) listed it again./v1/profile's online count already filteredstatus='online', so the count was right while the list was wrong — exactly the reported symptom.Fix
Make removal a soft-delete (
status='removed') and refuse self-resurrection:_handle_agent_remove— markstatus='removed'(keep the row) instead ofdb.delete; exclude removed members when reassigning a channel master._handle_agent_join— raiseEventRejectedwhen a removed agent tries to re-join, so/v1/join401s instead of upserting the membership back to online._handle_ping— don't flip a removed member back to online; surfacesession_revokedso the daemon stops its adapter for that agent./v1/discover— hide removed members. Offline members are intentionally kept (mobile clients key the "connect an agent" prompt off membership, not online status — pinned bytest_discover_keeps_stale_members_as_offline).POST /v1/cloud-agents— re-adding a previously-removed cloud agent reactivates it (refreshes its retainedCloudAgentConfig) instead of rejecting with "already exists", so removal is reversible by a human re-invite rather than permanent.Re-adding a self-joined (token) agent remains intentionally blocked — only a human re-invite (cloud-agents) clears the removed state, which is what makes removal sticky against a rogue/reconnecting daemon.
Test plan
pytest tests/test_agent_removal.py— 6/6 new tests pass: removed agent excluded from discover; re-join refused (401) and doesn't resurrect; heartbeat doesn't resurrect; removed row retained asstatus='removed'; offline member still listed (back-compat); cloud re-add reactivates.pytest workspace/backend/tests/— no new regressions. 20 tests fail on this machine both ondevelopand with this branch (browser-contexts, event-routing auth, migration-schema) — they're pre-existing local-env failures (SQLAlchemy/alembic/SQLite version drift), unrelated to this change; verified identical before/after viagit stashdiff.ruff— the changed source files introduce zero new violations (rule counts equal-or-fewer thandevelop); the new test file is ruff-clean.