Skip to content

fix(bots): re-read the item's open view when a refused reply was sent from one since closed - #48390

Merged
AmethystLiang merged 1 commit into
mainfrom
AmethystLiang/fix-home-chat-stale
Nov 25, 2026
Merged

AmethystLiang merged 1 commit into
mainfrom
AmethystLiang/fix-home-chat-stale

Conversation

@AmethystLiang

@AmethystLiang AmethystLiang commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

If you reply to an agent's question, then go back and open the item again before the host answers, and the host turns the reply down because the agent has since asked a new question, the screen you're looking at now loads the new question. Before this fix, only the screen you had left was reloaded, so the one in front of you kept showing the old question and your next reply was turned down too.

Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​194 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​194
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​24 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​20

What Changed

  • Before: fix(items): re-read an item after a reply to a replaced question is refused #48387 made a reply refused with item_changed re-read the item. On desktop it did this through the retry of the view the reply was sent from. Replies wait in a queue that outlives the view, so if the owner pressed Back and opened the item again, the refusal re-read a view that was already gone. The open view kept the replaced question as its reply target until some other change notice arrived.
  • After: each open view of an item registers its re-read, keyed by host, bot and item (rereadBotItemView in use-bot-item-view.ts), and removes it when it closes. The desktop's shared refresh for a refused reply is now () => rereadBotItemView(bot, uid), so whichever view of that item is open re-reads, and only that item's views. The hook no longer takes a callback, so BotItemView.tsx stops passing view.retry.
  • Unchanged: the refused words still go back to the comment box (an empty box takes them, a box with newer typing keeps it), nothing is re-sent, and a failed re-read shows the view's existing Retry.

Why

When the host refuses a write because the record changed, the screen the user is looking at should reload. The refused text should come back, and the screen should never keep pointing at an outdated target. Checked against how comparable products handle this. A registry of the item's open views reaches that screen, even when the refusal arrives after the screen it was sent from has closed. Re-reading through the sending view only works while that view is still open.

Linked Issue

Refs #48381

This addresses one way the reported symptom can persist (a refusal re-read lost across Back/reopen). It does not claim to explain the whole report, whose exact state was not captured.

Visual Proof

N/A: there is no new UI. The behaviour is the existing re-read, now reaching the open view; the tests below cover it.

Testing

src/renderer/src/components/bots/items/use-bot-item-pending-comments.test.tsx uses the real useBotItemView and the real pending-comments store, with host calls mocked:

  • A reply is held on its way; the item is closed and opened again (the new view reads the old question); then the agent asks again with no change notice. When the refusal arrives, the open view re-reads and shows the new question. The reply is posted once (nothing re-sent), an empty box gets the words back, a box with newer typing keeps it, and another item's view makes no read.
  • A failed re-read shows the view's Retry, which then loads the new question.
  • A refusal in the same view re-reads it, and an ordinary failure stays with Retry and makes no read.

