Skip to content

⚡ Bolt: [debounce search inputs and offload filtering] - #65

Merged
SayanthRock merged 1 commit into
mainfrom
bolt-debounce-search-12004666678209350778
Aug 4, 2026
Merged

⚡ Bolt: [debounce search inputs and offload filtering]#65
SayanthRock merged 1 commit into
mainfrom
bolt-debounce-search-12004666678209350778

Conversation

@SayanthRock

@SayanthRock SayanthRock commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

User description

💡 What: Replaced synchronous list filtering within remember blocks in ExperienceHome and ExperienceLibrary with asynchronous computation offloaded to a background thread using withContext(Dispatchers.Default) and debounced by 300ms using LaunchedEffect.

🎯 Why: Filtering thousands of tracks synchronously on every keystroke blocks the main thread, causing severe UI stutter and frame drops when typing in the search bar.

📊 Impact: Prevents UI stutter and dropped frames during search input. The main thread remains fully unblocked while typing, leading to a much smoother search experience.

🔬 Measurement: Type quickly in the search bar on the Home or Library screens. You can observe using the Android Studio Profiler that the main thread is no longer blocked on each keystroke and frames are not dropped.


PR created automatically by Jules for task 12004666678209350778 started by @SayanthRock


CodeAnt-AI Description

Debounce search and keep filtering off the main thread

What Changed

  • Search results on the Home and Library screens update after typing pauses for 300 ms
  • Large track lists are filtered in the background so typing does not block the interface
  • Results refresh when tracks, search text, or the selected source changes

Impact

✅ Smoother typing in track searches
✅ Fewer UI stalls with large libraries
✅ Lower main-thread work during filtering

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

Summary by CodeRabbit

  • Performance Improvements
    • Track filtering on the Home and Library screens now runs asynchronously in the background.
    • Results update after a brief delay while typing, providing smoother screen interactions.

- Modifies ExperienceHome and ExperienceLibrary in RockMusicExperience.kt to use `LaunchedEffect` for debouncing search input keystrokes by 300ms.
- Offloads expensive `UnifiedHomeLibrary.localTracks` filtering computations to `Dispatchers.Default`.
- Replaces synchronous `remember` blocks with state properties that are updated asynchronously, keeping the main thread responsive.

Co-authored-by: SayanthRock <202829406+SayanthRock@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.

Copilot AI lite review requested due to automatic review settings August 4, 2026 03:41
@codeant-ai

codeant-ai Bot commented Aug 4, 2026

Copy link
Copy Markdown

🤖 CodeAnt AI — Review Status

Status Commit Started (UTC) Finished (UTC)
✅ Reviewed your PR 0e737a1 Aug 04, 2026 · 03:41 03:43

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@codeant-ai

codeant-ai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Home and Library track filtering now runs asynchronously after a 300 ms debounce. Filtering executes on Dispatchers.Default, and each screen stores the computed results in mutable state.

Changes

Track filtering

Layer / File(s) Summary
Debounced background filtering
app/src/main/java/com/rockmusic/app/presentation/RockMusicExperience.kt
Coroutine imports support delayed background work. Home and Library filtering now updates mutable results after a 300 ms debounce on Dispatchers.Default.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested labels: zenable/risk:low

Suggested reviewers: copilot

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main changes: debouncing search inputs and moving filtering off the main thread.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bolt-debounce-search-12004666678209350778

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.

@codeant-ai codeant-ai Bot added the size:S This PR changes 10-29 lines, ignoring generated files label Aug 4, 2026

@ai-coding-guardrails ai-coding-guardrails Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I've got 1 comment for you to consider

Risk: 🟢 Low

Risk analysis

The highest scoring dimensions are operational_risk and blast_radius. The change introduces asynchronous behavior with a 300ms delay and background threading in two core UI components (ExperienceHome and ExperienceLibrary), which could lead to temporary incorrect UI states (like showing empty lists initially). The blast_radius is moderate because these changes affect key user-facing screens used by many users. Reversibility is low since the change is localized and can be reverted easily, and test_coverage is minimal due to lack of new tests for the async logic.

Did you know we can integrate this feedback directly into 50+ IDEs? Get setup in just one command


