{"record":{"id":"b237478386795026","repo":"abi/screenshot-to-code","slug":"update-requests-require-history-or-filestate-conte","errorCode":null,"errorMessage":"Update requests require history or fileState.content","messagePattern":"Update requests require history or fileState\\.content","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"backend/prompts/plan.py","lineNumber":22,"sourceCode":"    PromptHistoryMessage,\n    Stack,\n)\n\n\ndef derive_prompt_construction_plan(\n    stack: Stack,\n    input_mode: InputMode,\n    generation_type: str,\n    history: list[PromptHistoryMessage],\n    file_state: dict[str, str] | None,\n) -> PromptConstructionPlan:\n    if generation_type == \"update\":\n        if len(history) > 0:\n            strategy = \"update_from_history\"\n        elif file_state and file_state.get(\"content\", \"\").strip():\n            strategy = \"update_from_file_snapshot\"\n        else:\n            raise ValueError(\"Update requests require history or fileState.content\")\n        return {\n            \"generation_type\": \"update\",\n            \"input_mode\": input_mode,\n            \"stack\": stack,\n            \"construction_strategy\": strategy,\n        }\n\n    return {\n        \"generation_type\": \"create\",\n        \"input_mode\": input_mode,\n        \"stack\": stack,\n        \"construction_strategy\": \"create_from_input\",\n    }\n","sourceCodeStart":4,"sourceCodeEnd":36,"githubUrl":"https://github.com/abi/screenshot-to-code/blob/d026163f586dfa8c5c10d28c36edd59a9d3b0e88/backend/prompts/plan.py#L4-L36","documentation":"Raised in build_prompt_construction_plan (backend/prompts/plan.py) for generation_type == \"update\" when neither update source exists: the history list is empty AND file_state is None or its `content` is blank/whitespace. An update generation needs prior context — either chat history or a snapshot of the current file — to know what to update; with neither, no construction strategy can be selected and the plan fails fast.","triggerScenarios":"Calling the prompt pipeline with generation_type=\"update\", history=[] and file_state=None; or file_state={\"content\": \"   \"} (whitespace only, stripped to empty); or file_state={\"path\": \"...\"} with no content key. Typical producer: a WebSocket update request whose history array the client didn't populate.","commonSituations":"Frontend sends an update chat message before any prior generation exists in the session; session/history lost after a page reload or backend restart; clients constructing update requests manually without the file snapshot; frontend sends fileState without content (only path).","solutions":["Include the conversation history (at least one prior user message) in the update request.","Or include fileState with non-blank `content` — the current code snapshot to update from.","If there is genuinely nothing to update from, send generation_type \"create\" instead.","On the frontend, guard the update flow: require either an existing chat history or a loaded file before enabling update mode."],"exampleFix":"# before\nbuild_prompt_construction_plan(stack, input_mode, \"update\", history=[], file_state=None)\n\n# after — provide a snapshot\nbuild_prompt_construction_plan(\n    stack, input_mode, \"update\", history=[],\n    file_state={\"content\": current_code, \"path\": \"index.html\"},\n)","handlingStrategy":"validation","validationCode":"def can_build_update(history: list, file_state: dict | None) -> bool:\n    if len(history) > 0:\n        return True\n    return bool(file_state and file_state.get(\"content\", \"\").strip())","typeGuard":"from typing import Any\n\ndef has_update_source(history: list[dict], file_state: dict[str, Any] | None) -> bool:\n    \"\"\"True when an update generation has history or a usable file snapshot.\"\"\"\n    return len(history) > 0 or bool(\n        isinstance(file_state, dict) and file_state.get(\"content\", \"\").strip()\n    )","tryCatchPattern":"try:\n    plan = build_prompt_construction_plan(stack, input_mode, generation_type, history, file_state)\nexcept ValueError as e:\n    if \"require history or fileState.content\" in str(e):\n        return error_response(\"Update needs chat history or the current file content\", 400)\n    raise","preventionTips":["Before sending an update, confirm the session has history or a loaded file snapshot","Always populate fileState.content when updating from the code editor view","Use generation_type 'create' for the first message of a session"],"tags":["prompts","validation","update","chat-history"],"backgroundTag":null,"analyzedSha":"d026163f586dfa8c5c10d28c36edd59a9d3b0e88","analyzedAt":"2026-08-14T22:02:06.951Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}