Skip to content

fix(chat): cancel abandoned reads when a chat resumes - #2584

Merged
devswha merged 4 commits into
devswha:mainfrom
bonecool999:fix/chat-resume-cancel-reads-20261102
Nov 2, 2026
Merged

devswha merged 4 commits into
devswha:mainfrom
bonecool999:fix/chat-resume-cancel-reads-20261102

Conversation

@bonecool999

Copy link
Copy Markdown
Contributor

Change

Returning to a chat can wait for a request started before the chat was hidden. Recent tabs stay mounted, but ConversationRefresh.stop() previously stopped timers without cancelling the active read, leaving the serial read lane occupied until the old request or its 15-second local / 30-second remote deadline settled.

Tie newest-page, gap-fill, older-page and terminal-fallback reads to the visible screen's lifetime. Hiding or replacing the screen cancels that lifetime, including when the transport ignores abort, so the next visible read can start promptly. A pending press-read prefetch transfers its cancellation ownership to the one screen that takes it. Cancellation also reaches the existing single session-change retry.

Preserve #2576's pane/session cache ownership, stale-409 protection and bounded session retry. Signals are transport-only; there are no new HTTP/WS fields, settings, dependencies or server changes.

The lifecycle design follows the effect-owned fetch cancellation in Paseo's DocumentFrame, applied to Ovis's existing mounted-chat behavior from #1061. No code or visual assets were copied.

Validation

  • bun test src/lib/chatReadDeadline.test.ts src/lib/conversationFetch.test.ts src/lib/api.test.ts src/components/ChatFallback.test.ts: 80 passed, 0 failed. The same four files also passed inside the full-fast attempt.
  • Failing first: with the original 64ae5e72 scheduler/deadline helpers, the controlled-clock regression fails because the replacement reader never starts while the obsolete request is held. The candidate passes that same case.
  • bun scripts/chat-history-browser-qa.ts: the new same-mounted-key hide/return cases passed at 390px (83ms) and 1440px (69ms), with the obsolete HTTP request cancelled and fresh rows visible before it was released. These are controlled React/Chromium fixtures, not device or WAN timings. The whole existing script is not green: its later .chat-new-messages wait times out identically on the original 64ae5e72 source and the candidate; assertions and timeouts were not relaxed.
  • bun run check fast: generated types/themes, typecheck and production build passed. The unit gate did not pass. There were failures in 15 files outside this patch; the final server/usage-login-private.test.ts process stalled for over five minutes and was interrupted through the check runner after the other 655 of 656 files completed. Owned recorded descendants were confirmed gone.
  • Focused checks on the original 64ae5e72 source reproduced 22 of the 23 named failures from those 15 files. The additional server/remote-entry.test.ts case, reclaims a startup lock whose PID another process now holds, passed in the focused baseline and remains unexplained here. The original private-login file also exceeded a bounded 20-second comparison. These checks use the same Bun/dependencies but check run adds isolated XDG/config/state, whereas fast runs unit tests with the plain allowlisted environment; this is not an identical-environment full-suite comparison.
  • Environment: macOS arm64, Bun 1.4.2, Node 26.9.0. The runner warned that CI uses Node 22. Workflow syntax was automatically skipped on macOS because actionlint is pinned for Linux x64.
  • Not run: check full, the full integration/browser lanes, WebKit/physical iPhone or native Windows checks.
Files with local unit failures outside this patch
server/codex-processes.test.ts
server/session-history.test.ts
server/codex.test.ts
scripts/check.test.ts
scripts/self-hosted-runner.test.ts
server/statusline-install.test.ts
server/letta.test.ts
scripts/install-star.test.ts
scripts/shell-deploy-workflow.test.ts
scripts/ci-browser.test.ts
server/remote-entry.test.ts
scripts/shell-preview-workflow.test.ts
scripts/ci-browser-parallel.test.ts
server/core/composer-framing.test.ts
scripts/relay-ios-sim.test.ts

AI tools assisted implementation and static review.

@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Important

Review skipped

Auto incremental reviews are disabled on this repository.

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
  • Source mode: Auto
  • Repository: devswha/ovis
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: 99a6671
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d14fd8b6-e90d-48ce-b53c-8f9c61588067

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

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: devswha/ovis
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: 64ae5e7
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 91a4701c-3147-4162-84f5-e62e11f9af89
Commits

Reviewing files that changed from the base of the PR and between 64ae5e7 and d29cc5a.

