Files
librofm-downloader/AGENTS.md
T
AlexKucera 3dcae24d34 fix(orchestrator): Ctrl+C hangs and threading shutdown traceback
Python ThreadPoolExecutor workers cannot be killed when blocked in HTTP
I/O. Previous approach of waiting for graceful cancellation via
shutdown(wait=True) caused infinite hangs, and re-raising KeyboardInterrupt
still triggered Python's _python_exit thread-join cleanup on exit.

Replace with hard-exit strategy: first Ctrl+C marks all unfinished books
(active + pending) as cancelled, prints summary, returns partial result
with interrupted=True. CLI then calls os._exit(130) to bypass thread
cleanup entirely. Second Ctrl+C hard-exits immediately.

Also fixes: books_with_index[idx][0] returning int index instead of
Book object (AttributeError on summary), empty CancelledError reason
strings, missing cancel_event wiring through download_book->download_m4b
call chain, and corrupted test body from earlier edit collision.

256 tests pass.
2026-06-04 13:10:10 +02:00

9.8 KiB

Agent Instructions

Session Logs

Session logs are written to docs/devlog/ after each completed task, issue fix, or milestone. They capture what was done, decisions & rationale, gotchas & fixes, and next steps. Before starting a new session, read the previous session logs.

Date Type File Summary
2026-06-04 issue 20260604-fix-verbose-flag-not-wired-through-cli-entry-point_log.md Fix: -v/--verbose flag dead — argparse was in __main__ guard, never reached by installed console script. Extracted main(), updated entry point. 247/247 tests pass
2026-06-04 issue 20260604-fix-ctrl-c-hangs-and-threading-traceback_log.md Fix: Ctrl+C hangs + threading traceback. os._exit(130) hard exit, no-wait cancellation, wired cancel_event through full download stack, fixed books_with_index[idx][1] bug. 256/256 tests pass
2026-06-04 issue 20260604-fix-keyboardinterrupt-handling-and-test-alignment_log.md Fix: except BaseException in _download_one, cooperative cancellation framework, reporter lifecycle. 256/256 tests pass
2026-06-04 issue 20260604-issue22-xdg-config-path-resolution-with-cwd-fallback_log.md Issue #22 Complete: XDG→CWD path resolution, load_config(None, None) search, missing-config notice, OS→domain error wrapping. 9 new tests, 181 total · 8/8 AC
2026-06-03 issue 20260603-cli-parallel-integration-and-ctrl-c-drain-issue17_log.md Issue #17 Complete: CLI parallel integration + graceful Ctrl+C drain. Orchestrator catches KeyboardInterrupt, drains in-flight downloads (shutdown(wait=True)), double-Ctrl+C fast exit. 13 new tests, 231 total · 10/10 AC
2026-06-03 issue 20260603-parallel-download-orchestrator-issue16_log.md Issue #16 Complete: orchestrator.py — ThreadPoolExecutor parallel download engine. Replaces sequential for-loop in cli.py. OrchestratorResult dataclass, stable-sort ordering, failure isolation. 20 new tests, 218 total · 11/11 AC
2026-06-03 issue 20260603-api-rate-limiter-issue15_log.md Issue #15 Complete: threading.Semaphore(3) API rate limiter on LibroFmClient. Caps concurrent API calls; CDN downloads bypass. 4 new tests, 198 total · 6/6 AC
2026-06-03 issue 20260603-multi-bar-progress-per-book-identity-mapping-issue14_log.md Issue #14 Complete: Per-book identity mapping for concurrent progress bars. _tasks/_book_ids dicts, start_download() returns task_id, update(task_id=) targeting. 10 new tests, 194 total · 7/7 AC
2026-06-03 issue 20260603-thread-safe-downloadhistory-write-issue13_log.md Issue #13 Complete: Thread-safe DownloadHistory.write() with threading.Lock. 5 new tests, 184 total · 4/4 AC
2026-06-03 issue 20260603-slice-1-workers-config-and-cli-flag-issue12_log.md Issue #12 Complete: workers config field + -w/--workers CLI flag with 3-layer resolution (CLI > config > 3). InvalidWorkersError validation. 6 new tests, 179 total · 7/7 AC
2026-06-03 issue 20260603-issue10-documentation-site-and-readme_log.md Issue #10 Complete: MkDocs site (8 pages) + polished README. Material theme, flat URLs. 11/11 AC · 172 tests pass
2026-06-03 slice 20260603-slice-6b-summary-exit-codes-and-integration-tests-issue9_log.md Issue #9 Complete: Enhanced summary (failed/skipped book details) + graceful Ctrl+C (exit 130) + 3 integration tests. 12 new tests, 168 total · 15/15 AC
2026-06-03 issue 20260603-output-polish-progress-bars-and-failure-isolation-issue8_log.md Issue #8 Complete: TTY-aware download reporting — rich progress bars (interactive) + plain log lines (cron). Per-book failure isolation. Content-Length → live %/ETA/speed. 18 new tests, 156 total · 8/8 AC
2026-06-03 slice 20260603-slice-5-accompanying-files-and-output-structure-issue7_log.md Issue #7 Complete: PDF extras + cover art download with config toggles, .partial→atomic rename, non-critical failure handling, output structure verification. 12 new tests, 134 total · 11/11 AC
2026-06-03 slice 20260603-slice-6-mp3-fallback-issue6_log.md Issue #6 Complete: MP3 fallback pipeline — manifest fetch, ZIP download+extract+resume, format strategy selector (m4b_mp3_fallback/mp3_only/m4b_only), --limit CLI flag. 12 new tests, 122 total · 11/11 AC
2026-06-03 issue 20260603-slice-3b-live-testing-fixes-issue5_log.md Issue #5 Live Fixes: 4 critical API-shape bugs found & fixed (audiobooks key, m4b_url key, nested narrators, ISBN int/str). Download loop wired. --verbose flag. 109 tests, 6 books downloaded (~2.9 GB) · 11/11 AC
2026-06-03 slice 20260603-slice-3b-m4b-download-pipeline-issue5_log.md Issue #5 TDD: M4B download pipeline — client endpoint, streaming downloader with resume, path integration, history post-download, CLI orchestration. 11 new tests, 108 total · 11/11 AC
2026-06-03 slice 20260603-slice-3a-path-resolution-and-sanitization-issue4_log.md Issue #4 Complete: Path resolution + sanitization + Book model + custom patterns. 56 new tests, 97 total · 16/16 AC
2026-06-03 issue 20260603-fix-path-doubling-and-cover-download-issue_log.md Path doubling fix: needs_subdirectory() no longer triggered by always-present cover_url, title no longer double-appended in _resolve_output_dir(), cover download fixed (headers + protocol-relative URLs). 172/172 tests
2026-06-03 issue 20260603-project-scaffolding-and-config-module-issue2_log.md Issue #2 Complete: pyproject.toml + venv + config module (load/merge/validate) + 25 tests. 11/11 AC met

