Skip to main content
A candidate binds host intent to a reusable read, probability, horizon, and cost. Cogni then admits, orders, deduplicates, cancels, and measures the work.

Candidate fields

PredictionCandidate makes the decision inspectable: Malformed candidates throw TypeError before admission.

Admission and deduplication

predict(candidate, loader) returns immediately. Inspect accepted before assuming work entered the queue:
Defaults are 0.8 for ordinary work, 0.9 for high-cost work, two loaders, and 16 queued items. Matching keys return the active handle with deduplicated: true. Queued work sorts by priority, probability, then insertion order.

Lifecycle

waiting_for_reuse separates completion from usefulness. The host must report consumption before the horizon ends. The corresponding events are:
  • accepted when the candidate enters active work;
  • started immediately before Cogni calls the loader;
  • loaded when the loader resolves;
  • reused when the host reports that committed work consumed the same resource;
  • missed, failed, cancelled, or expired at terminal completion;
  • rejected when admission fails; and
  • deduplicated when an existing active key is reused.
onEvent failures are isolated from the lifecycle.

Mark reuse

Call handle.markReused() only when the committed action reads the same cached representation. Reuse reported during loading finalizes after completion. Reuse while still queued becomes superseded_by_committed_action. Do not mark reuse for these cases:
  • the foreground action fetched a different cache key or payload shape;
  • the predicted entry expired or was invalidated first;
  • navigation changed to another destination; or
  • the application merely observed that the prediction request completed.

Cancellation

Cancel through the handle or stable key:
Active loaders receive an aborted signal. dispose() uses coordinator_disposed; host cancellation uses cancelled_by_host.

Measure quality

quality(filter?) reads bounded terminal history filtered by cost, destination, policy, or trigger.
History retains 1,000 terminal outcomes by default. Persist events in host telemetry for durable or cross-user analysis.

Continue