Apply NLD history match to agent prompt history backed by ai_queries#12586
Apply NLD history match to agent prompt history backed by ai_queries#12586evelyn-with-warp wants to merge 2 commits into
Conversation
Fuzzy-match the input buffer against both shell command history and agent prompt history, locking NLD to whichever mode has the later matched timestamp. Prompt candidates combine in-memory conversation queries (via all_ai_queries) with a lightweight 2000-row read of the ai_queries table (empty inputs filtered in SQL), deduped to the latest timestamp per prompt text. Gated behind the nld_prompt_history_match feature, enabled for local/dev bundles only. Co-Authored-By: Oz <oz-agent@warp.dev>
|
I'm starting a first review of this pull request. You can view the conversation on Warp. I completed the review and no human review was requested for this pull request. Comment Powered by Oz |
There was a problem hiding this comment.
Overview
This PR extends NLD history matching so recent agent prompts from ai_queries can compete with shell command history, with the newer matching source deciding whether input locks to AI or Shell. It also adds startup persistence reads, feature gating for local/dev bundles, and unit coverage for source merging and the decision matrix.
Concerns
- The persisted
ai_queriesprompt source bypasses the existing conversation-aware filtering that skips child-agent synthetic first prompts, so those non-user prompts can become NLD prompt-history matches. - This is a user-facing behavior change to input mode autodetection, but the PR description has no manual test confirmation and no screenshots or recording. For this user-facing change, please include screenshots or a screen recording demonstrating it working end to end.
- Security pass: no direct security issue found in the changed diff.
- Spec check: no approved or repository spec context was provided for this PR.
Verdict
Found: 0 critical, 2 important, 1 suggestions
Request changes
Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).
Powered by Oz
| conn: &mut SqliteConnection, | ||
| limit: i64, | ||
| ) -> Result<Vec<(String, DateTime<Local>)>, diesel::result::Error> { | ||
| Ok(schema::ai_queries::table |
There was a problem hiding this comment.
ai_queries row as an NLD prompt candidate, but all_ai_queries deliberately skips the first exchange for child-agent conversations because it is the synthetic orchestrator prompt rather than user input. Persisted child-agent rows can now re-enter prompt history here and make unrelated text lock to AI; filter those child-agent initial exchanges or derive this source from conversation-aware metadata before matching.
There was a problem hiding this comment.
it's fine to bring back the filtered out prompt for this use case, as long as it is a prompt which aims to lock NLD to ai mode
| .load::<(String, NaiveDateTime)>(conn)? | ||
| .into_iter() | ||
| .filter_map(|(input, start_ts)| { | ||
| let inputs: Vec<PersistedAIInputType> = serde_json::from_str(&input).ok()?; |
There was a problem hiding this comment.
💡 [SUGGESTION] Deserializing PersistedAIInputType materializes context and attachment maps for up to 2,000 rows even though only Query.text is needed, so this startup read is not as lightweight as intended. Use a narrow deserializer that extracts only the prompt text before this feature graduates beyond dev.
There was a problem hiding this comment.
this is one-time read, not triggered at every keystroke per user type. so it's fine to not narrow read trading for reuse existing struct
Fuzzy-match the input buffer against both shell command history and agent prompt history, locking NLD to whichever mode has the later matched timestamp.
We did not reuse prompt history, which limit read ai_queries to most recent 100 rows due to lack of pagination implementation. However we did reuse the all_ai_queries (which include in memory conversation), combining with a light read of 2000 rows of ai_queries table, and dedup on text with only latest timestamp to form nld_prompt_history for NLD history match heuristic.
Description
Linked Issue
ready-to-specorready-to-implement.Testing
./script/runScreenshots / Videos
https://www.loom.com/share/06c6ef1c669d49818d39f5c4c04a9c30
Agent Mode