|
Entropic 2.14.3
Local-first agentic inference engine
|
gh#144 (v2.12.0): RAII turn claim + log scope, for the RUN paths. More...
#include </home/runner/work/entropic/entropic/src/facade/engine_handle.h>
Public Member Functions | |
| HandleTurnGuard (entropic_handle_t h, const char *session_key=nullptr) | |
| Enter the handle's log scope. | |
| ~HandleTurnGuard () | |
| Release the turn if this guard claimed it. | |
| HandleTurnGuard (const HandleTurnGuard &)=delete | |
| HandleTurnGuard & | operator= (const HandleTurnGuard &)=delete |
| bool | claim () |
| Claim the turn. | |
| const std::string & | key () const |
| The session this guard claims for. | |
| bool | claimed () const |
| Whether this guard owns the turn. | |
gh#144 (v2.12.0): RAII turn claim + log scope, for the RUN paths.
Sibling of HandleApiLock, and deliberately NOT built on it. HandleApiLock takes api_mutex; gh#109 removed that mutex from all six run entry points precisely so a long turn could not block entropic_interrupt() called from another thread. Reusing it here would silently re-break gh#109, which is the single mistake this refactor is most likely to make — hence a separate type rather than a subclass or a flag.
The claim is one compare-exchange on the engine's running_flag_. A second thread interrupting a 40-second turn still touches only atomics.
Usage at every run entry point:
gh#158 (v2.13.0): the claim is scoped to a SESSION KEY. The keyed run entry points pass theirs; the unkeyed ones claim the default session, which is what they have always effectively done. Whether a second key may proceed concurrently is the engine's decision (concurrent_sessions), not the guard's — the guard only makes sure the key it claims is the key it releases.
Holding the claim across the WHOLE entry point — not just the engine call — is the point: the facade serialises results out of the same conversation the engine appends to, so releasing early would let a second thread mutate that vector mid-read. That is the race gh#144 reported.
@req REQ-API-009
Definition at line 443 of file engine_handle.h.
|
inlineexplicit |
Enter the handle's log scope.
Does NOT claim the turn.
Construction is deliberately side-effect-free beyond logging so the guard can be declared ahead of argument validation; claim() is then evaluated last in the precondition chain. A call that is going to be rejected for a null argument must not momentarily claim the engine and bounce a legitimate concurrent caller.
Null-handle safe: log id 0 is the reserved "no handle scope" sentinel.
| h | Engine handle, possibly null. |
| session_key | Session this guard claims for (gh#158), and publishes to this thread for the call's duration (gh#166). |
Definition at line 461 of file engine_handle.h.
|
inline |
Release the turn if this guard claimed it.
Definition at line 476 of file engine_handle.h.
|
inline |
Claim the turn.
Idempotent for one guard.
Definition at line 490 of file engine_handle.h.
|
inline |
Whether this guard owns the turn.
@utility
Definition at line 510 of file engine_handle.h.
|
inline |
The session this guard claims for.
"" for the default session. @utility Definition at line 503 of file engine_handle.h.