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/quiet-worktrees-list.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"kilo-code": patch
---

Prevent Agent Manager overview requests from timing out while refreshing Git statistics across many worktrees.
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ export class AgentManagerProvider implements Disposable {
await this.stateReady
return this.state
},
stats: (refresh) => this.statsPoller.snapshot(refresh),
stats: () => this.statsPoller.snapshot(),
prs: () => this.prBridge.snapshot(),
push: () => this.pushState(),
managed: (id) => this.panelSessions.has(id) || !!this.state?.getSession(id),
Expand Down
14 changes: 4 additions & 10 deletions packages/kilo-vscode/src/agent-manager/GitStatsPoller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,7 @@ export class GitStatsPoller {
this.lastStats = {}
}

async snapshot(refresh = false): Promise<{ worktrees: WorktreeStats[]; local?: LocalStats }> {
if (refresh && !this.busy) {
this.busy = true
await Promise.all([this.fetchWorktreeStats(true), this.fetchLocalStats()]).finally(() => {
this.busy = false
})
}
async snapshot(): Promise<{ worktrees: WorktreeStats[]; local?: LocalStats }> {
return {
worktrees: Object.values(this.lastStats),
...(this.lastLocalStats ? { local: this.lastLocalStats } : {}),
Expand Down Expand Up @@ -170,10 +164,10 @@ export class GitStatsPoller {
}

private async fetch(generation = this.generation): Promise<void> {
await Promise.all([this.fetchWorktreeStats(false, generation), this.fetchLocalStats(generation)])
await Promise.all([this.fetchWorktreeStats(generation), this.fetchLocalStats(generation)])
}

private async fetchWorktreeStats(includeSkipped = false, generation = this.generation): Promise<void> {
private async fetchWorktreeStats(generation = this.generation): Promise<void> {
const worktrees = this.options.getWorktrees()
if (worktrees.length === 0) return

Expand All @@ -189,7 +183,7 @@ export class GitStatsPoller {
for (const id of Object.keys(this.lastStats)) {
if (!ids.has(id)) delete this.lastStats[id]
}
const active = includeSkipped ? available : available.filter((wt) => !this.skipWorktreeIds.has(wt.id))
const active = available.filter((wt) => !this.skipWorktreeIds.has(wt.id))
if (active.length === 0) {
if (available.length > 0) return
if (this.lastHash === "") return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ interface Options {
root(): string | undefined
ready(): Promise<WorktreeStateManager | undefined>
state(): WorktreeStateManager | undefined
stats(refresh?: boolean): Promise<{ worktrees: WorktreeStats[]; local?: LocalStats }>
stats(): Promise<{ worktrees: WorktreeStats[]; local?: LocalStats }>
prs(): Map<string, PRStatus>
push(): void
managed(sessionID: string): boolean
Expand Down Expand Up @@ -257,7 +257,10 @@ export class AgentManagerOrchestrationBridge {
if (this.disposed || active.cancelled) return
const client = this.connection.getClient()
if (request.operation === "overview") {
const stats = await this.options.stats(true)
// Git stats are refreshed by the poller independently. A forced refresh
// here can spawn one diff/ahead-behind pair per worktree and exceed the
// host request timeout before the overview can return its IDs.
const stats = await this.options.stats()
Comment thread
marius-kilocode marked this conversation as resolved.
Resolved
if (this.disposed || active.cancelled) return
const result = await overview({
client,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe("AgentManagerOrchestrationBridge", () => {
const replies: unknown[] = []
const rejections: unknown[] = []
const lists = new Map<string, AgentManagerRequest[]>()
const statsCalls: number[] = []
const handlers: {
event?: (event: SSEPayload, directory?: string) => void
state?: (state: "connecting" | "connected" | "disconnected" | "error") => void
Expand All @@ -54,6 +55,12 @@ describe("AgentManagerOrchestrationBridge", () => {
status: mock(async () => ({ data: {} })),
promptAsync,
},
permission: {
list: mock(async () => ({ data: [] })),
},
question: {
list: mock(async () => ({ data: [] })),
},
kilocode: {
agentManager: {
list: mock(async ({ directory }: { directory?: string }) => {
Expand Down Expand Up @@ -96,7 +103,10 @@ describe("AgentManagerOrchestrationBridge", () => {
root: () => root,
ready: async () => state,
state: () => state,
stats: async () => ({ worktrees: [] }),
stats: async () => {
statsCalls.push(1)
return { worktrees: [] }
},
prs: () => new Map(),
push,
managed: (id) => managed.has(id),
Expand All @@ -108,7 +118,21 @@ describe("AgentManagerOrchestrationBridge", () => {
{ id: `event-${value.id}`, type: "kilocode.agent_manager.requested", properties: value } as SSEPayload,
directory,
)
return { bridge, client, close, handlers, lists, managed, promptAsync, push, rejections, replies, request, status }
return {
bridge,
client,
close,
handlers,
lists,
managed,
promptAsync,
push,
rejections,
replies,
request,
statsCalls,
status,
}
}

const request: AgentManagerRequest = {
Expand Down Expand Up @@ -233,6 +257,30 @@ describe("AgentManagerOrchestrationBridge", () => {
test.bridge.dispose()
})

it("returns an overview with cached git stats", async () => {
const test = harness()
test.request({
id: "amr_overview",
sessionID: "ses_caller",
operation: "overview",
})
await waitFor(() => test.replies.length === 1)

expect(test.statsCalls).toEqual([1])
expect(test.replies[0]).toEqual({
requestID: "amr_overview",
directory: root,
result: {
operation: "overview",
overview: expect.objectContaining({
ungrouped: [expect.objectContaining({ id: expect.any(String) })],
sections: [],
}),
},
})
test.bridge.dispose()
})

it("stops a live panel session before it is persisted", async () => {
const test = harness()
test.managed.add("ses_live")
Expand Down
Loading