fix: address review feedback on reload handler

- Block reload for retry and offline session states, not just busy
  (hasActiveSession rejects any non-idle state)
- Close TOCTOU race by calling store.reload inline instead of deferring
  to a pre-response handler, so the busy check and reload run in the
  same effect
- Avoid double-firing reloadAfterAuthChange: only call it eagerly for
  worktree sessions where the SSE directory check won't match; for the
  workspace root the existing SSE handler already fires it
- Replace err: any with unknown + narrowing
- Add in-flight guard to the CLI /reload plugin to prevent overlapping
  reloads from rapid double-invocation
- Remove the TaskHeader reload button (redundant with /reload slash
  command, avoids chat visual regression baseline churn)
This commit is contained in:
marius-kilocode
2026-07-07 13:22:30 +02:00
parent 64deacf66c
commit 1c31d7ea49
5 changed files with 49 additions and 25 deletions
@@ -1,19 +1,19 @@
import { describe, expect, it } from "bun:test"
import { hasBusySession } from "@/kilocode/server/httpapi/handlers/instance-reload"
import { hasActiveSession } from "@/kilocode/server/httpapi/handlers/instance-reload"
import type { SessionStatus } from "@/session/status"
import { SessionID } from "@/session/schema"
const entries = (items: [string, SessionStatus.Info][]) =>
items.map(([k, v]) => [k as SessionID, v] as [SessionID, SessionStatus.Info])
describe("instance-reload hasBusySession", () => {
describe("instance-reload hasActiveSession", () => {
it("returns false for an empty map", () => {
expect(hasBusySession(new Map(entries([])))).toBe(false)
expect(hasActiveSession(new Map(entries([])))).toBe(false)
})
it("returns false when all sessions are idle", () => {
expect(
hasBusySession(
hasActiveSession(
new Map(
entries([
["s1", { type: "idle" }],
@@ -24,9 +24,9 @@ describe("instance-reload hasBusySession", () => {
).toBe(false)
})
it("returns true when any session is busy", () => {
it("returns true when a session is busy", () => {
expect(
hasBusySession(
hasActiveSession(
new Map(
entries([
["s1", { type: "idle" }],
@@ -37,7 +37,29 @@ describe("instance-reload hasBusySession", () => {
).toBe(true)
})
it("returns true when the only session is busy", () => {
expect(hasBusySession(new Map(entries([["s1", { type: "busy" }]])))).toBe(true)
it("returns true when a session is retrying", () => {
expect(
hasActiveSession(
new Map(
entries([
["s1", { type: "idle" }],
["s2", { type: "retry", attempt: 1, message: "retrying", next: 0 }],
]),
),
),
).toBe(true)
})
it("returns true when a session is offline", () => {
expect(
hasActiveSession(
new Map(
entries([
["s1", { type: "idle" }],
["s2", { type: "offline", requestID: "q1" as never, message: "waiting" }],
]),
),
),
).toBe(true)
})
})