The three reopen cases fail on main (the sending view's retry as refresh) and pass with this change; the same-view case passes on both. Also run: bot-item renderer suites and shared pending-comments tests (36 tests), scoped oxlint/oxfmt, the changed-code quality gate, the max-lines ratchet, test-runner and import-boundary checks, and the web typecheck. Hosted CI covers the rest.

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below
  • Every added test fails without this change and avoids the test anti-patterns

Performance

None. The work is a Set add/delete when an item view's read effect mounts or unmounts. A refusal (rare) now re-reads the open views of that one item, the same "changes since" read a change notice triggers.

Risk

Level: Low

Desktop only. The riskiest part is the registry's lifetime: a view that failed to unregister would keep a stale re-read. The cleanup removes it in the same effect that registers it, and drops the entry when an item's last view closes. The phone keeps #48387's view.retry. Back it out with a plain revert.

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • I stated the risk: what could break, for whom, and how to back it out
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • Resume reviews
  • Trigger review
Walkthrough

Question pairing now considers the host’s waiting ask and event timing when it selects a reply target. Desktop and mobile views use the selected ask for question pages and comment-box sends. When a pending reply is refused because its question was replaced, the open item view rereads its data. Tests cover stale reads, reply-target selection, text handling, and retry behavior.

Severity of issue fixed: Medium

Merge Risk: Moderate · previous review e6af8

Replies target the current waiting question when Activity is stale. On older hosts that do not report the waiting question, a stale read after a partial answer may leave the composer with no reply target. Current hosts are not affected, so merging with that known gap is a bounded risk.

Pre-merge checks: Passed 4

Check name Status Explanation
Linked Issues check Passed Issue #48381 requires two behaviors. Both are present at the reviewed head.

(1) Reply target follows the current question, or shows no target while it loads. In src/shared/bots/bot-item-question-answ…
Out of Scope Changes check Passed The changed areas relate to the stale reply-target bug in #48381:
- src/shared/bots/bot-item-question-answers.ts: pairing, the waiting gate, eventsRead and hostAsksLater, and the waiting-line fallback…
Title check Passed The title names the main change: a refused reply sent from a view that has since closed now causes the item's currently open view to re-read. The changeset adds rereadBotItemView, a per-item registry …
Description check Passed The description follows the repository template closely. It has ELI5, What Changed, Why, Linked Issue (Refs #48381, which the template says is not sufficient for outside contributors, though this is n…
Full details: Linked Issues check

Explanation

Issue #48381 requires two behaviors. Both are present at the reviewed head.

(1) Reply target follows the current question, or shows no target while it loads. In src/shared/bots/bot-item-question-answers.ts, botItemQuestionPairing sets an ask to waiting only when hostAsksLater(item.waitingAsk, open.id) is false. hostAsksLater is true when the host names an ask later than the latest ask in the loaded events. In the reported case (events hold older ask A, host names newer ask B), A does not wait. botItemWaitingLine then uses item.question as the target only when item.waitingAsk is unset or equals question.eventId and that event is not yet read. The result is the newer question, or null while it loads. This meets the requirement. The reverse case (item names A, events hold A and later B) keeps B waiting, which the issue also accepts because B is the current question.

(2) A reply refused with item_changed refreshes the owner's view and keeps the text. In src/renderer/src/components/bots/items/use-bot-item-view.ts, rereadBotItemView(bot, uid) calls every reread callback registered for the item's host, id, and uid. Each open useBotItemView effect registers its reread and unregisters it on cleanup. This covers a view opened after the refused send. The failed-send handler in use-bot-item-pending-comments.ts calls this re-read; this inspection did not read that file, so this link rests on the prior review and the PR description. The author reports tests in use-bot-item-pending-comments.test.tsx and bot-items-open-questions.test.ts. Those test files were not read in this review.

The objectives text describes an earlier commit rule (an ask waits only when the host names none or the same). The head code uses the later rule stated in the current PR description. The code at head is the authority here. No unmet coding requirement was found.

Full details: Out of Scope Changes check

Explanation

The changed areas relate to the stale reply-target bug in #48381:

  • src/shared/bots/bot-item-question-answers.ts: pairing, the waiting gate, eventsRead and hostAsksLater, and the waiting-line fallback. These choose the reply target and the waiting state.
  • src/renderer/src/components/bots/items/use-bot-item-view.ts: the reread registry used by the item_changed refresh.
  • Consumers of the same helpers (BotItemView.tsx, use-bot-item-question-steps.ts, bot-item-activity.ts, bot-item-reply-target.ts): these read the same reply target, so they follow the same fix.
  • Mobile files (MobileBotItemAskCard.tsx, use-phone-bot-item-view.ts): these reuse the shared pairing helpers. The issue names desktop only, so the phone change extends the scope. It is a consequence of the shared helper and is described in the PR, not an unrelated change.
  • Closed-item and plain-send handling (botItemBoxReply, reopen cases): these determine whether a send names the current ask, which is part of the stale-target symptom.
  • Tests: cover the stale-Activity and refresh cases.

No change was found that lacks a connection to the reply target or the refresh. The test files and the registry's pending-comments caller were not read in full, so the relation of the phone and reopen changes rests on the PR description and the head code of the shared helpers.

Full details: Title check

Explanation

The title names the main change: a refused reply sent from a view that has since closed now causes the item's currently open view to re-read. The changeset adds rereadBotItemView, a per-item registry of open views, and switches the refresh for item_changed refusals to use it. The title is specific and matches the primary change, and it follows the fix(bots) convention.

Full details: Description check

Explanation

The description follows the repository template closely. It has ELI5, What Changed, Why, Linked Issue (Refs #48381, which the template says is not sufficient for outside contributors, though this is not stated to be an outside contribution), Visual Proof (N/A with reason), Testing with a checklist, Performance (None, with a reason), and Risk with a level and revert plan. Gaps: the Review section is empty, the AI Disclosure section is left blank, the Notes section is only the template default, and the Linked Issue is a 'Refs' link rather than a 'Fixes' link. Checklist items for lint, typecheck, test and build are unchecked, though the author notes the checks were run locally. The Testing section states that manual testing is unchecked.

  • 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

@AmethystLiang
AmethystLiang force-pushed the AmethystLiang/fix-home-chat-stale branch 3 times, most recently from 823f3ed to 7913a51 Compare November 24, 2026 18:52

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5f26e0b5-256f-4100-aebc-e9400ebea5c7
Commits

Reviewing files that changed from the base of the PR and between 823f3ed and 7913a51.

Files selected for processing: 7

  • src/main/bots/bot-items-open-questions.test.ts
  • src/renderer/src/components/bots/items/BotItemView.tsx
  • src/renderer/src/components/bots/items/use-bot-item-question-steps.test.tsx
  • src/renderer/src/components/bots/items/use-bot-item-question-steps.ts
  • src/shared/bots/bot-item-activity.ts
  • src/shared/bots/bot-item-question-answers.ts
  • src/shared/bots/use-bot-item-question-steps.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

@AmethystLiang
AmethystLiang force-pushed the AmethystLiang/fix-home-chat-stale branch from 7913a51 to e6af8a6 Compare November 24, 2026 19:32

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b4c6cd73-4e32-48d1-8b92-ec70bd9a34a9
Commits

Reviewing files that changed from the base of the PR and between 7913a51 and e6af8a6.

Files selected for processing: 11

  • mobile/src/bots/items/MobileBotItemAskCard.test.ts
  • mobile/src/bots/items/MobileBotItemAskCard.tsx
  • mobile/src/bots/items/use-phone-bot-item-view.test.tsx
  • mobile/src/bots/items/use-phone-bot-item-view.ts
  • src/main/bots/bot-items-open-questions.test.ts
  • src/renderer/src/components/bots/items/BotItemView.tsx
  • src/renderer/src/components/bots/items/use-bot-item-question-steps.test.tsx
  • src/renderer/src/components/bots/items/use-bot-item-question-steps.ts
  • src/shared/bots/bot-item-question-answers.ts
  • src/shared/bots/bot-item-reply-target.ts
  • src/shared/bots/use-bot-item-question-steps.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.

@AmethystLiang
AmethystLiang force-pushed the AmethystLiang/fix-home-chat-stale branch 2 times, most recently from cce36c5 to 86d01c3 Compare November 24, 2026 23:34
@AmethystLiang AmethystLiang changed the title fix(bots): keep the reply box off an ask the host says was replaced fix(bots): re-read the item's open view when a refused reply was sent from one since closed Nov 24, 2026
… from one since closed

A reply the host refuses because the agent asked a new question re-read the
item through the view it was sent from. After Back and the item again, that
view was gone, so the open one kept naming the replaced question and the next
reply was refused too. Each open view of an item now registers its read, and
the refusal re-reads every open view of that item.

Refs #48381
@AmethystLiang
AmethystLiang force-pushed the AmethystLiang/fix-home-chat-stale branch from 86d01c3 to 9c088ef Compare November 25, 2026 08:23
@AmethystLiang
AmethystLiang merged commit e9c21b1 into main Nov 25, 2026
55 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.

1 participant