bytedance/deer-flow · warning · HTTPException

Could not find the user message for this assistant response

Error message

Could not find the user message for this assistant response

What it means

Raised in _prepare_regenerate_payload (HTTP 409) when no visible human message can be found preceding the target assistant message. Regeneration needs the originating user turn (for its run linkage and the base checkpoint), so an assistant message with no prior user message cannot be replayed.

Source

Thrown at backend/app/gateway/routers/thread_runs.py:677

        latest_visible_ai = next((message for message in reversed(messages) if _is_visible_ai_message(message)), None)
        if _message_id(latest_visible_ai) != message_id:
            raise HTTPException(status_code=409, detail="Only the latest assistant message can be regenerated")

        previous_human = next((message for message in reversed(messages[:target_index]) if _is_visible_human_message(message)), None)
        target_run_id = (
            await _find_target_run_id(
                thread_id,
                message_id,
                target_message,
                previous_human,
                request,
            )
            if previous_human is not None
            else None
        )
    if previous_human is None:
        raise HTTPException(status_code=409, detail="Could not find the user message for this assistant response")
    if target_run_id is None:
        raise HTTPException(status_code=409, detail="Could not find source run for assistant message")
    previous_human_id = _message_id(previous_human)
    if not previous_human_id:
        raise HTTPException(status_code=409, detail="The source user message is missing an id")

    base_checkpoint_tuple = await _find_base_checkpoint_before_human(
        thread_id,
        previous_human_id,
        request,
        head_checkpoint=latest_checkpoint,
    )
    checkpoint = _checkpoint_response(base_checkpoint_tuple)
    metadata = {
        "regenerate_from_message_id": message_id,
        "regenerate_from_run_id": target_run_id,
        "regenerate_checkpoint_id": checkpoint["checkpoint_id"],
    }

View on GitHub (pinned to 1dd6ba1acb)

Solutions

  1. Only regenerate assistant replies that answered a real user message.
  2. If the user turn was intentionally hidden, un-hide or re-add it so lineage is intact.
  3. For seeded/opening messages, regenerate is unsupported; send a new user message instead.
Defensive patterns

Strategy: validation

Validate before calling

const idx = messages.findIndex(m => m.id === messageId);
const hasPriorHuman = messages.slice(0, idx).some(m => m.type === 'human' && !m.hidden);
if (!hasPriorHuman) { disableRegenerate(); }

Type guard

function assistantHasSourceUser(messages: Msg[], targetId: string): boolean {
  const idx = messages.findIndex(m => m.id === targetId);
  return idx > 0 && messages.slice(0, idx).some(m => m.type === 'human' && !m.hidden);
}

Try / catch

try { await regeneratePrepare(threadId, messageId); } catch (e) { if (e.status === 409 && /user message for this assistant/.test(e.detail)) { notify('This message cannot be regenerated'); } else throw e; }

Prevention

When it happens

Trigger: Thread state where the assistant message is first (e.g. seeded/system-generated first message); the preceding human message was hidden or stripped from checkpoint state; corrupted message list ordering.

Common situations: Threads pre-seeded with an AI greeting; hidden user turns (internal triggers); checkpoint state edited externally.

Related errors


AI-assisted analysis of bytedance/deer-flow@1dd6ba1acb (2026-08-14). Data as JSON: /api/errors/5296a4734860badc. Report an issue: GitHub.