← Back to Guides

Companion to the book Harness Engineering for Production AI Systems · this part maps to Book closer

GuideFor: AI Engineers, ML Engineers, Platform Engineers, AI Systems Architects

LangGraph Guardrails: A Node That Skips the Executor

The same refund, on an invoice the customer does not own, is refused by my book's executor and paid by its LangGraph graph, and neither an import test nor a tool-name grep can see why.

#harness-engineering#langgraph#guardrails#human-in-the-loop#llm-agents#production-ai-systems#ai-safety

My book's LangGraph graph pays a refund on an invoice the customer does not own, and its plain executor, which runs the book's guardrails, refuses the same refund. In both runs the proposal is issue_refund(invoice_id="inv_4410"). Sent through the executor, Harness.act, nine controls leave a record, the ownership comparator fails, and the merge gate refuses. Sent through the graph the same book builds for approvals and restarts, the refund runs, because a person typed "approve" at an interrupt that showed them two fields:

python
{"tool": "issue_refund", "run_id": "r15"}

Both routes are real code in one repository, and they reach the same tool. All 386 tests pass at the book's closing tag, and a search for calls to issue_refund in the framework directory, the narrow form of the check Part 3 proposed, finds nothing. The separation checks report what they were built to report, and the money still moves.

If your LangGraph guardrails are nodes that call controls directly, your graph may do the same. This article shows how to find that second executor and route the node back through the first, whose refusals turn out to be the most useful part of the work.

LangGraph guardrails bypass: the Second Executor, a node that calls one control directly

Harness.act does one job in a fixed order. It runs every registered bound, then every comparator that judges the proposal, then every gate in registry order. Each decision goes to a recorder, and a gate that declines raises Refused. Its constructor refuses to build a harness in which a comparator's verdict has no gate reading it. Part 3 called that function the only path from a proposal to a tool.

