Session Orchestration

The saved records that let a session's chat orchestrate its graphs: the call pool, the directives its turns sent, and settlement events.

Session orchestration records make a session's chat turns act as its Orchestrator: one row with the provider-call pool, the directives each turn sent, the user's pool extensions, and the graph settlements the chat should hear about. ag-store keeps them, so a directive is applied at most once and a settlement is announced once across restarts. They are deleted with their session.

Lifecycle🔗

stateDiagram-v2
  [*] --> pending: turn saved
  [*] --> refused: turn saved
  pending --> applied
  pending --> refused
  pending --> awaiting_confirmation: cancel
  awaiting_confirmation --> confirmed
  awaiting_confirmation --> declined
  awaiting_confirmation --> refused: moot, restart, switch off, or refused cancel

The diagram shows what can happen to one directive after its turn is saved.

Records🔗

  • Orchestration: inserted once, in the transaction that approves the session's first graph proposal, with a pool of 200 provider calls, the calls the chat allotted, and enabled_at, when the session first orchestrated. Later approvals and canceled proposals change nothing. is_enabled is the orchestrator's switch and switched_on_at when it last went on. It also keeps the automatic turns counted in the current row, whether their stop was announced, and whether automatic turns are on for the session (is_automatic_turn_enabled), which they are by default.
  • Automatic turn: one per batch in session_orchestration_automatic_turn, queued until the turn persists (finished), or until it fails, is stopped or skipped, or a restart ends it (released), with whether it counts toward the row and when it ended. Its events carry its batch as claimed_batch_id from the moment it is queued, and its directives carry it too. The bounds are SessionOrchestration::AUTOMATIC_TURN_EVENTS, AUTOMATIC_TURN_CALLS, AUTOMATIC_TURN_CAP, and AUTOMATIC_TURN_EVENT_MAX_AGE_SECONDS.
  • Pool extension: one record per action ID of the user's terminal-only ExtendSessionCallPool, so a redelivery adds nothing; the pool includes every extension.
  • Directive: the batch and position of one directive, its resolved target, its state and detail, and whether a later brief reported its latest state.
  • Event: a node that succeeded, failed, or asked, or a graph that completed, with its execution or revision, a cleaned excerpt of at most 1024 bytes, its chat notice, whether it was announced, and the turn that claimed it.

Guarantees🔗

  • A pending directive is applied at most once. Startup refuses every directive a restart left pending or awaiting confirmation, and a failed refusal fails startup.
  • set_session_orchestration_enabled writes is_enabled and is_automatic_turn_enabled together in one transaction, which on the way off also refuses the session's unsettled directives with the query startup uses; switching on sets switched_on_at and never moves enabled_at.
  • The transaction that persists a turn reads the switch.
  • A second cancel of an execution already asked about is refused, and a cancel whose execution ended before the answer closes as refused.
  • An outcome counts as reported only while it still holds the state the brief showed.
  • A structural directive allots exactly its new graph's budget from the pool, and an extension allots its calls and records the graph's budget extension, each in one transaction.
  • Events are unique by session, kind, graph, node, and execution or revision, so a repeated reconcile, also from a second process, records nothing. Only executions created since enabled_at count, and only while the switch is on and when the execution's run finished at or after switched_on_at or has not finished; a canceled or withdrawn node records none, a graph whose every execution is older records no completion, and a settlement not stored yet waits for a later reconcile.
  • A reconcile reads node results only for settlements not recorded yet and writes nothing when none is new.
  • One transaction marks an event announced and appends its notice, so each notice is written exactly once, and a notice that fails to be written stays for the next reconcile.
  • A turn claims exactly the events its brief listed when it persists; a turn that fails first leaves them for the next. One transaction queues an automatic turn, counts it, allots its calls from the pool, and claims its events, and startup releases every automatic turn a previous run left queued. An event of a kind this version does not know stays unclaimed.