Pixir.Compaction.NativeReplay (pixir v0.1.14)

Copy Markdown View Source

Store, validate, and inspect history_compaction.data.native_replay (ADR 0040).

Slice C persists a live /responses/compact output as standalone_window. Slice D persists a live stream cmp_ as threshold_item and shares the same overlay preference, late-bound after Provider/backend resolve. Overlay on chatgpt_codex enables D only; standalone C stays local on that 404 host.

Summary

Functions

Capturing identity map used to persist and fold a native window.

Stable fallback_reason tokens (ADR 0040 Decision 2).

Fold-usable predicate for Provider replay.

Bounded inspect projection: mode, usability, item ids, fallback reason.

Accepted native_replay.mode values.

Overlay bit after Provider/backend resolve (ADR 0022 late-bound pattern).

Attach a standalone_window native replay from a compact output list.

Persist a live threshold_item capture without failing the local checkpoint.

Attach a threshold_item native replay window to local checkpoint data.

Replace a checkpoint's native_replay with the inspect projection and drop any encrypted_content keys. Used by CLI --json and diagnostics.

Sanitize a compact/complete result so JSON never prints ciphertext.

Validate a native_replay map for either persist mode.

Functions

capturing_identity(opts)

@spec capturing_identity(keyword()) :: map()

Capturing identity map used to persist and fold a native window.

fallback_reasons()

@spec fallback_reasons() :: [String.t()]

Stable fallback_reason tokens (ADR 0040 Decision 2).

fold_usable?(event_data, current)

@spec fold_usable?(map(), map()) :: boolean()

Fold-usable predicate for Provider replay.

Returns true when native_replay is present, recorded_usable, still validates, and current Provider/backend/dialect/model match the capturing values. Anthropic fold never consults this predicate.

inspect_native_replay(data)

@spec inspect_native_replay(term()) :: map() | nil

Bounded inspect projection: mode, usability, item ids, fallback reason.

Never includes items or encrypted_content. Accepts either checkpoint data or a native_replay map. Returns nil when no native replay is present.

modes()

@spec modes() :: [String.t()]

Accepted native_replay.mode values.

overlay_after_resolve(preference, identity)

@spec overlay_after_resolve(nil | boolean(), map()) :: {:on, nil} | {:off, String.t()}

Overlay bit after Provider/backend resolve (ADR 0022 late-bound pattern).

preference is nil (no preference), true (request on), or false (explicit off). identity carries string provider, backend, dialect, and optional responses_host from the resolved request.

Overlay on is not standalone C. chatgpt_codex enables D (compact_threshold). Official api.openai.com enables D and may POST C. Other open_responses hosts stay local.

persist_standalone_window(local_event_data, output, opts \\ [])

@spec persist_standalone_window(map(), term(), keyword()) ::
  {:ok, map()} | {:error, map()}

Attach a standalone_window native replay from a compact output list.

Persists the entire output array. Reducing that list to cmp_ alone is standalone_window_pruned. Local text checkpoint fields remain mandatory.

persist_threshold_capture(local_event_data, item_or_items, opts \\ [])

@spec persist_threshold_capture(map(), term(), keyword()) ::
  {:ok, map()} | {:error, map()}

Persist a live threshold_item capture without failing the local checkpoint.

Usable singleton cmp_ items are stored as today. Missing, malformed, or forced-fallback captures still return local text plus recorded_usable false.

persist_threshold_item(local_event_data, item_or_items, opts \\ [])

@spec persist_threshold_item(map(), map() | [map()], keyword()) ::
  {:ok, map()} | {:error, map()}

Attach a threshold_item native replay window to local checkpoint data.

item_or_items must be exactly the latest compaction item (type compaction, id matching cmp_…). A full compact output list is rejected as threshold_item_not_singleton — this helper never drops retained items to invent a singleton.

Local text checkpoint fields remain mandatory on the same Event. This does not call the Provider and does not change live Turn ingest.

project_checkpoint_for_inspect(data)

@spec project_checkpoint_for_inspect(map()) :: map()

Replace a checkpoint's native_replay with the inspect projection and drop any encrypted_content keys. Used by CLI --json and diagnostics.

project_compact_result_for_inspect(result)

@spec project_compact_result_for_inspect(map()) :: map()

Sanitize a compact/complete result so JSON never prints ciphertext.

validate_native_replay(native_replay, opts \\ [])

@spec validate_native_replay(
  term(),
  keyword()
) :: {:ok, map()} | {:error, map()}

Validate a native_replay map for either persist mode.

Returns {:ok, normalized} with recorded_usable set. Unusable windows keep the payload and set fallback_reason. Completely unparseable input returns {:error, structured}.

Pass compact_output: when validating standalone_window so a reduced items list (save-only-cmp_) is standalone_window_pruned.