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/agent-manager-multi-version-terminal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"kilo-code": patch
---

Fix Agent Manager multi-version sessions to wait for pending CLI processes so terminals are available per worktree.
1 change: 0 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions src/core/kilocode/agent-manager/AgentManagerProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,10 @@ export class AgentManagerProvider implements vscode.Disposable {
*/
private waitForPendingSessionToClear(): Promise<void> {
return new Promise((resolve) => {
// Check immediately - if no pending session, resolve right away
if (!this.registry.pendingSession) {
const hasPending = () => !!this.registry.pendingSession || this.processHandler?.hasPendingProcess()

// Check immediately - if no pending session/process, resolve right away
if (!hasPending()) {
resolve()
return
}
Expand All @@ -391,7 +393,7 @@ export class AgentManagerProvider implements vscode.Disposable {

// Poll until pending session clears
const checkInterval = setInterval(() => {
if (!this.registry.pendingSession) {
if (!hasPending()) {
clearInterval(checkInterval)
if (timeoutId) {
clearTimeout(timeoutId)
Expand Down
4 changes: 4 additions & 0 deletions src/core/kilocode/agent-manager/CliProcessHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,10 @@ export class CliProcessHandler {
return this.activeSessions.has(sessionId)
}

public hasPendingProcess(): boolean {
return this.pendingProcess !== null
}

/**
* Write a JSON message to a session's stdin
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,33 @@ describe("AgentManagerProvider CLI spawning", () => {
expect(sessions[0].sessionId).toBe("cli-session-123")
})

it("waits for pending processes to clear before resolving multi-version sequencing", async () => {
vi.useFakeTimers()

try {
const registry = (provider as any).registry
const processHandler = (provider as any).processHandler

registry.clearPendingSession()
processHandler.pendingProcess = {}

let resolved = false
const waitPromise = (provider as any).waitForPendingSessionToClear().then(() => {
resolved = true
})

await Promise.resolve()
expect(resolved).toBe(false)

processHandler.pendingProcess = null
vi.advanceTimersByTime(200)
await waitPromise
expect(resolved).toBe(true)
} finally {
vi.useRealTimers()
}
})

it("shows existing terminal when selecting a session", () => {
const sessionId = "session-terminal"
const registry = (provider as any).registry
Expand Down