Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@marius-kilocode
Copy link
Collaborator

@marius-kilocode marius-kilocode commented Jan 20, 2026

Summary

Implements session persistence for Agent Manager by storing the session ID directly in each worktree's .kilocode/session-id file. This enables session recovery by matching worktrees to their corresponding sessions.

Changes

WorktreeManager.ts

  • Added sessionId field to WorktreeInfo interface
  • Added writeSessionId() - writes session ID to .kilocode/session-id in worktree
  • Added readSessionId() - reads session ID from worktree
  • Added removeSessionId() - removes session ID file from worktree
  • Added ensureWorktreeGitExclude() - adds .kilocode/ to main repo's .git/info/exclude
  • Updated discoverWorktrees() to include sessionId in discovered worktree info

CliProcessHandler.ts

  • Added onWorktreeSessionCreated callback to CliProcessHandlerCallbacks
  • Calls callback in handleSessionCreated() and upgradeProvisionalSession()

AgentManagerProvider.ts

  • Added handleWorktreeSessionCreated() method that writes session ID to worktree
  • Wired up the callback in createCliProcessHandler()

Tests

  • Added comprehensive tests for session ID read/write/remove operations
  • Added tests for discoverWorktrees with sessionId integration
  • All 33 tests pass

Design Decisions

  1. Worktree-based persistence - Session ID stored in .kilocode/session-id within each worktree, making the worktree itself the single source of truth
  2. Git exclusion - Uses main repo's .git/info/exclude (shared by all worktrees) to prevent .kilocode/ from being committed
  3. Callback pattern - onWorktreeSessionCreated callback notifies when to write session ID, keeping concerns separated

@changeset-bot
Copy link

changeset-bot bot commented Jan 20, 2026

🦋 Changeset detected

Latest commit: 21ff206

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
kilo-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@kiloconnect
Copy link
Contributor

kiloconnect bot commented Jan 20, 2026

Code Review Summary

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 1
WARNING 0
SUGGESTION 0
Issue Details (click to expand)

CRITICAL

File Line Issue
src/core/kilocode/agent-manager/AgentManagerProvider.ts 196-201 Indentation error - onPaymentRequiredPrompt, onSessionRenamed, and onWorktreeSessionCreated callbacks have an extra tab compared to other callbacks in the same object. The closing brace also has incorrect indentation.
Files Reviewed (6 files)
  • .changeset/agent-manager-session-persistence.md - No issues
  • AGENTS.md - No issues
  • src/core/kilocode/agent-manager/AgentManagerProvider.ts - 1 issue (indentation)
  • src/core/kilocode/agent-manager/RuntimeProcessHandler.ts - No issues
  • src/core/kilocode/agent-manager/WorktreeManager.ts - No issues
  • src/core/kilocode/agent-manager/__tests__/WorktreeManager.test.ts - No issues

Fix these issues in Kilo Cloud

- Add sessionId field to WorktreeInfo interface
- Add writeSessionId/readSessionId/removeSessionId methods to WorktreeManager
- Add ensureWorktreeGitExclude to prevent .kilocode/ from being committed
- Add onWorktreeSessionCreated callback to CliProcessHandler
- Integrate session ID writing in AgentManagerProvider
- Add Error Handling rules to AGENTS.md
- Add comprehensive tests (33 passing)
@marius-kilocode marius-kilocode requested a review from a team January 20, 2026 12:16
Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
- Resolved modify/delete conflict for CliProcessHandler.ts (deleted in main)
- Ported onWorktreeSessionCreated callback to RuntimeProcessHandler
- Fixed indentation in AgentManagerProvider.ts callbacks
@marius-kilocode marius-kilocode enabled auto-merge (squash) January 22, 2026 14:19
@marius-kilocode marius-kilocode merged commit 86bcfee into main Jan 22, 2026
12 checks passed
@marius-kilocode marius-kilocode deleted the session-persistence-rq branch January 22, 2026 14:29
maywzh pushed a commit to maywzh/kilocode that referenced this pull request Jan 25, 2026
…5233)

* feat(agent-manager): Add session persistence for worktrees

* feat(agent-manager): Add session persistence for worktrees

- Add sessionId field to WorktreeInfo interface
- Add writeSessionId/readSessionId/removeSessionId methods to WorktreeManager
- Add ensureWorktreeGitExclude to prevent .kilocode/ from being committed
- Add onWorktreeSessionCreated callback to CliProcessHandler
- Integrate session ID writing in AgentManagerProvider
- Add Error Handling rules to AGENTS.md
- Add comprehensive tests (33 passing)

* Update src/core/kilocode/agent-manager/AgentManagerProvider.ts

Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>

---------

Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
maywzh pushed a commit to maywzh/kilocode that referenced this pull request Jan 25, 2026
…5233)

* feat(agent-manager): Add session persistence for worktrees

* feat(agent-manager): Add session persistence for worktrees

- Add sessionId field to WorktreeInfo interface
- Add writeSessionId/readSessionId/removeSessionId methods to WorktreeManager
- Add ensureWorktreeGitExclude to prevent .kilocode/ from being committed
- Add onWorktreeSessionCreated callback to CliProcessHandler
- Integrate session ID writing in AgentManagerProvider
- Add Error Handling rules to AGENTS.md
- Add comprehensive tests (33 passing)

* Update src/core/kilocode/agent-manager/AgentManagerProvider.ts

Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>

---------

Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
catrielmuller pushed a commit that referenced this pull request Jan 26, 2026
* feat(agent-manager): Add session persistence for worktrees

* feat(agent-manager): Add session persistence for worktrees

- Add sessionId field to WorktreeInfo interface
- Add writeSessionId/readSessionId/removeSessionId methods to WorktreeManager
- Add ensureWorktreeGitExclude to prevent .kilocode/ from being committed
- Add onWorktreeSessionCreated callback to CliProcessHandler
- Integrate session ID writing in AgentManagerProvider
- Add Error Handling rules to AGENTS.md
- Add comprehensive tests (33 passing)

* Update src/core/kilocode/agent-manager/AgentManagerProvider.ts

Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>

---------

Co-authored-by: kiloconnect[bot] <240665456+kiloconnect[bot]@users.noreply.github.com>
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.

3 participants