Module: Insika::Commands::SessionPurge

Included in:
DeleteTenantData, ForgetCustomer
Defined in:
lib/insika/commands/session_purge.rb

Overview

The CONVERSATION footprint of a session, purged (WS8/LGPD). Shared by forget_customer and delete_tenant_data because "erase this person" and "erase this tenant" differ only in WHICH sessions they name — what a session leaves behind is the same list, and a second copy of that list is a second thing to forget to update.

Deleting the session record alone is NOT erasure: the customer's own text lives in the task's persisted command payload, the whole transcript lives in the turn's checkpoints, and the answer as it was handed to the channel lives in the outbox record's payload. All four go together or none of them counts.

A task is deleted whatever its status — this is a deletion order, not the retention sweep (which spares live tasks on purpose). The stores it needs beyond the session are optional (deployment components): a graph without them purges what it has and reports zero for the rest.

Instance Method Summary collapse

Instance Method Details

#purge_sessions(ids) ⇒ Object

ids: the session ids to erase. -> { tasks:, checkpoints:, deliveries:, pairs: }



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/insika/commands/session_purge.rb', line 23

def purge_sessions(ids)
  ids = Array(ids).map(&:to_s)
  return { tasks: 0, checkpoints: 0, deliveries: 0, pairs: 0 } if ids.empty?

  tasks, checkpoints, model_visible = purge_tasks_of(ids)
  deliveries = @outbox_store ? @outbox_store.purge_sessions(ids) : 0
  pairs = @shadow_pairs ? @shadow_pairs.purge_sessions(ids) : 0
  ids.each do |id|
    @tool_trace_store&.clear(id)
    @context_trace_store&.clear(id)
    @session_store.delete(id)
  end
  { tasks: tasks, checkpoints: checkpoints, model_visible: model_visible,
    deliveries: deliveries, pairs: pairs }
end