Skip to content

feat: add queue remediation tool with bug fixes and documentation - #11

Closed
thesammykins wants to merge 10 commits into
mainfrom
feature/queue-remediation-tool
Closed

thesammykins wants to merge 10 commits into
mainfrom
feature/queue-remediation-tool

Conversation

@thesammykins

Copy link
Copy Markdown
Collaborator

Summary

  • New Feature: Implement queue-remediation CLI tool for managing Sonarr/Radarr queue issues including stuck downloads, stalled imports, and media unavailability scenarios
  • Critical Bug Fix: Fixed 26+ instances of ignored error handling in media-requests tool's readKeystroke() calls with proper error propagation
  • Build System Fix: Corrected Makefile shell syntax in build-all target (broken string concatenation and ternary operator logic)
  • Documentation: Comprehensive implementation guides, API research, and status message routing documentation

Changes

New Tool Implementation

  • queue-remediation.go: Complete CLI tool with direct API integration, queue status analysis, and recovery strategies
  • Full error handling, configurable timeouts, and retry logic

Quality Improvements

  • media-requests.go: Enhanced error handling with explicit error checks on all keystroke input operations
  • Makefile: Fixed shell syntax for Windows executable extensions and build matrix variables
  • AGENTS.md: Refined guidelines reflecting expanded toolkit

Testing & Documentation

  • queue-remediation_test.go: Full table-driven test suite with happy path and failure scenarios
  • docs/README_QUEUEFIX.md: Complete usage guide with examples
  • Implementation and research guides for API integration patterns

Features

  • Automatically identifies and categorizes queue issues (stuck, stalled, failed imports)
  • Recovers from transient API failures with configurable retry logic
  • Provides detailed status reporting and suggested remediation actions
  • Supports both dry-run analysis and actual remediation operations

Testing

✓ All existing tests pass: make test
✓ New queue-remediation tests fully implemented
✓ Manual testing of error handling paths
✓ Build verification for all target platforms

- Implement queue-remediation CLI tool for managing Sonarr/Radarr queue issues
- Fix critical error handling in media-requests: 26+ readKeystroke() calls now properly checked
- Fix Makefile shell syntax in build-all target (broken string concatenation, ternary operator)
- Update build system to include queue-remediation tool compilation
- Add comprehensive documentation and implementation guides
- Update AGENTS.md with refined build/test/style guidelines for expanded toolkit
- Include full test suite with table-driven tests for queue remediation functionality
@calmcacil

Copy link
Copy Markdown
Owner

Looks good to me, needs testing to make sure everything works but overall good additions.

Add interactive TUI mode (via -manual flag) for queue remediation with proper
user feedback and error handling during action execution.

Bugs Fixed:
- Bug #1: Add loading state when actions start (was silently executing)
- Bug #2: Clear loading state when actions complete (UI wasn't responsive)
- Bug #3: Clear error messages before each action (stale errors displayed)
- Bug #4: Wire TUI entry point in main (users couldn't launch TUI mode)

Changes:
- queue-remediation-tui.go: Core TUI implementation with Bubble Tea
  * All action handlers now set loading state and clear old errors
  * Action completion clears loading state and updates status
  * Comprehensive keyboard shortcuts (m=manual, d=delete, s=skip, r=refresh)

- queue-remediation-tui-main.go: Dedicated TUI binary entry point

- queue-remediation-shared.go: Shared API functions (fetchAllQueues,
  triggerManualImport, deleteQueueItem, getTokenForInstance, etc.)

- queue-remediation.go: Main entry with -manual flag to launch TUI

- Updated queue-remediation_test.go with 120+ comprehensive tests

Impact:
- Users can now launch interactive TUI with: queue-remediation -manual
- Full visual feedback during action execution (no more silent failures)
- Proper error handling and display
- All test suites passing (100% success rate)
…with proper request structure

Fixes critical API mismatch discovered through live testing - manual imports now correctly use POST /api/v3/command endpoint with ManualImportCommand wrapper structure instead of nonexistent endpoint. Adds mandatory folder parameter to scan requests and implements comprehensive debug logging (3-step API call tracking) to validate import workflow.

Key Improvements:
- Changed from non-existent POST /api/v3/manualimport to correct POST /api/v3/command endpoint
- Added ManualImportCommand struct wrapping individual import requests with proper API contract
- Fixed API parameter requirements: folder parameter is mandatory for scan operations
- Added DownloadID mapping from queue items to import requests for download tracking
- Enhanced logging with 3-phase API call tracking (scan → filter → import) for debugging
- Corrected Radarr handling to use MovieID appropriately without episode-specific fields

Testing:
- Added 800+ lines of comprehensive test coverage validating Command API structure
- Tests cover both Sonarr and Radarr scenarios with proper quality/language/downloadId mapping
- Validates error handling and fallback mechanisms
- All builds successful, full test suite passing
- Document API structure fixes based on live Sonarr testing
- Add proper ManualImportCommand format and endpoint corrections
- Highlight downloadId support and Radarr improvements
- Include recent improvements section with all fixes implemented
- Update examples with debug mode and multi-instance support
- Add reference to MANUAL_IMPORT_API_RESEARCH.md for technical details

README now accurately reflects current implementation with corrected
API behavior matching Sonarr's actual contract.
Replace broken folder+seriesId approach with downloadId parameter per HAR investigation
…e validation

Add comprehensive quality comparison engine to prevent accidental downgrades:
- Smart quality scoring combining resolution, version, REAL tag, and REPACK bonus
- Fuzzy title matching using Levenshtein distance (85% threshold) for series/movie validation
- API integration to fetch existing file quality from Sonarr/Radarr
- Enhanced decision logic in mapStatusToAction() to override risky deletions

New data structures for quality metadata and validation results support:
- EpisodeFileResource, MovieFileResource for API responses
- QualityComparison and TitleMatchResult for decision tracking

Comprehensive test coverage:
- 254 test cases total (added 44 new test functions)
- Quality scoring, comparison, and validation scenarios
- API mocking with edge case coverage
- Hybrid workflow validation with Command API fallback

All tests passing. No breaking changes - enhancements are fully additive.
…actor matching

Implement intelligent title matching that prevents false positives while
correctly handling legitimate variations (hyphenation, articles, punctuation).

- Add multi-factor scoring: character (60%) + token (30%) + length (10%)
- Add stop word filtering for token comparison (the, a, an)
- Implement hybrid logic: high char match OR high token match OR weighted score
- Add 6 comprehensive edge case tests (Cruel Summer, The Office, Avatar)
- All 254+ tests passing

Results:
  ✓ Spider-Man vs Spiderman: 90%+ character similarity → MATCH
  ✓ The Matrix vs Matrix: 100% token similarity → MATCH
  ✓ Cruel Summer vs Last Summer: 54% weighted score → REJECT
  ✓ The Office vs Office Space: 38% weighted score → REJECT
@calmcacil
calmcacil marked this pull request as draft January 27, 2026 00:46
@calmcacil

Copy link
Copy Markdown
Owner

Converted to draft as its still being enhanced and worked on.

@thesammykins
thesammykins marked this pull request as ready for review January 27, 2026 02:49
@calmcacil

Copy link
Copy Markdown
Owner

This PR needs to be updated to match the current repo structure.

Changes on main affecting this PR

Since this PR was opened, the repository has been restructured from flat package main files with build tags to a standard Go multi-binary layout:

  • Before: queue-remediation.go at root level (package main, build tag)
  • After: Logic goes in internal/remediation/ package, entry point in cmd/queue-remediation/main.go

Required updates

  1. Move core logic from queue-remediation.go → internal/remediation/ (similar to internal/feed/, internal/requests/)
  2. Create cmd/queue-remediation/main.go as a thin entry point
  3. Import shared types from internal/config instead of defining new config structs
  4. Import ANSI constants from internal/colors instead of defining new ones
  5. Remove build-tag directive (//go:build)
  6. Update Makefile to build from ./cmd/queue-remediation/
  7. Rebase on latest main to resolve merge conflicts

See PR #19 for the exact pattern used for the other tools.

@calmcacil

Copy link
Copy Markdown
Owner

This PR's rendering should conform to the project's terminal UX conventions documented in docs/UX_DESIGN.md (just added to main). Key requirements:

  • Use Unicode box-drawing characters (─│├┼┤└┴┘) for borders and containers
  • Use golang.org/x/term for terminal-width-aware proportional sizing
  • Use visibleLen/ padRight helpers for ANSI-safe text padding
  • Follow the color convention table for actions, statuses, and server labels
  • Buffer output through bytes.Buffer + bufio.Writer

See docs/UX_DESIGN.md for full details.

@calmcacil
calmcacil marked this pull request as draft July 15, 2026 14:47
@calmcacil

Copy link
Copy Markdown
Owner

Superseded by the unified CLI architecture in #37; closing before the public-history sanitization.

@calmcacil calmcacil closed this Jul 15, 2026
@calmcacil
calmcacil deleted the feature/queue-remediation-tool branch July 15, 2026 15:06
@calmcacil
calmcacil restored the feature/queue-remediation-tool branch July 23, 2026 11:43
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