Skip to content

fix(items): re-read an item after a reply to a replaced question is refused - #48387

Merged
nwparker merged 1 commit into
stablyai:mainfrom
413180794:fix/item-reply-stale-question-target
Nov 24, 2026
Merged

nwparker merged 1 commit into
stablyai:mainfrom
413180794:fix/item-reply-stale-question-target

Conversation

@413180794

@413180794 413180794 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

When you answer a bot's question in an item and the host says "that question was replaced by a newer one," Orca now goes back and re-loads the item once. If your screen had missed the newer question, it shows up, and your next answer goes to the right question. Before, Orca never re-loaded, so every try was refused the same way.

What Changed

Before: the "Replying to" target in the item comment box comes from the events the app has loaded. If the app missed the update that added a newer question (for example, a missed bots-changed push on desktop or a missed read on the phone), the box kept naming the old question. The host refused the reply with item_changed. deliver() in src/shared/bots/bot-item-pending-comments.ts showed a toast and put the words back in the box, but nothing re-read the item. The next send named the same stale question and was refused again.

After: BotItemPendingCommentDelivery has a required refresh: () => void. deliver() calls it once in the replaced (item_changed) branch, right after the words go back to the box. The re-read brings in the newer question, so the next reply targets it.

  • Shared: refresh is required, so typecheck makes both apps wire it.
  • Desktop: BotItemView passes view.retry (an incremental bots.items.owner.show read).
  • Phone: MobileBotItemPage passes view.retry through usePhoneBotItemPendingComments.

refresh only reads. Nothing is resent and nothing loops. Plain comments are unaffected, because the replaced branch needs a question id.

Why

A refusal is a clear sign the view is stale, so it is the cheapest point to heal it. One read per refusal, with no polling or new timers.

The original PR also changed botItemQuestionPairing to prefer the host's item.waitingAsk over the loaded events. That part was dropped. owner.show reads the item before its events, so a host waitingAsk newer than the loaded events can't happen. The reverse race can: a new question lands between the two reads, and with that change the box lost the live question.

Linked Issue

Refs #48381

This is a partial fix. It covers a view that missed an update. It does not cover a lasting disagreement between client and host about which question is waiting, for example a remote host on another build. In that case the re-read returns the same events and the target stays put. Each refusal still keeps the typed words. The issue says the stale target comes back after reopening the chat. A reopen already re-reads, so that symptom may have a second cause. The issue stays open for that.

Visual Proof

N/A. The change only adds a re-read on a refusal from the host, and the stale state depends on a missed push, which can't be set up reliably in the GUI. The visible result is that the comment box's "Replying to" line moves to the newer question after a refusal. It was checked with unit tests, not on screen.

Testing

  • Reproduced at unit level by driving the real useBotItemView retry path with a mocked host that adds a newer question and drops the bots-changed push. Without the fix, the composer still targeted the replaced question after the refusal (expected 'e1' to be 'e2'). With the fix, one extra read ran, the draft kept its text, and the next send carried the new question id and was accepted. That mock-heavy test was not kept, because AGENTS.md rules out wiring/mock-call tests.

  • vitest --config config/vitest.config.ts src/renderer/src/components/bots/items/ src/shared/bots/bot-item: 14 files, 57 tests passed.

  • mobile vitest run src/bots/items/: 2 files, 13 tests passed.

  • oxlint, oxfmt, anti-slop oxlint, native code-quality oxlint, ast-grep (warning), and the changed-code quality gate are clean on all 6 touched files.

  • Mobile tsc --noEmit shows no errors in touched files. Its 3 remaining errors are in an unrelated, pre-existing file.

  • Platforms: unit tests on macOS. No GUI run.

  • 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

The existing refused-reply draft test only gains the new required refresh stub. No assertion on the call count was kept (see above).

Performance

