Skip to content

refactor: one cancellation check for every screen - #1790

Merged
uzairansaruzi merged 2 commits into
masterfrom
issue/1782-shared-cancellation-check
Nov 20, 2026
Merged

uzairansaruzi merged 2 commits into
masterfrom
issue/1782-shared-cancellation-check

Conversation

@uzairansaruzi

@uzairansaruzi uzairansaruzi commented Nov 20, 2026 •

Copy link
Copy Markdown
Owner

Linked issue

Fixes #1782

What changed

Nine screens each kept their own "is this error a cancellation" check, and the copies didn't agree. On a Hermes server, a cancelled "Load more" in Archived Sessions showed "This action is no longer current. Refresh the conversation." because BotClient throws BotFailure.stale, not CancellationError, when the reading task is cancelled.

All nine now use one Error.isCancellation in APIError.swift. It matches CancellationError and URLError.cancelled, either on its own or wrapped in APIError.network. Sites whose old copy also checked Task.isCancelled (both Kanban states and the link preview) still check it inline.

How each site handles BotFailure.stale:

  • Changed: ArchivedSessionsViewModel.loadMore. It now drops a failure when its task was cancelled, the same check loadHermes already makes. It still shows stale if the task is still running, because that means the client has gone dead. Hiding that case would leave a "Load more" button that does nothing.
  • Unchanged: CronJobEditorConfigurationLoader. It keeps hiding stale, as before.
  • Unchanged, but they can throw stale:
    • Archived loadHermes already ignores cancelled tasks, and a stale while running closes and reports the dead client.
    • Archived delete is a write.
    • Hermes session export runs from a Task nothing cancels.
    • Files, Git diff and Kanban go over REST, where stale only means the connection was retired. Hiding it would leave a spinner or an empty screen.
  • Cannot throw stale: profile picker, link preview, and the webui paths in SessionList.

The link preview gains the APIError.network unwrap. It never receives an APIError, so nothing changes there.

The decision is recorded in docs/adr/0130-hermes-session-actions.md.

How it was tested

  • New HermesSessionActionsTests.testACancelledPageReadShowsNoError. It fails on the base with the "no longer current" message and passes with this change. The old profile-picker classifier test now targets the shared property (APIClientConfigurationTests.testCancellationDetection).
  • scripts/test-sim <udid> --only runs, all passing:
    • HermesSessionActionsTests, APIClientConfigurationTests and SessionListMutationTests: 112 passed.
    • CronJobEditorConfigurationTests, FileBrowserViewModelTests, GitDiffFileJumpTests, HermesSessionListTests, KanbanCardDetailStateTests, KanbanFeatureStateTests, TranscriptLinkPreviewTests and SessionNavigationStateTests: 204 passed.
    • After the review fix and the rebase, HermesSessionActionsTests and APIClientConfigurationTests: 38 passed.
  • ci/check_comments.py, ci/check_test_waits.py and python3 -m unittest discover -s ci -p 'test_*.py' pass.

Checklist

  • Local validation passes using scripts/test-sim <assigned-simulator-udid> with the tests required by AGENTS.md § Verifying; the selection and results are recorded above
  • New/changed Codable models decode tolerantly (optionals for fields the server might add or rename)
  • No new third-party dependencies (the list in AGENTS.md is locked)
  • No invented API endpoints or JSON shapes (verified against upstream source or a running server)

Reviewed with sol-loop: 2 rounds with gpt-6.2-sol. Sol verdict: approved

Created with Claude Opus 5.5 in Claude Code (T3 Code).

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change adds a shared Error.isCancellation property and replaces local cancellation helpers across multiple screens. It also adds a test for cancelled archived-session pagination and documents archived-session page-read handling.

Changes: Cancellation handling

Layer / File(s) Summary
Shared cancellation classifier
HermesMobile/Networking/APIError.swift, HermesMobileTests/APIClientConfigurationTests.swift
Error.isCancellation recognizes CancellationError, direct cancelled URLError, and APIError.network wrapping a cancelled URL error. Tests also check timeout and unauthorized errors.
Session and archived-session handling
HermesMobile/Features/SessionList/SessionListViewModel.swift, HermesMobile/Features/Settings/ArchivedSessionsViewModel.swift, HermesMobileTests/HermesSessionActionsTests.swift, docs/adr/0130-hermes-session-actions.md
Session and archived-session operations use the shared property. Archived-session page loading also checks task cancellation. A test verifies that cancelling loadMore() does not set an action error; the documentation describes page-read cancellation handling.
Other screen cancellation handling
HermesMobile/Features/Chat/TranscriptLinkPreviewView.swift, HermesMobile/Features/Kanban/*, HermesMobile/Features/Settings/DefaultProfilePickerView.swift, HermesMobile/Features/Tasks/CronJobEditorConfigurationLoader.swift, HermesMobile/Features/Workspace/*
These screens replace local cancellation helpers with Error.isCancellation. The cron-job configuration loaders continue to suppress BotFailure.stale errors.

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

Change: Refactor

Suggested reviewers: audichuang

Merge Risk: Minimal · up to 927cc

This refactor consolidates cancellation checks across screens. The only intended behavior change is that a cancelled archived-session page read no longer shows an error. No concrete merge-blocking risk was found.

Security architecture risk: Minimal · up to 927cc

The inspected changes preserve existing access controls and write-handling outcomes. The intentional behavior change suppresses error messages from cancelled archive-page reads without changing their cleanup or ownership checks.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The demonstrated propagation concerns mobile-client failure handling for existing reads and writes. The shared predicate itself accepts an already-thrown error and neither selects credentials nor initiates requests; the inspected callers do not gain additional authority through it.

Trust Boundaries and Controls

  • observed — Unauthorized errors are not classified as cancellation. Kanban retains its authentication-error forwarding after cancellation guards, and its existing mutation permission and identity checks remain separate from the shared predicate.

Resilience and Maintainability Implications

  • observed — A cancelled Kanban comment continues to bypass reconciliation and retain its existing submitting state. The inspected regression test explicitly expects that outcome. This behavior predates the shared classifier and is not an introduced recovery guarantee or regression.
Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "refactor: one cancellation check for every screen" matches the main change. The PR replaces nine screen-specific cancellation helpers with one shared Error.isCancellation property in APIErr…
Linked Issues check Passed Issue #1782 has four coding objectives. All are addressed in the current PR.

1. Shared classifier [#1782]: Error.isCancellation in HermesMobile/Networking/APIError.swift matches `CancellationErro…
Out of Scope Changes check Passed All changes relate to #1782 or its supporting work:
- APIError.swift: adds the shared Error.isCancellation property.
- Nine call-site files: replace local cancellation helpers with the shared prop…
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title "refactor: one cancellation check for every screen" matches the main change. The PR replaces nine screen-specific cancellation helpers with one shared Error.isCancellation property in APIError.swift, and the raw summary confirms the removal of those local helpers across the listed files. The title names the refactor type and the consolidation. It does not mention the one behavior change in ArchivedSessionsViewModel.loadMore, which is expected for a title. No unrelated or misleading content was found.

Full details: Linked Issues check

Explanation

Issue #1782 has four coding objectives. All are addressed in the current PR.

  1. Shared classifier [#1782]: Error.isCancellation in HermesMobile/Networking/APIError.swift matches CancellationError, a direct URLError.cancelled, and URLError.cancelled wrapped in APIError.network. Verified at head.
  2. Nine local copies removed [#1782]: the file summaries for all nine listed sites report removal of the local helper and use of Error.isCancellation. Verified directly for ArchivedSessionsViewModel.swift, which no longer declares isCancellationError. The other eight sites rest on the attested file summaries, not on direct inspection.
  3. Superseded Hermes read shows no error on a site that can throw BotFailure.stale [#1782]: in ArchivedSessionsViewModel.loadMore, the catch block returns when serial != readSerial, when Task.isCancelled, or when error.isCancellation. A read superseded by a new load or mutation is therefore silent. The new test HermesSessionActionsTests.testACancelledPageReadShowsNoError covers the cancelled case.
  4. Per-site stale decisions, no unnamed newly hidden errors [#1782]: the PR names ArchivedSessionsViewModel.loadMore as the only changed stale site. The code matches the PR text: a cancelled task drops the failure, and a running task still shows stale. CronJobEditorConfigurationLoader keeps its prior stale suppression. Kanban and link preview keep inline Task.isCancelled checks. The link preview gains the APIError.network unwrap, which the issue requests.

Stack note: stack review evidence is unavailable. The four objectives above are fully implemented by changes in this PR relative to the merge base. The PR does not state that another stack member contributes to them, so no stack objective depends on unavailable evidence.

Full details: Out of Scope Changes check

Explanation

All changes relate to #1782 or its supporting work:

  • APIError.swift: adds the shared Error.isCancellation property.
  • Nine call-site files: replace local cancellation helpers with the shared property. The summaries report no other behavior change except the named ArchivedSessionsViewModel.loadMore change.
  • ArchivedSessionsViewModel.swift: verified directly. The loadMore change matches the PR description and the issue. loadHermes and other paths are unchanged in intent.
  • APIClientConfigurationTests.swift and HermesSessionActionsTests.swift: tests for the shared property and the loadMore behavior.
  • docs/adr/0130-hermes-session-actions.md: records the per-site stale decision. This supports the requirement to say which sites changed.

No change was found that lacks a connection to #1782. The inspected code does not show unrelated edits.

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
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 93fd25d and 927ccaa.

Files selected for processing: 13

  • HermesMobile/Features/Chat/TranscriptLinkPreviewView.swift
  • HermesMobile/Features/Kanban/KanbanCardDetailState.swift
  • HermesMobile/Features/Kanban/KanbanFeatureState.swift
  • HermesMobile/Features/SessionList/SessionListViewModel.swift
  • HermesMobile/Features/Settings/ArchivedSessionsViewModel.swift
  • HermesMobile/Features/Settings/DefaultProfilePickerView.swift
  • HermesMobile/Features/Tasks/CronJobEditorConfigurationLoader.swift
  • HermesMobile/Features/Workspace/FileBrowserViewModel.swift
  • HermesMobile/Features/Workspace/GitDiffView.swift
  • HermesMobile/Networking/APIError.swift
  • HermesMobileTests/APIClientConfigurationTests.swift
  • HermesMobileTests/HermesSessionActionsTests.swift
  • docs/adr/0130-hermes-session-actions.md

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

@greptile-apps

greptile-apps Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

Moves nine screens to the shared Error.isCancellation property.

  • Cancelled archived-page reads leave the error message empty.
  • Screens share one rule for recognizing cancelled requests.

No actionable issues were found. Tests were inspected but not run during this review.

Reviews (2) · Last reviewed commit: "fix(archive): drop a cancelled page read..." · Reviewed by Greptile

uzairansaruzi and others added 2 commits November 20, 2026 13:38
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@uzairansaruzi
uzairansaruzi changed the base branch from chore/ban-comments to master November 20, 2026 18:38
@uzairansaruzi
uzairansaruzi force-pushed the issue/1782-shared-cancellation-check branch from 927ccaa to 6470745 Compare November 20, 2026 18:38
@uzairansaruzi
uzairansaruzi merged commit c841485 into master Nov 20, 2026
6 checks passed
@uzairansaruzi
uzairansaruzi deleted the issue/1782-shared-cancellation-check branch November 20, 2026 19:26
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.

refactor: one cancellation check for every screen

1 participant