Skip to content

Optimize related query response latency post resolution search - #785

Open
ngoiyaeric wants to merge 1 commit into
mainfrom
fix/optimize-related-query-tokens-16780678670469565873
Open

Optimize related query response latency post resolution search#785
ngoiyaeric wants to merge 1 commit into
mainfrom
fix/optimize-related-query-tokens-16780678670469565873

Conversation

@ngoiyaeric

Copy link
Copy Markdown
Collaborator

Eliminates response lag following resolution search and researcher streaming by removing artificial setTimeout delays in app/actions.tsx and improving stream updates in lib/agents/query-suggestor.tsx to update immediately on the first chunk.


PR created automatically by Jules for task 16780678670469565873 started by @ngoiyaeric

- Remove artificial 500ms delay in processResolutionSearch and processEvents
- Stream query suggestions immediately on initial chunk and throttle subsequent updates at 100ms
- Enhance cache key generation to handle complex array content safely

Co-authored-by: ngoiyaeric <115367894+ngoiyaeric@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@vercel

vercel Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
qcx Ready Ready Preview Sep 5, 2026 6:41am UTC

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@coderabbitai

coderabbitai Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 5 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Team

Run ID: 9488afa9-bd4d-4016-9608-a5455b74d6bd

📥 Commits

Reviewing files that changed from the base of the PR and between 371f9d6 and d551f3a.

📒 Files selected for processing (2)
  • app/actions.tsx
  • lib/agents/query-suggestor.tsx

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@qodo-code-review

Copy link
Copy Markdown
Contributor

PR Summary by Qodo

Reduce post-response related-query latency

🐞 Bug fix ✨ Enhancement 🕐 10-20 Minutes

Grey Divider

AI Description

• Removes 500 ms delays from resolution and researcher response flows.
• Streams the first related-query chunk immediately and throttles later updates every 100 ms.
• Builds bounded, content-aware cache keys for text and multipart messages.
Diagram

sequenceDiagram
  participant RF as Response Flow
  participant AA as Server Actions
  participant QS as Query Suggestor
  participant UI as UI Stream
  participant ST as AI State
  RF->>AA: Complete response
  AA->>QS: Generate related queries
  QS-->>UI: First chunk immediately
  loop Later chunks
    QS-->>UI: Throttled updates
  end
  QS-->>AA: Final suggestions
  AA->>UI: Append follow-up
  AA->>ST: Persist immediately
Loading
High-Level Assessment

The leading-edge throttle is the appropriate approach: it minimizes perceived latency while retaining protection against excessive re-renders. Removing throttling entirely would increase rendering pressure, while trailing-edge debouncing would recreate the initial lag. Bounded text extraction also improves cache specificity without introducing hashing or serialization dependencies.

Files changed (2) +11 / -11

Enhancement (1) +11 / -7
query-suggestor.tsxDeliver related-query streams sooner and improve cache keys +11/-7

Deliver related-query streams sooner and improve cache keys

• Publishes the first related-query chunk immediately and reduces the throttle interval for later chunks from 200 ms to 100 ms. Cache keys now use bounded recent text from string and multipart message content instead of collapsing all arrays to a generic marker.

lib/agents/query-suggestor.tsx

Bug fix (1) +0 / -4
actions.tsxRemove post-processing delays from response completion +0/-4

Remove post-processing delays from response completion

• Removes the artificial 500 ms waits before finalizing AI state in both resolution-search and researcher flows. Related queries and follow-up state are now persisted as soon as generation completes.

app/actions.tsx

@qodo-code-review

Copy link
Copy Markdown
Contributor

Code Review by Qodo

🐞 Bugs (2) 📘 Rule violations (0) 📜 Skill insights (0)

Grey Divider


Action required

1. Prompt suffix cache collisions 🐞 Bug ≡ Correctness
Description
getCacheKey now retains only the last 500 characters of string messages, so different prompts
sharing that suffix receive the same cache key. During the five-minute cache lifetime,
querySuggestor can consequently return suggestions generated from another request without
consulting the model.
Code

lib/agents/query-suggestor.tsx[24]

+      ? m.content.slice(-500)
Evidence
The cache is module-global and retained for five minutes, while the added slice(-500) discards
prompt prefixes. Cache hits are returned directly, although generation receives the original
untruncated messages; user input reaches this path as an unrestricted string.

