kimaai_chatbot_session_retention_before_cleanup

When it fires

When a run of the conversation cleanup goes ahead: after kimaai_chatbot_session_retention_should_run let it and the run took its lock, before the first batch is deleted. The run then deletes the conversations whose last message is older than cutoffTimestamp, batch by batch, until none is left or a batch fails.

The action is the place to keep a copy of what is about to go, for example in an archive of your own: read the conversations whose last message is older than $context['cutoffTimestamp']. It cannot stop the run; use kimaai_chatbot_session_retention_should_run for that.

Parameters

NameTypeDescription
contextarraysource (schedule or fallback), settings, mode, effectiveDays and cutoffTimestamp, the date and time (“Y-m-d H:i:s”, site time zone) before which conversations count as old.

Example

add_action(
  'kimaai_chatbot_session_retention_before_cleanup',
  function (array $context): void {
    error_log(sprintf('KimaAI deletes the conversations older than %s (%s)', $context['cutoffTimestamp'], $context['source']));
  }
);
  • kimaai_chatbot_session_retention_after_cleanup: fires after the run with what it deleted.
  • kimaai_chatbot_session_retention_should_run: pauses a run.

What are your feelings