abi/screenshot-to-code · error · ValueError

Update requests require history or fileState.content

Error message

Update requests require history or fileState.content

What it means

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.

Source

Thrown at backend/prompts/plan.py:22

    PromptHistoryMessage,
    Stack,
)


def derive_prompt_construction_plan(
    stack: Stack,
    input_mode: InputMode,
    generation_type: str,
    history: list[PromptHistoryMessage],
    file_state: dict[str, str] | None,
) -> PromptConstructionPlan:
    if generation_type == "update":
        if len(history) > 0:
            strategy = "update_from_history"
        elif file_state and file_state.get("content", "").strip():
            strategy = "update_from_file_snapshot"
        else:
            raise ValueError("Update requests require history or fileState.content")
        return {
            "generation_type": "update",
            "input_mode": input_mode,
            "stack": stack,
            "construction_strategy": strategy,
        }

    return {
        "generation_type": "create",
        "input_mode": input_mode,
        "stack": stack,
        "construction_strategy": "create_from_input",
    }

View on GitHub (pinned to d026163f58)

Solutions

  1. Include the conversation history (at least one prior user message) in the update request.
  2. Or include fileState with non-blank `content` — the current code snapshot to update from.
  3. If there is genuinely nothing to update from, send generation_type "create" instead.
  4. On the frontend, guard the update flow: require either an existing chat history or a loaded file before enabling update mode.

Example fix

# before
build_prompt_construction_plan(stack, input_mode, "update", history=[], file_state=None)

# after — provide a snapshot
build_prompt_construction_plan(
    stack, input_mode, "update", history=[],
    file_state={"content": current_code, "path": "index.html"},
)
Defensive patterns

Strategy: validation

Validate before calling

def can_build_update(history: list, file_state: dict | None) -> bool:
    if len(history) > 0:
        return True
    return bool(file_state and file_state.get("content", "").strip())

Type guard

from typing import Any

def has_update_source(history: list[dict], file_state: dict[str, Any] | None) -> bool:
    """True when an update generation has history or a usable file snapshot."""
    return len(history) > 0 or bool(
        isinstance(file_state, dict) and file_state.get("content", "").strip()
    )

Try / catch

try:
    plan = build_prompt_construction_plan(stack, input_mode, generation_type, history, file_state)
except ValueError as e:
    if "require history or fileState.content" in str(e):
        return error_response("Update needs chat history or the current file content", 400)
    raise

Prevention

When it happens

Trigger: 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.

Common situations: 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).

Related errors


AI-assisted analysis of abi/screenshot-to-code@d026163f58 (2026-08-14). Data as JSON: /api/errors/b237478386795026. Report an issue: GitHub.