fix: Edit tool always fails with "You must read the file" (case-sensitive name mismatch)#1332
Merged
Conversation
…ache_control
Split buildSystemPrompt to return SystemPromptBlock[] instead of string,
separating static content (base prompt, instructions, tool policy, tone)
from dynamic content (permission mode, language, env info, auto memory,
MEMORY.md). For Claude models, callAgent maps cacheable blocks with
cache_control: {type: 'ephemeral'} and non-cacheable blocks without it,
so dynamic content changes don't invalidate the static cache.
transformMessagesForExplicitCache idempotency check prevents double-marking.
- Add SystemPromptBlock interface to prompts/index.ts
- Widen CallAgentOptions.systemPrompt to string | SystemPromptBlock[]
- Update 9 existing tests across 3 files for array-based assertions
- Add 4 block structure tests in prompts.test.ts
- Add 3 SystemPromptBlock[] input tests in aiService.cacheControl.test.ts
- Update spec 019 with user story 5, FR-008, edge cases 7-8
- All 235 test files pass (3150 tests)
Follow the agent.noParams.test.ts pattern to avoid CI environment issues: - Add workdir: /tmp/test-system-prompt to isolate from CI filesystem - Add apiKey: test-key for proper agent initialization - Re-create AIManager after Agent.create() to pick up mock ToolManager - Register mock ConfigurationService in container - Clear mockCallAgent call history before sendMessage to ensure mock.calls[0] captures the sendMessage call, not any init call The CI test process was producing zero output (crash/hang), likely due to real MemoryService reading actual files from process.cwd() in CI.
Align with Claude Code: permission mode is handled purely at the tool execution layer (PermissionManager), not in the system prompt. This prevents dynamic block changes when mode switches, preserving prompt cache.
…tive name mismatch) Root cause: extractFileReadsFromMessage in messageManager.ts checked block.name === "read" (lowercase) but the actual tool name stored in message blocks is "Read" (capital R, from READ_TOOL_NAME constant). This caused recentFileReads to never be populated, so hasFileBeenRead() always returned false and the Edit tool's read-before-edit gate always failed. Fix: use READ_TOOL_NAME constant instead of hardcoded lowercase string. Also fixed test data that used lowercase "read" and added reproduction tests for hasFileBeenRead with production tool name. Fixes #1331
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root Cause
extractFileReadsFromMessageinmessageManager.ts:1037checkedblock.name === "read"(lowercase), but the actual tool name stored in message blocks is"Read"(capital R, fromREAD_TOOL_NAMEconstant).This caused
recentFileReadsMap to never be populated, sohasFileBeenRead()always returnedfalse, and the Edit tool's read-before-edit gate always failed — even after the file was Read multiple times.The sibling method
extractSkillInvocationsFromMessagecorrectly usedblock.name === "Skill"(capital S), confirming this was an isolated typo.Fix
READ_TOOL_NAMEconstant instead of hardcoded lowercase"read"string"read"(masked the bug)hasFileBeenRead()with production tool nameTest plan
pnpm -F wave-agent-sdk test tests/managers/messageManager.coverage.test.ts— 26 passedpnpm -F wave-agent-sdk test tests/managers/ tests/tools/editTool.test.ts tests/tools/readTool.test.ts— 852 passed, 1 skippedFixes #1331