Skip to content

Tick Loop

Raul Montoya Cardenas edited this page Jul 29, 2026 · 2 revisions

Tick Loop

Wiki hero

Generated with Grok Build: Grok 4.5 · xAI Imagine (/imagine)

Core orchestration in src/daemon.rs (run_tick + BrainstemDaemon::run).

Interval Setup

tick_duration = 1e9 ns / tick_rate_hz
MissedTickBehavior::Skip

Invalid tick_rate_hz (0 or > 1_000_000) aborts run() with an error.

Per-Tick Pipeline

  1. Ingresssource.next_ingress()
    • Ok(Some(packet)) → use packet
    • Ok(None) → empty stimuli packet, still step
    • Err → warn and return early (no step/emit this tick)
  2. Decodedecode_inputs(packet, &mut stimuli)
    • Copy min(len) floats into channel buffer; zero-fill remainder
    • Modulators: if Some and len >= 4, map to NeuroModulators { dopamine, cortisol, acetylcholine, tempo, aux_dopamine: 0 }
    • Else NeuroModulators::default()
  3. Networknetwork.step(stimuli, &modulators)
    • On error: log and return early
  4. Encode spikes — map neuron indices → SpikeEvent { channel: u16, time, strength: 1.0 }
    • Shared wall-clock millis truncated into u32 for time
    • Drop IDs that do not fit u16 (warn)
  5. Emitsink.emit(spike_buf, now) even if empty (stable per-tick cadence for consumers/tests)

Shutdown

On Ctrl+C:

  1. Break loop
  2. backend.sink.flush()
  3. backend.source.shutdown()
  4. Return Ok(())

Test Hook

run_tick_for_test is pub(crate) under #[cfg(test)] so unit tests drive one tick without exposing run_tick publicly.

Related


Last updated: July 28, 2026 Updated by: Grok Build: Grok 4.5 Package tip reference: 8176c58 (main)

Clone this wiki locally