Skip to content

Durable Conversation Identity

Everything durable the agent does — promises it must keep, attention items, restart notices, conversation memory — files under a numeric conversation id. Telegram conversations have one natively (the topic id); Slack conversations did not. Under the hood a Slack conversation was a throwaway routing string, and three separate copies of a hash function each improvised a number from it — in-memory only, collision-blind, and not even agreeing with each other (two of the copies hashed the channel id, one hashed the thread-aware routing key). The consequence: a promise made in a Slack thread died on the next server restart, because there was nothing durable to attach it to.

The conversation registry (ConversationRegistry) fixes the root. It is a sparse join table between three representations of a conversation: the canonical key (slack:<teamId>:<channelId>[:<threadTs>], a normalized lookup string), the structured tuple (platform, channelId, threadTs? — the actual identity), and the minted id (a stable NEGATIVE integer). Telegram topics are never registered — a positive id passes through verbatim, forever, which is what makes the whole design backward-compatible by construction. Every existing topicId field keeps its type; only its value domain widens.

A new conversation’s id candidate is the value the legacy hash would have produced — deliberately, because that buys zero-loss adoption of everything already written down under the old improvised numbers, and lets an old server and a new server compute identical ids during an upgrade window with no coordination. The registry’s job is what the hash could never do: detect the rare collision (two conversations hashing to one number would silently share state today) and probe DOWN to the next free id through one shared, frozen displacement rule, bounded at 64 steps. Mint is idempotent per tuple, gated behind authorized senders, and rate-limited per channel by a breaker whose durable-binding carve-out has its own budget and a typed refusal at the cap — never a silent drop.

Durability is a write-ahead log, not a hot-path file rewrite. A probed or durable-binding-forced mint appends and fsyncs ONE journal line (conversation-registry.jsonl, at the state-dir root so the deployed backup glob machinery actually captures it) before the id is handed to a consumer; the O(N) JSON snapshot is batched off the hot path with a size-adaptive interval — the exact opposite of the whole-file-write-per-mutation pattern that once froze production. Replay composes snapshot + tail in one global monotonic sequence across rotations and restarts. A torn tail (crash mid-append) is discarded as uncommitted; a corrupt line in the middle of the journal HALTS recovery loudly and preserves the file aside (a committed record is never silently skipped); a record from a NEWER version after a rollback is skipped-and-preserved, and snapshot flushing suspends until a recognizing version replays it in position — so a rollback stay can never bake a future record’s effects into the wrong state.

Recording is always-on foundation once shipped (behavior-identical: same ids, now durable, resolvable, and collision-checked), with an emergency kill-switch — conversationIdentity.recording.enabled: false degrades to today’s in-memory hashing without a redeploy. The Slack inbound dispatch eagerly mints (get-or-create) the conversation id on every message and carries it into the session’s bootstrap context as conversationId, so durable state finally has something real to bind to. DELIVERY to minted ids — the deliverToConversation funnel that will carry commitments, beacons, attention items, and reap notices to Slack — ships as a dark, dev-gated skeleton (conversationIdentity.followThrough, dry-run first): a non-delivery is always a typed, non-exceptional result, never success-shaped, so nothing can silently swallow a promise while the rollout ladder climbs.

The read surface is GET /conversations (inventory + alias table), GET /conversations/:id (resolution; positive ids answer as Telegram pass-through), GET /conversations/resolve (forward lookup that mints nothing), and GET /conversations/health — entry counts, origins, quarantine and snapshot-suspension state, and the growth tripwire that fires well before the JSON store’s ceiling.