Skip to content

Apply NLD history match to agent prompt history backed by ai_queries#12586

Open
evelyn-with-warp wants to merge 2 commits into
masterfrom
evelyn/history-match-on-ai-queries
Open

Apply NLD history match to agent prompt history backed by ai_queries#12586
evelyn-with-warp wants to merge 2 commits into
masterfrom
evelyn/history-match-on-ai-queries

Conversation

@evelyn-with-warp

@evelyn-with-warp evelyn-with-warp commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

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

  • The linked issue is labeled ready-to-spec or ready-to-implement.
  • Where appropriate, screenshots or a short video of the implementation are included below (especially for user-visible or UI changes).

Testing

  • I have manually tested my changes locally with ./script/run

Screenshots / Videos

https://www.loom.com/share/06c6ef1c669d49818d39f5c4c04a9c30

Agent Mode

  • Warp Agent Mode - This PR was created via Warp's AI Agent Mode

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>
@cla-bot cla-bot Bot added the cla-signed label Jun 12, 2026
@oz-for-oss

oz-for-oss Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

@evelyn-with-warp

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 /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

@oz-for-oss oz-for-oss Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_queries prompt 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [IMPORTANT] This reads every 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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 [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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@evelyn-with-warp evelyn-with-warp requested a review from szgupta June 12, 2026 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant