Skip to content

feat: consolidate chat memories with caps (experiment) - #29297

Closed
f0ssel wants to merge 32 commits into
f0ssel/chat-project-memoriesfrom
f0ssel/chat-memory-consolidation
Closed

f0ssel wants to merge 32 commits into
f0ssel/chat-project-memoriesfrom
f0ssel/chat-memory-consolidation

Conversation

@f0ssel

@f0ssel f0ssel commented Sep 14, 2026 •

Copy link
Copy Markdown
Member
  • Experiment, stacked on feat: add shared project memory API for chats in a project #29301. UI is in feat: add chat project folders to the sidebar #29583.
  • Adds consolidation of project memory that runs only when a project hits the 200-memory cap, after FinishTurn, at most once an hour per project (chat_projects.memory_consolidated_at, set before the model call so failures are rate-limited too).
  • The model sees the name and description index only and returns names to delete and {keep, drop} merge groups; it never writes memory text.
  • Apply runs in one transaction under the per-project advisory lock: dropped bodies are appended verbatim to the kept memory (a drop that would exceed 8 KiB is left in place), then dropped and deleted rows are removed. Runs are logged, not journaled.

Generated with Coder Agents on behalf of @f0ssel.

@f0ssel f0ssel added the experimental Changes that might not necessarily be merged, until its approved to proceed with. label Sep 14, 2026
@github-actions

github-actions Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Docs preview

Check off each page once it's been reviewed. If a page changes in a later push, its checkbox clears automatically so it gets a fresh look. Pages not yet wired into the docs navigation aren't listed here.

@f0ssel
f0ssel force-pushed the f0ssel/chat-user-memories branch from 0c69c28 to b5b2f14 Compare September 14, 2026 18:00
@f0ssel
f0ssel force-pushed the f0ssel/chat-memory-consolidation branch from 16e5201 to 824d636 Compare September 14, 2026 18:01
@f0ssel
f0ssel force-pushed the f0ssel/chat-user-memories branch from b5b2f14 to 53fcc19 Compare September 14, 2026 19:22
@f0ssel
f0ssel force-pushed the f0ssel/chat-memory-consolidation branch from 824d636 to c99d1ef Compare September 14, 2026 19:22
@f0ssel

f0ssel commented Sep 14, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-21T23:21:02.635315Z a45efbe Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c99d1efeed

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread coderd/x/chatd/memory_consolidate.go Resolved
Comment thread coderd/x/chatd/memory_consolidate.go Resolved
Comment thread coderd/x/chatd/memory_consolidate.go Resolved
Comment thread coderd/x/chatd/ARCHITECTURE.md Resolved
@f0ssel
f0ssel force-pushed the f0ssel/chat-user-memories branch from 53fcc19 to 4a251f2 Compare September 15, 2026 15:58
@f0ssel
f0ssel force-pushed the f0ssel/chat-memory-consolidation branch from c99d1ef to 5c67ac9 Compare September 15, 2026 15:58
@f0ssel
f0ssel force-pushed the f0ssel/chat-user-memories branch from 4a251f2 to 2ec2d16 Compare September 15, 2026 16:21
@f0ssel
f0ssel force-pushed the f0ssel/chat-memory-consolidation branch from 5c67ac9 to 57d338d Compare September 15, 2026 16:21
@f0ssel
f0ssel force-pushed the f0ssel/chat-user-memories branch from 2ec2d16 to 8e9e951 Compare September 15, 2026 22:53
@f0ssel
f0ssel force-pushed the f0ssel/chat-memory-consolidation branch from 57d338d to 63f9abe Compare September 15, 2026 22:54
@f0ssel
f0ssel force-pushed the f0ssel/chat-user-memories branch from 8e9e951 to cb5979d Compare September 16, 2026 14:52
@f0ssel
f0ssel force-pushed the f0ssel/chat-memory-consolidation branch from 146d221 to 97427a1 Compare September 16, 2026 14:52
@f0ssel
f0ssel force-pushed the f0ssel/chat-user-memories branch from cb5979d to 8e6a51d Compare September 16, 2026 15:38
@f0ssel
f0ssel force-pushed the f0ssel/chat-memory-consolidation branch from 97427a1 to 02e868b Compare September 16, 2026 15:39
@f0ssel f0ssel changed the title feat: put the memory index in read_memory and consolidate memories with caps (experiment) feat: consolidate chat memories with caps (experiment) Sep 16, 2026
@f0ssel
f0ssel force-pushed the f0ssel/chat-user-memories branch from 8e6a51d to 11b612f Compare September 17, 2026 16:44
@f0ssel
f0ssel force-pushed the f0ssel/chat-memory-consolidation branch from 02e868b to 51ababa Compare September 17, 2026 16:45
@f0ssel

