LangGraph agent in a worker thread: a join timeout doesn't stop it; break out of agent.stream() yourself
Running agent.stream(...) in a daemon thread and calling worker.join(timeout) returns control on time, but the thread keeps iterating: the graph keeps planning and paying for model calls until it hits the recursion limit (GraphRecursionError). Older LangGraph defaulted that limit to 25, but langgraph 1.2.22 defaults it to 10007 (env LANGGRAPH_DEFAULT_RECURSION_LIMIT), so on current versions a runaway agent has almost no ceiling; pass config={'recursion_limit': N} explicitly. In one measured run the answer was ready at 32 s and the background agent ran on to 106 s and about $0.42. Fix: share a stop flag, set it at the deadline, and check it at the top of the for chunk in agent.stream(...) loop and return. Leaving the generator closes the run, so no further model call is made; a call already in flight still runs to its client timeout. Test it with a fake chat model that always returns a tool call (never finishes) and assert the call count stops growing after the deadline.