LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangGraph
  • Web
  • Channels
  • Pregel
  • Prebuilt
  • Remote
  • Stream
LangGraph SDK
  • Ui
  • Client
  • Auth
  • React
  • Logging
  • React Ui
  • Utils
  • Server
  • Stream
LangGraph Checkpoint
LangGraph Checkpoint MongoDB
LangGraph Checkpoint Postgres
  • Store
LangGraph Checkpoint Redis
  • Shallow
  • Store
LangGraph Checkpoint SQLite
LangGraph Checkpoint Validation
  • Cli
LangGraph API
LangGraph CLI
LangGraph CUA
  • Utils
LangGraph Supervisor
LangGraph Swarm
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

LangGraph
WebChannelsPregelPrebuiltRemoteStream
LangGraph SDK
UiClientAuthReactLoggingReact UiUtilsServerStream
LangGraph Checkpoint
LangGraph Checkpoint MongoDB
LangGraph Checkpoint Postgres
Store
LangGraph Checkpoint Redis
ShallowStore
LangGraph Checkpoint SQLite
LangGraph Checkpoint Validation
Cli
LangGraph API
LangGraph CLI
LangGraph CUA
Utils
LangGraph Supervisor
LangGraph Swarm
Language
Theme
JavaScript@langchain/langgraphindexRunControl
Classā—Since v0.3

RunControl

Run-scoped control surface for cooperative draining.

Intended for a single graph run. Create a fresh RunControl per run; reusing a control after RunControl#requestDrain leaves it drained.

Safe to use from any concurrent context: the drain request is represented by a single field write, so no synchronization is needed for this signal. If more mutable state is added here, add synchronization.

The intended use is hooking SIGTERM (or any external supervisor signal) to RunControl#requestDrain so an in-flight graph run can stop cleanly at the next superstep boundary and be resumed later from the saved checkpoint.

Copy
class RunControl

Used in Docs

  • Fault tolerance

Example

Copy
import { RunControl, GraphDrained } from "@langchain/langgraph";

const control = new RunControl();

// In a signal handler, supervisor, etc.:
// control.requestDrain("sigterm");

try {
  const result = await graph.invoke(input, { ...config, control });
  if (control.drainRequested) {
    // finished naturally on the same tick where drain was requested
  }
} catch (e) {
  if (e instanceof GraphDrained) {
    // checkpoint saved; resume later with the same config
  } else {
    throw e;
  }
}

Constructors

constructor
constructor

Properties

property
drainReason: string | undefined
property
drainRequested: boolean

Methods

method
requestDrain

Request that the current run drain cooperatively, stopping at the next superstep boundary. Does not cancel work that is already running.

View source on GitHub