DO NOT MERGE: feat(ai): ensure data is stored correctly for gen-ai COMPASS-10314#7772
DO NOT MERGE: feat(ai): ensure data is stored correctly for gen-ai COMPASS-10314#7772
Conversation
There was a problem hiding this comment.
Pull request overview
Updates GenAI request metadata so OpenAI “store” is sent as a proper boolean and forwarded correctly, improving consistency of stored/returned items.
Changes:
- Switch
storemetadata from string ('true'|'false') to boolean (true|false) across prompt building and tests. - Forward
storeexplicitly in the OpenAI provider options for query responses. - Add assistant-side logic to disable storage in certain cases and a workaround to avoid
itemId-based message compaction.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/compass-generative-ai/src/utils/gen-ai-response.ts | Forwards store into OpenAI provider options to ensure storage behavior is applied. |
| packages/compass-generative-ai/src/utils/gen-ai-prompt.ts | Changes store type/value to boolean in prompt metadata. |
| packages/compass-generative-ai/src/utils/gen-ai-prompt.spec.ts | Updates expectations for boolean store. |
| packages/compass-generative-ai/src/atlas-ai-service.spec.ts | Adjusts request assertions for store handling and payload shape. |
| packages/compass-e2e-tests/tests/collection-ai-query.test.ts | Updates E2E assertions to validate boolean store at the request root (not metadata). |
| packages/compass-assistant/src/docs-provider-transport.ts | Adds storage-disabling logic + message transformation to avoid itemId compaction issues. |
| packages/compass-assistant/src/components/assistant-chat.tsx | Sets per-message “disable storage” metadata based on CSFLE connection detection. |
| packages/compass-assistant/src/compass-assistant-provider.tsx | Extends Assistant message metadata to carry the “disable storage” flag. |
| const disbleStorage = filteredMessages.some( | ||
| (message) => message.metadata?.disbleStorage | ||
| ); |
There was a problem hiding this comment.
This computes the storage flag based on any message in history. The metadata field is documented as applying to “this message”, so a single earlier disableStorage would unintentionally force store: false for subsequent messages. Prefer basing this on the outgoing message only (e.g., lastMessage.metadata?.disableStorage) or otherwise scoping it explicitly to the message(s) you intend to affect.
| const disbleStorage = filteredMessages.some( | |
| (message) => message.metadata?.disbleStorage | |
| ); | |
| const disbleStorage = !!lastMessage.metadata?.disbleStorage; |
There was a problem hiding this comment.
No, we want to disable storage for the whole conversation if any of the messages has disableStorage set.
| providerOptions: { | ||
| openai: { | ||
| store: process.env.COMPASS_ASSISTANT_STORE === 'true' ? true : false, | ||
| store: !disbleStorage, |
There was a problem hiding this comment.
This change removes the previous environment-based gate (COMPASS_ASSISTANT_STORE) and makes storage enabled by default whenever disableStorage is not set. If the env var is still intended as a global kill-switch/config, combine both controls (e.g., env allows storage AND the message doesn’t disable it) rather than dropping the env check.
There was a problem hiding this comment.
I don't think we still need that flag, cc @lerouxb
| const trimmedMessageBody = text.trim(); | ||
| if (trimmedMessageBody) { | ||
| await chat.stop(); | ||
| const isConnectedToCsfleCluster = activeConnections.some( |
There was a problem hiding this comment.
This is only the code for when a user manually sends a chat message. What about entrypoints? (ie. other places that also use ensureOptInAndSend)
There was a problem hiding this comment.
Good point, i'll handle those as well
|
|
||
| // EAI-1506 The chatbot API never forwards `store: true` to the OpenAI, as a | ||
| // result even when `store: true` is set the API response does not include a | ||
| // valid `itemId`. On client side (check openai > convertToOpenAIResponsesInput), |
There was a problem hiding this comment.
You can probably just add a link to https://github.com/vercel/ai/blob/610b98ed4764407d5cc2bfe64b9ad27b740e1cf9/packages/openai/src/responses/convert-to-openai-responses-input.ts#L171-L175 ?
| case 'tool-call': | ||
| case 'tool-result': | ||
| case 'reasoning': | ||
| case 'file': { |
There was a problem hiding this comment.
Is it safe to hardcode this list of types? why not just check for part.providerOptions?.openai?.itemId and ignore part.type completely? types still get added all the time at the speed that AI's been advancing.
| metadata: { | ||
| sendContext: true, | ||
| ...metadata, | ||
| disableStorage: isConnectedToCsfleCluster, |
There was a problem hiding this comment.
Let's not call this CSFLE if it also covers QE (which it does)
…b.com/mongodb-js/compass into COMPASS-10314-correctly-store-prompts
Description
Checklist
Motivation and Context
Open Questions
Dependents
Types of changes