None, because this only runs after the host refuses a quick reply with item_changed, a rare path that starts with a user send. Each refusal costs one incremental owner.show read. On both apps, retry re-runs the view effect, which also re-subscribes the bots-changed listener, a cheap step. No polling, timers, sync I/O, subprocesses or per-render work were added. Send, success and render paths are unchanged.

Risk

Level: Low

The riskiest part is the extra read after a refusal. If it failed, the view would show its normal read-error state, the same as a manual Retry. The change is client-side only and uses the existing owner.show read, so older paired phones and remote hosts are unaffected. On hosts without question-bound replies, the replaced branch never runs. 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

Thanks @413180794 for the analysis and original fix in #48387. Their authorship is kept as a co-author on the commit.

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 →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

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: 4ff5d39c-6d60-4cde-815a-a77afcf2802d
Commits

Reviewing files that changed from the base of the PR and between 5e20cd8 and ec72aa5.

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
Walkthrough

Pending-comment delivery now calls a refresh callback after a reply is refused because its question was replaced. Desktop and mobile item views pass their retry callbacks through the pending-comment hooks. On mobile, the page restores held draft text only when that text is not already recorded in card answers.

Severity of issue fixed: Medium

Merge Risk: Moderate · previous review 5e20c

When the host refuses an answer because the question was replaced, the refresh now targets the new question. The refused answer is only kept if the draft box is empty on desktop, and mobile card answers are not kept anywhere the owner can see. Owners can lose a typed answer in those cases, so these gaps should be fixed or explicitly accepted before merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Linked Issues check Passed Directly linked issue #48381 has two coding requirements. (1) The composer must target the current question, or show no target while it loads, when activity is stale. (2) After an item_changed refusal…
Out of Scope Changes check Passed The changed areas connect to #48381. They are: the shared waiting-ask selection in src/shared/bots/bot-item-question-answers.ts; the pending-comment refusal path in src/shared/bots/bot-item-pending-co…
Title check Passed The title names the main change: after a reply to a replaced question is refused, the item is re-read. The changeset adds a required refresh callback to the pending-comment delivery flow, wires view.r…
Description check Passed The description follows the template closely. It has ELI5, What Changed (before and after with the mechanism), Why (including the dropped waitingAsk change), Linked Issue (Refs #48381, with an explici…
Full details: Linked Issues check

Explanation

Directly linked issue #48381 has two coding requirements. (1) The composer must target the current question, or show no target while it loads, when activity is stale. (2) After an item_changed refusal, the desktop must refresh the item and keep the answer text for review. Requirement (1): the shared selection logic in src/shared/bots/bot-item-question-answers.ts compares the activity-derived open ask with item.waitingAsk. A stale ask that does not match is not marked waiting. When waitingAsk is absent, the logic falls back to item.question.eventId. The author reports a stale-selection regression test (bot-item-stale-question.test.ts) that fails without the fix and passes with it. Requirement (2): BotItemView passes view.retry into useBotItemPendingComments, and the shared pending-comment delivery calls refresh() after a replaced-question failure, while the answer text is returned to the draft. The author reports use-bot-item-pending-refresh.test.tsx as passing. Limit: the diffs for this head could not be read in this review (changed blobs unavailable). Requirement (2) and the mobile wiring therefore rest on the supplied summaries and the reported test results. Related issues #48135 and #48139 are closed context and add no requirements.

Full details: Out of Scope Changes check

Explanation

The changed areas connect to #48381. They are: the shared waiting-ask selection in src/shared/bots/bot-item-question-answers.ts; the pending-comment refusal path in src/shared/bots/bot-item-pending-comments.ts and the renderer hook use-bot-item-pending-comments.ts; the BotItemView wiring of view.retry; the mobile wiring in use-phone-bot-item-pending-comments.ts; and the matching tests. The mobile MobileBotItemPage change (held draft not returned when its text is already in cardAnswers) concerns draft restoration after refusal, which is part of this issue's requirement (2). The PR description does not describe this mobile dedupe rule in detail, so the author should confirm it in the description. The shared selection change also affects host-facing pairing semantics. That is an expected effect of requirement (1), not an unrelated change. The diffs could not be read in this review, so this verdict rests on the supplied summaries.

Full details: Title check

Explanation

The title names the main change: after a reply to a replaced question is refused, the item is re-read. The changeset adds a required refresh callback to the pending-comment delivery flow, wires view.retry on desktop and mobile, and calls refresh on the item_changed branch. The title uses the conventional fix(items) prefix and stays specific, at 75 characters.

Full details: Description check

Explanation

The description follows the template closely. It has ELI5, What Changed (before and after with the mechanism), Why (including the dropped waitingAsk change), Linked Issue (Refs #48381, with an explicit partial-fix note), Visual Proof (N/A with a reason), Testing, Performance, Risk with level and revert path, Review, Notes, and Checklist. Gaps: the Linked Issue uses 'Refs' rather than the 'Fixes #' form, and the description says the issue remains open. The AI Disclosure section is absent. The template's 'Fixes #' line is replaced, and the lint/typecheck/test/build checklist item is unchecked. These gaps are minor, and the description is mostly complete.

Finishing Touches

Fix failing CI checks

  • Create a new PR
  • 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

@nwparker
nwparker force-pushed the fix/item-reply-stale-question-target branch from 8b5306d to 5e20cd8 Compare November 24, 2026 18:36
@nwparker nwparker changed the title fix(items): refresh stale question reply targets fix(items): re-read an item after a reply to a replaced question is refused Nov 24, 2026

@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: 2

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: 8815f1de-65aa-4391-bbf5-7e4358740dfc
Commits

Reviewing files that changed from the base of the PR and between 8b5306d and 5e20cd8.

Files selected for processing: 5

  • mobile/src/bots/items/MobileBotItemPage.tsx
  • mobile/src/bots/items/use-phone-bot-item-pending-comments.ts
  • src/renderer/src/components/bots/items/bot-item-comment-draft.test.ts
  • src/renderer/src/components/bots/items/use-bot-item-pending-comments.ts
  • src/shared/bots/bot-item-pending-comments.ts

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

}
}
},
refresh: view.retry

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.

