NeoGraph 0.10.0
A C++17 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 <algorithm>
#include <atomic>
#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.

Two 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 the run's coroutine via asio::bind_cancellation_slot at co_spawn time. asio propagates cancel down through every co_await, including ConnPool::async_post, so an in-flight HTTPS socket is closed and the LLM request aborts on the wire. This is what closes the cost-leak gap reported in v0.2.3.

The signal must be emit()ed on the executor that owns it (asio rule). cancel() may be called from any thread; it stores the flag eagerly and posts the emit onto the bound executor so the actual signal fires on the right strand. bind_executor is called by the engine on the first co_await after spawning, before any HTTP work.

Definition in file cancel.h.