Fix Draft and Chat "System messages are not allowed" error - #572
Merged
Conversation
ai@7 rejects a `role: 'system'` message inside `messages` (InvalidPromptError: "System messages are not allowed in the prompt or messages fields. Use the instructions option instead."), so every Draft suggestion and every Chat turn failed before the request left the browser. Revise already passed its system prompt as `instructions`, which is why it kept working. - Draft: `buildMessages` now returns user messages only; the system prompt is exported as `DRAFT_INSTRUCTIONS` and passed as `instructions`. - Chat: the system prompt leaves the transcript entirely and becomes `CHAT_INSTRUCTIONS`. The seeded messages are now doc-context + greeting, so the doc-context refresh writes index 0 and the visible transcript starts at `SEEDED_MESSAGE_COUNT`. Tests cover both shapes against the ai@7 validator, and frontend/CLAUDE.md documents the rule. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013iq2h4nTQWWG4fYHmw1B4z
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.
The bug
Draft and Chat failed on every request with:
Since
ai@7,standardizePromptthrowsInvalidPromptErrorwhen arole: 'system'message appears inmessages— the system prompt has to travel as theinstructionsoption instead. The failure happens client-side, before the request reaches the proxy, so nothing in the backend or the model config is involved.Revise was already migrated (
instructions: systemPrompt), which is why it kept working. Draft (buildMessagesprepended a system message) and Chat (CHAT_SYSTEM_MESSAGEseeded at index 0 of the transcript) were not.The fix
buildMessagesnow returns user messages only; its system prompt is exported asDRAFT_INSTRUCTIONSand passed asinstructionson thegenerateFullTextcall.CHAT_INSTRUCTIONS, passed asinstructions. The seeded messages are now doc-context + greeting, sowithCurrentDocContextrefreshes index 0 instead of index 1, and the visible transcript starts at the namedSEEDED_MESSAGE_COUNTrather than a literal3. What the writer sees is unchanged.Verification
npm test(208 passing),npm run typecheck, andnpm run styleare all clean. New coverage:src/api/__tests__/prompts.test.ts—buildMessagesreturns user messages only, and still carries prompt, brief, document, and selection.src/pages/chat/__tests__/docContextMessage.test.ts— updated for the new indices, plus a case asserting no system message ever enters the transcript.Both call shapes were also run end-to-end through the real
ai@7validator against aMockLanguageModelV3: they pass validation, andinstructionsarrives as exactly one system entry at the head of the model prompt — the same place the old system message occupied.frontend/CLAUDE.mddocuments the rule so the next page doesn't reintroduce it.Generated by Claude Code