Skip to content

fix(native): a new question stops the background title or summary - #78

Merged
rferrari merged 2 commits into
rferrari:fullnative-devfrom
bgrana75:fix/native-cancel-background-on-send
Oct 10, 2026
Merged

rferrari merged 2 commits into
rferrari:fullnative-devfrom
bgrana75:fix/native-cancel-background-on-send

Conversation

@bgrana75

Copy link
Copy Markdown

A new question stops the background title or summary

Builds on #76 (CI, including the app compile step added there); the last commit is this PR's.

Finding 3 of the review. send() started with background?.join() (ChatViewModel.kt:199): the question waited for the chat title (the 2nd question of every new chat) or the summary (after every answer once a chat passes 6 exchanges). A summary reads every older turn before writing, so on a slower phone a question could wait tens of seconds before its own retrieval even started. The Expo app stops that task instead (cancelBackgroundTask in ChatScreen.tsx).

stopBackground() replaces the join:

  • background.cancel(): a title or summary that hasn't started never starts, and one that has throws out of Summarize.title/summary, so setTitle/setSummary never save a half-written result;
  • session.cancel(): stops the native prompt reading (checked between batches) or writing in progress;
  • then joins, so the answer never shares the context with it.

A stopped title leaves the question as the chat's title (what it shows until the model writes one). A stopped summary is written after a later answer, as in the Expo app. Your planned prefix refill at the end of the background job is unaffected: a stopped job just doesn't reach it, and the answer reads the prefix itself.

Not measured. The app has no unit tests for ChatViewModel; CI only compiles it (#76). I haven't built or run it (no Android toolchain here), so it needs a check on a phone: in a new chat, send a second question right after the first answer; it should start without waiting for the title. No CodeRabbit CLI review was run before pushing (cr isn't installed here).

send() waited for the background job (background?.join()). After 6 exchanges a summary runs after
every answer and reads every older turn first, so on a slow phone each question could wait tens of
seconds before its own work started. ChatScreen.tsx stops that task instead (cancelBackgroundTask).

stopBackground() cancels the job (one that hasn't started never starts; one that has throws, so a
half-written title or summary is never saved) and cancels the native generation in progress, then
waits for it to return.
@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0649f303-48aa-471d-837c-50ac9e8d1099

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@rferrari

Copy link
Copy Markdown
Owner

Approve. Checked against the prompt-cache refill I added at the end of the background
job (fc6b923):

  • a cancelled job never reaches the refill;
  • the native cancel flag is reset at the start of the answer's own generate, so a stale
    cancel can't stop the answer.
    runCatching around setTitle/setSummary swallows the CancellationException, but it's thrown
    inside title()/summary() before anything is saved, so nothing half-written lands.
    Phone check still to do: the second question in a new chat starts without waiting for the
    title.

@bgrana75

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@rferrari
rferrari merged commit 74e4776 into rferrari:fullnative-dev Oct 10, 2026
3 checks passed
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