Skip to content

fix(goal): preserve prompt cache across goal turns and keep timers running - #14680

Merged
marius-kilocode merged 2 commits into
mainfrom
fix-goal-feature-cache-and-timers
Sep 30, 2026
Merged

marius-kilocode merged 2 commits into
mainfrom
fix-goal-feature-cache-and-timers

Conversation

@marius-kilocode

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Long-running goals wasted prompt cache and showed a resetting timer.

  1. Cache invalidation at goal transitions. Starting or finishing a goal changed the advertised tool set, and automatic goal turns dropped the user's shell and custom system context. Any of these changes invalidates the provider's cached prompt prefix, forcing a full prefill on the next request. This happened when a goal started, on the first automatic goal turn, and again on the first normal message after a goal finished.

  2. The working timer reset every turn. The live session clock was cleared on each goal-turn boundary and during the between-turn wait, so elapsed goal time never accumulated.

  3. Repeated history scans. Each automatic goal turn rescanned the whole session history to recover the user's context, which grew quadratically across a long goal.

Why This Change Was Made

  • Goal tool restrictions were enforced by removing tools from the request, which made the request prefix unstable. The schema list is now stable, and the same restrictions are enforced at tool execution time, so a blocked tool still errors instead of running.
  • Automatic goal turns now inherit the user's editorContext and system prompt, so the early part of the request stays byte-identical. The context is loaded once per goal run and refreshed only when a real user message arrives; internal compaction markers cannot replace it.
  • The webview clock now tracks active goals across turns and idle gaps and stops on completion, pause, blocking, or terminal error. A rejected command (for example a mistyped /gaol) is an admission error that leaves the goal running, so it no longer clears the clock. Error phase now travels from the backend through the legacy SSE bridge and host mapper to the webview.

User Impact

  • Fewer full prefills during long goals, which reduces latency and cost.
  • The working timer keeps counting from the start of the goal until it stops, instead of resetting each turn.
  • Goal restrictions are unchanged: a tool that is not allowed during a goal still fails, now with a clear message.
  • Context is preserved across compaction, so later goal turns keep the same shell and system instructions.

Evidence

  • CLI goal, request-prefix, and compaction regressions: bun test ./test/kilocode/session/goal.test.ts and ./test/kilocode/provider/session-resume-cache.test.ts.
  • Admission-error transport: ./test/kilocode/legacy-sse-event.test.ts verifies the phase survives the legacy SSE bridge.
  • VS Code timer and fixture regressions: bun test tests/unit/session-provider-activity.test.ts tests/unit/session-timing.test.ts tests/unit/session-dock.test.ts tests/unit/working-indicator.test.ts tests/unit/kilo-provider-utils.test.ts.
  • Confirmed in isolated VS Code against a local provider: the clock advanced without resetting across goal turns and the five-second inter-turn gap, and captured requests kept stable tool and system prefixes with append-only history.
  • Typechecks, extension lint, Knip, and annotation checks pass.

Limitations

Live vendor cache-hit metrics were not measured. Cache expiry or compaction can still cause legitimate misses; this change only removes the unintended prefix changes.

…nning

Keep goal tool schemas stable so starting, continuing, and finishing a goal does not invalidate the provider prompt cache. Carry the user's shell and custom system context into automatic goal turns, including after compaction, and refresh it from real user input instead of rescanning the growing transcript.

Keep the session working timer running across goal turns and between-turn waits instead of resetting each turn. Rejected commands no longer clear an active goal's clock; completion, pause, blocking, and terminal errors still stop it.
@kilo-code-bot

kilo-code-bot Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

The previously reported warning (offline reconnect resetting the goal clock) is fixed: parked now holds a session whose goal is active while offline, and createTiming skips deleting the timing entry while parked, so banked goal time survives a transient reconnect.

Files Reviewed (3 files, incremental commit)
  • packages/kilo-vscode/tests/fixtures/session-provider-activity.tsx
  • packages/kilo-vscode/webview-ui/src/context/session-timing.ts
  • packages/kilo-vscode/webview-ui/src/context/session.tsx
Previous Review Summary (commit ac4a092)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit ac4a092)

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
packages/kilo-vscode/webview-ui/src/context/session-timing.ts 20 Goal clock is deleted (reset to 0) while the session is offline, so a transient reconnect mid-goal restarts the elapsed timer even though the goal never stopped.
Files Reviewed (17 files)
  • .changeset/stable-goal-turns.md - clean
  • packages/kilo-vscode/src/kilo-provider-utils.ts - clean
  • packages/kilo-vscode/tests/fixtures/session-provider-activity.tsx - clean
  • packages/kilo-vscode/tests/unit/kilo-provider-utils.test.ts - clean
  • packages/kilo-vscode/tests/unit/session-dock.test.ts - clean
  • packages/kilo-vscode/tests/unit/working-indicator.test.ts - clean
  • packages/kilo-vscode/webview-ui/src/components/chat/SessionDock.tsx - clean
  • packages/kilo-vscode/webview-ui/src/components/shared/WorkingIndicator.tsx - clean
  • packages/kilo-vscode/webview-ui/src/components/shared/working-indicator-utils.ts - clean
  • packages/kilo-vscode/webview-ui/src/context/session-timing.ts - 1 issue
  • packages/kilo-vscode/webview-ui/src/context/session.tsx - clean
  • packages/kilo-vscode/webview-ui/src/types/messages/extension-messages.ts - clean
  • packages/opencode/src/event-v2-bridge.ts - clean
  • packages/opencode/src/kilocode/session/goal/runner.ts - clean
  • packages/opencode/src/session/tools.ts - clean
  • packages/opencode/test/kilocode/legacy-sse-event.test.ts - clean
  • packages/opencode/test/kilocode/session/goal.test.ts - clean

Fix these issues in Kilo Cloud


Reviewed by deepseek-v4.1-flash · Input: 0 · Output: 0 · Cached: 0

Review guidance: REVIEW.md from base branch main

@marius-kilocode
marius-kilocode merged commit 27e0eec into main Sep 30, 2026
34 of 35 checks passed
@marius-kilocode
marius-kilocode deleted the fix-goal-feature-cache-and-timers branch September 30, 2026 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants