Skip to content

mig: add team memory tables and chat summary flags - #8302

Draft
simplesagar wants to merge 7 commits into
mainfrom
claude/project-thread-jeck5c
Draft

simplesagar wants to merge 7 commits into
mainfrom
claude/project-thread-jeck5c

Conversation

@simplesagar

@simplesagar simplesagar commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

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.

Written for commit 3b6d3b0. Summary will update on new commits.

View guided diff Turn on auto-fix

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011XLiZ9Pjyud5BdXQtZfFVY
@simplesagar simplesagar self-assigned this Oct 30, 2026
@changeset-bot

changeset-bot Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 3b6d3b0

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

atlas migrate lint on server/migrations

Status Step Result
1 new migration file detected 20261030014307_team-memory.sql
ERD and visual diff generated View Visualization
No issues found View Report
Read the full linting report on Atlas Cloud

@github-actions

Copy link
Copy Markdown
Contributor

atlas migrate lint on clickhouse/migrations

Status Step Result
No migration files detected  
ERD and visual diff generated View Visualization
No issues found View Report
Read the full linting report on Atlas Cloud

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

7 issues found across 3 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="server/database/schema.sql">

<violation number="1" location="server/database/schema.sql:6180">
P2: Regenerating a summary in place does not reset `summary_redacted`. Once the background job sets it true, an on-demand summary from the unmasked transcript would still count as redacted and could enter team memory. `UpdateChatSummary` should set `summary_redacted = false`, or the write should be made atomic with the flag, before the background job starts writing it.</violation>

<violation number="2" location="server/database/schema.sql:16516">
P2: `memory_memos.author_agent_id` has no foreign key, so an arbitrary or cross-tenant UUID can be stored. Add a composite FK to `agents (organization_id, id)`, matching the other agent references in this file.</violation>

<violation number="3" location="server/database/schema.sql:16525">
P1: The memory tables duplicate `organization_id`, but their foreign keys validate only `project_id`; the database therefore accepts mismatched organization/project tenants. Use `(organization_id, project_id) REFERENCES projects (organization_id, id)` for both tables.</violation>

<violation number="4" location="server/database/schema.sql:16526">
P1: The memo chat FK does not bind the source chat to the memo's project, so project A can store a memo citing project B's chat. Enforce the chat/project relationship and validate or normalize digest source references before using them for project-scoped memory.</violation>

<violation number="5" location="server/database/schema.sql:16527">
P2: The author contract is not enforced: a memo can have both `author_user_id` and `author_agent_id` set. Add `CHECK (num_nonnulls(author_user_id, author_agent_id) <= 1)` so system memos remain allowed while authored memos have one principal.</violation>

<violation number="6" location="server/database/schema.sql:16573">
P2: Digest token usage accepts negative values, producing invalid model-usage metadata. Add nonnegative checks for both nullable token columns.</violation>

<violation number="7" location="server/database/schema.sql:16583">
P2: The period check permits lengths unrelated to `level`, so an invalid interval can become the unique day, week, or month digest. Enforce each level's canonical UTC boundary and interval shape in the database or a dedicated validation constraint.</violation>
</file>

Reply with feedback, questions, or to request a fix.

View guided diff | Turn on auto-fix | Re-trigger cubic

Comment thread server/database/schema.sql
Comment thread server/database/schema.sql Outdated
Comment thread server/database/schema.sql Outdated
Comment thread server/database/schema.sql
Comment thread server/database/schema.sql
Comment thread server/database/schema.sql
Comment thread server/database/schema.sql
@blacksmith-sh

This comment has been minimized.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011XLiZ9Pjyud5BdXQtZfFVY
… clear them

Atlas drops the SET NULL column list, which would null project_id or
organization_id on a chat or agent delete.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011XLiZ9Pjyud5BdXQtZfFVY
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011XLiZ9Pjyud5BdXQtZfFVY
@blacksmith-sh

This comment has been minimized.

simplesagar commented Oct 30, 2026 •

Copy link
Copy Markdown
Member Author

One check is red: server-test (shard 4/5). In it, internal/litellm TestTracePersistenceKeepsOnlyAllowlistedAttributes gets 0 trace rows where it expects 4. This PR didn't cause it. The test depends on the date: its fixture spans are dated 2026-08-01, and telemetry_logs has a 90-day TTL, so from today ClickHouse drops the rows on insert. Main fails the same way, and #8306 fixes it. I tried porting that fix here, but the migration-isolation check doesn't allow a migration PR to carry other server files, so I reverted it in 3b6d3b0. Once #8306 lands I'll merge main into this branch.


Generated by Claude Code

@blacksmith-sh

This comment has been minimized.

Same change as #8306, ported so this PR's CI can go green; it no-ops once
main carries it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011XLiZ9Pjyud5BdXQtZfFVY
…y TTL"

Migration PRs must not carry other server changes (migration isolation
check). The fix lands on main via #8306.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011XLiZ9Pjyud5BdXQtZfFVY
@blacksmith-sh

blacksmith-sh Bot commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Found 1 test failure on Blacksmith runners:

Failure

Test View Logs
github.com/speakeasy-api/gram/server/internal/litellm/
TestTracePersistenceKeepsOnlyAllowlistedAttributes
View Logs

Fix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants