Skip to content

[JS] Prompts always appends user message on resume, breaking interrupt resume #4652

@Ehesp

Description

@Ehesp

Given the scenario; I've got a Genkit prompt which generates a poem. The prompt has a tool, which handles interruption (asking the user to review the poem).

I invoke this like so:

const response = await poemPrompt(input, {
  messages: input.resumable?.messages ?? [],
  resume: input.resumable ? {
    respond: input.resumable?.responses,
  } : undefined,
});

This works fine, and the tool is triggered. I collate the response(s), the messages which existed on the response at the time the interrupts happened.

I then run the prompt again with the resumable object, containing those messages and responses, as above.

I get an error:

GenkitError3: FAILED_PRECONDITION: Cannot 'resume' generation unless the previous message is a model message with at least one tool request.

Looking at the code:

When resuming an interrupted generation by calling a defined prompt with existing history and the resume payload (e.g. prompt(input, { messages: response.messages, resume: { respond: answers } })), the prompt pipeline still appends the template as a new user message in renderUserPrompt().

That makes the last message in messages a user message instead of the model message that contains the tool request, so the resume check in generate() fails with "Cannot 'resume' generation unless the previous message is a model message with at least one tool request." The resume option is correctly forwarded into the final generate options, but the message list is already wrong.

I think the prompt layer should skip appending the user prompt when renderOptions.resume is set (e.g. in renderUserPrompt(), only push the user message when !renderOptions?.resume), but I'm not 100% sure.

Runtime (please complete the following information):

  • OS: MacOS
  • Version 26.2

** Node version
v24.8.0

Additional context

Note, I'm not using dotprompt files, I'm defining the prompts in code but not sure this makes any difference.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingjs

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions