Skip to main content

Module runtime

Module runtime 

Source
Expand description

The advisor runtime — drives the advisor agent from primary transcript deltas. Ported from omp AdvisorRuntime (runtime.ts).

Each primary turn, the host calls AdvisorRuntime::on_turn_end with the (new) transcript. The runtime renders a delta (messages added since the last drain) and feeds it to the advisor agent’s prompt(). Accepted advice flows back through the host’s enqueue_advice callback (the host owns the crate::advisor::emission_guard::AdvisorEmissionGuard and the delivery channel decision).

§Concurrency

omp’s drain loop is safe only because JS’s event loop serializes the synchronous segment between “queue empty? stop” and “release the busy flag”. tokio’s multithreaded runtime breaks that: a concurrent on_turn_end on another worker can push + spawn a drain in the gap, and that spawned drain bails (busy still set) leaving the queue non-empty with no drain running — a lost-wakeup stall. The fix folds the “draining” role into the same lock that guards the pending queue, so “decide-to-stop” and “push-new-work + spawn” are each one atomic critical section (design doc §9.2). The catchup-waiter path has the same race and the same fix (register + check backlog under one lock).

§Attribution

Translated to Rust from omp (oh-my-pi), MIT licensed.

Structs§

AdvisorRuntime
Drives the advisor agent. Construct via AdvisorRuntime::new, wrap in Arc, then call AdvisorRuntime::install_self so it can self-spawn its drain task.

Traits§

AdvisorAgent
Minimal slice of an agent the runtime drives. omp AdvisorAgent. Satisfied by oxicode_agent::Agent via a host adapter; tests hand-roll a fake.
AdvisorRuntimeHost
Host callbacks the runtime needs. omp AdvisorRuntimeHost.