Skip to content

fix: clear a removed crewmate's thread session record - #32924

Merged
bolichen97 merged 1 commit into
mainfrom
fix/22486-delete-clears-thread-session
Nov 8, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/22486-delete-clears-thread-session

Conversation

@bolichen97

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Deleting a crewmate also clears its thread's saved session record, so a bad record no longer outlives the crewmate.

A crewmate's standing thread is saved in session_map.json under dashboard:member-<slug>, or dashboard:member-<slug>.memory-<store> on a private store. When that record goes bad (in #22486 the thread mounted only one of its MCP servers), nothing clears it: deleting the crewmate leaves the entry in the file, a restart restores it, Fresh start keeps the key, and member threads are not listed where a session can be deleted.

Why it matters

Delete reads like the reset, and it is not. A person whose crewmate thread breaks has no supported way out except building a second crewmate, and the dead entry stays in session_map.json for good.

Not a goal

  • Freeing the member id a deleted crewmate keeps reserved (the companion issue).
  • kirocrew agent delete: it runs without the gateway's session manager, so it leaves the map alone.
  • A way to reset a live crewmate's thread without deleting the crewmate.
  • Removing the deleted thread's conversation history.

What changed (motivation → approach → change)

Deleting a crewmate left its thread's session_map.json entry behind. The removal teardown every gateway removal runs (crew_removal._remove_member_leftovers) had a step for each other leftover (avatar, goal check-ins, worktrees, private template copy) but none for the thread's session.

It gets one, _destroy_member_thread_sessions, which hands each of the thread's keys to the gateway's session manager. destroy ends a live process for the key and deletes its entry, the same permanent removal a destroyed session gets anywhere else.

Keys destroyed the V1 key and the current store's key, named outright (so an entry Fresh start left without a session ID goes too), plus each earlier store generation that still maps a session, matched on the exact .memory- boundary, which a sibling slug like mate-0a2620b15f41 cannot share
Kept every key, when another live crew still derives the slug (the same check the goal check-ins use)
On failure one failed row in the teardown report; the committed delete still answers 200
Who runs it DELETE /api/agents/{name}, the POST /api/agents/sync prune (installed_agents.py) and the startup prune (crewmate_prune.py), each passing state.sessions; handlers/agents.py exposes the step to the composed facade

crew-mode.md records the step and why the CLI delete skips it.

Builds on #28613 by @cruisercohen.

Backwards compatibility

Compatible: nothing a live crewmate uses changes; only a removed crewmate's own thread entries are deleted, and a slug a live crew still derives keeps them.

Reader: src/kiro_crew/dashboard/handlers/members_thread.py:api_member_thread -- crew page -- a thread opens only for a crewmate in the roster, and a slug a live crew still derives keeps its entries (test_crew_delete_forgets_member_thread_session.py::test_a_slug_another_live_crew_still_derives_keeps_its_entries)
Reader: src/kiro_crew/dashboard/handlers/session_storage.py:_build_index -- crew page -- the removed thread's session ID is no longer counted as resumable, the outcome every destroyed session already has; a sibling crewmate's entry stays (test_crew_delete_forgets_member_thread_session.py::test_delete_destroys_the_departed_crewmates_thread_entries)
Reader: src/kiro_crew/cli_commands_agent.py:_remove_deleted_agent_leftovers -- release -- the CLI passes no session manager, so the map file is untouched (test_crew_delete_forgets_member_thread_session.py::test_leftovers_without_a_session_manager_touch_no_session)

Tests

  • test/test_crew_delete_forgets_member_thread_session.py (new) drives the real DELETE /api/agents/{name} route over a real SessionMap: the deleted crewmate's V1 and private-store keys go, its sibling mate-0a2620b15f41 and an unrelated chat stay; an entry Fresh start left without a session ID goes; a claimed slug keeps every entry; a failing destroy still answers 200; the teardown with no manager leaves the file byte-identical.
  • test/test_pruned_crewmate_leftovers.py: the sync prune and the startup prune each destroy the pruned crewmate's thread key and no other.

Proof: PROVEN test/test_crew_delete_forgets_member_thread_session.py::test_delete_destroys_the_departed_crewmates_thread_entries, test/test_crew_delete_forgets_member_thread_session.py::test_an_entry_a_fresh_start_left_without_a_sid_goes_too, test/test_pruned_crewmate_leftovers.py::test_agent_sync_prune_removes_the_pruned_crews_leftovers, test/test_pruned_crewmate_leftovers.py::test_startup_prune_removes_the_removed_crewmates_leftovers (head 4848ee4)

Determinism (testing-conventions D12), every new or changed test: 20/20 green at -n0; 10/10 green at -n 4 --dist loadgroup --max-worker-restart=2 beside test_crew_delete_dashboard_lock.py and test_agent_delete_prunes_private_copy.py; all 9 ids of both files green in a shuffled order (seed 11164).

Manual verification

N/A — unit coverage sufficient: the tests run the real delete route and both prunes against a real session_map.json; the session manager's destroy (process teardown plus map delete) is unchanged and covered by its own tests.

Screenshots / video

N/A — no user-visible surface changes: the diff is backend-only and removes a server-side record.

Related Issues

Fixes #22486

Sibling sweep

Swept: git grep -n "_remove_member_leftovers(" -- src/
Sibling: src/kiro_crew/dashboard/agent_admin/installed_agents.py:367 -- changed here
Sibling: src/kiro_crew/dashboard/server_runtime/crewmate_prune.py:182 -- changed here
Sibling: src/kiro_crew/cli_commands_agent.py:519 -- not affected -- runs without the gateway, whose live session manager owns the map

Pattern harvest

Not generalizable: each removal step in this teardown names its own resource, and the missing one was a store keyed by a derived alias that no generic check could see.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Deleting a crewmate tore down its config row, crew log, avatar, goal
check-ins, worktrees and private template copy, but never its pinned
thread's session_map.json entry. A bad dashboard:member-<slug> record
then outlived the crewmate, and nothing else could clear it.

The shared removal teardown now destroys the thread's keys through the
gateway's session manager, which also ends a live process for the
thread: the V1 key, the current store's key and earlier store
generations on the exact .memory- boundary. A slug another live crew
still derives keeps its entries, and a failure never fails the delete.
The dashboard delete and both prunes pass the manager; the CLI delete
has none and leaves the map alone.

Builds on #28613 by @cruisercohen.

Co-authored-by: Matt Cohen <1832296+cruisercohen@users.noreply.github.com>
@bolichen97
bolichen97 requested review from a team and KiroCrewCaptain as code owners November 8, 2026 04:24
@bolichen97
bolichen97 requested a review from Zedmor November 8, 2026 04:24
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Nov 8, 2026
@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 4848ee4a4620335c4bef37f5bfe6714a57a8039e touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 4848ee4a4620335c4bef37f5bfe6714a57a8039e — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks. The change adds a missing step to the existing removal teardown, it runs on all three gateway removal paths, and it deletes only the removed crewmate's own thread entries.

Notes

  • _destroy_member_thread_sessions reads sessions._session_map, a private attribute of the session manager. If that attribute is renamed, the bare except turns this step into a failed row that only shows up in logs. A small public method on the manager that lists a key prefix would make this coupling visible.

[DESIGN-REVIEWED] 4848ee4

Description read

[DESCRIPTION-READ] 5d280d0ffc5b8c1a760eb28b7211fe8b9bbb9816b654afc3058bad768d840691

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 4848ee4a4620335c4bef37f5bfe6714a57a8039e — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

Nothing blocks: the change adds the one missing removal step to the teardown every gateway removal already runs, and the defect has a linked issue (#22486) plus a test that fails on base.

Inventory (8 items) — 8 justified

Intent: when a person deletes a crewmate, its broken thread's saved session record goes with it, so the bad record can't come back after a restart. This is a FIX.

  1. Deleting a crewmate from the dashboard removes its thread's session_map.json entries (the V1 key, the current store's key, and earlier store generations) — justified
  2. The POST /api/agents/sync prune removes the pruned crewmate's thread entries too — justified
  3. The startup prune removes the removed crewmate's thread entries too — justified
  4. A live process still running for the deleted crewmate's thread is ended — justified
  5. An entry that Fresh start left without a session ID is removed too — justified
  6. A slug that another live crew still derives keeps its entries — justified
  7. The teardown report gains thread session rows, and a failure there still answers 200 — justified
  8. handlers/agents.py re-exports the new step so the composed facade can resolve it, and crew-mode.md records the step — justified

