Skip to content

fix(security): bind conversation history to its workspace and bound it - #37

Merged
homer6 merged 1 commit into
devfrom
fix/35-bound-conversation-history
Nov 16, 2026
Merged

homer6 merged 1 commit into
devfrom
fix/35-bound-conversation-history

Conversation

@homer6

@homer6 homer6 commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

What: ExperimentsAgent now keeps each conversation's history under its workspace as well as its conversation id, and limits how many conversations and how much history the pod holds.
Why: The pod serves every workspace and looked history up by conversation id alone, so another workspace that knew the id could read or write into it, and new ids grew memory without limit (#35, G1 of https://github.com/oramasearch/orama-bridge/issues/273).
How: A small bounded store keyed by (customer, workspace, conversation), with least-recently-used eviction, idle expiry and a size cap per history; turns work on a copy saved back under the lock.

Changes

  • src/agent_experiments/conversations.py (new): ConversationKey (customer id, the checked workspace path lake_url, workspace_id and user_id when the turn has them, conversation id) and ConversationStore: at most 256 conversations, least recently used dropped first; idle expiry after an hour; each history keeps its system prompt plus at most 60 messages and 200,000 characters, dropping the oldest whole exchanges so a tool reply never loses its call.
  • service.py: run_turn checks out a copy of the key's history, passes it to answer_turn, and stores it back whole. The old unbounded State.conversations dict and State.history() are gone.
  • Docs: docs/operations/service.md (Conversation history) and the README.

Lake's side

Lake's own check of the conversation id across workspaces is being fixed separately in lake. This PR makes the agent safe without relying on it.

Tests

New tests/test_conversations.py: workspace B with A's conversation id gets an empty history and cannot write into A's; a turn's copy is not shared; 10,000 conversation ids (directly and through run_turn) stay within the bound; idle expiry; a long history keeps its prompt and newest whole exchanges within the message and character bounds.

The tests were not run and nothing was built (Steve, 2026-11-14: tests run at review and release time).

The shared pod kept every conversation's history in one dict keyed by
conversation id alone, never removed. A turn from another workspace
naming the same id continued that conversation, and new ids grew the
pod's memory without limit. The list was also mutated outside the lock.

- New conversations.ConversationStore keyed by customer, checked
  workspace path, workspace and user ids, and conversation id.
- At most 256 conversations (least recently used dropped), an hour of
  idle time, and 60 messages and 200,000 characters per history after
  its system prompt, dropping whole exchanges.
- A turn works on a copy and saves it back whole under the lock.

Refs #35
@homer6

homer6 commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

Merged into dev as a merge commit (825daaaa) on Steve's review (2026-11-15). Low risk, on Steve's 2026-11-15 instruction to merge the low-risk PRs. Not built or tested in review (tests run at the release cut).

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.

1 participant