GitNexus — Code Intelligence

This project is indexed by GitNexus as librofm-downloader (1427 symbols, 2585 relationships, 11 execution flows). Use the GitNexus MCP tools to understand code, assess impact, and navigate safely.

If any GitNexus tool warns the index is stale, run npx gitnexus analyze in terminal first.

Always Do

  • MUST run impact analysis before editing any symbol. Before modifying a function, class, or method, run gitnexus_impact({target: "symbolName", direction: "upstream"}) and report the blast radius (direct callers, affected processes, risk level) to the user.
  • MUST run gitnexus_detect_changes() before committing to verify your changes only affect expected symbols and execution flows.
  • MUST warn the user if impact analysis returns HIGH or CRITICAL risk before proceeding with edits.
  • When exploring unfamiliar code, use gitnexus_query({query: "concept"}) to find execution flows instead of grepping. It returns process-grouped results ranked by relevance.
  • When you need full context on a specific symbol — callers, callees, which execution flows it participates in — use gitnexus_context({name: "symbolName"}).

Never Do

  • NEVER edit a function, class, or method without first running gitnexus_impact on it.
  • NEVER ignore HIGH or CRITICAL risk warnings from impact analysis.
  • NEVER rename symbols with find-and-replace — use gitnexus_rename which understands the call graph.
  • NEVER commit changes without running gitnexus_detect_changes() to check affected scope.

Resources

Resource Use for
gitnexus://repo/librofm-downloader/context Codebase overview, check index freshness
gitnexus://repo/librofm-downloader/clusters All functional areas
gitnexus://repo/librofm-downloader/processes All execution flows
gitnexus://repo/librofm-downloader/process/{name} Step-by-step execution trace

CLI

Task Read this skill file
Understand architecture / "How does X work?" .claude/skills/gitnexus/gitnexus-exploring/SKILL.md
Blast radius / "What breaks if I change X?" .claude/skills/gitnexus/gitnexus-impact-analysis/SKILL.md
Trace bugs / "Why is X failing?" .claude/skills/gitnexus/gitnexus-debugging/SKILL.md
Rename / extract / split / refactor .claude/skills/gitnexus/gitnexus-refactoring/SKILL.md
Tools, resources, schema reference .claude/skills/gitnexus/gitnexus-guide/SKILL.md
Index, status, clean, wiki CLI commands .claude/skills/gitnexus/gitnexus-cli/SKILL.md