No node in the framework directory calls it. A search for .act( under harness/ returns nothing; all 29 call sites in the repository sit in tests/ and examples/. Seventeen lines in harness/graph/ call a control or a sensor directly instead.

My book has a name for this shape. A Second Executor is "a framework node that calls a control directly rather than through the executor". Such a node keeps whatever part of the executor's discipline its author needed and drops the rest without saying so. Its tests never treat it as an executor. They test the control it calls, and the control is fine.

Most of the diagnosis is the chapter's, and I want it credited before I add anything. It finds the shape by reading its own code. It proposes a diff of each node against the object it wraps "on returns rather than on calls", and a test that drives one proposal down both routes, which it calls "the missing piece". It also states the conclusion: the separation "holds at the import boundary rather than at the discipline boundary", and "Keeping it at both is work nobody has done yet".

This article does that work for the refund path, tries the same move on a second module, and comes back with three things the chapter does not have:

  1. A lint over result handling. "Only the executor may call a gate" is a dependency rule of the kind fitness-function tools are built to check. The drift that matters most is in what a node does with a control's inputs and outputs: an empty verdict map, verdicts frozen when the graph is built, a record bound to _, a record read only as a truth value. drift_lint.py finds those: 12 drifted calls across the book's ten graph modules, 10 of them in shipped nodes, where Part 3's tool-name grep finds none.
  2. The executor as a missing-stage detector. Route a node through the executor and it fails closed. That refusal names the first stage the graph is missing; fix it and run again. On the refund graph it was a verdict on the model's raw text; on the merge graph, the run's authority band. A refusal is a better specification for the redesign than a design document, because it comes from the code that will enforce it.
  3. A seam between two chapters. Finishing the redesign exposed a defect where Chapter 12's checkpointing meets Chapter 13's spend journal, which neither chapter's tests compose.

The property all three serve I call control-trace equivalence. The name borrows "trace equivalence" from process algebra (Hoare's CSP), where two processes are equivalent when they can perform the same sequences of events. Here the trace is a set of (control, outcome) pairs, deliberately weaker than CSP's: order and repetition are dropped, so two routes that run the same gates in a different order still count as equivalent. Two routes to an effect are control-trace equivalent when, for every proposal, they agree on whether the effect ran and on that set. Comparing control names alone is not enough, as the negative control later shows, though there whether the tool ran differs as well. A Second Executor is a route that breaks the property.

Where the seam belongs is the chapter's claim: at the executor, the discipline boundary. My thesis is about how you get it there. Route each node through the executor and treat every fail-closed refusal as the name of a missing stage, then prove the move with a control-trace equivalence test that compares every control's outcome as well as whether the tool ran. The lint says where a node drifts; the equivalence test says whether the drift changes an outcome. Import tests and tool-name greps measure where code lives and what it is called. Once authority.py moves to the right directory, both would pass on a codebase full of Second Executors.

The Common Weakness Enumeration (CWE) already covers the general weakness. CWE-424 is a product that "does not sufficiently protect all possible paths", which includes a partly guarded one. What it does not give is a way to find the partial guard in a framework's wiring, where every path has some check on it and a review that asks "is there a check here?" finds one and stops.

Side by side, the two routes end at the same tool function.

d2
grid-rows: 1
grid-gap: 40
exec: "Route A: Harness.act" {
  label.near: top-center
  style: {fill: "#F4F8FD"; stroke: "#2C6FB0"; font-color: "#2C2C2A"}
  grid-columns: 1
  grid-gap: 14
  b: "4 bounds\nband, run ceilings, replay,\ndaily refund ceiling" {style: {fill: "#4A90E2"; stroke: "#2C6FB0"; font-color: "#FFFFFF"}}
  c: "3 comparators\nschema, ownership,\namounts grounded" {style: {fill: "#7B68EE"; stroke: "#5A4BC4"; font-color: "#FFFFFF"}}
  g: "4 gates in order\nadmission, merge, band, policy" {style: {fill: "#7B68EE"; stroke: "#5A4BC4"; font-color: "#FFFFFF"}}
  r: "recorder: one signal\nper control" {style: {fill: "#98D8C8"; stroke: "#5FA898"; font-color: "#2C2C2A"}}
  t: "issue_refund" {style: {fill: "#6BCF7F"; stroke: "#3F9E52"; font-color: "#2C2C2A"}}
}
graph: "Route B: the LangGraph graph" {
  label.near: top-center
  style: {fill: "#FDF4F4"; stroke: "#B03A2E"; font-color: "#2C2C2A"}
  grid-columns: 1
  grid-gap: 14
  p: "plan, read, propose" {style: {fill: "#95A5A6"; stroke: "#6B7B7C"; font-color: "#FFFFFF"}}
  a: "approve: interrupt\nshows tool + run_id" {style: {fill: "#FFD93D"; stroke: "#C9A800"; font-color: "#2C2C2A"}}
  rb: "replay bound\n(in resume, unrecorded)" {style: {fill: "#4A90E2"; stroke: "#2C6FB0"; font-color: "#FFFFFF"}}
  s: "2 string comparisons\nstatus, tool name" {style: {fill: "#FFA07A"; stroke: "#D9785A"; font-color: "#2C2C2A"}}
  e: "effect log\n(stops a second run)" {style: {fill: "#98D8C8"; stroke: "#5FA898"; font-color: "#2C2C2A"}}
  t: "issue_refund" {style: {fill: "#E74C3C"; stroke: "#B03A2E"; font-color: "#FFFFFF"}}
}

On the left, eleven checks and a recorder stand between the proposal and the tool. On the right stand a pause, two string comparisons and an effect log that stops the same refund running twice. Route B also runs the replay bound inside resume(), before LangGraph re-enters the run. No step on route B asks whether this refund is owed, and none writes to the recorder.

Why an import-boundary test would pass with every node a Second Executor

The usual advice for keeping an agent portable comes from hexagonal architecture, also called ports and adapters: keep framework imports out of the core. One write-up of the pattern for AI agents states the rule, "No import in the domain points to an external library ... That restriction is the heart of the pattern", and goes on to claim that observability "emerges naturally from the architecture" (dinacode, undated). Tian Pan gives the same direction: "The core never imports the adapter; the adapter imports the core" (Pan, 2026-07-02). import-linter and ArchUnit turn that rule into a continuous integration (CI) check. Thoughtworks files checks like these as architectural fitness functions, "an objective integrity assessment of some architectural characteristics" (Thoughtworks Technology Radar).

I have no quarrel with the import rule. What I dispute is the second claim, that observability, or any other control property, follows from it. My book's chapter writes the check in six lines:

python
from pathlib import Pathdef test_the_framework_is_exactly_one_directory() -> None:    for p in Path("harness").rglob("[!_]*.py"):        src = "\n" + p.read_text("utf-8")        uses = "\nfrom lang" in src or "\nimport lang" in src        assert uses == ("graph" in p.parts), p

At the tag it fails, on exactly one file, for a reason unrelated to the refund. harness/graph/authority.py holds 102 lines in the framework directory that import no framework. Move that file and the test goes green, and the foreign-invoice refund still runs with no recorder hearing about it. An import rule constrains which way the dependency arrows point. Whether the code at the end of an arrow calls the executor or one control is a question it never asks:

d2
grid-rows: 1
grid-gap: 40
imp: "What an import test checks" {
  label.near: top-center
  style: {fill: "#F4F8FD"; stroke: "#2C6FB0"; font-color: "#2C2C2A"}
  grid-columns: 1
  grid-gap: 16
  q: "Does any core module\nimport langgraph?" {style: {fill: "#7B68EE"; stroke: "#5A4BC4"; font-color: "#FFFFFF"}}
  a: "At the tag: one file in the\nwrong directory (authority.py)" {style: {fill: "#FFD93D"; stroke: "#C9A800"; font-color: "#2C2C2A"}}
  v: "Move it: test passes" {style: {fill: "#6BCF7F"; stroke: "#3F9E52"; font-color: "#2C2C2A"}}
}
beh: "What it never checks" {
  label.near: top-center
  style: {fill: "#FDF4F4"; stroke: "#B03A2E"; font-color: "#2C2C2A"}
  grid-columns: 1
  grid-gap: 16
  q: "Does each node call the\nexecutor, or one control?" {style: {fill: "#7B68EE"; stroke: "#5A4BC4"; font-color: "#FFFFFF"}}
  a: "At the tag: 0 calls to act,\n12 drifted control calls" {style: {fill: "#E74C3C"; stroke: "#B03A2E"; font-color: "#FFFFFF"}}
  v: "Foreign refund still runs" {style: {fill: "#E74C3C"; stroke: "#B03A2E"; font-color: "#FFFFFF"}}
}

Alistair Cockburn anticipated the gap when he described the pattern in 2005. Teams add a layer "with the promise that this time, really and truly, no business logic will be put into the new layer", and then, "having no mechanism to detect when a violation of that promise occurs, the organization finds a few years later that the new layer is cluttered with business logic" (Cockburn, 2005). A Second Executor is that clutter, arriving in the adapter. Cockburn's stated intent even supports this article's point: an application should be "equally ... driven by users, programs, automated test or batch scripts", many drivers entering through one port. A node that calls a gate directly is a driver that does not use the port at all.

Why a grep for the tool's name finds no second caller

Part 3 gave the one-call-site rule a crude enforcement: "A CI test that searches the codebase for direct references to issue_refund outside that function is crude, and it catches a second caller, such as a new background job, before it ships." Part 3 also named the risk, a second dispatch path, and its rule does catch a background job that imports the tool. The book's graph escapes it, because its nodes never name the tool. They receive it.

The execute node at the tag shows how. The book's build() takes the tool as a parameter typed Call = Callable[[str, dict[str, object]], object] and hands it to the node factory. Here is the node, trimmed to the part that decides:

python
def execute(state: RunState[Any]) -> dict[str, Any]:    proposal = state.proposal    if proposal is None or state.status != APPROVED:        state.record("replay-guard", "refuse", "no approved proposal to execute")        return {"decisions": state.decisions}    if proposal.tool != allowed:        state.record(            "replay-guard",            "refuse",            f"{node} is priced for {allowed} and was handed {proposal.tool}",        )        return {"decisions": state.decisions}    done = guard.perform(        proposal.tool,        proposal.arguments,        lambda: call(proposal.tool, dict(proposal.arguments)),    )

Inside call is where the money moves. A grep for issue_refund( in harness/graph/ returns zero lines, which is exactly what Part 3's test asks for, so it passes.

I am narrowing Part 3's rule here. One call site is still the right design, and CWE gives the same advice for authentication bypass through an alternate path: "Funnel all access through a single choke point" (CWE-288). The graph also breaks the other half of Part 3's rule, that tool functions are registered only inside the executor: build() accepts the tool as a parameter, so a tool reaches a node without being registered there. What changes is what the CI check looks for. The drift is in callers of the controls, and in what those callers pass and keep.

So I wrote a lint for it, drift_lint.py, 103 lines of ast, printed in full at the end of this section. It reads every *.py file in one directory and matches calls to nine method names: decide, check, compare, admit, assemble, run, reserve, admit_fanout and perform. A control called under another name, such as table.resolve in authority.py, is outside its reach. For each match it reports which kinds of drift apply:

KindWhat the node did
outsidecalled a gate, bound or comparator directly, not through act()
emptypassed a literal {} where the executor passes the run's verdicts
frozentook its verdicts from the factory's arguments, fixed when the graph was built
discardedbound part of the result to _, or to a name it never reads
collapsedread a returned record only as a truth value
unrecordedis a gate, bound or comparator call in a module that never references a recorder

Two caveats on the table. unrecorded is a plain substring test, true when the module's source never contains the word "recorder", and the count of "control calls" includes sensors and the effect log as well as gates and bounds. Two more labels are not drift on their own. input-gate marks the input admission gate, which act() has no stage for; it still counts as drift when its decision is also unrecorded. beyond-act marks work the executor, as written, does not do: reservations and the effect log. The lint is tuned to this repository: its method list and its verdict name heuristic will flag unrelated run and check calls elsewhere, it skips async def nodes, and it reads only positional arguments, so adapt it before running it on another codebase. Run against the framework directory at the tag:

text
assembly.py:23     assemble      collapsed:evictionsauthority.py:49    decide        outside empty unrecordedauthority.py:93    check         outside unrecordedceilings.py:53     reserve       beyond-actceilings.py:72     admit_fanout  beyond-actceilings.py:107    reserve       beyond-actcheckpoint.py:133  perform       beyond-actcheckpoint.py:193  check         outside unrecordedgating.py:24       decide        outside frozen unrecordedintake.py:21       admit         input-gate unrecordedintake.py:22       assemble      discarded:removalsintake.py:35       admit         input-gate unrecordedintake.py:36       assemble      discarded:_merge.py:57        decide        outside empty unrecordedtooling.py:39      decide        outside empty unrecordedtooling.py:63      decide        outside frozen unrecordedvalidation.py:27   run           17 control calls outside the executor, 12 drifted

It exits 1. Seven calls run a gate or bound outside the executor. Three of those gates get {} for verdicts, and two more, in gating.py and tooling.py, get verdicts fixed at build time, so no node can hand them a fresh one.

Both intake nodes drop the removal record that Part 4 built so a sensor's losses could be counted. The node the chapter calls correct binds it to removals and never returns it. The chapter's deliberate wrong-way node at lines 35-36 binds it to _, and that node accounts for 2 of the 12 drifted calls, so the shipped nodes carry 10.

assembly.py reads Part 5's eviction rows only as a truth value that lowers the band. validation.py comes back clean, though it dropped two of the repair ladder's four fields until the closing chapter fixed it.

Those four beyond-act calls are the reason the graph exists; a later section comes back to them. Against the redesigned graph built later in this article, the same lint reports:

text
seam_graph.py:73   perform       beyond-act1 control calls outside the executor, 0 drifted
drift_lint.py, in full
python
"""Find Second Executors: every control call outside the executor, and how it drifts.Usage: python drift_lint.py harness/graphA static companion to the both-routes test. It reads each node function and reports,per control call, which part of the executor's discipline the node changed:  outside     a gate, bound or comparator called directly, not through act()  input-gate  the input admission gate, which act() has no stage for  beyond-act  work act() cannot do (reserve, admit a fan-out, the effect log)  empty       a literal {} passed where the executor passes the run's verdicts  frozen      verdicts taken from the factory's arguments, fixed at build time  discarded   part of the result bound to _ or to a name never read again  collapsed   a returned record read only as a truth value  unrecorded  the module never references a recorder"""from __future__ import annotationsimport astimport sysfrom pathlib import PathDECIDES = {"decide", "check", "compare"}                 # what act() would runINPUT = {"admit"}                                         # input gate, no act() stageSENSES = {"assemble", "run"}                              # sensors, repair ladderBEYOND = {"reserve", "admit_fanout", "perform"}           # work act() cannot doNOT_DRIFT = {"beyond-act", "input-gate"}                  # labels, not driftdef loads(fn: ast.AST, name: str, after: int) -> list[ast.Name]:    return [n for n in ast.walk(fn) if isinstance(n, ast.Name) and n.id == name            and isinstance(n.ctx, ast.Load) and n.lineno > after]def truth_only(fn: ast.AST, uses: list[ast.Name]) -> bool:    tests = [t for n in ast.walk(fn) if isinstance(n, (ast.If, ast.IfExp, ast.While))             for t in [n.test]]    inside = {id(x) for t in tests for x in ast.walk(t)}    return bool(uses) and all(id(u) in inside for u in uses)def findings(path: Path) -> list[tuple[int, str, list[str]]]:    src = path.read_text("utf-8")    tree = ast.parse(src)    unrecorded = "recorder" not in src.lower()    funcs = [f for f in ast.walk(tree) if isinstance(f, ast.FunctionDef)]    out: list[tuple[int, str, list[str]]] = []    for node in ast.walk(tree):        if not isinstance(node, ast.Call) or not isinstance(node.func, ast.Attribute):            continue        method = node.func.attr        if method not in DECIDES | INPUT | SENSES | BEYOND:            continue        around = sorted((f for f in funcs                         if f.lineno <= node.lineno <= (f.end_lineno or 0)),                        key=lambda f: (f.end_lineno or 0) - f.lineno)        fn, outer = around[0], around[1:]        built = {a.arg for f in outer for a in f.args.args}        kinds: list[str] = []        if method in BEYOND:            kinds.append("beyond-act")        if method in INPUT:            kinds.append("input-gate")        if method in DECIDES:            kinds.append("outside")        for arg in node.args:            if isinstance(arg, ast.Dict) and not arg.keys:                kinds.append("empty")            if isinstance(arg, ast.Name) and "verdict" in arg.id and arg.id in built:                kinds.append("frozen")        parent = next((p for p in ast.walk(fn) if isinstance(p, ast.Assign)                       and p.value is node), None)        if parent is not None:            target = parent.targets[0]            for t in target.elts if isinstance(target, ast.Tuple) else [target]:                if not isinstance(t, ast.Name):                    continue                uses = loads(fn, t.id, node.lineno)                if t.id == "_" or not uses:                    kinds.append(f"discarded:{t.id}")                elif truth_only(fn, uses):                    kinds.append(f"collapsed:{t.id}")        if unrecorded and method in DECIDES | INPUT:            kinds.append("unrecorded")        out.append((node.lineno, method, kinds))    return sorted(out)def main(root: str) -> int:    total = drifted = 0    for path in sorted(Path(root).glob("*.py")):        for line, method, kinds in findings(path):            total += 1            drifted += any(k not in NOT_DRIFT for k in kinds)            where = f"{path.name}:{line}"            print(f"{where:<18} {method:<13} {' '.join(kinds)}")    print(f"{total} control calls outside the executor, {drifted} drifted")    return 1 if drifted else 0if __name__ == "__main__":    sys.exit(main(sys.argv[1] if len(sys.argv) > 1 else "harness/graph"))

Run against one directory, the two searches disagree:

d2
direction: down
dir: "harness/graph/ at the tag" {style: {fill: "#95A5A6"; stroke: "#6B7B7C"; font-color: "#FFFFFF"}}
s1: "Search 1: callers of issue_refund\n(Part 3's CI test)" {style: {fill: "#7B68EE"; stroke: "#5A4BC4"; font-color: "#FFFFFF"}}
s2: "Search 2: drift_lint.py\nevery control call, six drift kinds" {style: {fill: "#7B68EE"; stroke: "#5A4BC4"; font-color: "#FFFFFF"}}
r1: "0 hits: the tool arrives\nas an injected call" {style: {fill: "#6BCF7F"; stroke: "#3F9E52"; font-color: "#2C2C2A"}}
r2: "17 calls, 12 drifted\n4 do work act() cannot,\n1 clean" {style: {fill: "#E74C3C"; stroke: "#B03A2E"; font-color: "#FFFFFF"}}
dir -> s1
dir -> s2
s1 -> r1: "test passes"
s2 -> r2: "finds the drift"

Search 1 passes for a reason that has nothing to do with the refund. The lint says where each node drifts and how, and it still cannot say whether a given drift changes an outcome. That takes a test that runs.

A human approval does not replace the gates it skipped

Route B has a real defence, and I want to state it at full strength first. This run reached the execute node through interrupt(). A person saw the proposal and typed "approve". LangChain's guardrails page calls human-in-the-loop (HITL) review "one of the most effective guardrails for high-stakes decisions" (LangChain, Guardrails). Why run four gates after a person has said yes?

A person can only approve the question they were shown, and in the book's graph that question is a tool name and a run id. LangChain's HumanInTheLoopMiddleware shows more: the tool name, its arguments and a description, plus a tool_call_id and a response schema in per-call mode (LangChain, Human-in-the-loop). So my book's graph showed less than the framework would have. Even the middleware leaves out what the gates check. A reviewer sees invoice_id: inv_4410. They do not see that the ledger has no such invoice on this account, what band the run holds, how much has been refunded today, or whether a refund was in the frozen plan.

Against what the reviewer saw, here is what the skipped gates would have read.

d2
grid-rows: 1
grid-gap: 40
saw: "Shown at the interrupt" {
  label.near: top-center
  style: {fill: "#FFFBEA"; stroke: "#C9A800"; font-color: "#2C2C2A"}
  grid-columns: 1
  grid-gap: 14
  a: "book graph:\ntool, run_id" {style: {fill: "#FFD93D"; stroke: "#C9A800"; font-color: "#2C2C2A"}}
  b: "HITL middleware:\ntool, args, description" {style: {fill: "#FFD93D"; stroke: "#C9A800"; font-color: "#2C2C2A"}}
}
read: "Read by the gates route B skipped" {
  label.near: top-center
  style: {fill: "#F4F8FD"; stroke: "#2C6FB0"; font-color: "#2C2C2A"}
  grid-columns: 2
  grid-gap: 14
  l: "ledger: does this account\nown inv_4410?" {style: {fill: "#4A90E2"; stroke: "#2C6FB0"; font-color: "#FFFFFF"}}
  p: "frozen plan: is a refund\na planned step?" {style: {fill: "#4A90E2"; stroke: "#2C6FB0"; font-color: "#FFFFFF"}}
  bd: "band: may this mode\nmove money at all?" {style: {fill: "#4A90E2"; stroke: "#2C6FB0"; font-color: "#FFFFFF"}}
  c: "ceilings: refunded today,\nrun budget left" {style: {fill: "#4A90E2"; stroke: "#2C6FB0"; font-color: "#FFFFFF"}}
}

Grant LangChain the arguments, and a reviewer who sees inv_4410 still cannot see who owns it, unless someone renders a ledger lookup into the prompt, which is a gate's work done by hand and recorded nowhere. The belief that stays wrong is that an approval can stand in for gates that read state the reviewer never sees. Record the approval as a person's judgement, and keep the gates.

Saltzer and Schroeder wrote the principle down in 1975. Complete mediation: "Every access to every object must be checked for authority." It covers "initialization, recovery, shutdown, and maintenance", and "proposals to gain performance by remembering the result of an authority check be examined skeptically" (Saltzer and Schroeder, 1975). Anderson's 1972 Air Force study is where the reference monitor comes from, and NIST's glossary states the same requirement for it as "always invoked" (NIST). CWE catalogues the failure as CWE-424, "Improper Protection of Alternate Path", a child of CWE-638, "Not Using Complete Mediation". A resume after an interrupt is recovery, and an approval given at the pause and trusted at the execute node is a remembered result. Part 12 made the same argument about an approval restored from a checkpoint: it is a conclusion, and it holds only while the facts it was given still hold.

Other frameworks draw the line where I would. In the OpenAI Agents SDK, "input tool guardrails normally run after approval and immediately before execution", and calls that pass a pre-approval check "are still checked again after approval" (OpenAI Agents SDK, Guardrails). Arcjet's LangGraph guide, written for the JavaScript version, is blunter: "Don't treat interrupt() as a policy gate", and "test policy enforcement after retries and human-approval resumes" (Arcjet, 2026). That last sentence is the closest prior art I found for the test in the next section, and I credit it.

None of this contradicts what earlier parts said about approvals. Part 6 let a human approval clear a gate's refusal, and Part 9 narrowed it: inside the band a failed check may go to a person for edit or reject, never approve, and only a passing proposal can be approved. In both, the gate ran first and the person answered a question the gate had asked. On route B no gate ran, so the person answered a question nobody had checked.

The both-routes test: differential testing for guardrails

Differential testing runs two implementations of one specification on the same input and treats any difference as a bug (McKeeman, 1998). A both-routes test applies that idea to a harness, with one change: what it compares is the control trace, meaning whether the tool ran and which controls left a record. N-version programming also builds several versions, but on purpose and to be independent (Avizienis, 1985), and Knight and Leveson's 1986 experiment is reported as finding that independence much weaker than assumed (summary of both; I have not read the primary papers). Here the two routes were meant to run the same discipline, and they drifted by accident.

My chapter sets the test as its third exercise; the companion repository does not contain it. Mine runs at the tag's pins (langgraph 1.2.12, langgraph-checkpoint 4.2.0, langchain-core 1.6.5, pydantic 2.13.5). Route A is the book's Chapter 15 fixture for the composed harness, with a recorder attached and a stub tool that notes whether it was called. Imports are omitted:

python
EPOCH = datetime(1970, 1, 1, tzinfo=timezone.utc)SPEC = CheckpointSpec.load("policies/checkpoint-spec.toml")@dataclass(frozen=True)class Route:    recorded: frozenset[str]  # every control that left a record on this route    ran: bool                 # did the tool execute    outcomes: frozenset[tuple[str, str]] = frozenset()   # (control, outcome) pairsdef executor_route(proposal: Proposal) -> Route:    """Harness.act, the fixture from Chapter 15 with a recorder attached."""    log, ran = ExerciseLog(), []    h = harness(Artifacts.load())    h._recorder = log    h._tools[proposal.tool] = lambda **kw: ran.append(kw)    run = a_run()    text = json.dumps({"tool": proposal.tool, "arguments": dict(proposal.arguments)})    try:        h.act(proposal, run, h.judge(Draft(text), run))    except (Refused, BoundExceeded):        pass    seen = log.since(EPOCH)    return Route(frozenset(e.component for e in seen), bool(ran),                 frozenset((e.component, e.outcome.value) for e in seen))

Route B is the Chapter 12 graph, built with the book's own build() and resumed with its own resume(), which checks the replay bound first. The person answers "approve":

python
def graph_route(proposal: Proposal) -> Route:    """The Chapter 12 graph: plan, read, propose, approve, refund. A person says yes."""    ran: list[object] = []    log = InMemoryEffectLog()    app = build(        InMemorySaver(), SPEC, EffectGuard(log=log, run_id="r15"),        freeze=lambda s: Plan("duplicate-charge", ("get_invoice", "issue_refund")),        fetch=lambda s: ((Origin.TOOL_RESULT, "inv_9002 40.00 paid", "get_invoice"),),        propose=lambda s: proposal,        call=lambda tool, args: ran.append(args),    )    config: RunnableConfig = {"configurable": {"thread_id": "r15"}}    app.invoke(RunState(run_id="r15", mode=Mode.COPILOT, facts=a_run().facts), config)    resume(app, config, SPEC, log, "approve")    decisions = app.get_state(config).values["decisions"]    return Route(frozenset(d.gate for d in decisions), bool(ran))

Route B takes no recorder argument because there is nowhere to pass one: build() has no parameter for it, and the word Recorder appears nowhere in harness/graph/. Its record is therefore its decision trail, the only record of control decisions the graph keeps.

By design, the check is lopsided. Comparators and passing bounds never write to a decision trail on either route, so even a graph that called every control directly would fail it, and the failure measures the missing recorder as much as the missing controls. That is the finding: nothing on route B writes where the rest of the harness reads.

This test checks one direction only, that every control the executor recorded also left a record on the graph. The control-trace equivalence test later in the article checks outcomes in both directions. Both run two proposals, the refund the customer is owed and the one on the foreign invoice:

python
PROPOSALS = {    "owed": Proposal("issue_refund", {"invoice_id": "inv_9002"}),    "foreign": Proposal("issue_refund", {"invoice_id": "inv_4410"}),}@pytest.mark.parametrize("name", PROPOSALS)def test_both_routes_run_the_same_controls(name: str) -> None:    a = executor_route(PROPOSALS[name])    b = graph_route(PROPOSALS[name])    assert a.ran == b.ran, f"executor ran={a.ran}, graph ran={b.ran}"    missing = sorted(a.recorded - b.recorded)    assert not missing, "no record on the graph:\n" + "\n".join(missing)

Both cases fail, each on its own assertion. This is pytest's output with --tb=short, trimmed to the section headers, the assertion messages and the summary line:

text
________________ test_both_routes_run_the_same_controls[owed] _________________E   AssertionError: no record on the graph:E     amounts-groundedE     band-gateE     band-integrityE     daily-refund-ceilingE     invoice-belongs-to-accountE     merge-gateE     policy-gateE     replay-boundE     run-ceilingsE     structured-outputE     tool-admission_______________ test_both_routes_run_the_same_controls[foreign] _______________E   AssertionError: executor ran=False, graph ran=True2 failed in 1.68s

The owed refund runs on both routes, so the second assertion is the one that fails. Eleven controls left a record on route A and none on route B, whose trail holds one entry, effect-guard: executed. Ten of the eleven never ran on route B. The eleventh, replay-bound, did run, inside resume(), and wrote nothing. That is a smaller defect, but Part 6's Second Stream and Part 17's readiness check both read the record, and neither can tell "ran and said nothing" from "never ran".

On the foreign refund the first assertion fails: the executor refused it and the graph paid it. That assertion exists because two sets of records can match by accident, and a tool that runs on one route and not on the other cannot.

Nothing in the test's shape depends on LangGraph:

d2
direction: down
p: "one proposal\n(owed, or foreign invoice)" {style: {fill: "#95A5A6"; stroke: "#6B7B7C"; font-color: "#FFFFFF"}}
a: "Route A: executor\nwith a recorder" {style: {fill: "#4A90E2"; stroke: "#2C6FB0"; font-color: "#FFFFFF"}}
b: "Route B: compiled graph\nresumed with approve" {style: {fill: "#4A90E2"; stroke: "#2C6FB0"; font-color: "#FFFFFF"}}
c: "compare: did the tool run?\nwhich controls left a record?" {style: {fill: "#7B68EE"; stroke: "#5A4BC4"; font-color: "#FFFFFF"}}
f: "the failure message is the list\nof what the wiring dropped" {style: {fill: "#FFD93D"; stroke: "#C9A800"; font-color: "#2C2C2A"}}
p -> a
p -> b
a -> c
b -> c
c -> f

The chapter's exercise says to keep the failure message, and it is right: the message is the specification of what the wiring owes, in a form a CI run can check.

Route the node through the executor, and let the refusal name the gap

Making the node call the executor is the obvious fix, and the book's build() makes a first attempt cheap. It takes the tool as an injected call, so inject Harness.act. Nothing else in the node changes; it keeps its pause, its string comparisons and its effect log. The executor is the same fixture as route A. Its run is a fresh fixture run, separate from the graph's state, and that separation is why this approach cannot pass:

python
h = harness(Artifacts.load())h._recorder = logrun = a_run()          # separate from the graph's state: act() never sees itdef call(tool: str, args: dict[str, object]) -> object:    return h.act(Proposal(tool, args), run)

The node does not catch a Refused raised inside call, so it propagates out of resume(). The script catches it there and prints the gate, then reads which node is pending and what the effect log recorded:

text
  refused inside the graph by policy-gate:    structured_output was required and no comparator emitted it  next node: ('refund',)  effect log: ['failed']owed: executor ran=True  graph ran=False  no record on the graph: ['structured-output']  only on the graph: []  refused inside the graph by merge-gate:    foreign: invoice_id <- model: 'inv_4410'  next node: ('refund',)  effect log: ['failed']foreign: executor ran=False  graph ran=False  no record on the graph: ['structured-output']  only on the graph: []

The merge gate now refuses the foreign refund, for the reason the executor gives. It also refuses the owed one, this time at the policy gate, which requires a structured_output verdict. On route A that verdict comes from judging the model's raw text before a proposal exists, and the caller carries it into act as prior. In the graph, the propose node returns a proposal and discards the text, so there is nothing to judge and no verdict to carry. The executor's own docstring predicts the result: "Forgetting it fails closed: Chapter 9's gate refuses a rule whose required verdict is absent." The run confirms it. The refusal is correct, because it fails closed and its reason names the first stage the graph is missing. When the graph raised out of resume(), it left the thread pending at refund. I did not test what a second resume does from there.

On the left is where the verdict is made on route A; on the right, why it never exists on the graph.

d2
grid-rows: 1
grid-gap: 40
a: "Route A" {
  label.near: top-center
  style: {fill: "#F4F8FD"; stroke: "#2C6FB0"; font-color: "#2C2C2A"}
  grid-columns: 1
  grid-gap: 12
  t: "model's raw text" {style: {fill: "#95A5A6"; stroke: "#6B7B7C"; font-color: "#FFFFFF"}}
  j: "judge(Draft): schema\nverdict passed" {style: {fill: "#7B68EE"; stroke: "#5A4BC4"; font-color: "#FFFFFF"}}
  x: "act(..., prior=verdicts)\npolicy gate allows" {style: {fill: "#6BCF7F"; stroke: "#3F9E52"; font-color: "#2C2C2A"}}
}
b: "Graph with call = act" {
  label.near: top-center
  style: {fill: "#FFFBEA"; stroke: "#C9A800"; font-color: "#2C2C2A"}
  grid-columns: 1
  grid-gap: 12
  t: "propose returns a Proposal;\nthe text is gone" {style: {fill: "#95A5A6"; stroke: "#6B7B7C"; font-color: "#FFFFFF"}}
  j: "no draft to judge,\nno verdict in state" {style: {fill: "#FFD93D"; stroke: "#C9A800"; font-color: "#2C2C2A"}}
  x: "act(...) with no prior\npolicy gate refuses" {style: {fill: "#FFA07A"; stroke: "#D9785A"; font-color: "#2C2C2A"}}
}

A missing input caused the refusal, which is why the missing structured-output record shows on the owed case and the foreign one alike. A one-line swap has turned a silent pass into a loud refusal that points at the next piece of work. It cannot finish the job, though. An injected call never sees the graph's state, so it has no draft to judge and no state to hand the executor.

A second module names a different missing stage

One refusal could be a coincidence of this graph. So I ran the same move on a second module, Chapter 11's merge graph (plan -> read -> merge), using the book's own plan and read nodes and the fixtures from its tests. I replaced only the merge node, with one that calls Harness.act on the graph's own state and judges the draft so the schema verdict exists:

python
def merge(state: RunState[Any]) -> dict[str, Any]:    try:        h.act(state.proposal, state, h.judge(Draft(text), state))        said.append("allowed")    except (Refused, BoundExceeded) as exc:        said.append(f"{type(exc).__name__}: {exc}")    return {"decisions": state.decisions}

For the owed refund, the book's merge graph and the routed one disagree:

text
book merge graph:   merge-gate: allowrouted through act: Refused: band-gate returned refuse: observe produces no actions  structured-output: passed  band-integrity: within  run-ceilings: within  replay-bound: within  daily-refund-ceiling: within  invoice-belongs-to-account: passed  amounts-grounded: passed  tool-admission: allowed  merge-gate: allowed  band-gate: refused

With the merge gate as its only check, the book's graph allows the refund. Routed through the executor, nine other controls run and the band gate refuses with "observe produces no actions". The merge graph never runs Chapter 14's authority admission, so the run's band stays at RunState's default, observe, the band that may do nothing. That is a design gap, not a fixture omission: no node in the merge graph sets a band, so no fixture could supply one. On the refund graph the missing stage was a verdict on the model's draft. Here it is the authority band. Neither stage is visible in the graph's drawing, in its tests, or in the lint's output; both surfaced the first time the node went through the executor.

A graph that calls the executor: the redesign, built

The chapter declines to do the redesign. On this path it needs two changes, and I built it. First, the propose node keeps the model's draft and judges it where it is written, so the schema verdict lives in state. Second, the execute node hands the graph's own state to Harness.act, so every control runs on the state the run actually holds, and what act changes leaves through the channel:

python
def journal(old: Sequence[Spend], new: Sequence[Spend]) -> tuple[Spend, ...]:    return (*old, *new)                       # why: the spend section below@dataclassclass SeamState(RunState[Any]):    draft: str = ""                                   # what the model wrote    verdicts: dict[str, Verdict] = field(default_factory=dict)    spend: Annotated[tuple[Spend, ...], journal] = ()def make_propose_node(h: Harness[Any], model: Any) -> Any:    def propose(state: SeamState) -> dict[str, Any]:        text = model(state)        verdicts = h.judge(Draft(text), state)        # judged where it is written        proposal = None        if verdicts["structured_output"].passed:            payload = json.loads(text)            proposal = Proposal(payload["tool"], payload["arguments"])        return {            "draft": text,            "verdicts": verdicts,            "proposal": proposal,            "budget": replace(state.budget, model_calls=state.budget.model_calls + 1),        }    return proposedef make_execute_node(h: Harness[Any], guard: EffectGuard, allowed: str) -> Any:    def execute(state: SeamState) -> dict[str, Any]:        proposal = state.proposal        if proposal is None or state.status != APPROVED:            state.record("replay-guard", "refuse", "no approved proposal to execute")            return {"decisions": state.decisions}        if proposal.tool != allowed:                  # the book node's pricing rule            state.record("replay-guard", "refuse", f"priced for {allowed}")            return {"decisions": state.decisions}        before = len(state.spend)        try:            guard.perform(proposal.tool, proposal.arguments,                          lambda: h.act(proposal, state, state.verdicts))        except (Refused, BoundExceeded):            return {"decisions": state.decisions, "status": "refused"}        # Return every field act() mutates; savers that do not persist        # in-place mutation lose anything left out.        return {            "decisions": state.decisions,            "budget": state.budget,            "spend": state.spend[before:],            # the reducer adds; send the delta        }    return execute

The graph wraps both nodes in the book's rehydrating, reuses its make_plan_node and approve, compiles with a checkpointer, and resumes through the book's resume(). Because the fixture supplies the context, there is no read node, so the merge gate reads the fixture's spans rather than spans a read node added. Keep that difference from the book's graph in mind when comparing the two. The execute node keeps the book node's rule that it runs only the tool its spec priced. My first version dropped that check, and a scorer caught it: a redesign can be a small Second Executor too.

This is the control-trace equivalence test. With the executor's recorder on both routes, it asserts that the tool outcome and the set of (control, outcome) pairs are identical. seam_route builds the graph above with the same fixture as executor_route, starts it from the fixture's run, and resumes it with "approve":

python
@pytest.mark.parametrize("name", PROPOSALS)def test_seam_graph_runs_the_executor(name: str) -> None:    a = executor_route(PROPOSALS[name])    b = seam_route(PROPOSALS[name])    assert a.ran == b.ran, f"executor ran={a.ran}, graph ran={b.ran}"    assert a.outcomes == b.outcomes, sorted(a.outcomes ^ b.outcomes)def test_negative_control_is_caught() -> None:    """Drop the judged verdicts from state: the owed refund no longer matches."""    a = executor_route(PROPOSALS["owed"])    b = seam_route(PROPOSALS["owed"], forget=True)    assert a.recorded == b.recorded            # the same 11 controls left a record    assert a.outcomes != b.outcomes            # but policy-gate's outcome flipped

Both routes call the same Harness.act with the same recorder, so a pass could be a test that cannot fail. The negative control rules that out. forget=True wraps the propose node so it leaves the judged verdicts out of state, and nothing else changes:

text
  test_seam_graph_runs_the_executor[owed] PASSED          [ 33%]  test_seam_graph_runs_the_executor[foreign] PASSED       [ 66%]  test_negative_control_is_caught PASSED                  [100%]============================== 3 passed in 1.22s ==============================

All four routes, side by side:

text
owed     executor    tool ran=True   records=11owed     book graph  tool ran=True   records= 1owed     seam graph  tool ran=True   records=11owed     forgetful   tool ran=False  records=11foreign  executor    tool ran=False  records= 9foreign  book graph  tool ran=True   records= 1foreign  seam graph  tool ran=False  records= 9foreign  forgetful   tool ran=False  records= 9

The forgetful graph refuses the owed refund, and the negative control shows why names alone are not enough; whether outcomes add anything beyond ran is taken up below the output. On that refund the two routes record the same 11 control names. Of the trace, only the outcomes differ:

text
names equal:    Trueoutcomes equal: False  executor  policy-gate: allowed  forgetful policy-gate: refused

A names-only comparison would call the forgetful graph equivalent. Its ran field differs too, though, so this case does not show the outcome comparison catching something a (ran, names) check would miss. None of the outcome changes I produced was of that kind: each also changed whether the tool ran or which gate refused first. I keep outcomes in the definition anyway, because a flipped verdict can be masked. assert_closed guarantees that some gate reads every comparator verdict, not that a flip changes what that gate decides: on a proposal where two comparators already fail and feed the same gate, a graph that corrupts only one of them gets the same ran, the same names and the same first refusal, and only the (control, outcome) set differs. I did not build that case here, so it remains an argument, not a measurement. The forgetful graph also refuses the foreign refund, as it should, and on that case no comparison could tell it apart from the working graph, because the missing verdict only matters when everything else passes.

One line in SeamState is there because building the redesign found a second seam. spend is Chapter 13's journal of every unit the run spent, with operator.add as its reducer, and Chapter 13's graph nodes write it as tuples. No graph in the book writes spend under a checkpointer, though; the one checkpointed graph, Chapter 12's, never touches it. A minimal graph that uses both patterns fails on the first spend after a resume. It uses only the book's types and writes spend in the shape ceilings.py uses, {"spend": (step,)}. It is not the two chapters' graphs composed, but it is their two patterns in one graph:

python
def spend(state: RunState) -> dict:    return {"spend": (Spend("model", model_calls=1),)}     # Chapter 13's shapedef pause(state: RunState) -> dict:    interrupt({"tool": "issue_refund", "run_id": state.run_id})    return {}

With before -> approve -> after compiled on an InMemorySaver, resumed once:

text
paused; spend is listresumed: TypeError: can only concatenate list (not "tuple") to list

After the resume the serializer brings the journal back as a list, and operator.add refuses to add a tuple to a list. Each chapter's wiring passes its own tests, and nothing tests them together. Defined alongside SeamState, the journal reducer folds whatever sequence type each side arrives as. Its docstring, omitted above:

python
def journal(old: Sequence[Spend], new: Sequence[Spend]) -> tuple[Spend, ...]:    """Chapter 13's reducer is operator.add. After a resume the stored value is a    list and list + tuple raises, so fold whatever sequence type each side is."""    return (*old, *new)

Across the three versions of the graph's last node, each proposal ends like this:

d2
grid-rows: 1
grid-gap: 30
n1: "As shipped" {
  label.near: top-center
  style: {fill: "#FDF4F4"; stroke: "#B03A2E"; font-color: "#2C2C2A"}
  grid-columns: 1
  grid-gap: 12
  a: "call = the tool" {style: {fill: "#95A5A6"; stroke: "#6B7B7C"; font-color: "#FFFFFF"}}
  b: "owed: paid\nforeign: paid" {style: {fill: "#E74C3C"; stroke: "#B03A2E"; font-color: "#FFFFFF"}}
}
n2: "call = Harness.act" {
  label.near: top-center
  style: {fill: "#FFFBEA"; stroke: "#C9A800"; font-color: "#2C2C2A"}
  grid-columns: 1
  grid-gap: 12
  a: "no draft verdict\nin state" {style: {fill: "#FFD93D"; stroke: "#C9A800"; font-color: "#2C2C2A"}}
  b: "owed: refused\nforeign: refused" {style: {fill: "#FFA07A"; stroke: "#D9785A"; font-color: "#2C2C2A"}}
}
n3: "Seam graph (built)" {
  label.near: top-center
  style: {fill: "#F4FBF6"; stroke: "#3F9E52"; font-color: "#2C2C2A"}
  grid-columns: 1
  grid-gap: 12
  a: "verdict in state,\nexecutor on graph state" {style: {fill: "#98D8C8"; stroke: "#5FA898"; font-color: "#2C2C2A"}}
  b: "owed: paid\nforeign: refused" {style: {fill: "#6BCF7F"; stroke: "#3F9E52"; font-color: "#2C2C2A"}}
}

Keep the middle column as a step on the way: every refusal there has a reason, the effect log records the attempt as failed, and nothing is paid. The right-hand column covers one path, the refund. Every other graph module in the book still calls controls directly, and each would need the same two changes and its own both-routes test.

Agent decision logs that miss every LangGraph run

The Second Executor drops more than gates. Three chapters of the book depend on the recorder's stream. Part 6 built it, as the Second Stream, to answer why a run did what it did. Part 16's attribution reads it to decide which layer failed. Part 17's readiness check reads it to decide whether each control was exercised on the current build. Every one of those records comes from Harness.act, and no shipped node calls it.

A system wired the way the book wires its graph therefore keeps a decision log of everything the plain executor decided, and if production runs the graph, the log stays empty. Every tool on top of it reasons about a route that carried no traffic. Part 17 named a dead control that looks healthy The Silent Pass. This time what died is the observability layer itself, and every test of it passes, because the tests drive the executor and production drives the graph.

One check in this series would notice. Part 6 declared owed decisions per effect: a refund must carry an allowing decision from each control the declaration names, or it is a finding. That check is this series' code, not the book's, and nothing in the book's repository checks the graph's runs for missing decisions. Pointed at the graph's refunds, it would flag every one, owed or not, by construction, because none of them carries any recorded decision. I did not run it here. It only helps if someone points it at the route production takes.

Every consumer of the record hangs off the left-hand route, the one that in this repository carries only test traffic:

d2
direction: down
exec: "Harness.act\n(tests and examples)" {style: {fill: "#4A90E2"; stroke: "#2C6FB0"; font-color: "#FFFFFF"}}
graph: "compiled graph\n(the route that pauses and resumes)" {style: {fill: "#E74C3C"; stroke: "#B03A2E"; font-color: "#FFFFFF"}}
rec: "recorder: Second Stream" {style: {fill: "#98D8C8"; stroke: "#5FA898"; font-color: "#2C2C2A"}}
users: "Part 6 owed decisions\nPart 16 attribution\nPart 17 readiness" {style: {fill: "#7B68EE"; stroke: "#5A4BC4"; font-color: "#FFFFFF"}}
trail: "decision trail only:\neffect-guard executed" {style: {fill: "#FFD93D"; stroke: "#C9A800"; font-color: "#2C2C2A"}}
exec -> rec: "one signal per control"
rec -> users
graph -> trail: "nothing reaches the recorder"

LangChain Deep Agents and ToolNode: the same bypass inside the framework

The shape is not a quirk of one book's wiring. Frameworks produce it wherever one control has two routes to an effect.

LangChain's Deep Agents give a subagent the parent's tools and not the parent's middleware. Its docs state both halves: subagent tools "Inherits from main agent by default", and "Isolated subagents do not inherit the main agent's custom middleware" (LangChain, Deep Agents subagents). On the LangChain forum in October 2026, a user set ToolCallLimitMiddleware(tool_name="sigma_search", run_limit=2) on the main agent. "The limit worked correctly for the main agent's own direct calls." Then the default subagent "fired three parallel sigma_search calls in a single turn". A reply diagnosed it: "isolated subagents don't inherit the parent's custom middleware. Your limiter only ever sees the main agent's own calls" (LangChain Forum, 2026-10-28).

LangGraph fixed a two-route defect inside its own ToolNode in October 2026. The commit for pull request #9232 reads: "With wrap_tool_call set and a handle_tool_errors other than the default, _run_one turned any exception from the wrapper into an error ToolMessage. That included GraphInterrupt, so the tool never paused, and invalid resumes, so a bad answer reached the model. Re-raise both, as the path without a wrapper already does" (LangGraph PR #9232). One route through the node dropped the approval pause, and the fix made the routes agree. It shipped in langgraph 1.2.15. The book's graphs do not use ToolNode, so the tag's pinned 1.2.12 is not affected.

The OpenAI Agents SDK documents its routes. "Input guardrails run only for the first agent in the chain", and "Handoffs run through the SDK's handoff pipeline rather than the function-tool pipeline, so tool guardrails do not apply to the handoff call itself" (OpenAI Agents SDK, Guardrails). Writing a skipped route down is necessary and not enough: Deep Agents documents its subagent rule, and a user still hit it. A route the docs name can at least be tested for. One nobody wrote down has to be found from the code: a lint shows where it is, and a test that drives every route shows what it does.

Placed next to the book's own case, red marks a route nobody declared, yellow one that was documented or fixed but still reached a user, and green one documented with its gaps listed:

d2
grid-rows: 2
grid-columns: 2
grid-gap: 24
book: "Book graph (tag)" {
  label.near: top-center
  style: {fill: "#FDF4F4"; stroke: "#B03A2E"; font-color: "#2C2C2A"}
  x: "execute node: tool reached,\ngates and recorder not" {style: {fill: "#E74C3C"; stroke: "#B03A2E"; font-color: "#FFFFFF"}}
}
deep: "Deep Agents subagent" {
  label.near: top-center
  style: {fill: "#FFFBEA"; stroke: "#C9A800"; font-color: "#2C2C2A"}
  x: "documented: tool inherited,\ncall limit not; a user hit it" {style: {fill: "#FFD93D"; stroke: "#C9A800"; font-color: "#2C2C2A"}}
}
tn: "ToolNode before 1.2.15" {
  label.near: top-center
  style: {fill: "#FFFBEA"; stroke: "#C9A800"; font-color: "#2C2C2A"}
  x: "wrapped route swallowed\nthe approval pause" {style: {fill: "#FFD93D"; stroke: "#C9A800"; font-color: "#2C2C2A"}}
}
oai: "OpenAI Agents SDK" {
  label.near: top-center
  style: {fill: "#F4FBF6"; stroke: "#3F9E52"; font-color: "#2C2C2A"}
  x: "handoffs skip tool guardrails,\nand the docs say so" {style: {fill: "#6BCF7F"; stroke: "#3F9E52"; font-color: "#2C2C2A"}}
}

Does LangGraph draw_mermaid show your guardrails? The Unrendered Edge

The chapter pairs the Second Executor with one more concept, adopted from my earlier writing, for the constraint that a graph's picture leaves out. LangGraph will render a compiled graph for you, and the picture is correct about its nodes and edges. In LangGraph create_agent: The Graph Isn't the Runtime I found the prebuilt agent's rendered graph byte-identical with one tool, three or twenty, and named the shape there. An Unrendered Edge is "a state-dependent constraint on which action a transition may carry, enforced by the runtime on either the emission side (which action the model is offered) or the execution side (which action the runtime will dispatch), that appears on no rendered artifact of the graph it constrains". My book adopts the term with that definition.

The book's graphs carry a node-level cousin: guards inside a node that the drawing omits. They are not runtime-enforced constraints on a transition, so they are not Unrendered Edges in the earlier post's sense, but they hide the same way. In the Chapter 12 graph, the two string comparisons in the execute node decide whether a refund happens, and no drawing of that graph shows them. Draw it and you get plan -> read -> propose -> approve -> refund, true and silent about what guards the last edge. In the Chapter 9 gating graph, the frozen verdicts mapping in gating.py decides what the policy gate can conclude, and it is a constructor argument, not a node.

What draw_mermaid() renders sits on the left, and what decides sits on the right.

d2
grid-rows: 1
grid-gap: 40
drawn: "draw_mermaid() renders" {
  label.near: top-center
  style: {fill: "#F4F8FD"; stroke: "#2C6FB0"; font-color: "#2C2C2A"}
  grid-columns: 1
  grid-gap: 10
  a: "plan" {style: {fill: "#4A90E2"; stroke: "#2C6FB0"; font-color: "#FFFFFF"}}
  b: "read -> propose" {style: {fill: "#4A90E2"; stroke: "#2C6FB0"; font-color: "#FFFFFF"}}
  c: "approve -> refund" {style: {fill: "#4A90E2"; stroke: "#2C6FB0"; font-color: "#FFFFFF"}}
}
hidden: "Decides, and is not drawn" {
  label.near: top-center
  style: {fill: "#FDF4F4"; stroke: "#B03A2E"; font-color: "#2C2C2A"}
  grid-columns: 1
  grid-gap: 10
  a: "status == approved\ntool == issue_refund" {style: {fill: "#FFA07A"; stroke: "#D9785A"; font-color: "#2C2C2A"}}
  b: "verdicts frozen at\nbuild() time (Ch 9 graph)" {style: {fill: "#FFA07A"; stroke: "#D9785A"; font-color: "#2C2C2A"}}
  c: "no gate before the tool" {style: {fill: "#E74C3C"; stroke: "#B03A2E"; font-color: "#FFFFFF"}}
}

Trust the drawing for order. Which node can follow which is all it records, and a design review that reads it as the policy has read the wrong document. Put the control-trace equivalence test in that review next to it.

What LangGraph adds that a plain executor cannot

None of this is an argument against the framework, and the chapter is careful to say so. It lists ten things in the book that only work because a graph is underneath them, none of which Harness.act can express. Two of them matter more than the rest, and the second, reservation, is what the lint's beyond-act calls are.

The first is ordering you can diff. Part 11's frozen plan must be fixed before the first untrusted span enters the context. With plain objects that is a convention a caller can get wrong without an error; in the graph it is an edge, and a test can hold it there. The second is reserve-before-spend. Part 13 showed that a limit checked against spend already incurred, the Receipt Ceiling, fires one unit late. Harness.act calls the ceilings' check, which is that receipt. The graph calls reserve and admit_fanout, which refuse the unit before it is spent. Someone who copies the plain objects and leaves the graph behind gets the bound that fires late, with a signature that looks the same as the one that does not.

What each route has that the other lacks:

d2
grid-rows: 1
grid-gap: 40
g: "Only the graph has" {
  label.near: top-center
  style: {fill: "#F4FBF6"; stroke: "#3F9E52"; font-color: "#2C2C2A"}
  grid-columns: 1
  grid-gap: 12
  a: "plan frozen before\nretrieval (an edge)" {style: {fill: "#6BCF7F"; stroke: "#3F9E52"; font-color: "#2C2C2A"}}
  b: "reserve before spend\n(refuses the next unit)" {style: {fill: "#6BCF7F"; stroke: "#3F9E52"; font-color: "#2C2C2A"}}
}
e: "Only the executor has" {
  label.near: top-center
  style: {fill: "#F4F8FD"; stroke: "#2C6FB0"; font-color: "#2C2C2A"}
  grid-columns: 1
  grid-gap: 12
  a: "every gate, in order,\nbefore the tool" {style: {fill: "#4A90E2"; stroke: "#2C6FB0"; font-color: "#FFFFFF"}}
  b: "one recorded signal\nper control" {style: {fill: "#4A90E2"; stroke: "#2C6FB0"; font-color: "#FFFFFF"}}
}

That is the strongest case for the both-routes test: while both routes exist, neither can be trusted alone.

The equivalence test also has a limit. It is measured against the executor, so it inherits the executor's defects. Run it on ceilings.py and the graph that reserves would refuse the unit at the ceiling while act allows it; the test would fail, and "change the graph until it matches" would put Part 13's defect back. The seam graph's refund path already runs the Receipt Ceiling, because its execute node calls act, not reserve. That is only an improvement because Chapter 12's graph had no ceiling at all. Where the graph is deliberately the better route, fix the executor first (have act call reserve), or list the divergence as a declared exception the test asserts. Equivalence means "matches the executor", not "correct". Whether to adopt a framework at all is a separate question, which I have answered elsewhere. Do You Need an Agent Framework? Start With Plain Code argues that durability, control flow that must outlive the process, should move you off plain code. LangGraph or a While Loop? You Already Have a Runtime argues that one irreversible action obliges you to specify the runtime's next-step space. This article picks up after you have adopted one.

How to move LangGraph guardrails behind the executor

My book's closing chapter says the separation holds at the import boundary and not yet at the discipline boundary. On the refund path, this article moved it to the second. Routing the execute node through Harness.act refused the owed refund and named the missing stage, a verdict on the model's draft. Two node changes and one reducer later, a seam graph of the refund path, built without the read node, passes the control-trace equivalence test, and a graph that forgets the verdict fails it. On the merge graph the same move named a different stage, the authority band. Across the ten graph modules the lint still finds 12 drifted calls, and each one is a known location for the next piece of work.

The method should carry to other harnesses, though I have shown it on two modules of one book. Run the lint to see where the nodes drift. Route each node through the executor and read the refusals, because each one names a stage the graph is missing. Add those stages, where the executor gets them right, until the control-trace equivalence test passes on outcomes and the lint reports only beyond-act calls and input-gate calls whose decisions you have confirmed reach the recorder.

Checklist: finding Second Executors in a codebase you did not write

Once, when you inherit the codebase. Items 1 to 3 are the chapter's own diagnostic from its "Telling" section, restated:

  1. Grep the framework directory for your executor's name. Zero call sites means no node runs the executor's full discipline. Expect some direct calls to be work the executor, as written, does not do, such as reservations and effect logs, and read the rest as partial executors.
  2. Grep it for whatever writes your decision log. In the book's repository that is Recorder, and the answer was zero. Confirm the route production takes reaches the log, not only the route the tests take.
  3. Find the node that calls the irreversible tool. Read it line by line and count the gates between its first line and the call. At this tag the count was zero.
  4. Lint the callers of the controls, not of the tool. List every .decide(, .admit(, .check(, .assemble( and similar call outside the executor. For each, note what it passes (an empty {}, or verdicts fixed at build time) and what it keeps (_, a name never read, a record read only as a truth value).

Every change, in CI:

  1. Run a control-trace equivalence test for each irreversible tool. Assert two things separately: that the tool ran on both routes or on neither, and that both routes recorded the same (control, outcome) pairs, not only the same names. Give it a negative control that drops one stage, and check that it fails. Where the graph is deliberately better than the executor, as with reserve-before-spend, fix the executor or declare the divergence; never change the graph to match a defect.
  2. Re-run the lint after every redesign. Only beyond-act calls and input-gate calls whose decisions you have confirmed reach the recorder may remain.
  3. Compose the chapters' wiring in one test. A resume followed by a spend found a reducer defect that each chapter's own tests missed.
  4. Keep the import-boundary test. It catches a different defect, a file in the wrong place, and costs six lines.
  5. Treat an approval as one more record, never as the gates it replaced. Show the reviewer the arguments at minimum, and run the gates after the approval, immediately before the tool.

The Framework Seam chapter, and what this article adds

This is Part 18, the last part, of a series that follows Harness Engineering for Production AI Systems one chapter at a time. The closing chapter, "The Framework Seam," covers what this article leaves out: the two experiments that take the framework away and why their numbers disagree, a module-by-module account of the ten things LangGraph supplied, the four defects the chapter found in its own repository and fixed (one of them an unused parameter that recorded an intention nobody carried out), where irreversibility and durability each point when you choose a framework, and whether writing every control twice was worth its cost.

This part adds control-trace equivalence as the property to test, a drift lint, the both-routes test the chapter set as an exercise, the routing experiment, a built redesign of the refund path, and the reducer defect the redesign exposed. The scripts behind every result here (the route tests, the seam graph, the merge experiment and the lint) are not in the companion repository. The article prints the lint, the seam graph and the core of each test, but not every fixture: seam_route, the forgetful graph, the four-route table script, the names-and-outcomes script and the full merge_routed.py harness are described, not printed. Code for the chapter is in the closer-framework-seam tag of the companion repository.

A note on versions. Every number here was measured at the tag's pins: langgraph 1.2.12, langgraph-checkpoint 4.2.0, langchain-core 1.6.5 and pydantic 2.13.5. As of 2026-11-16 the current releases are langgraph 1.2.22, langgraph-checkpoint 4.3.2, langchain-core 1.8.1 and pydantic 2.14.3, and I have not re-run the suite on them. The interrupt and resume behaviour this article depends on is unchanged for a node that asks once (LangGraph, Interrupts), and strict checkpoint deserialisation is still opt-in.

References


Agentic AI

Follow for more technical deep dives on AI/ML systems, production engineering, and building real-world applications:


Books by Ranjan Kumar

Federated AI Agents cover

Federated AI Agents

Right-Sized AI cover

Right-Sized AI

Harness Engineering for Production AI Systems cover

Harness Engineering

The 7 GenAI Architectures cover

The 7 GenAI Architectures

Building Real-World Agentic AI Systems with LangGraph cover

Building Real-World Agentic AI Systems

The ChatML Handbook cover

The ChatML Handbook

The Chat Templates Handbook cover

The Chat Templates Handbook

Comments