Build1 distinct publisher3 min readUpdated
A lease-analysis pipeline built on Mastra gates three of its four processing stages behind skip flags read from the database. The fourth is chained unconditionally and re-runs on every resume.
The Engineer · Build desk
Compiled by The EngineerSomething wrong?How this is made
The first line of the workflow definition is the one doing the work. `initiateStateHydration` runs before any agent, and every stage after it is wrapped in a branch that fires only if a flag says the work is not already finished [8]. The pipeline does not remember what it did; it asks Postgres and gets booleans back [8][9]. That is checkpointed batch processing, and it predates the agents by decades. What the models change is the price of a lost step.
The second useful decision is that each sub-workflow is two steps rather than one: the agent call, then the write [9]. The agent writes into workflow state and the persistence step reads from it, so a failed insert can be retried without paying for the completion again [10]. Be precise about the scope of that. The post describes workflow state as an in-memory, transient object [10], so the failure it covers is a database write that fails inside a process still running. The failure the post opens with, a worker that crashes mid-pipeline [3], takes that state with it, and the step in flight is paid for twice [13].
Then the gap. Three of the four processing stages sit behind skip guards: parser, summary, risk [8]. The embedding workflow is chained with a plain `.then()` and carries no flag [12]. Every resumed run re-executes it. The post's own list of things that go wrong includes burning API quota re-processing steps that already succeeded [3], and embedding is that step, unguarded [12]. Whatever it costs, in tokens or in wall-clock across the chunks of a long lease, the resume path pays it in full each time.
It is also worth naming what a skip flag records. Zod validation proves shape, and the post is explicit that a step either validates or fails [6]. A parser that returns null for an expiry date it could not find is behaving correctly and validates [5]. So does a confidently wrong governing law. Once the stage is marked complete, the checkpoint that saves quota also shields that output from ever being recomputed, which means reprocessing after a prompt or model change needs a way to clear flags per stage. The text available to us stops before it gets there [11].
The same truncation covers the fourth failure mode. Contention between concurrent uploads for rate-limited endpoints is on the list of problems the design claims to have handled from the start [3], but no concurrency limit appears in the portion of the post we can read [15].
The granularity is the part to carry away. The smallest recoverable unit here is one sub-workflow, meaning one agent's entire call [14]. That sets a rule with nothing to do with AI: if a step is expensive enough that repeating it hurts, it has to be small enough that repeating it is cheap.
Follow any of these and your For You feed starts watching them — no settings page required.
Ranked by verification strength, evidence, and original report placement.
A dev.to post titled "Building a Multi-Agent AI Pipeline with Mastra and TypeScript" describes the architecture behind Clause AI, a platform that analyzes rental and lease agreements, extracts key terms, flags risky clauses, and lets users chat with their contracts using RAG.
Rather than one monolithic prompt, the system uses four purpose-built agents, each with a focused responsibility, tuned model parameters, and a structured output schema.
The post lists the failure modes that appear once a pipeline has multiple steps (parsing, summarizing, embedding, risk analysis): a worker crashes mid-pipeline and everything re-runs from scratch; API quota is burned re-processing steps that already succeeded; partial writes leave the database inconsistent; multiple uploads compete for rate-limited model endpoints. It says the system was designed for these from the start, not as an afterthought.
The Parser Agent runs at temperature 0.2 because extraction requires precision; the Query Agent runs at 0.7 because conversational responses benefit from more natural phrasing.
Every agent produces validated, structured output using Zod schemas; the Parser Agent returns a typed object with nullable fields and returns null rather than hallucinating data when information is missing from the document.
The post states the schema-first approach lets downstream agents and database writes trust the shape of the data, with no defensive parsing: it either validates or it fails.
Evidence-backed comparisons of source perspectives and observed adoption signals. Read the methodology
Which Builder, Operator, and Investor concerns the observed source mix emphasized—not a truth score.
Evidence, demonstrated adoption, hype gap, incentives, and confidence are assessed independently, each on its own current evidence. How these are measured.
Primary code, single self-reported source
The architectural claims are backed by first-party artifacts rather than assertion: the actual Mastra workflow definition, the Zod response schema, the summary sub-workflow and the hydration function are all reproduced, which is what makes the unguarded embedding stage directly checkable. Ceiling is set by there being exactly one publisher, no independent verification, no measurements of any kind, and a body that ends mid-word.
One self-disclosed implementation
Adoption evidence amounts to a single author describing his own project running this pipeline on Mastra and Postgres. There are no user numbers, document volumes, throughput, spend figures or third-party deployments, so this registers as an existence proof only.
Reliability promises outrun the shipped guards
The post opens by naming four failure modes and asserts the system was designed for all of them from the start, then concludes that crash recovery is free, no API calls are wasted and the workflow is idempotent by design. The published code supports a weaker version: three of four stages are guarded, embedding re-runs unconditionally on every resume, transient in-memory state means an in-flight model call is re-paid after a worker crash, and no concurrency control appears anywhere for the rate-limit failure mode it lists. The overstatement is bounded because the core pattern shown is genuine and the code is disclosed rather than hidden.
Self-promotional build log
The single source is a developer writing up his own product's architecture on a personal-branding platform, which rewards confident 'here is how I built it right' framing and discourages publishing the rough edges. That incentive is visible in the unqualified reliability conclusions. Offsetting it: the author publishes the real code, which is what allows the gap to be found, and there is no visible vendor sponsorship, pricing pitch or funding angle in the supplied text.
Verifiable code, thin corroboration
Confidence is moderate: the descriptive facts and the central derived finding rest on quoted code and are hard to dispute, but everything comes from one self-interested publisher, the body is truncated so some of the author's own reasoning is missing, and the operational consequences (embedding re-spend, crash behaviour, concurrency) are inferred from what the code omits rather than observed in production.
build
The NestJS default path puts the query inside the business rule, and nothing fails when it moves1 distinct publisher
build
The refund that fired three times: tool calls are a systems problem, not a prompt problem1 distinct publisher
build
The only gate that ran was a hand-typed enum, and it had never heard of the new value1 distinct publisher
build
Thirty MCP tools become three: the reliability bug is in your schema, not the model1 distinct publisher
Distinct publishers with included, body-backed reporting in this cluster.
dev.to
1 article · August 22, 2026