Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-agent-manager-session-disappears.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"kilo-code": patch
---

Fix Agent Manager session disappearing immediately after starting due to gitUrl race condition
6 changes: 6 additions & 0 deletions src/core/kilocode/agent-manager/AgentManagerProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,12 @@ export class AgentManagerProvider implements vscode.Disposable {
if (workspaceFolder) {
try {
gitUrl = normalizeGitUrl(await getRemoteUrl(workspaceFolder))
// Update currentGitUrl to ensure consistency between session gitUrl and filter
// This fixes a race condition where initializeCurrentGitUrl() hasn't completed yet
if (gitUrl && !this.currentGitUrl) {
this.currentGitUrl = gitUrl
this.outputChannel.appendLine(`[AgentManager] Updated current git URL: ${gitUrl}`)
}
} catch (error) {
this.outputChannel.appendLine(
`[AgentManager] Could not get git URL: ${error instanceof Error ? error.message : String(error)}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,28 @@ describe("AgentManagerProvider gitUrl filtering", () => {
expect(state.sessions[0].sessionId).toBe("session-2")
})

it("updates currentGitUrl when starting a session if not already set (race condition fix)", async () => {
// Simulate the race condition: currentGitUrl is undefined because initializeCurrentGitUrl hasn't completed
;(provider as any).currentGitUrl = undefined

// Start a session - this should update currentGitUrl
await (provider as any).startAgentSession("test prompt")

// currentGitUrl should now be set from the session's gitUrl
expect((provider as any).currentGitUrl).toBe("https://github.com/org/repo.git")
})

it("does not overwrite currentGitUrl if already set", async () => {
// Set a different currentGitUrl
;(provider as any).currentGitUrl = "https://github.com/org/other-repo.git"

// Start a session
await (provider as any).startAgentSession("test prompt")

// currentGitUrl should NOT be overwritten
expect((provider as any).currentGitUrl).toBe("https://github.com/org/other-repo.git")
})

describe("filterRemoteSessionsByGitUrl", () => {
it("returns only sessions with matching git_url when currentGitUrl is set", () => {
const remoteSessions = [
Expand Down