Files selected for processing: 10
  • changelog.d/chat-resume-cancel-reads.md
  • scripts/chat-history-browser-qa.ts
  • scripts/chat-history-fixture.tsx
  • src/components/ChatView.tsx
  • src/lib/api.ts
  • src/lib/chatReadDeadline.test.ts
  • src/lib/chatReadDeadline.ts
  • src/lib/conversationFetch.test.ts
  • src/lib/conversationRefresh.ts
  • src/lib/machineContext.tsx

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

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Leaving a hidden chat now cancels its pending conversation and older-message reads. Returning to the chat no longer has to wait for an abandoned request to time out, and fresh conversation updates appear promptly.
    • Prevented late responses from abandoned reads from replacing newer conversation data.

Conversation reads and older-page reads now use cancellation signals tied to the active chat read scope. The changes cover API requests, ChatView fetches, and browser checks that hide and restore a mounted chat.

Changes: Chat read lifecycle

Layer / File(s) Summary
Read scopes and deadlines
src/lib/conversationRefresh.ts, src/lib/chatReadDeadline.ts, src/lib/chatReadDeadline.test.ts
Replacing or stopping a ConversationRefresh reader aborts its active scope. withChatReadDeadline accepts an external signal and removes its abort listener during cleanup. Tests cover cancellation and listener cleanup.
Signal-aware conversation API
src/lib/api.ts, src/lib/machineContext.tsx, src/lib/conversationFetch.test.ts
Transcript and conversation reads pass signals through bounded requests, adopted press reads, and session-change retries. Tests cover canceled requests, queued reads, and cache behavior after late responses.
ChatView wiring and resume checks
src/components/ChatView.tsx, scripts/chat-history-fixture.tsx, scripts/chat-history-browser-qa.ts, changelog.d/chat-resume-cancel-reads.md
ChatView passes signals to conversation, gap-page, fallback, and older-page reads. Browser checks hide and restore the same mounted chat at 390px and 1440px and verify that fresh content appears.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

  • devswha/ovis#2562: Introduces press-prefetched conversation reads that this change makes cancelable by the adopting screen.
  • devswha/ovis#1937: Invalidates in-flight older-page reads in ChatView, which this change also addresses through read-scope cancellation.
  • devswha/ovis#2576: Binds conversation reads to pane sessions; this change adds cancellation to those same reads.

Suggested reviewers: devswha, kilhyeonjun

Merge Risk: Minimal · previous review d29cc

No actionable issue with the chat-read cancellation change remains identified. It is mergeable after normal checks.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: cancelling abandoned chat reads when a chat resumes.
Description check Passed The description includes the required Change and Validation sections. It explains the problem and behavior, lists executed checks and results, documents failures and skipped checks, and states that no…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
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: Description check

Explanation

The description includes the required Change and Validation sections. It explains the problem and behavior, lists executed checks and results, documents failures and skipped checks, and states that no HTTP/WS protocol changes were made.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 4 functions across 9 files. (1 skipped: 1 unsupported.)

Finishing Touches
Generate unit tests (beta)
  • 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

An older page still queued when its screen closes is now rejected before its callback runs, so the callback's finally never cleared loadingOlder and the loading state, and Load older stayed disabled until the history changed. The cancellation catch clears them while the page's generation is still current.
@devswha

devswha commented Nov 2, 2026

Copy link
Copy Markdown
Owner

Thanks @bonecool999. Review (omo code reviewer + Codex) found no way for an abandoned read to write the cache or show another session, and the tests fail without the fix. One regression is fixed on your branch in 5e1f961 (main merged in first): an older page still queued when the screen closes is now rejected before its callback runs, so the callback's finally never cleared loadingOlder and the loading state, and Load older could stay disabled until the history changed. The cancellation .catch now clears them while the page's generation is current. bun run check fast passed. This lands after the 0.4.22 release.

@devswha

devswha commented Nov 2, 2026

Copy link
Copy Markdown
Owner

Merging after the 0.4.22 Release run with credit to @bonecool999. A chat tab that was hidden no longer waits up to 15 s (30 s remote) for an abandoned read when it comes back: newest-page, gap-fill, older-page and terminal-fallback reads are tied to the visible screen's lifetime and cancelled with it, even when the transport ignores abort, and a taken press read hands its cancellation to the one screen that adopts it.

Merge-pass review: omo code reviewer (APPROVE) and Codex Terra xhigh. No path found for a cancelled read to write or purge the conversation cache, disturb the newest-read order or the session-bound cache, or show another session; the serial lane never runs two reads at once; the tests fail without the fix (six fail with the three fixed files reverted).

  • Fixed on the branch (5e1f961, after merging main): a queued older page cancelled with its screen left Load older disabled until the history changed; the cancellation catch now clears the loading state.
  • LOW: a 409 that already won the race before the screen aborts can still clear the pane's cached answers, as main does for every 409; the abort-error line is repeated in five places; some it.each names print a literal %s.

CodeRabbit did not review this head (its check shows skipping); the merge pass reviewed it.

@devswha
devswha merged commit 4560571 into devswha:main Nov 2, 2026
20 of 22 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