[FIRST-PRINCIPLES-REVIEWED] 4848ee4

Description read

[DESCRIPTION-READ] fee20f016380d09302eca73a48f05a66fcb2da8be593e35b27f51ff59b2d042c

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 4848ee4a4620335c4bef37f5bfe6714a57a8039e — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 4848ee4

Verdict parsed from the review's SHA-scoped output markers for commit 4848ee4a4620335c4bef37f5bfe6714a57a8039e.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 4848ee4a4620335c4bef37f5bfe6714a57a8039e false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 4848ee4a4620335c4bef37f5bfe6714a57a8039e and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 4848ee4

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 4848ee4a4620335c4bef37f5bfe6714a57a8039e false-positive: <reason, 20 to 500 characters>

@bolichen97
bolichen97 enabled auto-merge (squash) November 8, 2026 04:44
@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Nov 8, 2026

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The review checked head 4848ee4. All three gateway removal paths (the dashboard DELETE, the sync prune and the startup prune) now pass the session manager into the shared teardown, and the CLI path passes none, as crew-mode.md says. The fail-closed claimed-slug check runs before any key is derived. The .memory- boundary cannot match a sibling slug. SessionManager.destroy removes a sid-less entry. Mutations on the slug guard, the boundary, the has_hint filter and both prune call sites each turn the tests red.
Done well: the step reuses SessionManager.destroy instead of editing session_map.json directly, so only the process that owns the map rewrites it.
Optional: add a test that seeds mate with a private V2 memory_store and a sid-less current-store key. Today, deleting lines 228-229 of crew_removal.py leaves all 9 tests green, and the failed-destroy failed report row is not asserted either.
Optional: build the store key only for a V2 store record, or build each key in its own try. A legacy store name the validator rejects then no longer aborts the step and leaves the V1 key behind.
Optional: when this lands, close #28613 as superseded. Also decide whether #22486 needs a follow-up issue for resetting a live crewmate's thread, or whether "Part of" fits better than "Fixes".

@bolichen97
bolichen97 merged commit bed3c8a into main Nov 8, 2026
100 checks passed
@bolichen97
bolichen97 deleted the fix/22486-delete-clears-thread-session branch November 8, 2026 05:37
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 8, 2026
buluoray added a commit that referenced this pull request Nov 8, 2026
Deleting a crewmate tore down its config row, crew log, avatar, goal
check-ins, worktrees and private template copy, but never its pinned
thread's session_map.json entry. A bad dashboard:member-<slug> record
then outlived the crewmate, and nothing else could clear it.

The shared removal teardown now destroys the thread's keys through the
gateway's session manager, which also ends a live process for the
thread: the V1 key, the current store's key and earlier store
generations on the exact .memory- boundary. A slug another live crew
still derives keeps its entries, and a failure never fails the delete.
The dashboard delete and both prunes pass the manager; the CLI delete
has none and leaves the map alone.

Builds on #28613 by @cruisercohen.

Co-authored-by: Matt Cohen <1832296+cruisercohen@users.noreply.github.com>
(cherry picked from commit bed3c8a)

Original author: @bolichen97
buluoray added a commit that referenced this pull request Nov 8, 2026
Deleting a crewmate tore down its config row, crew log, avatar, goal
check-ins, worktrees and private template copy, but never its pinned
thread's session_map.json entry. A bad dashboard:member-<slug> record
then outlived the crewmate, and nothing else could clear it.

The shared removal teardown now destroys the thread's keys through the
gateway's session manager, which also ends a live process for the
thread: the V1 key, the current store's key and earlier store
generations on the exact .memory- boundary. A slug another live crew
still derives keeps its entries, and a failure never fails the delete.
The dashboard delete and both prunes pass the manager; the CLI delete
has none and leaves the map alone.

Builds on #28613 by @cruisercohen.

Co-authored-by: Matt Cohen <1832296+cruisercohen@users.noreply.github.com>
(cherry picked from commit bed3c8a)

Original author: @bolichen97
buluoray added a commit that referenced this pull request Nov 8, 2026
Deleting a crewmate tore down its config row, crew log, avatar, goal
check-ins, worktrees and private template copy, but never its pinned
thread's session_map.json entry. A bad dashboard:member-<slug> record
then outlived the crewmate, and nothing else could clear it.

