Issue
The CLI testing tool failed to maintain conversation history between sequential messages from the same user. Follow-up messages were processed without context of prior messages, even though they used the same email address. This discrepancy between CLI and production email flows made multi-turn testing impossible, as the CLI silently dropped all conversation state.
Culprit
The CLI bypassed the database storage layer, unlike the production email flow, which followed a ‘store-first’ pattern. This led to three key issues:
- Missing Email ID Generation: The CLI did not generate or use an
email_id, which is essential for tracking conversation history. - No Database Interaction: Unlike production, the CLI did not store messages before processing or update responses after processing.
- Architectural Divergence: The CLI used a stateless approach, while production relied on database-backed conversation state.
Solution
Database Integration
Added functions to store CLI messages and update responses in the database, aligning the CLI with production processes. This ensures that conversation history is maintained consistently across both environments.
Three-Step CLI Flow
Modified the CLI workflow to follow a store-first pattern:
- Store First: Store the message in the database and generate an
email_idfor context. - Process with Context: Pass the
email_idto the processing workflow to maintain conversation history. - Update After: Update the database with the processed response after handling the message.
Backward Compatibility
Made the email_id parameter optional in the processing function to accommodate both CLI and production use cases. This allows the CLI to function in both stateless and stateful modes, depending on the availability of an email_id.
User Feedback
Added console output to indicate database operations, such as storing messages and updating responses. This provides users with feedback on the process and improves transparency.
The solution successfully aligns the CLI with production email flows, enabling accurate multi-turn testing and maintaining conversation history. While this adds slight latency due to database round-trips, it ensures functional parity between CLI and production workflows.