Skip to content

fix(rtorrent): make adding torrent work with upstream json rpc enabled without extra config#930

Merged
trim21 merged 3 commits into
jesec:masterfrom
trim21:upstream-json
Oct 22, 2025
Merged

fix(rtorrent): make adding torrent work with upstream json rpc enabled without extra config#930
trim21 merged 3 commits into
jesec:masterfrom
trim21:upstream-json

Conversation

@trim21

@trim21 trim21 commented Oct 22, 2025

Copy link
Copy Markdown
Collaborator

Description

Related Issue

Screenshots

Types of changes

  • Breaking change (changes that break backward compatibility of public API or CLI - semver MAJOR)
  • New feature (non-breaking change which adds functionality - semver MINOR)
  • Bug fix (non-breaking change which fixes an issue - semver PATCH)

Copilot AI review requested due to automatic review settings October 22, 2025 16:00

Copilot AI 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.

Pull Request Overview

This PR fixes a compatibility issue with rTorrent when upstream JSON-RPC is enabled. The changes update the method names used for adding torrents to use non-throwing variants (load.start and load.normal instead of load.start_throw and load.throw), and removes hash extraction logic that was processing responses from the multicall.

  • Changed method names from throwing to non-throwing variants for better compatibility
  • Removed response processing logic that extracted torrent hashes from multicall responses

Comment thread server/services/rTorrent/clientGatewayService.ts
@trim21 trim21 merged commit 082d3e9 into jesec:master Oct 22, 2025
27 of 28 checks passed
@trim21 trim21 deleted the upstream-json branch October 22, 2025 16:10
jesec pushed a commit that referenced this pull request Oct 26, 2025
## Problem

Following PR #930's fix for file-based torrents, URL-based torrent addition
still relied on the deprecated load.start_throw and load.throw methods.
These methods were removed in rTorrent >0.15.1 and only exist as user-defined
redirects (via method.redirect).

Users without these redirects experienced failures when adding torrents via
URL from external applications like Sonarr.

## Solution

Implemented intelligent runtime detection that:

1. **Detects .throw method availability** via system.listMethods during service
   initialization
2. **Caches the result** per service instance (checked only once)
3. **Prioritizes .throw methods** when available (superior error reporting)
4. **Falls back gracefully** to load.normal/load.start when unavailable
5. **Assumes symmetry**: if load.throw exists, load.start_throw also exists
   (they're typically defined together)

## Implementation Details

### Detection Strategy

- Calls system.listMethods during testGateway()
- Checks for load.throw presence in method list
- Caches result in loadThrowSupported property
- Defaults to false on detection errors (safer default)

### Method Selection

- getLoadMethodName(start) helper chooses correct method:
  - With .throw support: load.start_throw / load.throw
  - Without .throw support: load.start / load.normal

### Consistency

Applied to both:
- addTorrentsByURL (fixes the reported bug)
- addTorrentsByFile (consistency + better error reporting)

## Deep Dive Research

### rTorrent Command History

- **Native commands**: load.normal, load.start (exist in all versions)
- **.throw variants**: NOT native, user-defined via method.redirect
- **Purpose of .throw**: Better error reporting (throw vs silent failure)
- **Deprecation**: Removed in rTorrent >0.15.1

### JSON-RPC Behavior

- Error -32601: Standard "Method not found" error
- isJSONCapable ≠ .throw methods available
- system.listMethods provides authoritative method list

### References

- rTorrent source: src/command_events.cc defines load commands
- JSON-RPC spec: github.com/jesec/rtorrent/discussions/52
- Method redirects: README.md lines 28-29

## Testing

✅ TypeScript type checking passed
✅ ESLint passed (0 warnings)
✅ Works with and without .throw method redirects
✅ Maintains backwards compatibility

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
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