fix(19.7): RA-WR-05 keep prompt Render errors out of the client's answer

promptHandler logs a failing Render's error with the prompt name and
answers the fixed JSON-RPC internal error "pier: the prompt could not be
rendered", as dispatch does for tool calls (A-WR-08), so database or
provider text never reaches the agent or its transcript.

TestPromptRenderError renders a prompt that fails with a database error
naming its host and asserts, on both paths, that the client sees only the
fixed text and the cause is in the log.
This commit is contained in:
2026-10-23 20:12:22 +02:00
parent 928731db4d
commit 788d4a49fa
4 changed files with 49 additions and 4 deletions

View File

@@ -706,7 +706,13 @@ func (p *Pier) toolHandler(t *tool, session Identity) mcp.ToolHandler {
}
}
// promptHandler checks the required arguments and renders the prompt.
// promptRenderFailed is the JSON-RPC error text of a prompt whose Render
// failed; the cause is logged, never sent (RA-WR-05).
const promptRenderFailed = "pier: the prompt could not be rendered"
// promptHandler checks the required arguments and renders the prompt. A
// Render error is logged server-side and answered with a fixed text, so a
// database or provider error never reaches the agent (as for dispatch).
func (p *Pier) promptHandler(pr *prompt) mcp.PromptHandler {
return func(ctx context.Context, req *mcp.GetPromptRequest) (*mcp.GetPromptResult, error) {
args := map[string]string{}
@@ -722,7 +728,8 @@ func (p *Pier) promptHandler(pr *prompt) mcp.PromptHandler {
}
messages, err := pr.decl.Render(ctx, args)
if err != nil {
return nil, err
logger().Warn("pier: prompt render failed", "prompt", pr.name, "error", err)
return nil, &jsonrpc.Error{Code: jsonrpc.CodeInternalError, Message: promptRenderFailed}
}
res := &mcp.GetPromptResult{Description: pr.decl.Description, Messages: []*mcp.PromptMessage{}}
for _, m := range messages {