Skip to content

fix(coding-agent): preserve task-state prompt cache prefixes - #293

Merged
ZouR-Ma merged 1 commit into
mainfrom
fix/task-state-cache-prefix
Oct 22, 2026
Merged

ZouR-Ma merged 1 commit into
mainfrom
fix/task-state-cache-prefix

Conversation

@ZouR-Ma

@ZouR-Ma ZouR-Ma commented Oct 22, 2026

Copy link
Copy Markdown
Collaborator

Problem

The task context hook added by baa1ef8 (merged in #232) rebuilds a request-only task snapshot at the end of every model request. On the following turn, that previous input item disappears and assistant/tool messages take its place. This breaks append-only prompt-cache prefixes even when the task state has not changed. The initial 4fdb781 implementation did not have this hook.

Changes

  • Keep task snapshots at their original request boundaries using the existing stable-notice mechanism.
  • Append a new snapshot only when the rendered task state changes; reuse unchanged content and timestamps.
  • Append an empty snapshot when the last task is deleted, and reset request-only state on context replacement, branch restoration, or disabled task tools.
  • Add unit, session, and mocked HTTP Responses regressions and document the latest-snapshot semantics.

Behavior and compatibility

This is a single fix cherry-picked from 7704518 onto current main, not a merge of the Desktop branch. The diff contains only six coding-agent source, test, and documentation files; no Desktop/Web changes, dependencies, or lockfile updates.

Task state remains authoritative in its existing store. Historical request snapshots are data; the last snapshot is current. Canonical transcripts, editable CLM mirrors, task permissions, and explicit completion rules are unchanged. CLI, RPC, SDK, Web, and Desktop share this extension.

Validation

On macOS with Node 24.3.0 and pnpm 9.15.9, in the independent main-based worktree:

  • pnpm run build:offline — passed.
  • pnpm run check — passed.
  • TMPDIR=/tmp ./test.sh — all workspace suites passed; existing provider/platform skips retained.
  • 14 targeted task/context/compaction/retry regression files — 236 tests passed.
  • Offline replay of the same 136 successful requests, comparing 135 adjacent serialized message-input prefixes: initialization path 0 violations; previous task projection 125 violations; fixed task projection 0 violations.

The Desktop branch also passed its repository checks and isolated full suite. The first full run with the default macOS temporary directory hit the existing tsx Unix-socket path-length failure; the documented TMPDIR=/tmp run passed without changing tests or timeouts.

Limitations

Provider-side cache hit rates have not been re-measured with paid requests. Intentional context edits, changed system/tool definitions, cold process resumes, and provider eviction can still invalidate caches. Previously issued request-only snapshots are not persisted across process restarts. Installed applications need a rebuilt runtime and restart to use this fix.

Keep request-only task snapshots at their original conversation boundaries and append a new version only when visible task state changes. Reuse unchanged snapshot content and timestamps without rewriting canonical history.

Reset snapshots on branch restoration, context replacement, or disabled task tools, and supersede deleted tasks with an empty snapshot. Add regression coverage for append-only turns, serialized Responses requests, retries, and compaction behavior.
@ZouR-Ma
ZouR-Ma merged commit 3de15c1 into main Oct 22, 2026
2 checks passed
@ZouR-Ma
ZouR-Ma deleted the fix/task-state-cache-prefix branch October 22, 2026 09:05
liuedcson added a commit that referenced this pull request Oct 23, 2026
Brings the seven commits main gained since dff413f:

- feat(coding-agent): make a feedback report investigable (#297)
- fix(coding-agent): settle extension command turns before returning (#298)
- fix(coding-agent): keep the tool block stable across plan mode (#296)
- fix(cli): save model selection as default on Enter (#285)
- feat(cli): add -C/--cwd flag (#289)
- fix(coding-agent): preserve task-state prompt cache prefixes (#293)

Two conflicts, both in the plan extension, where this branch had added
behaviour on top of files main rewrote:

- `plan-mode-tools.ts`: main's comment for `exitPlanMode` ("restore any tools
  plan mode added") with this branch's optional `submittedPlanHash` parameter,
  which records the proposal handed to an external reviewer.
- `step-plan.ts`: main's `version: 2` entry and `carriesLegacyTools` migration
  path, plus this branch's `submittedPlanHash` / `planHashAtEnter` on the same
  entry, and both sides of the restore step (legacy tool baseline and the
  persisted hashes). Main's `resolveToCwd` guard and `planModeAddedTools`
  bookkeeping are kept as-is: plan mode now appends tools instead of replacing
  the list, which is what keeps the request's tool block stable.

The host plan-mode test asserted the old refusal wording; the guard now says
"Only the plan file may be written", so it matches on that.
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.

1 participant