Skip to content

ADFA-7267 AI-Code-Suggestions: cancel the pending suggestion when the word is gone - #177

Open
davidschachterADFA wants to merge 1 commit into
mainfrom
fix/ADFA-7267-stale-suggestion
Open

davidschachterADFA wants to merge 1 commit into
mainfrom
fix/ADFA-7267-stale-suggestion

Conversation

@davidschachterADFA

@davidschachterADFA davidschachterADFA commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

ADFA-7267

Problem. Typing fun and then a space could show a suggestion for fun with the cursor already past the space. CodeSuggestionsPlugin.onEditorContentChanged returned early when no word of 2+ letters was left before the cursor (:136), before it cancelled the pending request (:143). The request started for fun therefore still ran 0.8 s later and showed its suggestion. A one-letter word after fun did the same. Found by reading the code.

Fix. Every edit now cancels the pending request first, then either dismisses (no word to complete) or starts a new one.

Also in this PR: IDE range. The plugin review (.claude/skills/plugin-review) failed rubric 6.1: plugin.max_ide_version was 26.30, and the current release is 26.47. It is now 26.99, like AI-Core and the other first-party plugins. Code on the Go reads this value but doesn't enforce it today, so installs were not blocked. plugin.min_ide_version stays 26.17.

Tests: the plugin's first unit tests, CodeSuggestionsPluginTest, drive the plugin through its content-change listener with a fake editor and a fake LLM:

  • a word of 2+ letters gets a suggestion;
  • fun then fun never sends fun to the model, and nothing is shown;
  • fun then fun x (a one-letter word) likewise.

Before the fix, the last two failed: the model was asked about fun at about 0.8 s. After it, all three pass. They use real time, so the two cancel tests wait 2 s each. CI does not run plugin unit tests; run them with ./gradlew testDebugUnitTest in plugins/AI-Code-Suggestions.

Checks at 8d2dcd4: testDebugUnitTest, assemblePlugin (no warnings) and addons check pass. The plugin review passes every clause. Build security audit: nothing found. The .cgp records revision 8d2dcd4f5068 (not dirty) and an IDE range of 26.17 to 26.99.

Not covered. A request already past its last cancellation check (between ensureActive() and showInlineSuggestion) can still show its suggestion. The window is microseconds.

Version: 1.1.0 / versionCode 2 → 1.1.1 / versionCode 3 (PATCH).

Not yet verified on a device. A retest on a Galaxy Note 20 is planned: the current build first, to see whether suggestions appear at all (the one earlier check was invalid), then this build.

Screens: no layout change.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Vh2DAZWMkFWJh7CY7P4kCH

… word is gone

Typing "fun" and then a space showed a suggestion for "fun" after the space.
An edit that left no word of 2+ letters before the cursor returned before
cancelling the request started for the previous word, so that request ran
0.8 s later and showed its suggestion. Every edit now cancels the pending
request first.

Adds the plugin's first unit tests: a word still gets a suggestion, and
neither a space nor a one-letter word after "fun" sends "fun" to the model.
Both of those fail without the fix.

Also raises plugin.max_ide_version from 26.30 to 26.99, like AI-Core and the
other first-party plugins: the plugin review failed rubric 6.1 because the
declared range excluded the current release (26.47).

Version 1.1.0 -> 1.1.1 (versionCode 2 -> 3).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Vh2DAZWMkFWJh7CY7P4kCH
@coderabbitai

coderabbitai Bot commented Nov 23, 2026

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

  • Fixed: A pending suggestion request now cancels on every edit. Before, a prefix shorter than two letters or a space left the earlier request running, so it could show a stale suggestion for fun.
  • Added: CodeSuggestionsPluginTest covers a two-letter word (suggestion shown) and a space or one-letter word (no LLM request, no suggestion).
  • Version: plugin 1.1.0 (code 2) changes to 1.1.1 (code 3).
  • IDE range: plugin.max_ide_version changes from 26.30 to 26.99. plugin.min_ide_version stays at 26.17.

