Skip to content

fix(cli): keep sub-agents of a chat in use during session cleanup - #14502

Merged
marius-kilocode merged 2 commits into
Kilo-Org:mainfrom
hdcodedev:fix/cleanup-keeps-subagents
Sep 25, 2026
Merged

marius-kilocode merged 2 commits into
Kilo-Org:mainfrom
hdcodedev:fix/cleanup-keeps-subagents

Conversation

@hdcodedev

Copy link
Copy Markdown
Contributor

Issue

Fixes #14500

Context

Automatic session cleanup deleted sub-agent sessions from chats that were still in use. A sub-agent's timestamp stops changing when it finishes, and a new message in the chat updates only the chat. Cleanup judged each sub-agent on its own timestamp, so returning to an older chat left its earlier sub-agents to be deleted on the next pass. The sub-agent cards then showed no content, the sub-agent viewer stayed on "Initializing", and the agent could no longer resume those sub-agents.

Implementation

KiloSessionRetention.expiredRoots now judges every session by its top-level chat, so a chat and all its sub-agents are kept, held back as busy, or deleted together.

Screenshots / Video

Before

data-cleanup-bug.mp4

After

data-cleanup-fix.mp4

How to Test

Manual/local verification

  • Human: reproduced the bug in bun run extension:isolated on 776d8b2c56 using the reviewer steps below. The sub-agent was deleted, and its viewer stayed on "Initializing". After the fix, the same steps keep the sub-agent.
  • Agent: ran the old expiredRoots over a read-only copy of a real profile. One chat resumed a day after its first sub-agents ran lost 7 of its 17 sub-agents at a 12-day limit, with no manual edits to the data.
  • Agent: bun test ./test/kilocode/session/retention.test.ts and bun run typecheck in packages/opencode pass.

Reviewer test steps

Use an isolated instance. With a 1-day limit, cleanup deletes every chat in the profile older than a day.

  1. Run bun run extension:isolated.
  2. In the Kilo sidebar, send:
    Use the task tool to start a general subagent. Have the subagent run `ls` in the current folder and report the file names back to you. Do not list the files yourself.
    
    Wait for the General Agent card to finish.
  3. Make the sub-agent 3 days old:
    sqlite3 .kilo-dev/data/kilo/kilo.db "
    create temp table kid as select id from session where parent_id is not null order by time_created desc limit 1;
    update session set time_updated = time_updated - 259200000 where id in kid;
    update message set time_created = time_created - 259200000 where session_id in kid;
    update part set time_updated = time_updated - 259200000 where session_id in kid;"
  4. Open Settings → Checkpoints, turn on Enable automatic session cleanup, set Keep sessions for (days) to 1, and click Run Cleanup Now.
  5. Open the chat from History and click the sub-agent card. It still lists its tool calls, and the last-run summary reports 0 deleted.

Blocked checks and substitute verification

  • None.

Checklist

  • Issue linked above, or exception explained
  • Tests/verification described
  • Screenshots/video included for visual changes, or marked N/A
  • Changeset considered for user-facing changes
  • I personally reviewed the diff and can explain the changes, including any AI-assisted work.

@kilo-code-bot

kilo-code-bot Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (4 files)
  • .changeset/cleanup-keeps-subagents.md
  • packages/kilo-docs/pages/code-with-ai/features/checkpoints.md
  • packages/opencode/src/kilocode/session/retention.ts
  • packages/opencode/test/kilocode/session/retention.test.ts

The new top() climb makes each session's expiry decision come from its top-level chat, so expired is upward-closed and a chat plus all its sub-agents are kept, held back as busy, or deleted together. I traced the busy/candidate two-pass flow and the unchanged cascade, progress, and abort tests; behavior stays consistent, the cycle guard terminates on cyclic parent links, and orphan rows fall back to their own subtree. No memory or resource leaks introduced.


Reviewed by deepseek-v4.1-flash · Input: 0 · Output: 0 · Cached: 0

Review guidance: REVIEW.md from base branch main

@marius-kilocode

marius-kilocode commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator

Thanks for the fix!

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.

[Bug] Session cleanup deletes sub-agents of a chat that is still in use

2 participants