feat(consult): classify consultation workflow failures for diagnosis
Independent Staging Quality Gate / validate (push) Failing after 13m12s
Independent Staging Quality Gate / publish (push) Has been skipped

Every workflow fault except abort and timeout collapsed into the single
calculation_failed code, and the upstream message was discarded, so a failing
run left no evidence of whether the API rejected the call or returned a payload
that missed the response contract.

Classify failures into a closed vocabulary carried on ConsultationWorkflowError
and record it as the failureCode of the runtime step. The observability tool
call schema gains one controlled optional field; upstream error text stays out
of logs, as that contract requires. Forward request_id to the API so a run can
be aligned with its access log.

Build public receipts from an explicit allowlist. The internal failure code
must not reach the client contract, whose step schema is strict and would
otherwise reject a successful run.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Jesse_Chen
2026-08-17 12:44:19 +08:00
parent 7886629b36
commit 8169bd85f7
6 changed files with 165 additions and 7 deletions
+4 -2
View File
@@ -39,6 +39,7 @@ import {
consultationStepBudgetReceipt,
createConsultationRuntimeHooks,
createConsultationRuntimeState,
publicConsultationRuntimeSteps,
} from "@/mastra/consultation-tools";
import {
applyBirthTimeModeToWorkflowContext,
@@ -549,6 +550,7 @@ export async function POST(request: Request) {
name: step.name,
durationMs: Math.max(0, Math.trunc(step.durationMs ?? 0)),
status: step.status,
...(step.failureCode ? { failureCode: step.failureCode } : {}),
})),
contractPhases: [
{
@@ -652,7 +654,7 @@ export async function POST(request: Request) {
runId: requestId,
runtime: "mastra-agentic",
skill: { name: "jyotish-vedic-astrology", loaded: state.jyotishSkillLoaded },
steps: state.steps,
steps: publicConsultationRuntimeSteps(state),
stepBudget: consultationStepBudgetReceipt(state),
workflow: workflowReceipt,
techniqueTruth: generalDailyContext ? "public-panchanga-only" : "not-applicable",
@@ -716,7 +718,7 @@ export async function POST(request: Request) {
runId: requestId,
runtime: "mastra-agentic",
skill: { name: "jyotish-vedic-astrology", loaded: state.jyotishSkillLoaded },
steps: state.steps,
steps: publicConsultationRuntimeSteps(state),
stepBudget: consultationStepBudgetReceipt(state),
workflow: state.workflowReceipt ?? workflowReceipt,
techniqueTruth: state.techniqueTruth ?? "unknown",