Risks:

  • A request can still show a suggestion if it passes its last cancellation check before showInlineSuggestion. The race is not closed.
  • Plugin unit tests are not run in CI. Only the author ran them locally, with ./gradlew testDebugUnitTest.
  • The tests use real time and wait 2 seconds per cancellation case. This can make them slow or flaky.
  • Device retesting is planned but not done.
  • The author states that Code on the Go reads the maximum IDE version but does not enforce it. The raised limit therefore has no install-blocking effect now, and a future enforcement change could affect this plugin.

The plugin now cancels pending suggestion jobs before checking whether a prefix is empty or shorter than two characters. Tests cover valid and short prefixes. The plugin version, maximum IDE version, and test configuration also changed.

Changes: Suggestion cancellation

Layer / File(s) Summary
Cancellation behavior and validation
plugins/AI-Code-Suggestions/build.gradle.kts, plugins/AI-Code-Suggestions/src/main/AndroidManifest.xml, plugins/AI-Code-Suggestions/src/main/kotlin/com/itsaky/androidide/plugins/aicodesuggestions/CodeSuggestionsPlugin.kt, plugins/AI-Code-Suggestions/src/test/kotlin/com/itsaky/androidide/plugins/aicodesuggestions/CodeSuggestionsPluginTest.kt
The plugin cancels the pending job before checking prefix length. Tests verify that fun displays a suggestion, while a trailing space or one-letter word prevents a pending prompt and suggestion. Test dependencies and configuration were added. Plugin version and maximum IDE version were updated.

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

Suggested reviewers: jatezzz, hal-eisen-adfa

Merge Risk: Minimal · up to 8d2dc

This change cancels a pending code suggestion when the typed word disappears, so a stale suggestion for an earlier word is much less likely to appear. It also bumps the plugin version and widens the declared maximum IDE version. No concrete merge-blocking risk was found. A narrow timing window that predates this change remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the fix: the pending AI code suggestion is cancelled when the word it was for is gone. It matches the main change in CodeSuggestionsPlugin.onEditorContentChanged, which now cancels the…
Description check Passed The description is closely related to the changeset. It explains the stale-request bug in onEditorContentChanged and the fix that cancels first. It also covers the new CodeSuggestionsPluginTest cases,…
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.
Full details: Title check

Explanation

The title names the fix: the pending AI code suggestion is cancelled when the word it was for is gone. It matches the main change in CodeSuggestionsPlugin.onEditorContentChanged, which now cancels the pending job before the early returns. The version bump and IDE range change are secondary and need not appear in the title.

Full details: Description check

Explanation

The description is closely related to the changeset. It explains the stale-request bug in onEditorContentChanged and the fix that cancels first. It also covers the new CodeSuggestionsPluginTest cases, the max_ide_version change from 26.30 to 26.99, and the version bump to 1.1.1 / versionCode 3. It is detailed and matches the diff summaries.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

A rabbit taps a word, then waits,
A fresh request now checks its gates.
Short prefixes end the pending chase,
Longer words can earn their place.
Tests watch each prompt appear or cease,
And version numbers hop in peace.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: 4eef648e-a998-4aaa-8b6b-0655d1eae7d6
Commits

Reviewing files that changed from the base of the PR and between 1bd273b and 8d2dcd4.

Files selected for processing: 4

  • plugins/AI-Code-Suggestions/build.gradle.kts
  • plugins/AI-Code-Suggestions/src/main/AndroidManifest.xml
  • plugins/AI-Code-Suggestions/src/main/kotlin/com/itsaky/androidide/plugins/aicodesuggestions/CodeSuggestionsPlugin.kt
  • plugins/AI-Code-Suggestions/src/test/kotlin/com/itsaky/androidide/plugins/aicodesuggestions/CodeSuggestionsPluginTest.kt

Included review availability: This review used your included allowance. 1 included review remains after this review. Your included PR review attempts over the past 7 days set your current allowance at 2 reviews per hour.

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.

1 participant