15#include <asio/awaitable.hpp>
25#include <unordered_set>
26#include <unordered_map>
31namespace neograph::graph {
32class NativeGraphCheckpoint;
36class ManagedBudgetJournalAccess;
42NEOGRAPH_API asio::awaitable<
void> run_on_blocking_pool(std::function<
void()> work);
67struct ManagedBudgetLeaseScope {
68 std::string owner_scope;
69 std::string thread_id;
70 std::string storage_thread_id;
71 std::string graph_identity;
72 std::uint64_t original_ceiling = 0;
73 std::optional<std::int64_t> original_deadline_ticks;
74 std::string deadline_clock_identity;
80 const ManagedBudgetLeaseScope& scope()
const noexcept;
81 const std::string& actor_id()
const noexcept;
82 const std::string& bank_generation()
const noexcept;
83 std::uint64_t revision()
const noexcept;
84 std::string head_checkpoint_id()
const;
85 std::string head_commitment()
const;
86 const std::string& execution_thread_id()
const noexcept;
87 const std::string& execution_storage_thread_id()
const noexcept;
91 std::shared_ptr<Impl> impl_;
92 friend class detail::ManagedBudgetJournalAccess;
99 bool active()
const noexcept;
100 const std::string& effect_id()
const;
101 std::uint64_t claim_amount()
const;
102 const std::string& request_digest()
const;
106 std::shared_ptr<const Impl> impl_;
107 friend class detail::ManagedBudgetJournalAccess;
202 std::shared_ptr<const std::vector<ChannelWrite>> native_subgraph_writes;
220NEOGRAPH_API std::string managed_budget_checkpoint_commitment(
const Checkpoint& checkpoint);
221NEOGRAPH_API
bool checkpoint_channel_blob_eligible(
const json& channel);
222NEOGRAPH_API json checkpoint_storage_shape(
const Checkpoint& checkpoint);
223NEOGRAPH_API
void restore_checkpoint_storage_shape(
Checkpoint& checkpoint,
const json& shape,
224 const std::map<std::string, json>& blobs);
251 std::shared_ptr<const NodeResult> native_result;
256NEOGRAPH_API
void restore_checkpoint_storage_envelope(
Checkpoint& checkpoint);
270 virtual std::optional<Checkpoint> load_latest(
const std::string& thread_id) = 0;
271 virtual std::optional<Checkpoint> load_by_id(
const std::string&
id) = 0;
272 virtual std::vector<Checkpoint> list(
const std::string& thread_id,
273 int limit = 100) = 0;
274 virtual void delete_thread(
const std::string& thread_id) = 0;
279 virtual std::shared_ptr<OwnedManagedBudgetLease> acquire_managed_budget_lease(
280 const ManagedBudgetLeaseScope& scope,
const std::string& expected_checkpoint_id,
281 const std::string& expected_checkpoint_commitment);
283 const std::shared_ptr<OwnedManagedBudgetLease>& lease,
const std::string& effect_id,
284 std::uint64_t exact_claim_amount,
const std::string& prepared_request_digest);
285 virtual void settle_managed_budget_effect(
const std::shared_ptr<OwnedManagedBudgetLease>& lease,
287 const UsageAccumulator::AuthoritySnapshot& authority);
288 virtual void publish_managed_budget_checkpoint(
289 const std::shared_ptr<OwnedManagedBudgetLease>& lease,
const Checkpoint& checkpoint);
290 virtual void release_managed_budget_lease(
const std::shared_ptr<OwnedManagedBudgetLease>& lease);
293 virtual void publish_managed_budget_fork(
307 virtual asio::awaitable<void> save_async(
const Checkpoint& cp) = 0;
308 virtual asio::awaitable<std::optional<Checkpoint>>
309 load_latest_async(
const std::string& thread_id) = 0;
310 virtual asio::awaitable<std::optional<Checkpoint>>
311 load_by_id_async(
const std::string&
id) = 0;
312 virtual asio::awaitable<std::vector<Checkpoint>>
313 list_async(
const std::string& thread_id,
int limit = 100) = 0;
314 virtual asio::awaitable<void>
315 delete_thread_async(
const std::string& thread_id) = 0;
317 virtual asio::awaitable<bool> requires_managed_budget_async(std::string thread_id);
318 virtual asio::awaitable<std::shared_ptr<OwnedManagedBudgetLease>> acquire_managed_budget_lease_async(
319 ManagedBudgetLeaseScope scope, std::string expected_checkpoint_id,
320 std::string expected_checkpoint_commitment);
321 virtual asio::awaitable<ManagedBudgetEffectReceipt> begin_managed_budget_effect_async(
322 std::shared_ptr<OwnedManagedBudgetLease> lease, std::string effect_id,
323 std::uint64_t exact_claim_amount, std::string prepared_request_digest);
324 virtual asio::awaitable<void> settle_managed_budget_effect_async(
326 sp::runtime::Result genuine_outcome, UsageAccumulator::AuthoritySnapshot authority);
327 virtual asio::awaitable<void> publish_managed_budget_checkpoint_async(
328 std::shared_ptr<OwnedManagedBudgetLease> lease,
Checkpoint checkpoint);
329 virtual asio::awaitable<void> release_managed_budget_lease_async(
330 std::shared_ptr<OwnedManagedBudgetLease> lease);
331 virtual bool retains_native_checkpoint()
const noexcept {
return false; }
332 virtual asio::awaitable<void> publish_managed_budget_fork_async(
343 virtual void put_writes(
const std::string& thread_id,
344 const std::string& parent_checkpoint_id,
346 virtual std::vector<PendingWrite> get_writes(
347 const std::string& thread_id,
348 const std::string& parent_checkpoint_id) = 0;
349 virtual void clear_writes(
const std::string& thread_id,
350 const std::string& parent_checkpoint_id) = 0;
427 virtual std::optional<Checkpoint>
load_latest(
const std::string& thread_id);
434 virtual std::optional<Checkpoint>
load_by_id(
const std::string&
id);
443 virtual std::vector<Checkpoint>
list(
const std::string& thread_id,
456 virtual asio::awaitable<void> save_async(
const Checkpoint& cp);
457 virtual asio::awaitable<std::optional<Checkpoint>>
458 load_latest_async(
const std::string& thread_id);
459 virtual asio::awaitable<std::optional<Checkpoint>>
460 load_by_id_async(
const std::string&
id);
461 virtual asio::awaitable<std::vector<Checkpoint>>
462 list_async(
const std::string& thread_id,
int limit = 100);
463 virtual asio::awaitable<void>
464 delete_thread_async(
const std::string& thread_id);
499 const std::string& ) {
return {}; }
513 const std::string& ) {}
519 virtual asio::awaitable<void> put_writes_async(
520 const std::string& thread_id,
521 const std::string& parent_checkpoint_id,
523 virtual asio::awaitable<std::vector<PendingWrite>> get_writes_async(
524 const std::string& thread_id,
525 const std::string& parent_checkpoint_id);
526 virtual asio::awaitable<void> clear_writes_async(
527 const std::string& thread_id,
528 const std::string& parent_checkpoint_id);
536 virtual asio::awaitable<bool> requires_managed_budget_async(std::string thread_id);
538 virtual std::shared_ptr<OwnedManagedBudgetLease> acquire_managed_budget_lease(
539 const ManagedBudgetLeaseScope& scope,
const std::string& expected_checkpoint_id,
540 const std::string& expected_checkpoint_commitment);
541 virtual asio::awaitable<std::shared_ptr<OwnedManagedBudgetLease>> acquire_managed_budget_lease_async(
542 ManagedBudgetLeaseScope scope, std::string expected_checkpoint_id,
543 std::string expected_checkpoint_commitment);
545 const std::shared_ptr<OwnedManagedBudgetLease>& lease,
const std::string& effect_id,
546 std::uint64_t exact_claim_amount,
const std::string& prepared_request_digest);
547 virtual asio::awaitable<ManagedBudgetEffectReceipt> begin_managed_budget_effect_async(
548 std::shared_ptr<OwnedManagedBudgetLease> lease, std::string effect_id,
549 std::uint64_t exact_claim_amount, std::string prepared_request_digest);
550 virtual void settle_managed_budget_effect(
const std::shared_ptr<OwnedManagedBudgetLease>& lease,
552 const UsageAccumulator::AuthoritySnapshot& authority);
553 virtual asio::awaitable<void> settle_managed_budget_effect_async(
555 sp::runtime::Result genuine_outcome, UsageAccumulator::AuthoritySnapshot authority);
556 virtual void publish_managed_budget_checkpoint(
557 const std::shared_ptr<OwnedManagedBudgetLease>& lease,
const Checkpoint& checkpoint);
558 virtual asio::awaitable<void> publish_managed_budget_checkpoint_async(
559 std::shared_ptr<OwnedManagedBudgetLease> lease,
Checkpoint checkpoint);
560 virtual void release_managed_budget_lease(
const std::shared_ptr<OwnedManagedBudgetLease>& lease);
561 virtual asio::awaitable<void> release_managed_budget_lease_async(
562 std::shared_ptr<OwnedManagedBudgetLease> lease);
565 virtual void publish_managed_budget_fork(
567 virtual asio::awaitable<void> publish_managed_budget_fork_async(
584NEOGRAPH_API std::shared_ptr<CheckpointStore>
592NEOGRAPH_API std::shared_ptr<CheckpointStore>
622 std::optional<Checkpoint>
load_latest(
const std::string& thread_id)
override;
623 std::optional<Checkpoint>
load_by_id(
const std::string&
id)
override;
624 std::vector<Checkpoint>
list(
const std::string& thread_id,
625 int limit = 100)
override;
632 asio::awaitable<void> save_async(
const Checkpoint& cp)
override;
633 asio::awaitable<std::optional<Checkpoint>>
634 load_latest_async(
const std::string& thread_id)
override;
635 asio::awaitable<std::optional<Checkpoint>>
636 load_by_id_async(
const std::string&
id)
override;
637 asio::awaitable<std::vector<Checkpoint>>
638 list_async(
const std::string& thread_id,
int limit = 100)
override;
639 asio::awaitable<void>
640 delete_thread_async(
const std::string& thread_id)
override;
643 const std::string& parent_checkpoint_id,
646 const std::string& thread_id,
647 const std::string& parent_checkpoint_id)
override;
649 const std::string& parent_checkpoint_id)
override;
651 asio::awaitable<void> put_writes_async(
652 const std::string& thread_id,
653 const std::string& parent_checkpoint_id,
655 asio::awaitable<std::vector<PendingWrite>> get_writes_async(
656 const std::string& thread_id,
657 const std::string& parent_checkpoint_id)
override;
658 asio::awaitable<void> clear_writes_async(
659 const std::string& thread_id,
660 const std::string& parent_checkpoint_id)
override;
663 asio::awaitable<bool> requires_managed_budget_async(std::string thread_id)
override;
664 std::shared_ptr<OwnedManagedBudgetLease> acquire_managed_budget_lease(
665 const ManagedBudgetLeaseScope& scope,
const std::string& expected_checkpoint_id,
666 const std::string& expected_checkpoint_commitment)
override;
668 const std::shared_ptr<OwnedManagedBudgetLease>& lease,
const std::string& effect_id,
669 std::uint64_t exact_claim_amount,
const std::string& prepared_request_digest)
override;
670 void settle_managed_budget_effect(
const std::shared_ptr<OwnedManagedBudgetLease>& lease,
672 const UsageAccumulator::AuthoritySnapshot& authority)
override;
673 void publish_managed_budget_checkpoint(
674 const std::shared_ptr<OwnedManagedBudgetLease>& lease,
const Checkpoint& checkpoint)
override;
675 void release_managed_budget_lease(
const std::shared_ptr<OwnedManagedBudgetLease>& lease)
override;
677 void publish_managed_budget_fork(
683 asio::awaitable<std::shared_ptr<OwnedManagedBudgetLease>> acquire_managed_budget_lease_async(
684 ManagedBudgetLeaseScope scope, std::string expected_checkpoint_id,
685 std::string expected_checkpoint_commitment)
override;
686 asio::awaitable<ManagedBudgetEffectReceipt> begin_managed_budget_effect_async(
687 std::shared_ptr<OwnedManagedBudgetLease> lease, std::string effect_id,
688 std::uint64_t exact_claim_amount, std::string prepared_request_digest)
override;
689 asio::awaitable<void> settle_managed_budget_effect_async(
691 sp::runtime::Result genuine_outcome, UsageAccumulator::AuthoritySnapshot authority)
override;
692 asio::awaitable<void> publish_managed_budget_checkpoint_async(
693 std::shared_ptr<OwnedManagedBudgetLease> lease,
Checkpoint checkpoint)
override;
694 asio::awaitable<void> release_managed_budget_lease_async(
695 std::shared_ptr<OwnedManagedBudgetLease> lease)
override;
696 asio::awaitable<void> publish_managed_budget_fork_async(
717 const std::string& parent_checkpoint_id)
const;
735 mutable std::mutex mutex_;
736 std::map<std::string, std::vector<Checkpoint>> by_thread_;
737 std::map<std::string, Checkpoint> by_id_;
741 std::map<std::tuple<std::string, std::string, uint64_t>, json> blobs_;
743 std::map<std::pair<std::string, std::string>, std::vector<PendingWrite>> pending_;
744 std::unordered_set<std::string> managed_budget_obligations_;
745 std::unordered_map<std::string, json> managed_budget_journals_;
746 std::map<std::tuple<std::string, std::string, std::string>, json> managed_budget_effects_;
747 std::map<std::tuple<std::string, std::string, std::string>, sp::runtime::Result> managed_budget_results_;
748 struct ManagedBudgetBranchHead {
749 std::string financial_storage_thread_id;
750 std::string execution_thread_id;
751 std::string checkpoint_id;
752 std::string commitment;
753 std::shared_ptr<const NativeGraphCheckpoint> native_history;
756 const ManagedBudgetBranchHead& authenticate_managed_budget_branch_locked(
757 const Checkpoint& source,
const std::string& commitment)
const;
758 void validate_managed_budget_execution_locked(
759 const std::shared_ptr<OwnedManagedBudgetLease>& lease,
const json& head)
const;
760 std::unordered_map<std::string, ManagedBudgetBranchHead> managed_budget_branch_heads_;
NEOGRAPH_API export/import macro for shared-library builds.
CheckpointPhase
Phase at which a Checkpoint was produced.
@ After
Saved just after an interrupt_after node completed.
@ Before
Saved just before an interrupt_before node fires.
@ Updated
Saved by update_state() injecting state externally.
NEOGRAPH_API std::uint64_t blocking_checkpoint_hops() noexcept
How many operations of a synchronous checkpoint store have been handed to the pool of worker threads ...
NEOGRAPH_API std::shared_ptr< CheckpointStore > adapt_async_checkpoint_store(std::shared_ptr< AsyncCheckpointStore > backend)
Explicit sync facade for an async-native backend.
NEOGRAPH_API json checkpoint_storage_metadata(const Checkpoint &checkpoint)
Preserve the complete durable provider-state envelope without changing store schemas.
NEOGRAPH_API std::shared_ptr< CheckpointStore > adapt_checkpoint_store(std::shared_ptr< CheckpointStoreCore > core)
Adapt split checkpoint capabilities to the legacy engine contract.
NEOGRAPH_API CheckpointPhase parse_checkpoint_phase(std::string_view s)
Parse a phase string back to the enum.
constexpr std::uint32_t CHECKPOINT_SCHEMA_VERSION
Current Checkpoint layout version.
Canonical coroutine contract for a native async backend.
Mandatory synchronous operations for a sync-only backend.
virtual bool requires_managed_budget(const std::string &thread_id)
A persistent denial obligation, never authority to spend or restore.
virtual bool retains_native_checkpoint() const noexcept
Storage retention only; never currency or native replay authority.
Abstract interface for checkpoint persistence backends.
virtual void clear_writes(const std::string &, const std::string &)
Discard pending writes for a parent checkpoint once its successor super-step has been fully committed...
virtual std::vector< PendingWrite > get_writes(const std::string &, const std::string &)
Load all pending writes attached to a parent checkpoint.
virtual bool retains_native_checkpoint() const noexcept
Describes real local C++ custody, not a financial admission/grant.
virtual std::optional< Checkpoint > load_latest(const std::string &thread_id)
Load the most recently saved checkpoint for a thread.
virtual bool requires_managed_budget(const std::string &thread_id)
Whether this trusted checkpoint namespace/thread has ever held an active standalone managed bank.
virtual void put_writes(const std::string &, const std::string &, const PendingWrite &)
Record a successful node execution within an in-progress super-step.
virtual void save(const Checkpoint &cp)
Save a checkpoint.
virtual std::optional< Checkpoint > load_by_id(const std::string &id)
Load a checkpoint by its unique ID.
virtual void delete_thread(const std::string &thread_id)
Delete all checkpoints for a thread.
virtual std::vector< Checkpoint > list(const std::string &thread_id, int limit=100)
List checkpoints for a thread, most recently saved first, one entry per ID; the first entry is load_l...
Marks an exception type as a configuration or definition verdict.
In-memory checkpoint store for testing and single-process use.
bool retains_native_checkpoint() const noexcept override
Describes real local C++ custody, not a financial admission/grant.
bool requires_managed_budget(const std::string &thread_id) override
Whether this trusted checkpoint namespace/thread has ever held an active standalone managed bank.
size_t pending_writes_count(const std::string &thread_id, const std::string &parent_checkpoint_id) const
Get the number of pending writes for a parent checkpoint (test helper).
void delete_thread(const std::string &thread_id) override
Delete all checkpoints for a thread.
std::vector< PendingWrite > get_writes(const std::string &thread_id, const std::string &parent_checkpoint_id) override
Load all pending writes attached to a parent checkpoint.
std::optional< Checkpoint > load_latest(const std::string &thread_id) override
Load the most recently saved checkpoint for a thread.
size_t blob_count() const
Number of distinct channel-value blobs currently held (test helper).
std::optional< Checkpoint > load_by_id(const std::string &id) override
Load a checkpoint by its unique ID.
void put_writes(const std::string &thread_id, const std::string &parent_checkpoint_id, const PendingWrite &write) override
Record a successful node execution within an in-progress super-step.
std::vector< Checkpoint > list(const std::string &thread_id, int limit=100) override
List checkpoints for a thread, most recently saved first, one entry per ID; the first entry is load_l...
size_t size() const
Get the total number of stored checkpoints (test helper).
void clear_writes(const std::string &thread_id, const std::string &parent_checkpoint_id) override
Discard pending writes for a parent checkpoint once its successor super-step has been fully committed...
void save(const Checkpoint &cp) override
Save a checkpoint.
A managed model-token budget with a deadline binds the deadline to the clock it counts on,...
Actual write-ahead claim, bound to one original generation and owned actor.
Exception thrown from inside a node to trigger a dynamic breakpoint.
Store-issued ownership; JSON or an archived observation cannot create it.
Optional fine-grained pending-writes capability.
A checkpoint store that is not asynchronous (it implements CheckpointStoreCore, or a CheckpointStore ...
Marker for exceptions that are configuration or definition verdicts (#364).
Graph engine type definitions: channels, edges, nodes, events, and control flow.
Serialized snapshot of graph execution state at a single super-step.
std::string thread_id
Conversation/session identifier.
int64_t step
Super-step number.
int64_t timestamp
Unix epoch milliseconds.
std::map< std::string, std::set< std::string > > barrier_state
Per-barrier accumulator: each entry maps a declared barrier node to the set of upstreams that have si...
json channel_versions
The engine does not set this field.
std::string current_node
Node that was active at checkpoint time.
std::string parent_id
Previous checkpoint ID (for time-travel chain).
json metadata
User-defined metadata.
json channel_values
Serialized channel data.
static NEOGRAPH_API std::string generate_id()
Generate a new UUID v4 string.
std::vector< std::string > next_nodes
Nodes to execute on resume.
std::shared_ptr< const NativeGraphCheckpoint > native_history
Original trusted C++ custody only; never reconstructed from checkpoint JSON.
std::string id
Unique checkpoint ID (UUID v4).
Successful node writes recorded within an in-progress super-step.
std::string task_id
Deterministic per-execution ID (survives replay).
std::string node_name
Node that produced these writes.
int64_t step
Super-step number this write belongs to.
json writes
Serialized ChannelWrite vector (json array of {channel, value}).
std::string task_path
Human-readable path, e.g. "s3:executor_2" or "s3:send[0]:searcher".
json command
Serialized optional Command, or null if the node didn't emit one.
json sends
Serialized Send vector (json array of {target_node, input}); empty if none.
int64_t timestamp
Unix epoch milliseconds at record time.