Major · Data Integrity & Integration · Heavy lift

Keep refused card answers reviewable after an item_changed refusal.

When the host refuses a card answer because the question was replaced, returnText skips the comment-box draft for any text in cardAnswers. The pending entry is removed, and refresh only re-reads the item. The inspected card and page do not render the refused text afterward, so the owner can lose the answer. The PR requires the refused answer text to remain available for review.

Keep the refused card answer available to the owner after the refresh. The comment box names the replacement question, so the answer must not appear there as a reply to that question. Choosing the surface is a design decision.

Comment on lines 225 to 226
update(key, id, null)
delivery.returnText(botItemPendingCommentText(entry), entry)

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.

Major · Data Integrity & Integration · Heavy lift

Keep the refused answer when the draft is occupied.

If the owner types a new draft while the answer is in flight, the desktop returnText callback does not overwrite that draft. The pending entry has already been removed, so the refused answer is lost. Keep the answer in a recoverable state when it cannot be restored to the draft, without allowing an automatic resend.

…efused

When the host refuses a quick reply with item_changed, the shared
pending-comment delivery now calls a required refresh() once, right after
the words go back to the comment box. Desktop and phone both pass
view.retry, so a view that missed the newer question re-reads the item
and the next reply names the current question instead of being refused
again. Nothing is resent and nothing loops.

Refs stablyai#48381

Co-authored-by: makeSail <[email protected]>
@nwparker
nwparker force-pushed the fix/item-reply-stale-question-target branch from 5e20cd8 to ec72aa5 Compare November 24, 2026 19:15
@nwparker
nwparker merged commit af1293c into stablyai:main Nov 24, 2026
58 checks passed
@413180794
413180794 deleted the fix/item-reply-stale-question-target branch November 25, 2026 06:30
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