lib/agents/query-suggestor.tsx[14-16]
lib/agents/query-suggestor.tsx[18-28]
lib/agents/query-suggestor.tsx[38-49]
lib/agents/query-suggestor.tsx[64-68]
app/actions.tsx[339-342]
app/actions.tsx[540-542]
app/actions.tsx[572-574]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Cache keys truncate string messages to their final 500 characters, allowing distinct model requests to share cached related-query results.

## Issue Context
The model receives the complete messages, while the module-level cache uses the truncated representation for five minutes. Generate a deterministic key from all semantically relevant message content; hash the canonical representation if bounded key size is necessary.

## Fix Focus Areas
- lib/agents/query-suggestor.tsx[18-29]
- lib/agents/query-suggestor.tsx[37-49]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

2. Incomplete suggestions become clickable 🐞 Bug ≡ Correctness
Description
The first partialObjectStream value is now published immediately even though its query strings can
still be incomplete. SearchRelated enables any non-empty partial query, allowing a user to submit
truncated text before later chunks or final validation arrive.
Code

lib/agents/query-suggestor.tsx[R90-92]

+        // Update UI immediately on first yield or after throttle interval
+        if (lastUpdateTime === 0 || now - lastUpdateTime > UPDATE_THROTTLE) {
          objectStream.update(obj as PartialRelated)
Evidence
The changed branch publishes the first partial object immediately. The stream type permits
incomplete values, while the client renders and enables every query not exactly equal to an empty
string and passes that current partial text directly to submit; only after streaming ends is the
value sanitized and finalized.

lib/agents/query-suggestor.tsx[85-95]
lib/agents/query-suggestor.tsx[101-106]
lib/agents/query-suggestor.tsx[122-123]
lib/schema/related.tsx[4-13]
components/search-related.tsx[36-52]
components/search-related.tsx[65-82]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Immediately streamed partial query text is rendered as an enabled action and can be submitted before generation completes.

## Issue Context
`PartialRelated` is explicitly a deep-partial stream type. Preserve immediate visual feedback, but do not enable submission until the suggestion stream has finalized, or publish only values known to be complete.

## Fix Focus Areas
- lib/agents/query-suggestor.tsx[81-106]
- components/search-related.tsx[31-52]
- components/search-related.tsx[65-85]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Context sources
Review mode: ⚖️ Balanced: This is a localized runtime streaming and response-timing change, but it alters observable update behavior and cache-key handling, warranting a careful single-pass review.

Grey Divider

Tip of the day
💡 Did you know, you can keep summaries lean with Finding overflow, which tucks the rest behind 'View more'

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

role: m.role,
content: typeof m.content === 'string' ? m.content : '[complex content]'
content: typeof m.content === 'string'
? m.content.slice(-500)

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.

Action required

1. Prompt suffix cache collisions 🐞 Bug ≡ Correctness

getCacheKey now retains only the last 500 characters of string messages, so different prompts
sharing that suffix receive the same cache key. During the five-minute cache lifetime,
querySuggestor can consequently return suggestions generated from another request without
consulting the model.
Agent Prompt
## Issue description
Cache keys truncate string messages to their final 500 characters, allowing distinct model requests to share cached related-query results.

## Issue Context
The model receives the complete messages, while the module-level cache uses the truncated representation for five minutes. Generate a deterministic key from all semantically relevant message content; hash the canonical representation if bounded key size is necessary.

## Fix Focus Areas
- lib/agents/query-suggestor.tsx[18-29]
- lib/agents/query-suggestor.tsx[37-49]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment on lines +90 to 92
// Update UI immediately on first yield or after throttle interval
if (lastUpdateTime === 0 || now - lastUpdateTime > UPDATE_THROTTLE) {
objectStream.update(obj as PartialRelated)

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.

Remediation recommended

2. Incomplete suggestions become clickable 🐞 Bug ≡ Correctness

The first partialObjectStream value is now published immediately even though its query strings can
still be incomplete. SearchRelated enables any non-empty partial query, allowing a user to submit
truncated text before later chunks or final validation arrive.
Agent Prompt
## Issue description
Immediately streamed partial query text is rendered as an enabled action and can be submitted before generation completes.

## Issue Context
`PartialRelated` is explicitly a deep-partial stream type. Preserve immediate visual feedback, but do not enable submission until the suggestion stream has finalized, or publish only values known to be complete.

## Fix Focus Areas
- lib/agents/query-suggestor.tsx[81-106]
- components/search-related.tsx[31-52]
- components/search-related.tsx[65-85]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

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.

2 participants