| Stage | Behavior |
| First accepted batch | Creates a session with creation and expiry timestamps. The expiry is 30 days after creation, not 30 days after the original agent activity. |
| Additional batches | Append or deduplicate events without moving the expiry timestamp. |
| Expiry | Session reads and listings stop returning the session. MCP searches and derived activity queries exclude expired sessions. Further ingestion into that session returns 410. |
| Retention cleanup | Removes expired session events and clears titles. A minimal removed-session record remains so replays cannot recreate the same session ID. |
12span login span unshare --session 6b2863cf-ce34-405e-af75-27748912d239
span share while signed in with the authorized sharer identity, or the API's explicit reshare route. Resharing sends the events again and starts a new 30-day lifetime. Normal ingestion does not restore an unshared session.| Action | Shared events and title | Can the same session ID return? | Local transcript |
| Unshare | Deleted and hidden. | Yes, through explicit resharing before the old expiry. | Kept. |
| Forget | Deleted and marked removed. | No. | Kept. |
| Expire | Hidden at expiry; deleted by the retention job. | No. | Kept. |
span remove | Unchanged. | Existing sharing stays available until removed or expired. | Kept. |
span logout | Unchanged. | Existing sharing stays available until removed or expired. | Kept. |
123just go-build HALFSPAN_TELEMETRY_DATABASE_URL="$TELEMETRY_DATABASE_URL" \ services/bin/agent-retention workspace-id
HALFSPAN_CLICKHOUSE_URL, HALFSPAN_CLICKHOUSE_DATABASE, HALFSPAN_CLICKHOUSE_USER, and HALFSPAN_CLICKHOUSE_PASSWORD on the API and retention processes, then run just clickhouse-init with schema-owner credentials. Use separate scoped runtime credentials for reads and maintenance. Deployment and migration instructions are in infra/observability/storage.md.services/bin/agent-retention --copy-events-to-clickhouse workspace-id. The command verifies source and destination checksums and can be rerun. Existing S3 event chunks remain readable as a fallback and are removed with ClickHouse copies during normal session cleanup. Artifact content continues to use S3.HALFSPAN_ARCHIVE_BUCKET_URL to a private bucket URL, for example https://my-bucket.s3.us-east-1.amazonaws.com. Supply HALFSPAN_ARCHIVE_REGION, HALFSPAN_ARCHIVE_ACCESS_KEY_ID, and HALFSPAN_ARCHIVE_SECRET_ACCESS_KEY to the API and retention processes. Temporary credentials also use HALFSPAN_ARCHIVE_SESSION_TOKEN. The API reads objects. The retention process needs permission to conditionally create, read, and delete them. Keep the bucket private and use an unversioned bucket for physical deletion, or configure expiry of noncurrent object versions.events/v1/ prefix, with allowance for in-flight writes. Keep the archive endpoint and credentials available to readers for the lifetime of compacted sessions.artifacts/v1/ prefix. An upload requires a redacted capture record, the producing sharer or workspace admin, and bytes matching the event's SHA-256 digest. Identical bytes share an object within a tenant. Each producing event keeps its own reference. Removing a session drops its references. The worker deletes the object after the last reference is removed, so use reference-based deletion for this prefix. A later session can keep an artifact active beyond 30 days from its initial upload.workspace to the authorized organization ID. The first query reports eligible events still waiting for a chunk. The second shows verification progress, stored bytes, and objects waiting for deletion.12345678910111213BEGIN; SELECT set_config('halfspan.organization_id', :'workspace', true); SELECT count(*) AS eligible_events, min(e.journaled_at) AS oldest_eligible FROM agent_events e JOIN agent_sessions s ON s.organization_id=e.organization_id AND s.id=e.session_id WHERE e.organization_id=:'workspace' AND e.archive_id IS NULL AND e.journaled_at <= now() - interval '5 minutes' AND NOT s.deleted AND s.expires_at > now(); SELECT state, discard AS awaiting_deletion, count(*) AS chunks, sum(event_count) AS events, sum(stored_bytes) AS compressed_bytes FROM agent_archives WHERE organization_id=:'workspace' GROUP BY state, discard ORDER BY state, discard; COMMIT;