mig: add team memory tables and chat summary flags

Draft
SI
3h ago
+343-2

Requested by Sagar · project thread

Summary

Schema for team chat memory in the Platform MCP. DDL only; nothing reads or writes these yet.

  • chats.summary_redacted (bool, default false): set when summary came from the risk-redacted transcript via the upcoming background summary job. Memory only reads summaries where this is true, so older on-demand summaries (built from unmasked transcripts) never reach it.
  • chats.memory_excluded_at (nullable timestamptz): per-chat opt-out from team memory.
  • memory_memos: facts an agent saves on purpose (remember tool). Org + project scoped, optional source chat, author user or agent, redacted content (1 to 4000 chars), generated english tsvector with a GIN index.
  • memory_digests: day, week and month rollups. Half-open [period_start, period_end), typed source arrays (chat_ids, memo_ids, child_digest_ids), model + token counts for cost tracking, generated tsvector with a GIN index, unique on (project_id, level, period_start), and a GIN index on chat_ids so digests citing a chat can be rebuilt.
  • Regenerated sqlc models (chats gains two fields).

No index on chats.summary yet. That would be a concurrent index on a hot table and force a non-transactional migration, so search computes the vector on the fly inside its project + time filter for now.

Motivation

Agents on the Platform MCP lose all context between sessions. This lays the storage for shared, masked team memory: background chat summaries, saved memos, and period digests. The feature lands in later PRs behind a flag.

Open questions (defaults picked, not blocking this schema):

  • Team boundary = project.
  • memory:read / memory:write stay out of every system role by default, like chat:read.
  • Opt-out is per chat; individual memos can be soft-deleted.

The migration file and atlas.sum are pending: they will be generated by atlas migrate diff and committed before this leaves draft.


Generated by Claude Code


Summary by cubic

Adds the database schema for shared, masked team memory in the Platform MCP so agents retain context across sessions. DDL only — nothing reads or writes these tables yet.

Schema

  • Adds chats.summary_redacted and chats.memory_excluded_at; memory readers only consume summaries marked redacted (from the upcoming background summary job) and skip excluded chats.
  • Adds memory_memos for facts saved via the remember tool — project-scoped, optional source chat, redacted content, generated English tsvector with GIN index.
  • Adds memory_digests, day/week/month rollups with half-open [period_start, period_end) periods, typed source arrays (chat_ids, memo_ids, child_digest_ids), and model/token counts for cost tracking.
  • Memo chat and agent foreign keys are single-column so a hard delete can SET NULL just that column; a composite key would also null the NOT NULL project_id or organization_id (Atlas doesn't model Postgres 15's column-list SET NULL).
  • Checks constrain author cardinality, digest levels, canonical UTC periods, and non-negative tokens.
  • Regenerated sqlc models pick up the two new chats fields.
  • chats.summary gets no index yet — a concurrent index on that hot table would force a non-transactional migration, so search computes the vector on the fly.
  • Migration file and atlas.sum are generated and committed.