The shared removal teardown now destroys the thread's keys through the
gateway's session manager, which also ends a live process for the
thread: the V1 key, the current store's key and earlier store
generations on the exact .memory- boundary. A slug another live crew
still derives keeps its entries, and a failure never fails the delete.
The dashboard delete and both prunes pass the manager; the CLI delete
has none and leaves the map alone.

Builds on #28613 by @cruisercohen.

Co-authored-by: Matt Cohen <1832296+cruisercohen@users.noreply.github.com>
(cherry picked from commit bed3c8a)

Original author: @bolichen97
buluoray added a commit that referenced this pull request Nov 8, 2026
Deleting a crewmate tore down its config row, crew log, avatar, goal
check-ins, worktrees and private template copy, but never its pinned
thread's session_map.json entry. A bad dashboard:member-<slug> record
then outlived the crewmate, and nothing else could clear it.

The shared removal teardown now destroys the thread's keys through the
gateway's session manager, which also ends a live process for the
thread: the V1 key, the current store's key and earlier store
generations on the exact .memory- boundary. A slug another live crew
still derives keeps its entries, and a failure never fails the delete.
The dashboard delete and both prunes pass the manager; the CLI delete
has none and leaves the map alone.

Builds on #28613 by @cruisercohen.

Co-authored-by: Matt Cohen <1832296+cruisercohen@users.noreply.github.com>
(cherry picked from commit bed3c8a)

Original author: @bolichen97
buluoray added a commit that referenced this pull request Nov 8, 2026
Deleting a crewmate tore down its config row, crew log, avatar, goal
check-ins, worktrees and private template copy, but never its pinned
thread's session_map.json entry. A bad dashboard:member-<slug> record
then outlived the crewmate, and nothing else could clear it.

The shared removal teardown now destroys the thread's keys through the
gateway's session manager, which also ends a live process for the
thread: the V1 key, the current store's key and earlier store
generations on the exact .memory- boundary. A slug another live crew
still derives keeps its entries, and a failure never fails the delete.
The dashboard delete and both prunes pass the manager; the CLI delete
has none and leaves the map alone.

Builds on #28613 by @cruisercohen.

Co-authored-by: Matt Cohen <1832296+cruisercohen@users.noreply.github.com>
(cherry picked from commit bed3c8a)

Original author: @bolichen97
buluoray added a commit that referenced this pull request Nov 8, 2026
Deleting a crewmate tore down its config row, crew log, avatar, goal
check-ins, worktrees and private template copy, but never its pinned
thread's session_map.json entry. A bad dashboard:member-<slug> record
then outlived the crewmate, and nothing else could clear it.

The shared removal teardown now destroys the thread's keys through the
gateway's session manager, which also ends a live process for the
thread: the V1 key, the current store's key and earlier store
generations on the exact .memory- boundary. A slug another live crew
still derives keeps its entries, and a failure never fails the delete.
The dashboard delete and both prunes pass the manager; the CLI delete
has none and leaves the map alone.

Builds on #28613 by @cruisercohen.

Co-authored-by: Matt Cohen <1832296+cruisercohen@users.noreply.github.com>
(cherry picked from commit bed3c8a)

Original author: @bolichen97
buluoray added a commit that referenced this pull request Nov 8, 2026
Deleting a crewmate tore down its config row, crew log, avatar, goal
check-ins, worktrees and private template copy, but never its pinned
thread's session_map.json entry. A bad dashboard:member-<slug> record
then outlived the crewmate, and nothing else could clear it.

The shared removal teardown now destroys the thread's keys through the
gateway's session manager, which also ends a live process for the
thread: the V1 key, the current store's key and earlier store
generations on the exact .memory- boundary. A slug another live crew
still derives keeps its entries, and a failure never fails the delete.
The dashboard delete and both prunes pass the manager; the CLI delete
has none and leaves the map alone.

Builds on #28613 by @cruisercohen.

Co-authored-by: Matt Cohen <1832296+cruisercohen@users.noreply.github.com>
(cherry picked from commit bed3c8a)

Original author: @bolichen97
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Corrupt crewmate slot record cannot be cleared by any supported control

2 participants