fix: move context files after cache boundary to prevent invalidation#61422
fix: move context files after cache boundary to prevent invalidation#61422daniel-rudaev wants to merge 10000 commits into
Conversation
* plugins: include resolved workspaceDir in provider hook cache keys resolveProviderPluginsForHooks, resolveProviderPluginsForCatalogHooks, and resolveProviderRuntimePlugin used the raw params.workspaceDir for cache keys and plugin-id discovery while resolvePluginProviders already fell back to the active registry workspace. Resolve workspaceDir once at the top of each function so cache keys, candidate filtering, and loading all use the same workspace root. * fix(plugins): inherit runtime workspace for snapshot loads * test(gateway): stub runtime registry seam * fix(plugins): restore workspace fallback after rebase --------- Co-authored-by: Vincent Koc <[email protected]>
…8943) (thanks @imechZhangLY) * fix(infra): windows-task-restart fallback to startup entry when schtasks task is unregistered * fix code style problem * use /min for startup fallback and assert schtasks pre-check in test * fix: windows restart fallback when scheduled task is unregistered (#58943) (thanks @imechZhangLY) --------- Co-authored-by: Luyao Zhang <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]>
Co-authored-by: Vincent Koc <[email protected]>
Co-authored-by: Vincent Koc <[email protected]>
…fahmedjoy) * fix: implement Windows stale gateway process cleanup before restart findGatewayPidsOnPortSync() returned [] immediately on Windows, causing cleanStaleGatewayProcessesSync() to skip killing old gateway processes during self-restart (triggerOpenClawRestart -> schtasks path). This led to an infinite retry loop: 'gateway already running under schtasks; waiting 5000ms before retrying startup'. Changes: - Extract Windows port/process helpers into shared windows-port-pids.ts to break the circular import between restart-stale-pids.ts and gateway-processes.ts, with configurable timeoutMs for poll compliance - findGatewayPidsOnPortSync: discover + verify Windows gateway PIDs via readWindowsListeningPidsOnPortSync + readWindowsProcessArgsSync - pollPortOnceWindows: use short POLL_SPAWN_TIMEOUT_MS (400ms) so a single slow PowerShell call cannot exceed the 2s polling budget - terminateStaleProcessesSync: add terminateStaleProcessesWindows using taskkill.exe (graceful /T first, then /F force-kill) Fixes the Windows gateway restart infinite loop caused by the schtasks supervisor detecting a port conflict it cannot resolve. * fix: tighten windows stale gateway cleanup * fix: preserve windows restart probe failures * refactor: unify windows gateway pid verification * fix: preserve windows argv probe failures * fix: windows self-restart stale gateway cleanup (#60480) (thanks @arifahmedjoy) --------- Co-authored-by: Ayaan Zaidi <[email protected]>
Context files (MEMORY.md, SOUL.md, USER.md, etc.) were rendered in the stable prefix before SYSTEM_PROMPT_CACHE_BOUNDARY. When memory plugins write between turns, the prefix changes and Anthropic's prompt cache is invalidated — resulting in 0% cache hit rate. Move the "# Project Context" section to after the cache boundary so that the stable prefix (system prompt, identity, tools, skills) remains constant across turns. Dynamic context files were already after the boundary and are unaffected. Measured impact: 0% → cache hits observed after the fix on a production instance using memory-core plugin with frequent MEMORY.md writes.
Greptile SummaryMoves the Confidence Score: 4/5Safe to merge after fixing the stale test assertion that directly contradicts the new ordering. The implementation correctly addresses the cache invalidation problem described in the PR. One P1 test assertion on line 710 inverts the expected index relationship and will cause a CI failure. src/agents/system-prompt.test.ts — the test at line 686 needs its assertion on line 710 and its name updated to match the new post-boundary ordering.
|
|
Codex review: needs changes before merge. Summary Reproducibility: yes. A high-confidence static reproduction exists by building a prompt with a changing Next step before merge Security Review findings
Review detailsBest possible solution: Implement a stable-vs-volatile context split: keep AGENTS/SOUL/IDENTITY/USER/TOOLS/BOOTSTRAP cacheable, move only volatile context such as auto-written memory or explicitly marked dynamic context below the boundary, and lock it with tests/docs/changelog. Do we have a high-confidence way to reproduce the issue? Yes. A high-confidence static reproduction exists by building a prompt with a changing Is this the best way to solve the issue? No. Moving all Project Context below the boundary avoids invalidation but forfeits caching for stable workspace context; a narrower volatility classification is the maintainable fix. Full review comments:
Overall correctness: patch is incorrect Acceptance criteria:
What I checked:
Likely related people:
Remaining risk / open question:
Codex review notes: model gpt-5.5, reasoning high; reviewed against 4532e5d85803. |
6615f97 to
1813c29
Compare
Summary
Context files (MEMORY.md, SOUL.md, USER.md, etc.) are currently rendered in the stable prefix before
SYSTEM_PROMPT_CACHE_BOUNDARY. When memory plugins write between turns, the prefix changes and Anthropic's prompt cache is invalidated — resulting in ~0% cache hit rate for anyone using workspace files that change between turns.This PR moves the
# Project Contextsection to after the cache boundary, keeping the stable prefix (system prompt, identity, tools, skills, silent replies) constant across turns.Impact
Measured on a production instance using
memory-coreplugin with frequent MEMORY.md writes:cache_read_input_tokens > 0starting from turn 2)This affects anyone using workspace files that are modified between turns (memory plugins, auto-updated context files, etc.).
Test plan
cache_read_input_tokens > 0on consecutive turns with Anthropic provider