NeoGraph 0.16.0
A C++20 Graph Agent Engine Library — LangGraph for C++
Loading...
Searching...
No Matches
sqlite_provider_call_broker.h
1#pragma once
2
4#include <neograph/program/core_provider_call.h>
6#include <neograph/types.h>
7#include <neograph/provider.h>
8#include <core/native_archive.h>
9#include <runtime/client.h>
10
11#include <cstdint>
12#include <exception>
13#include <stdexcept>
14#include <utility>
15#include <memory>
16#include <optional>
17#include <string>
18#include <string_view>
19#include <vector>
20
21namespace neograph::program {
22
26class NEOGRAPH_PROGRAM_API ProgramProviderOutcomePersistenceError final : public ProviderOutcomeError {
27public:
29 sp::runtime::Result outcome, std::exception_ptr cause,
30 std::exception_ptr observer_error = {})
31 : ProviderOutcomeError("Program provider outcome could not be persisted",
32 std::move(outcome), std::move(cause)),
33 observer_error_(std::move(observer_error)) {}
34 const std::exception_ptr& observer_error() const noexcept { return observer_error_; }
35private:
36 std::exception_ptr observer_error_;
37};
38
49class NEOGRAPH_PROGRAM_API ProgramProviderDispatchUncertainError final : public ProviderOutcomeError {
50public:
51 explicit ProgramProviderDispatchUncertainError(std::string message,
52 std::exception_ptr cause = {})
53 : ProviderOutcomeError(message.c_str(), nullptr, std::move(cause)) {}
54};
55
65class NEOGRAPH_PROGRAM_API ProgramProviderForkResendRefusedError final
66 : public std::runtime_error,
68public:
69 enum class Reason : std::uint8_t {
73 Unverifiable,
76 EncoderDiffers,
79 DeploymentDiffers,
80 };
81 ProgramProviderForkResendRefusedError(Reason reason, std::string call_id,
82 std::string source_run_id, std::string source_call_id);
83 Reason reason() const noexcept { return reason_; }
85 const std::string& call_id() const noexcept { return call_id_; }
86 const std::string& source_run_id() const noexcept { return source_run_id_; }
88 const std::string& source_call_id() const noexcept { return source_call_id_; }
89private:
90 Reason reason_;
91 std::string call_id_, source_run_id_, source_call_id_;
92};
93
107class NEOGRAPH_PROGRAM_API ProgramProviderUploadResendRequiredError final
108 : public std::runtime_error,
110public:
111 ProgramProviderUploadResendRequiredError(std::string call_id, std::string later_call_id);
113 const std::string& call_id() const noexcept { return call_id_; }
115 const std::string& later_call_id() const noexcept { return later_call_id_; }
116private:
117 std::string call_id_, later_call_id_;
118};
119
160class NEOGRAPH_PROGRAM_API SQLiteProgramProviderCallJournal final {
161public:
163 std::string database_path, std::shared_ptr<sp::NativeArchive> native_archive = {});
167
172 std::string provider_binding_identity);
181 std::string provider_binding_identity);
183 static std::string logical_call_id(const ProgramCoreProviderCallContext& context,
184 const graph::ProviderCallIdentity& call);
185
186 enum class State { Dispatched, Succeeded, ReconciliationRequired, Failed };
187 struct Record {
188 State state;
189 std::string request_digest;
190 std::string provider_binding_identity;
191 std::string original_attempt;
192 std::string outcome_digest;
193 std::string provider_name;
194 std::string model;
195 std::string family;
196 std::string mode;
197 std::string original_deadline;
198 std::uint32_t encoding_version;
200 std::uint64_t claim_amount;
201 std::uint64_t committed_amount;
205 std::optional<ProgramMonetaryRecord> monetary_record;
210 std::uint32_t identity_version = 2;
212 std::string content_digest;
214 std::string policy_identity;
216 std::string producer;
219 bool opens_upload_session = false;
222 std::uint32_t restarts = 0;
226 bool superseded = false;
227 };
228 std::optional<Record> inspect(std::string_view owner_scope,
229 std::string_view dispatch_id) const;
230
234 enum class Via : std::uint8_t {
236 Replay,
238 Adoption,
239 };
240 std::string journaled_policy_identity;
241 std::string observed_policy_identity;
242 std::uint64_t attempt = 0;
243 Via via = Via::Replay;
244 };
247 std::vector<PolicyChange> policy_changes(std::string_view owner_scope,
248 std::string_view dispatch_id) const;
249
252 struct Restart {
253 enum class Reason : std::uint8_t {
255 SessionNotStored,
258 OutcomeUnknown,
259 };
260 Reason reason = Reason::OutcomeUnknown;
261 std::uint64_t attempt = 0;
263 State replaced_state = State::Dispatched;
264 std::string replaced_outcome_digest;
265 };
269 std::vector<Restart> restarts(std::string_view owner_scope,
270 std::string_view dispatch_id) const;
271
286 void reconcile_success(std::string_view owner_scope, std::string_view dispatch_id,
287 std::string evidence_identity, sp::runtime::Result completion);
288
289 struct Impl;
290private:
291 std::shared_ptr<Impl> impl_;
292};
293
294} // namespace neograph::program
Post-dispatch host failure retaining the exact drained provider outcome.
Definition provider.h:204
Marks an exception type as a configuration or definition verdict.
A dispatch may have reached the provider, but no outcome is known: the transport raised instead of re...
A fork reached a provider call its source already journaled at the same position, and could neither a...
const std::string & call_id() const noexcept
The fork's logical call id (SQLiteProgramProviderCallJournal::logical_call_id).
const std::string & source_call_id() const noexcept
The source's logical call id of the record that could not be adopted.
Transport returned this exact outcome, but its durable settlement failed.
A resumed Program reached a chunked upload that cannot continue (#541).
const std::string & later_call_id() const noexcept
The logical call id of the first later call of the same node that the journal holds.
const std::string & call_id() const noexcept
The logical call id (SQLiteProgramProviderCallJournal::logical_call_id) of the call that opened the u...
void reconcile_success(std::string_view owner_scope, std::string_view dispatch_id, std::string evidence_identity, sp::runtime::Result completion)
Only after independent provider-side evidence establishes this exact result.
std::vector< PolicyChange > policy_changes(std::string_view owner_scope, std::string_view dispatch_id) const
The policy changes noted for one call, oldest first.
ProgramCoreProviderCallBinding bind(const ProgramCoreProviderCallContext &context, std::string provider_binding_identity)
The provider identity is the host's immutable deployment/credential-route digest.
ProgramCoreProviderCallBinding bind_priced(const ProgramCoreProviderCallContext &context, std::string provider_binding_identity)
bind() that also prices every call against the context's monetary account, as bind_priced_provider_ca...
static std::string logical_call_id(const ProgramCoreProviderCallContext &context, const graph::ProviderCallIdentity &call)
Stable across Program attempts; request content is bound to the slot.
std::vector< Restart > restarts(std::string_view owner_scope, std::string_view dispatch_id) const
The restarts noted for one call, oldest first.
Marker for exceptions that are configuration or definition verdicts (#364).
Immutable outcome of one Program run attempt.
Host binding for one Program operation.
Exact Program operation requesting a host-owned Core provider broker.
A time a call was matched to its record under another descriptor policy identity than the record name...
A time a resume sent a call that opens a chunked upload's session again, in place of its record (#541...