{"record":{"id":"d3c44518ed07ad93","repo":"earendil-works/pi","slug":"agent-run-ended-with-unexpected-stop-reason-ass","errorCode":null,"errorMessage":"Agent run ended with unexpected stop reason: ${assistant.stopReason}.","messagePattern":"Agent run ended with unexpected stop reason: (.+?)\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/evals/src/pi-harness.ts","lineNumber":100,"sourceCode":"\t\t\t\tcontent: message.content.every((part) => part.type === \"text\") ? text : toJsonValue(message.content),\n\t\t\t\t...(message.isError ? { error: { message: text || \"Tool failed\" } } : {}),\n\t\t\t});\n\t\t}\n\t}\n\treturn events;\n}\n\nasync function promptAgent(session: AgentSession, input: string, signal: AbortSignal | undefined): Promise<string> {\n\tsignal?.throwIfAborted();\n\tconst previousMessageCount = session.messages.length;\n\tawait session.prompt(input);\n\tconst assistant = session.messages\n\t\t.slice(previousMessageCount)\n\t\t.reverse()\n\t\t.find((message) => message.role === \"assistant\");\n\tif (!assistant) throw new Error(\"Agent run completed without an assistant message.\");\n\tif (assistant.stopReason !== \"stop\") {\n\t\tthrow new Error(\n\t\t\tassistant.errorMessage ?? `Agent run ended with unexpected stop reason: ${assistant.stopReason}.`,\n\t\t);\n\t}\n\tconst output = session.getLastAssistantText();\n\tif (!output) throw new Error(\"Agent run produced no assistant text.\");\n\treturn output;\n}\n\nasync function runPiCodingAgent<TOutput extends JsonValue>(\n\tinput: PiCodingAgentInput,\n\tsignal: AbortSignal | undefined,\n\tsetArtifact: HarnessContext[\"setArtifact\"],\n\toptions: PiCodingAgentHarnessOptions | PiCodingAgentHarnessWithOutput<TOutput>,\n): Promise<SimpleHarnessResult<string | TOutput>> {\n\tconst startedAt = performance.now();\n\tsignal?.throwIfAborted();\n\tconst selection = resolveModelSelection(options.model);\n\tconst modelRuntime = await ModelRuntime.create();","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/earendil-works/pi/blob/4af9d21d3b4d664e4a29fcabfec85171077248e3/packages/evals/src/pi-harness.ts#L82-L118","documentation":"Thrown by promptAgent when the last assistant message's stopReason is not \"stop\" (e.g. length, refusal, or error). Uses the assistant's own errorMessage when present, otherwise constructs the message from the stop reason.","triggerScenarios":"Thrown at packages/evals/src/pi-harness.ts:100 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Read the model's errorMessage/stopReason detail to find the cause","For length stops, reduce output size or raise token limits","Retry transient provider-side aborts"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"4af9d21d3b4d664e4a29fcabfec85171077248e3","analyzedAt":"2026-08-24T13:07:14.692Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}