NeoGraph 0.16.0
A C++20 Graph Agent Engine Library — LangGraph for C++
Loading...
Searching...
No Matches
cancel.h File Reference

Cooperative cancellation primitive for graph runs. More...

#include <neograph/api.h>
#include <asio/any_io_executor.hpp>
#include <asio/cancellation_signal.hpp>
#include <asio/post.hpp>
#include <asio/strand.hpp>
#include <algorithm>
#include <condition_variable>
#include <stop_token>
#include <cstdint>
#include <functional>
#include <memory>
#include <mutex>
#include <stdexcept>
#include <utility>
#include <vector>
Include dependency graph for cancel.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  neograph::graph::CancelledException
 Thrown by the engine when a run is cancelled mid-flight via CancelToken::cancel(). More...
 
class  neograph::graph::CancelToken
 Cooperative cancel primitive shared between caller and engine. More...
 

Detailed Description

Cooperative cancellation primitive for graph runs.

v0.3 introduces CancelToken so a caller can abort an in-flight GraphEngine::run_async cleanly, including the LLM HTTP request downstream of the engine super-step.

Three propagation paths from one token:

  1. Polling (is_cancelled()) — the engine super-step loop and the per-node dispatch checkpoint poll this between steps. Stops future node work after the next checkpoint, so a time.sleep in a Python node won't be preempted but the subsequent node won't fire.
  2. asio cancellation_signal (slot()) — bound to an Asio coroutine via asio::bind_cancellation_slot at co_spawn time. Asio propagates cancellation through awaited operations, including ConnPool::async_post. Closing local transport does not establish that the server stopped its work or did not charge.
  3. std::stop_token (stop_token()) — thread-safe subscriptions forward cancellation to native SDK operations without binding an Asio executor or occupying the caller's single cancellation slot.

The signal must be emit()ed and connected on one serial executor (asio rule). cancel() may be called from any thread; it stores the flag eagerly and posts the emit onto the returned serial executor. bind_executor is called before the operation is spawned, and the slot-bound co_spawn setup runs on that same executor.

Definition in file cancel.h.