Skip to content

Isolate memory by channel/chat to prevent cross-chat leakage#23

Open
lawyered0 wants to merge 2 commits into
louisho5:mainfrom
lawyered0:codex/fix-memory-scope-isolation
Open

Isolate memory by channel/chat to prevent cross-chat leakage#23
lawyered0 wants to merge 2 commits into
louisho5:mainfrom
lawyered0:codex/fix-memory-scope-isolation

Conversation

@lawyered0
Copy link
Copy Markdown

Summary

This PR closes a critical data-isolation issue by scoping agent memory per channel + chatID.

Critical issue addressed

Memory context was previously shared across chats, which allowed data from one conversation to leak into another conversation’s prompt context.

What changed

  • Updated internal/agent/loop.go:
    • Memory store selection now scopes by sanitized channel and chatID for all channels, including cli.
    • Per-message memory context and recent memories now come from the scoped store.
    • write_memory tool is pointed at the active scoped memory store before tool execution.
  • Updated internal/agent/tools/write_memory.go:
    • Added runtime store switching support (SetStore) with synchronization.
  • Added regression coverage in internal/agent/loop_memory_scope_test.go:
    • verifies isolation for Telegram chat IDs
    • verifies isolation for CLI chat IDs
  • Updated related tests to use scoped reads and temp workspaces:
    • internal/agent/loop_processdirect_test.go
    • internal/agent/loop_remember_test.go
    • internal/agent/loop_write_memory_test.go
    • plus other loop tests using explicit temp workspaces for isolation hygiene.

Validation

  • go test ./internal/agent -run "MemoryIsScoped|RemembersToday|ExecutesWriteMemoryToolCall" -count=1
  • go test ./internal/agent/tools -run WriteMemory -count=1
  • go test -race ./internal/agent -run "MemoryIsScoped|RemembersToday|ExecutesWriteMemoryToolCall|ProcessDirectExecutesToolCall" -count=1
  • go test ./...

@louisho5 louisho5 added security Belongs to security related features enhancement New feature or request and removed security Belongs to security related features labels Feb 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants