Skip to content

Conversation

@marius-kilocode
Copy link
Collaborator

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

Fix: Agent Manager sessions disappearing immediately after starting

Fixes an issue where Agent Manager sessions would disappear immediately after starting, particularly when there's already a session running in the right sidebar.

Root Cause

A race condition in currentGitUrl initialization caused Agent Manager sessions to be filtered out immediately after creation:

  1. In AgentManagerProvider constructor, initializeCurrentGitUrl() is called asynchronously but not awaited
  2. currentGitUrl starts as undefined
  3. When startAgentSession() is called, it fetches gitUrl from the workspace and creates the session with this gitUrl
  4. postStateToWebview() is called, which uses getFilteredState() with this.currentGitUrl
  5. If currentGitUrl is still undefined (because initializeCurrentGitUrl() hasn't completed), but the session has a gitUrl, the session is filtered out by getSessionsForGitUrl()
  6. The webview receives state without the session and removes it

Fix

Modified startAgentSession() to update currentGitUrl when fetching the git URL for a new session, ensuring the filter matches the session's gitUrl:

if (gitUrl && !this.currentGitUrl) {
    this.currentGitUrl = gitUrl
    this.outputChannel.appendLine(`[AgentManager] Updated current git URL: ${gitUrl}`)
}

@changeset-bot
Copy link

changeset-bot bot commented Jan 9, 2026

🦋 Changeset detected

Latest commit: 5d990e0

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 9, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Overview

This PR correctly fixes a race condition where Agent Manager sessions would disappear immediately after starting. The issue occurs when initializeCurrentGitUrl() (called asynchronously in the constructor) hasn't completed by the time startAgentSession() is called.

The Fix:

  • Updates currentGitUrl during session start if it's not already set (lines 476-481)
  • Ensures consistency between the session's gitUrl and the filter used to display sessions
  • Properly guards against overwriting an already-set currentGitUrl

Code Quality:

  • ✅ Logic is sound and addresses the race condition correctly
  • ✅ Tests cover both scenarios (updating when not set, not overwriting when set)
  • ✅ Follows existing code patterns and conventions
  • ✅ Includes appropriate logging for debugging
  • ✅ Changeset is properly formatted
Files Reviewed (3 files)
  • .changeset/fix-agent-manager-session-disappears.md - Changeset documentation
  • src/core/kilocode/agent-manager/AgentManagerProvider.ts - Race condition fix
  • src/core/kilocode/agent-manager/__tests__/AgentManagerProvider.spec.ts - Test coverage

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