fix(team-mode): remove members from state.json on idle auto-cleanup - #371
Open
Million-mo wants to merge 2 commits into
Open
fix(team-mode): remove members from state.json on idle auto-cleanup#371Million-mo wants to merge 2 commits into
Million-mo wants to merge 2 commits into
Conversation
The idle auto-cleanup (_schedule_member_cleanup) closed member sessions but left them in state.json's members dict. Since team_add_member counts members from state.json to enforce max_members, the freed sessions still occupied capacity slots and subsequent team_add_member calls were incorrectly rejected with 'Team exceeds max_members'. Add _remove_members_from_state helper that pops members whose session IDs match the closed set, mirroring the existing _schedule_ephemeral_cleanup pattern. Pass team_id and base_dir from team_create to the cleanup scheduler. Includes regression test that creates a team at max_members capacity, triggers idle cleanup, and verifies team_add_member succeeds afterward.
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.
Problem
In team mode, when the lead goes idle for longer than
idle_timeout(default 300s), the idle auto-cleanup (_schedule_member_cleanup) closes member sessions but does not remove them fromstate.json'smembersdict. Sinceteam_add_membercounts members fromstate.jsonto enforcemax_members, the freed sessions still occupy capacity slots and subsequentteam_add_membercalls are incorrectly rejected with"Team exceeds max_members".This means: after the lead returns from idle and tries to add new members, the old members' slots are still counted even though their sessions are gone.
Root Cause
_schedule_member_cleanup(team_comm_capability.py) closed sessions and clearedteam_member_sessionsmetadata, but never touchedstate.json. Compare with_schedule_ephemeral_cleanup, which correctly pops members fromstate.jsonbefore closing — that path works fine.Fix
_schedule_member_cleanupnow acceptsteam_idandbase_dirparameters._remove_members_from_statehelper that readsstate.json, pops members whosesession_idis in the closed set, and atomically writes back — mirroring the_schedule_ephemeral_cleanuppattern.team_createpassesteam_idandbase_dirto the cleanup scheduler.Test
New regression test
test_idle_cleanup_frees_state_json_slots_for_add_member:max_members=2(full capacity)team_add_memberfails before cleanup (expected)state.jsonteam_add_membersucceeds after cleanup (slot freed)All 333 existing team-mode tests + 124 delegation tests pass.
Files Changed
src/wolfharness/capabilities/team_comm_capability.py— fix + new helpertests/team_mode/test_integration_session.py— regression testchangelog/unreleased/2026-08-14-team-idle-cleanup-state-json.md— changelog