val visibleTracks = remember(state.tracks, query, source) {
UnifiedHomeLibrary.localTracks(state.tracks, query, source)
var visibleTracks by remember { mutableStateOf<List<LocalTrack>>(emptyList()) }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

visibleTracks initialises as empty list, causing a brief flash of empty-state UI on first load before the 300ms debounce fires

Initialising visibleTracks (and results in ExperienceLibrary) as emptyList() means that on first composition — before the 300ms LaunchedEffect delay completes — the UI will briefly show the empty-state message ("No imported songs match…" or "Your library is empty") even when state.tracks is already populated. This is a regression from the previous remember(…) approach which computed synchronously.

Consider seeding the initial value synchronously (e.g. remember { UnifiedHomeLibrary.localTracks(state.tracks, query, source) } or using null as a sentinel to distinguish "not yet computed" from "genuinely empty"), so the correct list is shown immediately on first render.

Why did I show this?

Category: bug
Comment Quality: high

Based on general best practices

@ai-coding-guardrails ai-coding-guardrails Bot added the zenable/risk:low Zenable assessed this PR as LOW risk. label Aug 4, 2026
Comment on lines +295 to 300
LaunchedEffect(state.tracks, query, source) {
delay(300)
visibleTracks = withContext(Dispatchers.Default) {
UnifiedHomeLibrary.localTracks(state.tracks, query, source)
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggestion: During the 300 ms debounce, visibleTracks retains the results for the previous query, source, or track snapshot. The UI already reflects the new query, but the displayed cards, count, and onPlayAll(visibleTracks) action still use stale data, so a quick tap can queue songs that do not match the current search. Clear or otherwise invalidate the displayed results when the effect starts, and only enable result actions for the current computation. [stale reference]

Severity Level: Major ⚠️
- ⚠️ Home cards temporarily show results for the previous query.
- ❌ Home Play all can queue non-matching tracks.
- ⚠️ Speed-dial count and featured songs become temporarily inaccurate.

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** app/src/main/java/com/rockmusic/app/presentation/RockMusicExperience.kt
**Line:** 295:300
**Comment:**
	*Stale Reference: During the 300 ms debounce, `visibleTracks` retains the results for the previous `query`, `source`, or track snapshot. The UI already reflects the new query, but the displayed cards, count, and `onPlayAll(visibleTracks)` action still use stale data, so a quick tap can queue songs that do not match the current search. Clear or otherwise invalidate the displayed results when the effect starts, and only enable result actions for the current computation.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

Comment on lines +607 to 612
LaunchedEffect(tracks, query) {
delay(300)
results = withContext(Dispatchers.Default) {
UnifiedHomeLibrary.localTracks(tracks, query, UnifiedHomeSource.SONGS)
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggestion: The library now starts with an empty results list and keeps the previous list while the delayed computation runs. This briefly shows “No songs match this search” when tracks already exist, and after changing or clearing a query the visible rows and Play all results button can operate on the prior query's tracks. Reset or mark the results as pending when the effect is restarted so the rendered list and play action cannot use stale data. [stale reference]

Severity Level: Major ⚠️
- ⚠️ Library briefly reports no matches during initial filtering.
- ❌ Play all results can queue stale query results.
- ⚠️ Library rows can remain inconsistent with search text.

Fix in Cursor Fix in VSCode Claude

(Use Cmd/Ctrl + Click for best experience)

Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** app/src/main/java/com/rockmusic/app/presentation/RockMusicExperience.kt
**Line:** 607:612
**Comment:**
	*Stale Reference: The library now starts with an empty `results` list and keeps the previous list while the delayed computation runs. This briefly shows “No songs match this search” when tracks already exist, and after changing or clearing a query the visible rows and `Play all results` button can operate on the prior query's tracks. Reset or mark the results as pending when the effect is restarted so the rendered list and play action cannot use stale data.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
👍 | 👎

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 6

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@app/src/main/java/com/rockmusic/app/presentation/RockMusicExperience.kt`:
- Around line 291-300: Clear visibleTracks at the start of the LaunchedEffect
keyed by state.tracks, query, and source, before the debounce delay and
background filtering begin. Ensure result actions such as Play all cannot use
results from the previous query or source while the new filter is pending.
- Around line 609-610: Update UnifiedHomeLibrary.localTracks to cooperate with
coroutine cancellation while scanning large inputs: add periodic
currentCoroutineContext().ensureActive() checks or process the distinctBy/filter
work in cancellable chunks, while preserving its existing filtering and result
behavior.
- Around line 297-299: Make the localTracks filtering invoked from the
LaunchedEffect cancellation-cooperative by updating
UnifiedHomeLibrary.localTracks and its filter/distinctBy path to periodically
call currentCoroutineContext().ensureActive() during synchronous CPU work.
Preserve the existing filtering and ordering behavior while ensuring
cancellation is detected before completing stale work.
- Around line 607-608: Update the LaunchedEffect keyed by tracks and query to
bypass the 300 ms delay when query is blank, computing the all-tracks result
immediately; retain the 300 ms debounce only for non-blank queries so results
are populated before the empty-state message appears.
- Around line 603-611: Update the LaunchedEffect keyed by tracks and query and
the nearby Play all results action so stale results cannot be played while
debounce or background filtering is in progress. Clear results when a new search
begins or disable the action until filtering completes, then publish the newly
filtered list only after UnifiedHomeLibrary.localTracks returns.
- Around line 295-296: Update the Home LaunchedEffect around state.tracks,
query, and source so blank queries compute and publish visible tracks
immediately without delay; retain the 300 ms debounce only for non-blank query
filtering. Preserve the existing no-match behavior for genuinely empty filtered
results.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 7212bf15-052d-4cc0-9a6e-67ac0aaf986b

📥 Commits

Reviewing files that changed from the base of the PR and between 9aeca73 and 0e737a1.

📒 Files selected for processing (1)
  • app/src/main/java/com/rockmusic/app/presentation/RockMusicExperience.kt

Comment on lines +291 to 300
var visibleTracks by remember { mutableStateOf<List<LocalTrack>>(emptyList()) }

// ⚡ Bolt: Debounce keystrokes and offload expensive list filtering to a background thread
// to prevent UI stutter and main thread blocking.
LaunchedEffect(state.tracks, query, source) {
delay(300)
visibleTracks = withContext(Dispatchers.Default) {
UnifiedHomeLibrary.localTracks(state.tracks, query, source)
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Files:"
git ls-files | rg 'RockMusicExperience\.kt|MainViewModel\.kt|UnifiedHomeLibrary' || true

echo
echo "RockMusicExperience relevant excerpts:"
if [ -f app/src/main/java/com/rockmusic/app/presentation/RockMusicExperience.kt ]; then
  wc -l app/src/main/java/com/rockmusic/app/presentation/RockMusicExperience.kt
  sed -n '270,320p' app/src/main/java/com/rockmusic/app/presentation/RockMusicExperience.kt
  sed -n '440,475p' app/src/main/java/com/rockmusic/app/presentation/RockMusicExperience.kt
fi

echo
echo "MainViewModel relevant excerpts:"
if [ -f app/src/main/java/com/rockmusic/app/viewmodel/MainViewModel.kt ]; then
  wc -l app/src/main/java/com/rockmusic/app/viewmodel/MainViewModel.kt
  sed -n '240,305p' app/src/main/java/com/rockmusic/app/viewmodel/MainViewModel.kt
fi

echo
echo "UnifiedHomeLibrary definitions/usages:"
rg -n "object UnifiedHomeLibrary|class UnifiedHomeLibrary|fun localTracks|localTracks\\(" app/src/main/java -S

Repository: Sayanthrock-Developer/Rock-music

Length of output: 4946


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "UnifiedHomeLibrary excerpt:"
wc -l app/src/main/java/com/rockmusic/app/presentation/UnifiedHomeLibrary.kt
sed -n '1,80p' app/src/main/java/com/rockmusic/app/presentation/UnifiedHomeLibrary.kt

echo
echo "Play all usages:"
rg -n "playAll\\(|Play all|Source|Source\\s*=|onPlayAll" app/src/main/java/com/rockmusic/app/presentation app/src/main/java/com/rockmusic/app -S

echo
echo "RockMusicExperience excerpt around all Play/Source state:"
sed -n '1,80p' app/src/main/java/com/rockmusic/app/presentation/RockMusicExperience.kt
sed -n '580,630p' app/src/main/java/com/rockmusic/app/presentation/RockMusicExperience.kt

Repository: Sayanthrock-Developer/Rock-music

Length of output: 17031


Clear filter results before the next filter starts.

visibleTracks remains visible during the 300ms debounce and background filtering, so Play all can queue songs for the previous query/source at line 459. Clear or disable result actions when a new query, source, or state.tracks change starts.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/src/main/java/com/rockmusic/app/presentation/RockMusicExperience.kt`
around lines 291 - 300, Clear visibleTracks at the start of the LaunchedEffect
keyed by state.tracks, query, and source, before the debounce delay and
background filtering begin. Ensure result actions such as Play all cannot use
results from the previous query or source while the new filter is pending.

Comment on lines +295 to +296
LaunchedEffect(state.tracks, query, source) {
delay(300)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== locate files =="
fd -a 'RockMusicExperience.kt|UnifiedHomeLibrary.kt' . | sed 's#^\./##'

echo "== file sizes =="
while IFS= read -r f; do
  echo "$f: $(wc -l < "$f")"
done < <(fd 'RockMusicExperience.kt|UnifiedHomeLibrary.kt' .)

echo "== outlines =="
for f in $(fd 'RockMusicExperience.kt|UnifiedHomeLibrary.kt' .); do
  echo "--- $f ---"
  ast-grep outline "$f" || true
done

echo "== relevant RockMusicExperience sections =="
f=$(fd 'RockMusicExperience.kt' . | head -n1)
if [ -n "${f:-}" ]; then
  sed -n '260,330p;410,445p' "$f" | cat -n
  echo "--- all visibleTracks usages in $f ---"
  rg -n "visibleTracks|LocalTracks|localTracks|LaunchedEffect|state\\.tracks|query|source" "$f"
fi

echo "== UnifiedHomeLibrary relevant sections =="
g=$(fd 'UnifiedHomeLibrary.kt' . | head -n1)
if [ -n "${g:-}" ]; then
  sed -n '1,120p;330,410p' "$g" | cat -n
  echo "--- localTracks usages in $g ---"
  rg -n "fun localTracks|localTracks|visibleTracks|query|source" "$g"
fi

Repository: Sayanthrock-Developer/Rock-music

Length of output: 440


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== locate files =="
files=()
while IFS= read -r f; do
  files+=("$f")
done < <(find . -path '*/app/src/main/java/com/rockmusic/app/presentation/RockMusicExperience.kt' -o -path '*/app/src/main/java/com/rockmusic/app/presentation/UnifiedHomeLibrary.kt' 2>/dev/null | sort)
printf '%s\n' "${files[@]}"

echo "== file sizes =="
for f in "${files[@]}"; do
  echo "$f: $(wc -l < "$f")"
done

echo "== outlines =="
for f in "${files[@]}"; do
  echo "--- $f ---"
  ast-grep outline "$f" || true
done

echo "== relevant RockMusicExperience sections =="
f="${files[0]}"
sed -n '260,330p;410,445p' "$f" | cat -n
echo "--- all visibleTracks usages in $f ---"
rg -n "visibleTracks|LocalTracks|localTracks|LaunchedEffect|state\.tracks|query|source" "$f"

echo "== UnifiedHomeLibrary relevant sections =="
g="${files[1]}"
sed -n '1,120p;330,410p' "$g" | cat -n
echo "--- localTracks usages in $g ---"
rg -n "fun localTracks|localTracks|visibleTracks|query|source" "$g"

Repository: Sayanthrock-Developer/Rock-music

Length of output: 241


🏁 Script executed:

#!/bin/bash
set -u

echo "== locate files =="
find . -path '*/app/src/main/java/com/rockmusic/app/presentation/RockMusicExperience.kt' -o -path '*/app/src/main/java/com/rockmusic/app/presentation/UnifiedHomeLibrary.kt' 2>/dev/null | sort

echo "== file sizes =="
for f in $(find . -path '*/app/src/main/java/com/rockmusic/app/presentation/RockMusicExperience.kt' -o -path '*/app/src/main/java/com/rockmusic/app/presentation/UnifiedHomeLibrary.kt' 2>/dev/null | sort); do
  echo "$f: $(wc -l < "$f")"
done

Repository: Sayanthrock-Developer/Rock-music

Length of output: 510


🏁 Script executed:

#!/bin/bash
set -u

rock_file="./app/src/main/java/com/rockmusic/app/presentation/RockMusicExperience.kt"
lib_file="./app/src/main/java/com/rockmusic/app/presentation/UnifiedHomeLibrary.kt"

echo "== UnifiedHomeLibrary.kt =="
cat -n "$lib_file"

echo "== RockMusicExperience.kt relevant sections =="
sed -n '260,330p;410,445p' "$rock_file" | cat -n
echo "--- relevant usages in $rock_file ---"
rg -n "visibleTracks|LocalTracks|localTracks|LaunchedEffect|state\.tracks|query|source|debounce|debounced|collectAsStateWithLifecycle|LaunchedEffect" "$rock_file"

echo "== state definition/usages context =="
rg -n "data class .*State|State<|mutableStateOf|tracks|visibleTracks" "$rock_file"
sed -n '1,140p' "$rock_file" | cat -n

Repository: Sayanthrock-Developer/Rock-music

Length of output: 19518


Do not debounce the blank-query results path.

LocalTracksSearch computes UnifiedHomeLibrary.localTracks(tracks, query, UnifiedHomeSource.SONGS) immediately, but the Home LaunchedEffect waits 300 ms for every state.tracks, query, and source change. When query is blank and state.tracks contains tracks, visibleTracks stays empty while awaiting the result, and the UI shows the no-match status. Handle the blank query synchronously and debounce only non-blank query filtering.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/src/main/java/com/rockmusic/app/presentation/RockMusicExperience.kt`
around lines 295 - 296, Update the Home LaunchedEffect around state.tracks,
query, and source so blank queries compute and publish visible tracks
immediately without delay; retain the 300 ms debounce only for non-blank query
filtering. Preserve the existing no-match behavior for genuinely empty filtered
results.

Comment on lines +297 to +299
visibleTracks = withContext(Dispatchers.Default) {
UnifiedHomeLibrary.localTracks(state.tracks, query, source)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🚀 Performance & Scalability | 🟠 Major | 🏗️ Heavy lift

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== locate file =="
fd -a 'RockMusicExperience\.kt|UnifiedHomeLibrary\.(kt|kts|java)$' . | sed 's#^\./##'

echo "== git diff stat =="
git diff --stat || true

echo "== outline RockMusicExperience =="
ast-grep outline app/src/main/java/com/rockmusic/app/presentation/RockMusicExperience.kt --view compact || true

echo "== relevant lines RockMusicExperience =="
sed -n '250,340p' app/src/main/java/com/rockmusic/app/presentation/RockMusicExperience.kt

echo "== UnifiedHomeLibrary files =="
for f in $(fd 'UnifiedHomeLibrary\.(kt|kts|java)$' .); do
  echo "--- $f"
  ast-grep outline "$f" --view compact || true
  rg -n "fun localTracks|class UnifiedHomeLibrary|object UnifiedHomeLibrary|localTracks|delay\\(|ensureActive\\(|withContext" "$f"
done

Repository: Sayanthrock-Developer/Rock-music

Length of output: 4506


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== UnifiedHomeLibrary localTracks implementation =="
sed -n '1,220p' app/src/main/java/com/rockmusic/app/presentation/UnifiedHomeLibrary.kt

echo "== all localTracks usages =="
rg -n "localTracks\\(" app/src/main/java/com/rockmusic/app/presentation app/src/main/java/com/rockmusic/app || true

echo "== coroutine/cancellation usages near relevant file =="
rg -n "currentCoroutineContext\\(|ensureActive\\(|isActive|Dispatchers\\.Default|withContext" app/src/main/java/com/rockmusic/app/presentation/RockMusicExperience.kt app/src/main/java/com/rockmusic/app/presentation/UnifiedHomeLibrary.kt || true

echo "== behavioral probe: cancellation context on synchronous cpu work =="
python3 - <<'PY'
print("Kotlin coroutines cancellation checks cancellation state only at suspension points or explicit checks during non-suspending CPU work.")
PY

Repository: Sayanthrock-Developer/Rock-music

Length of output: 3508


Make the background localTracks filter cancellation-cooperative.

When LaunchedEffect restarts after delay(300), the suspended withContext block is cancelled, but UnifiedHomeLibrary.localTracks runs synchronous CPU work through filter/distinctBy without any suspension points or explicit cancellation checks. Add periodic currentCoroutineContext().ensureActive() checks in the filter path, or use a cancellable chunked implementation.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/src/main/java/com/rockmusic/app/presentation/RockMusicExperience.kt`
around lines 297 - 299, Make the localTracks filtering invoked from the
LaunchedEffect cancellation-cooperative by updating
UnifiedHomeLibrary.localTracks and its filter/distinctBy path to periodically
call currentCoroutineContext().ensureActive() during synchronous CPU work.
Preserve the existing filtering and ordering behavior while ensuring
cancellation is detected before completing stale work.

Comment on lines +603 to +611
var results by remember { mutableStateOf<List<LocalTrack>>(emptyList()) }

// ⚡ Bolt: Debounce keystrokes and offload expensive list filtering to a background thread
// to prevent UI stutter and main thread blocking.
LaunchedEffect(tracks, query) {
delay(300)
results = withContext(Dispatchers.Default) {
UnifiedHomeLibrary.localTracks(tracks, query, UnifiedHomeSource.SONGS)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Locate and inspect the relevant file and nearby implementation.
fd -a 'RockMusicExperience.kt' .
echo '--- outline ---'
ast-grep outline app/src/main/java/com/rockmusic/app/presentation/RockMusicExperience.kt --view compact || true
echo '--- relevant lines 560-710 ---'
sed -n '560,710p' app/src/main/java/com/rockmusic/app/presentation/RockMusicExperience.kt | nl -ba -v560
echo '--- related search ---'
rg -n "onPlayAll|Play all|results|LaunchedEffect|UnifiedHomeLibrary|LocalTrack|search|Play all" app/src/main/java/com/rockmusic/app/presentation/RockMusicExperience.kt

Repository: Sayanthrock-Developer/Rock-music

Length of output: 499


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- relevant lines 560-710 ---'
awk 'NR>=560 && NR<=710 { printf ("%6d\t%s\n", NR, $0) }' app/src/main/java/com/rockmusic/app/presentation/RockMusicExperience.kt

echo '--- related search ---'
rg -n "onPlayAll|Play all|results|LaunchedEffect|UnifiedHomeLibrary|LocalTrack|search|Play all" app/src/main/java/com/rockmusic/app/presentation/RockMusicExperience.kt

echo '--- outline ---'
ast-grep outline app/src/main/java/com/rockmusic/app/presentation/RockMusicExperience.kt || true

Repository: Sayanthrock-Developer/Rock-music

Length of output: 9983


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- inspect playAll implementation ---'
fd -a 'RockMusicExperienceViewModel.kt|*ViewModel*.kt|*Presentation*.kt' . | sed -n '1,80p'
rg -n "fun .*playAll|playAll\\s*=|fun .*Search|onSearch|playAll\\(" . -g '*.kt'

echo '--- read candidate files ---'
for f in $(fd 'RockMusicExperienceViewModel.kt|.*ViewModel.*\\.kt' . | sed -n '1,20p'); do
  echo "---- $f ----"
  wc -l "$f"
  sed -n '1,180p' "$f"
done

Repository: Sayanthrock-Developer/Rock-music

Length of output: 585


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- locate files ---'
fd 'RockMusicExperienceViewModel.kt|.*ViewModel.*\.kt|.*Presentation.*\.kt' . | sed -n '1,80p'

echo '--- search playAll and search actions ---'
rg -n -n "fun .*playAll|playAll\\s*=|fun .*Search|onSearch|playAll\\(" . -g '*.kt' || true

echo '--- read candidate files ---'
while IFS= read -r f; do
  echo "---- $f ----"
  wc -l "$f"
  sed -n '1,220p' "$f"
done < <(fd 'RockMusicExperienceViewModel.kt|.*ViewModel.*\.kt|.*Presentation.*\.kt' . | sed -n '1,20p')

Repository: Sayanthrock-Developer/Rock-music

Length of output: 3621


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- MainViewModel playAll implementation ---'
awk 'NR>=240 && NR<=290 { printf ("%6d\t%s\n", NR, $0) }' app/src/main/java/com/rockmusic/app/presentation/MainViewModel.kt

echo '--- RockMusicRoot library composition ---'
awk 'NR>=440 && NR<=510 { printf ("%6d\t%s\n", NR, $0) }' app/src/main/java/com/rockmusic/app/presentation/RockMusicRoot.kt

echo '--- stable programmatic check for stale-result behavior ---'
python3 - <<'PY'
from pathlib import Path
p = Path('app/src/main/java/com/rockmusic/app/presentation/RockMusicExperience.kt')
s = p.read_text()
checks = {
    'debounce_before_filter': 'delay(300)' in s and 'LaunchedEffect(tracks, query)' in s,
    'publish_after_filter': 'results = withContext(Dispatchers.Default)' in s and 'UnifiedHomeLibrary.localTracks(tracks, query, UnifiedHomeSource.SONGS)' in s,
    'play_uses_current_results': 'TextButton(onClick = { onPlayAll(results) })' in s,
    'no_running_state': 'var isRunning' not in s and 'var pending' not in s,
}
for name, ok in checks.items():
    print(f'{name}={ok}')
if not all(checks.values()):
    print('CHECKS_FAILED')
PY

Repository: Sayanthrock-Developer/Rock-music

Length of output: 6085


Do not publish library search results before filtering completes.

LaunchedEffect(tracks, query) publishes the previous results while the 300 ms debounce and filtering for the new query run. Tap Play all results in that window, and playAll(results) queues tracks for the old filter instead of the current query. Disable the action during filtering, or clear results while a new filter is pending.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/src/main/java/com/rockmusic/app/presentation/RockMusicExperience.kt`
around lines 603 - 611, Update the LaunchedEffect keyed by tracks and query and
the nearby Play all results action so stale results cannot be played while
debounce or background filtering is in progress. Clear results when a new search
begins or disable the action until filtering completes, then publish the newly
filtered list only after UnifiedHomeLibrary.localTracks returns.

Comment on lines +607 to +608
LaunchedEffect(tracks, query) {
delay(300)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Locate and inspect the relevant files and line ranges.
echo "== files =="
git ls-files | rg 'RockMusicExperience\.kt|UnifiedHomeLibrary\.kt$' || true

echo "== RockMusicExperience outline =="
ast-grep outline 'app/src/main/java/com/rockmusic/app/presentation/RockMusicExperience.kt' --view compact || true

echo "== relevant RockMusicExperience lines 560-690 =="
sed -n '560,690p' 'app/src/main/java/com/rockmusic/app/presentation/RockMusicExperience.kt' | nl -ba -v560

echo "== UnifiedHomeLibrary lines 1-80 =="
sed -n '1,80p' 'app/src/main/java/com/rockmusic/app/data/UnifiedHomeLibrary.kt' | nl -ba -v1

Repository: Sayanthrock-Developer/Rock-music

Length of output: 600


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== relevant RockMusicExperience lines 560-690 =="
sed -n '560,690p' 'app/src/main/java/com/rockmusic/app/presentation/RockMusicExperience.kt' | awk '{printf "%7d\t%s\n", $1+559, $2}'

echo "== UnifiedHomeLibrary lines 1-80 =="
sed -n '1,80p' 'app/src/main/java/com/rockmusic/app/presentation/UnifiedHomeLibrary.kt' | awk '{printf "%7d\t%s\n", NR, $0}'

echo "== references to LaunchedEffect/debounce/null search =="
rg -n "LaunchedEffect|debounce|300|UnifiedHomeLibrary|localTracks|No songs match" 'app/src/main/java/com/rockmusic/app/presentation/RockMusicExperience.kt'

Repository: Sayanthrock-Developer/Rock-music

Length of output: 4669


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== relevant RockMusicExperience lines 260-320 =="
sed -n '260,320p' 'app/src/main/java/com/rockmusic/app/presentation/RockMusicExperience.kt' | awk '{printf "%7d\t%s\n", NR+259, $0}'

echo "== RockMusicExperience around target LaunchedEffect/empty state =="
sed -n '580,675p' 'app/src/main/java/com/rockmusic/app/presentation/RockMusicExperience.kt' | awk '{printf "%7d\t%s\n", NR+579, $0}'

echo "== deterministic invariant probe from source text =="
python3 - <<'PY'
from pathlib import Path
text = Path('app/src/main/java/com/rockmusic/app/presentation/RockMusicExperience.kt').read_text()
needle = '''LaunchedEffect(tracks, query) {
        delay(300)'''
print("target_exact_early_return_condition_exists=", "if (query.isBlank()) return" in text[text.index(needle):text.index(needle)+300])
print("target_has_unique_delay_300=", text.count("      delay(300)") + text.count("        delay(300)") == 1 or text.count("delay(300)") >= 1)
print("query_isBlank_guard_nearby=", "if (query.isBlank()) return" in text or "if (query.isEmpty()) return" in text)
print("no_songs_text=", "No songs match this search." in text)
print("Blank query local tracks source=", "cleanedQuery.isBlank()" in Path('app/src/main/java/com/rockmusic/app/presentation/UnifiedHomeLibrary.kt').read_text())
PY

Repository: Sayanthrock-Developer/Rock-music

Length of output: 7755


Do not debounce the blank-query path.

UnifiedHomeLibrary.localTracks returns all distinct tracks when query is blank, but the effect always waits 300 ms. Since results is still empty during that wait, the UI shows “No songs match this search.” Compute blank-query results immediately and debounce only non-blank queries.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/src/main/java/com/rockmusic/app/presentation/RockMusicExperience.kt`
around lines 607 - 608, Update the LaunchedEffect keyed by tracks and query to
bypass the 300 ms delay when query is blank, computing the all-tracks result
immediately; retain the 300 ms debounce only for non-blank queries so results
are populated before the empty-state message appears.

Comment on lines +609 to +610
results = withContext(Dispatchers.Default) {
UnifiedHomeLibrary.localTracks(tracks, query, UnifiedHomeSource.SONGS)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🚀 Performance & Scalability | 🟠 Major | 🏗️ Heavy lift

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== locate file and symbols =="
git ls-files | rg 'app/src/main/java/com/rockmusic/app/presentation/RockMusicExperience\.kt|UnifiedHomeLibrary|UnifiedHomeSource' || true

echo
echo "== relevant lines around usage =="
if [ -f app/src/main/java/com/rockmusic/app/presentation/RockMusicExperience.kt ]; then
  sed -n '580,635p' app/src/main/java/com/rockmusic/app/presentation/RockMusicExperience.kt | cat -n -v
fi

echo
echo "== definitions/usages =="
rg -n "object UnifiedHomeLibrary|class UnifiedHomeLibrary|fun localTracks|localTracks\\(" .

Repository: Sayanthrock-Developer/Rock-music

Length of output: 4312


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== UnifiedHomeLibrary.kt outline/size =="
wc -l app/src/main/java/com/rockmusic/app/presentation/UnifiedHomeLibrary.kt
ast-grep outline app/src/main/java/com/rockmusic/app/presentation/UnifiedHomeLibrary.kt || true

echo
echo "== UnifiedHomeLibrary.kt contents =="
cat -n -v app/src/main/java/com/rockmusic/app/presentation/UnifiedHomeLibrary.kt

echo
echo "== surrounding usages in RockMusicExperience.kt =="
sed -n '260,315p' app/src/main/java/com/rockmusic/app/presentation/RockMusicExperience.kt | cat -n -v

Repository: Sayanthrock-Developer/Rock-music

Length of output: 5321


Make UnifiedHomeLibrary.localTracks cancellation-cooperative.

localTracks is a non-suspending List<LocalTrack> helper that can scan a large input via distinctBy and filter. Add periodic currentCoroutineContext().ensureActive() checks, or process the input in cancellable chunks.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/src/main/java/com/rockmusic/app/presentation/RockMusicExperience.kt`
around lines 609 - 610, Update UnifiedHomeLibrary.localTracks to cooperate with
coroutine cancellation while scanning large inputs: add periodic
currentCoroutineContext().ensureActive() checks or process the distinctBy/filter
work in cancellable chunks, while preserving its existing filtering and result
behavior.

@SayanthRock
SayanthRock merged commit c15d063 into main Aug 4, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S This PR changes 10-29 lines, ignoring generated files zenable/risk:low Zenable assessed this PR as LOW risk.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants