Services.BgIndexingControl (fnord v0.9.29)

View Source

Session-local (per BEAM node) control plane for pausing background indexing on a per-model basis.

Why this exists

Background indexing is a convenience feature. When OpenAI starts returning throttling responses (HTTP 429 with a recognized throttling code), we can disable background indexing for the affected model(s) to reduce load.

This module is intentionally:

  • model-agnostic: any model string encountered can be tracked
  • boolean-only: models are either paused or not paused (no timers)
  • session-local: state is stored in Services.Globals and seeded idempotently

State

Stored in Services.Globals under the :fnord app:

  • :bg_indexer_paused_models => %{model => true}
  • :bg_indexer_throttle_counts => %{model => consecutive_throttles}
  • :bg_indexer_throttle_threshold => integer (default: 3)

Summary

Functions

Reset the consecutive throttling count for the model back to 0.

Increment the consecutive throttling count for the model.

Functions

clear_pause(model)

@spec clear_pause(binary() | nil) :: :ok

ensure_init()

@spec ensure_init() :: :ok

note_success(model)

@spec note_success(binary() | nil) :: :ok

Reset the consecutive throttling count for the model back to 0.

Returns :ok and ignores nil models.

note_throttle(model)

@spec note_throttle(binary() | nil) :: :ok

Increment the consecutive throttling count for the model.

If the count reaches the configured threshold, the model is paused.

Returns :ok and ignores nil models.

pause(model)

@spec pause(binary() | nil) :: :ok

paused?(model)

@spec paused?(binary() | nil) :: boolean()

set_threshold(n)

@spec set_threshold(non_neg_integer()) :: :ok

threshold()

@spec threshold() :: non_neg_integer()