kilocode icon indicating copy to clipboard operation
kilocode copied to clipboard

[Bug] Orphaned VS Code permission popups are never reconciled — recovery only adds, never removes, and the only wipe path (config save) destroys running sessions

Open kz363 opened this issue 1 month ago • 1 comments

Description

Verified by source reading against Kilo 7.8.8.

When a permission request shown as a popup in the VS Code webview becomes stale server-side (serve process restarted, request resolved via another surface while SSE was down, permission.replied event dropped during a SSE disconnect, or kilo serve process died), the popup never disappears on its own and — depending on which failure path the user hits — clicking Allow/Reject only shows the toast "Failed to update permissions" and leaves the popup in place.

Recovery is additive-only. fetchAndSendPendingPermissions (packages/kilo-vscode/src/kilo-provider/handlers/permission-handler.ts:180-234) re-fetches pending permissions on SSE reconnect, message load, etc., but it only posts permissionRequest messages (which upsert into the webview's permissions signal at webview-ui/src/context/session.tsx:1551-1554) and prunePermissionDirectories (which cleans the host-side routing map only, not the webview). It never sends any message that removes webview entries that are no longer pending server-side.

The full popup-removal surface (verified)

The webview permissions signal has exactly four removal paths in webview-ui/src/context/session.tsx:

  1. handlePermissionResolved (session.tsx:1557) — fed by successful local reply and by SSE permission.replied mapped at kilo-provider-utils.ts:713-717
  2. handlePermissionError with stale: true (session.tsx:1568) — reached only when the server answers NotFound/404 (permission-handler.ts:133-136) or permissionSettled proves absence
  3. clearPendingPrompts broadcast → setPermissions([]) (session.tsx:940) — only fired by config save (see below)
  4. removeSessionPermissions inside handleSessionDeleted (session.tsx:1947) — only when the extension host deletes the session

There is no reconcile step in fetchAndSendPendingPermissions or fetchAndSendPendingQuestions (handlers/question.ts:54-130, same gap).

Where clicks dead-end with a toast and a persistent popup

handlePermissionResponse (permission-handler.ts:95-172) has three error paths that post permissionError without stale (session.tsx:1580-1583 then only shows a toast, leaves the popup, and re-enables the buttons):

  • :104-106 !client — extension has no live client while the popup is shown
  • :112-116 "Unknown permission route" — when the sessionID/directory maps in connectionService don't contain the permission id (this state can persist after the SSE permission.replied handler cleared the maps via clearPermissionDirectory, connection-service.ts:1103, if the mapped permissionResolved was missed)
  • :157-160 catch-all transport error from runPermissionResponse — dead serve process, timeout after 3 attempts/15 s (sdk-permission.ts:12,45-54), parse failure

The 404 → stale:true → popup removed self-heal exists only for the happy transport path where the server is alive to return 404. Against a dead kilo serve process or a stale route map the click dead-ends indefinitely.

The only wipe path is destructive

clearPendingPrompts has exactly one producer: drainPendingPrompts() (connection-service.ts:686-729), whose only non-test caller is config save (KiloProvider.ts:4053, handleUpdateConfig). Before broadcasting it rejects every pending permission/question server-side and then runs config.overlayUpdate, which disposes instances — see the comment on drainPendingPrompts and webview-ui/src/context/config.tsx:8. So it cannot be used while sessions are running, making it unusable as a manual workaround.

A webview remount (Developer: Reload Webviews) or window reload clears the popup because the permissions signal and terminalPermissions LRU are in-memory only (session.tsx:175, 247); nothing is persisted to globalState/workspaceState.

Steps to reproduce

  1. Trigger a permission request from any session (primary or subagent) so the popup shows.
  2. Kill the kilo serve process before clicking, or drop the SSE stream, so the pending request resolves server-side without the extension observing permission.replied (real-world trigger observed: serve process froze and was SIGKILLed; a newer serve on a different port was healthy and returned HTTP 200 for a direct REST reply to the request ID, but the popup stayed).
  3. Click Allow or Reject → toast "Failed to update permissions" (settings.permissions.toast.updateFailed.title at webview-ui/src/i18n/en.ts:498); popup stays.
  4. Ask the daemon directly (GET /permission) or POST /permission/{id}/reply from curl/bash: server returns 200 and clears the request, the agent proceeds — the popup still stays, because the extension only learns of resolution via the SSE permission.replied event that was already missed.
  5. The only ways to remove the popup: webview remount (Developer: Reload Webviews), window reload, delete the session, or save config (which rejects all live prompts and disposes instances).

Expected vs actual. Expected: popup clears when the request is no longer pending server-side — either when the extension reconnects (reconcile) or when the user clicks a stale popup (clarify stale and remove, as the 404 path already does). Actual: recovery only re-adds popups the webview missed; it never removes popups the server already cleared; clicks through the three dead-end paths toast and keep the popup.

Per-surface and frequency

-CLI/TUI unaffected: TUI renders its own state from SSE (packages/tui/src/context/sync.tsx); the CLI respond path works independently of the webview signal. The agent is always still unblockable through the CLI.

  • Observed 3 occurrences in one week on one machine with heavy multi-agent (parent sessions spawning subagents) use: all three recovered by either killing the stale serve process or by API-replying the pending request and then reloading webviews.

Severity

P3 — UI state only; no data loss; agent work is not blocked (CLI reply path works). Heavy multi-agent users hit the orphan variant rarely but persistently enough (3×/week in this environment) that the workaround is well-worn.

Environment

Field Value
Operating System Linux x64 (WSL2)
Kilo version 7.8.8 (VS Code extension, kilo serve daemon)
Source inspected at commit main of Kilo-Org/kilocode

Suggested fix (first cut — maintainer-idiomatic)

The minimal, in-keeping-with-recent-commits fix is not a bulk-reconcile message but to extend the existing per-id settlement pattern already used by commit f6d761e65c (aborted rule saves): give the three handlePermissionResponse dead-ends a stale:true escape after a permissionSettled-style verification round-trip — i.e. when a reply fails with a non-404 error, try permissionSettled(client, dir, requestID) and, if settled, treat it as stale and let the webview remove the popup.

The three locations to touch: permission-handler.ts:104-106 (!client — only after a settle attempt, or defer until client present), :112-116 (unknown route — after settle against the recorded dir, or as a last resort defer to permission.list for that session), and :157-160 (transport error catch — after settle retry). This removes permanently-stranded popups on the click path, which is how revive attempts currently fail.

Longer term (separate cut, requires care to avoid coverage gap): add reconcile-on-fetch to fetchAndSendPendingPermissions/fetchAndSendPendingQuestions that emits removals for server-absent ids. Caution: recoveryDirs (permission-handler.ts:186) is the workspace root + sessionDirectories + extraDirectories and does not include the connectionService rootDirectory/currentDirectory when those aren't in the tracked set, and validIds must be built from the raw data arrays, not from recoverablePermissions-filtered results (which drop claimed and non-tracked-session ids) — otherwise reconcile would wrongly remove popups that are actually live in uncovered directories.

Related upstream work (areas already iterated on this file)

  • 51d5d9b0ed — shared 404 detection
  • 3c049845e7 — resolve subagent permission cards after replies
  • d12a1392bb — prevent permission prompt races
  • d8eaefdf1d — recover stalled permission approvals
  • fa897b854d — simplify stalled permission recovery
  • f6d761e65c — reconcile aborted permission rule saves
  • 675ed4b12d — retry dropped permission replies
  • d9f9d72e58 — fall back to session directory for permission replies

No commit yet adds a reconcile step to fetchAndSendPendingPermissions.

Notes

  • Related prior report of session-dispose behavior on config save: #14823 (dispose pattern).
  • Question flow (handlers/question.ts:34-46) already has an absence-implies-stale path for a clicked card when the scan is complete; it lacks the same bulk reconcile, but its per-id click path is somewhat more resilient than the permission flow's three dead-ends.
  • Unverified from source alone: whether permissionResolved posts to all mounted webview panels or only the currently active one (could affect multi-panel setups); whether ctx.postMessage is FIFO-synchronous (matters only for the long-term reconcile design).

kz363 avatar Oct 08 '26 23:10 kz363

I'm picking this up, planning the minimal first cut you outlined: extend the existing per-id stale-escape pattern to the dead-end paths in handlePermissionResponse — the transport-error catch and the unknown-route path get a permissionSettled-style verification round-trip (via permission.list fallback when the route/dir map is gone) and post permissionError with stale: true when the request is provably no longer pending, so the webview removes the popup instead of stranding it behind a toast. I'll follow the unit-test conventions in this package and link a PR shortly. (Bulk reconcile in fetchAndSendPendingPermissions I'll leave untouched for a maintainer-led follow-up, per the coverage-gap concern in your report.)

Hardik180704 avatar Oct 18 '26 07:10 Hardik180704