f0ssel commented Sep 17, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 51ababaa32

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread coderd/x/chatd/memory_consolidate.go Resolved
Comment thread coderd/x/chatd/memory_consolidate.go Resolved
Comment thread coderd/x/chatd/memory_consolidate.go Resolved
Adds the user-scoped memory table keyed by (user, organization), the
chat_user_memory RBAC resource with owner-scoped member permissions, the
chat_personal_memory_enabled user config, and renames the extraction
cursor table to chat_memory_cursors since it serves both scopes.
Memory tools, index rendering, and post-turn extraction now work against a
MemoryStore interface with project and personal adapters. A root chat in a
project uses project memory; a root chat without one uses the owner's
personal memory for that organization unless they disabled it. Tools are
renamed read_memory, save_memory, and delete_memory since the scope is
implicit.
…toggle

Exposes the caller's personal memories at /api/experimental/chats/memories
and the per-user enable flag at /chats/config/user-memory, with SDK
methods, audit entries, and cross-replica cache invalidation for the
toggle.
…onsolidation

Sharing is out of the stack; the consolidation migration returns to 000600.
@f0ssel

f0ssel commented Sep 21, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4dec64beb1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread coderd/x/chatd/memory_consolidate.go Resolved
…to f0ssel/chat-memory-consolidation

# Conflicts:
#	coderd/x/chatd/memory_extract.go
@f0ssel

f0ssel commented Sep 21, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 92413ebe09

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread coderd/x/chatd/memory_consolidate.go Resolved
@f0ssel

f0ssel commented Sep 21, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b19f1b438a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread coderd/x/chatd/memory_consolidate.go Resolved
Comment thread coderd/x/chatd/memory_consolidate.go Resolved
Comment thread coderd/x/chatd/memory_consolidate.go Resolved
Comment thread coderd/chat_memory_consolidations.go Resolved
…d runs at the cap, and record empty applies as skipped
@f0ssel

f0ssel commented Sep 21, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a0f8003bac

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread coderd/x/chatd/memory_consolidate.go Resolved
Comment thread coderd/x/chatd/memory_consolidate.go Resolved
Comment thread coderd/x/chatd/memory_consolidate.go Resolved
@f0ssel

f0ssel commented Sep 21, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 945764c9b5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread coderd/x/chatd/memory_consolidate.go Resolved
@f0ssel

f0ssel commented Sep 21, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a45efbe762

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

return
}
call := resolved.newObjectCall("memory_consolidation", "Choose memories to delete or merge.", memoryConsolidationMaxOutputTokens)
call.Prompt = quickgenPrompt(memoryConsolidationPrompt, chattool.FormatMemoryIndexForTool(entries))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep untrusted descriptions out of destructive model plans

When a stored memory description contains prompt-injection text, this places it verbatim in the user message that decides which rows to delete or merge. NormalizeMemoryText preserves ordinary instructions and newlines, while planMemoryConsolidation only verifies that returned names exist, so a crafted description can induce the model to name unrelated memories and the Chatd-scoped apply transaction will delete them. Treat descriptions as untrusted data and avoid using an unreviewed model response as authorization for destructive mutations.

Useful? React with 👍 / 👎.

@f0ssel

f0ssel commented Sep 21, 2026

Copy link
Copy Markdown
Member Author

Closing: consolidation is replaced by the in-turn contract in #29301 (save_memory warns from 180 memories and, at the cap, tells the agent to delete or fold in the same turn), mirroring how Claude Code handles its MEMORY.md limit. No background cleanup ships in this round.

@f0ssel f0ssel closed this Sep 21, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 21, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

experimental Changes that might not necessarily be merged, until its approved to proceed with.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant