Skip to content

fix(chat): say why the host won't open a session, and ask it only once - #1809

Merged
uzairansaruzi merged 4 commits into
masterfrom
issue/1808-resume-refusal
Nov 25, 2026
Merged

uzairansaruzi merged 4 commits into
masterfrom
issue/1808-resume-refusal

Conversation

@uzairansaruzi

@uzairansaruzi uzairansaruzi commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Linked issue

Fixes #1808

What changed

When a Hermes host refuses to open a session, the chat showed "Connection lost. The bot may still be working…", which reads like a network blip, and it asked the host again two or three times on every open.

  • The reason reaches the screen. Hermes answers every session.resume refusal with code 4001 and puts the cause in data.reason (runtime_coordination_required, not_found, session_busy and others). HermesGateway now hands that over as BotFailure.resumeRefused. runtime_coordination_required gets its own text; any other reason is shown in a fallback that names it. The issue's suggested patch mapped every 4001 to the coordination text, which would be wrong for the other reasons.
  • A refused open is sent once. Appearing, the first load and its follow-up each attached again after a refusal. They now reattach only a chat that was suspended (backgrounded or navigated away from). Try Again, sending and a network change still attach.
  • 4001 no longer counts as retryable for the inbox, session list, rooms and screen sharing.

I kept the retry change to 4001. A wider allowlist (408, 429, 5xx only) broke the deliberate quiet retry of -32603.

Verified contract: the wire capture in the issue, and upstream hermes-agent raising AuthorityRefusal('runtime_coordination_required') among other reasons under the same code (gateway/session_bot.py, gateway/session_local_migration.py).

How it was tested

  • scripts/test-sim on the 16 affected classes (HermesChatTurnTests, HermesConversationTests, HermesGatewayTests, BotInboxTests, HermesSessionListTests, LocalizationCatalogTests, HermesOfflineCacheTests, HermesChatSideTaskTests, HermesChatRequestTests, HermesConnectionLogTests, ChatViewModelSendTests, HermesChatSettingsTests, HermesChatLiveActivityTests, HermesChatAttachmentTests, HermesSlashCommandTests, HermesCompressClearTests): 753 passed; HermesOfflineCacheTests and HermesChatTurnTests rerun on the final head: 137 passed.
  • Both new tests fail on the old behaviour: testARefusedResumeShowsTheHostsReasonAndIsNotRetriedUnasked (2 resumes instead of 1, generic text, 4001 retryable) and testAFirstLoadClearsAHistoryFailureItRecoversFrom.
  • Signed Debug build on the simulator against a live Hermes host (read-only): opening a session attaches once, and backgrounding then returning reattaches once, per the connection log.
  • ci/check_string_catalog.py and ci/check_comments.py pass. Both new strings carry all 18 translations.
  • Not reproduced end to end: no host I can use refuses a resume, so there is no screenshot of the new text.

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 astra-loop: 3 rounds with gpt-6.2-astra on high. Astra verdict: approved

Created with Claude Fable 5.2 in Claude Code (T3 Code).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Chat now avoids repeatedly reconnecting after the host refuses to resume a session. The refusal reason is shown, and another attempt waits for an explicit retry or relevant connection change.
    • When a session must be coordinated on the host, chat explains that it needs to be opened in Hermes Desktop.
    • Successful initial message loading clears errors from an earlier history-read failure.
    • Resume refusals are treated as non-retryable, and host-provided details are excluded from connection logs.
  • Documentation
    • Added guidance on handling refused session attachments.

uzairansaruzi and others added 3 commits November 25, 2026 14:11
Fixes #1808

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Explain Change →

Walkthrough

Hermes resume error code 4001 now produces a dedicated failure that includes the host’s reason and is not automatically retried. Chat loading and reconnect behavior track refused resumes. Tests, localized messages, and documentation cover the updated handling.

Changes: Hermes resume refusal handling

Layer / File(s) Summary
Map resume refusals
HermesMobile/Networking/Bots/BotProtocol.swift, HermesMobile/Networking/Hermes/HermesGateway.swift, HermesMobile/Networking/Hermes/HermesConnection.swift, HermesMobile/Features/Kanban/KanbanFeatureState.swift
The gateway maps resume error code 4001 to BotFailure.resumeRefused, using the error reason or message. Retry advice treats resume refusals and rejected code 4001 as non-retryable. The failure has a specific error description, log reason, and Kanban classification.
Handle chat loading and reconnects
HermesMobile/Features/Chat/ChatViewModel.swift, HermesMobile/Features/Chat/HermesChatTurnCoordinator.swift
The coordinator records refused resumes and skips reconnect activation while the refusal remains set. Initial-prefetch loads use the unasked reconnect path. Attach and suspension actions reset the refusal state.
Surface and verify refusal behavior
HermesMobile/Resources/Localizable.xcstrings, HermesMobileTests/HermesChatTurnTests.swift, HermesMobileTests/HermesConnectionLogTests.swift, HermesMobileTests/HermesOfflineCacheTests.swift, docs/adr/0091-hermes-session-attach.md, docs/agents/hermes-server.md
Localized messages and documentation describe host refusals. Tests cover retry behavior, displayed refusal reasons, logging, and clearing an error after a successful initial-prefetch load.

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

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant ChatViewModel
  participant HermesChatTurnCoordinator
  participant HermesGateway
  ChatViewModel->>HermesChatTurnCoordinator: Request unasked reconnect
  HermesChatTurnCoordinator->>HermesGateway: Request session.resume
  HermesGateway-->>HermesChatTurnCoordinator: Return BotFailure.resumeRefused
  HermesChatTurnCoordinator->>HermesChatTurnCoordinator: Record refusal and skip reconnect activation
  HermesChatTurnCoordinator-->>ChatViewModel: Preserve refusal error message
Loading

Possibly related issues

Suggested reviewers: audichuang

Merge Risk: Low · up to 13f23

When a host refuses to open a session, the chat can keep showing "Reconnecting stream" even though no reconnect is pending. Behavior is otherwise correct, so this is a small status-accuracy follow-up before or shortly after merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the two main changes: the host refusal reason is now shown, and a refused session open is sent only once. Both match the changeset and the PR objectives. The conventional-commit prefix…
Linked Issues check Passed Issue #1808 has two coding requirements. (1) Replace the generic "Connection lost…" text for a host-refused session.resume with a diagnostic message. The change adds BotFailure.resumeRefused(String). …
Out of Scope Changes check Passed Each changed area connects to the #1808 requirements. BotProtocol.swift and HermesGateway.swift add the resumeRefused case, the 4001 mapping, and the non-retryable rule. HermesConnection.swift maps th…
Full details: Title check

Explanation

The title names the two main changes: the host refusal reason is now shown, and a refused session open is sent only once. Both match the changeset and the PR objectives. The conventional-commit prefix 'fix(chat):' fits the bug-fix scope. The title is 70 characters, which is within a reasonable length for a single-sentence title.

Full details: Linked Issues check

Explanation

Issue #1808 has two coding requirements. (1) Replace the generic "Connection lost…" text for a host-refused session.resume with a diagnostic message. The change adds BotFailure.resumeRefused(String). HermesGateway.consume maps code 4001 on resume calls to this case and takes the reason from data.reason. BotFailure.errorDescription gives runtime_coordination_required its own text. Other reasons appear in a fallback text that names the reason. This differs from the issue's suggested patch, which maps every 4001 to the coordination text. The difference is justified by the reason values the host returns under code 4001. (2) Stop the deterministic reconnect loop. BotConnectionAdvice.isRetryable returns false for resumeRefused and for rejected(4001). A refused chat reattaches only when its engine was suspended. Try Again, send, and network change still attach. The 4009 path is unchanged, so 4009 remains retryable as the issue requests. Tests testARefusedResumeShowsTheHostsReasonAndIsNotRetriedUnasked and testAFirstLoadClearsAHistoryFailureItRecoversFrom cover this behavior. The author reports both fail on the old code. The issue's suggested patch also lists -32601, 4090 and 4130 as non-retryable. This PR does not change those codes. The issue title and its primary scope concern 4001, so this does not fail the assessment. End-to-end refusal was not reproduced, so live-host behavior rests on unit tests and the wire capture in the issue.

Full details: Out of Scope Changes check

Explanation

Each changed area connects to the #1808 requirements. BotProtocol.swift and HermesGateway.swift add the resumeRefused case, the 4001 mapping, and the non-retryable rule. HermesConnection.swift maps the new case to a log reason. Localizable.xcstrings adds the two new strings. ChatViewModel.swift and HermesChatTurnCoordinator.swift implement the attach-once rule for a refused open. KanbanFeatureState.swift classifies the new case as an incompatible contract, which keeps the switch over BotFailure complete. This follows from the new case and does not add a separate feature. HermesConnectionLogTests and HermesOfflineCacheTests cover the new case and the first-load change. The ADR and hermes-server.md entries document the same behavior. No change addresses unrelated features.

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

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

@greptile-apps

greptile-apps Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with a non-blocking startup error-message issue.

Fix All in Claude CodeFindings

  1. P2 Sign-in explanation disappears ▶

Summary

This PR shows why a host refused to open a session and prevents repeated automatic attempts after that refusal.

  • Hermes chat explains refused session opens and waits for another attach.
  • Shared retry advice stops retrying refused session opens.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Chat appears or loads] --> B{Previous resume refused?}
    B -->|Yes| C[Keep refusal text; do not attach]
    B -->|No| D[Try attaching]
    D --> E{Host refuses resume?}
    E -->|Yes| F[Show host reason and remember refusal]
    E -->|No| G[Continue normal recovery]
    H[Explicit retry, send, network change, or return] --> I[Clear refusal flag]
    I --> D
Loading

Reviews (2) · Last reviewed commit: "fix(chat): hold back the unasked reattac..." · Reviewed by Greptile

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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

Commits

Reviewing files that changed from the base of the PR and between 6234f81 and d7ee649.

Files selected for processing: 12

  • HermesMobile/Features/Chat/ChatViewModel.swift
  • HermesMobile/Features/Chat/HermesChatTurnCoordinator.swift
  • HermesMobile/Features/Kanban/KanbanFeatureState.swift
  • HermesMobile/Networking/Bots/BotProtocol.swift
  • HermesMobile/Networking/Hermes/HermesConnection.swift
  • HermesMobile/Networking/Hermes/HermesGateway.swift
  • HermesMobile/Resources/Localizable.xcstrings
  • HermesMobileTests/HermesChatTurnTests.swift
  • HermesMobileTests/HermesConnectionLogTests.swift
  • HermesMobileTests/HermesOfflineCacheTests.swift
  • docs/adr/0091-hermes-session-attach.md
  • docs/agents/hermes-server.md

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

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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

Commits

Reviewing files that changed from the base of the PR and between d7ee649 and 13f2336.

Files selected for processing: 4

  • HermesMobile/Features/Chat/ChatViewModel.swift
  • HermesMobile/Features/Chat/HermesChatTurnCoordinator.swift
  • HermesMobileTests/HermesChatTurnTests.swift
  • docs/adr/0091-hermes-session-attach.md

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

@uzairansaruzi
uzairansaruzi merged commit 2afe76e into master Nov 25, 2026
8 of 10 checks passed
@uzairansaruzi
uzairansaruzi deleted the issue/1808-resume-refusal branch November 25, 2026 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant