Commit 606b82f
feat: Add async caching with background task management (#39)
* feat: Add async caching with background task management
Implement async caching architecture that returns immediately with task IDs,
allowing users to monitor and manage long-running caching operations.
## New Features
- **Task Manager**: Thread-safe background task tracking with status, stages, and cancellation
- **Async Caching**: `cache_crate` now spawns background tasks and returns immediately
- **Rich Markdown Output**: LLM-optimized formatting with embedded action commands
- **Unified Monitoring**: Single `cache_operations` tool for list/query/cancel/clear
## Architecture
- `task_manager.rs`: Core task management with TaskManager, CachingTask, TaskStatus, CachingStage
- `task_formatter.rs`: Markdown formatting optimized for AI agent consumption
- Background tokio tasks with cancellation support via CancellationToken
- Memory-only storage (cleared on server restart)
## API Examples
```rust
// Start caching (returns immediately with task ID)
cache_crate({crate_name: "tokio", source_type: "cratesio", version: "1.35.0"})
// Monitor progress
cache_operations({})
cache_operations({task_id: "abc-123-def"})
// Cancel/clear
cache_operations({task_id: "abc-123-def", cancel: true})
cache_operations({clear: true})
```
## Benefits
- Non-blocking caching for large crates
- Real-time progress tracking
- Cancellation support for user control
- AI-friendly markdown output with embedded commands
- Grouped task listings by status
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
* feat: Return JSON from cache_crate for test compatibility
Changes:
- Added CacheTaskStartedOutput struct to outputs.rs for JSON responses
- Updated cache_crate to return JSON format instead of markdown
- Created test helper infrastructure (TaskResult enum, wait_for_task_completion)
- Updated test helper functions (setup_test_crate, parse_cache_task_started)
- Modified test_cache_from_crates_io and test_cache_from_github
Rationale:
The async caching architecture returns immediately with a task ID, but
integration tests were written expecting synchronous completion. This
commit adds JSON output for structured verification and test helpers
to wait for async tasks to complete.
Status: Compilation works, test infrastructure in place. Most tests
still need updates to handle async behavior (18/21 remaining).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
* fix: Update all integration tests for async caching behavior
Changes:
- Updated all 21 integration tests to handle async caching with task IDs
- Added TaskResult enum for structured result handling
- Updated wait_for_task_completion to return detailed results
- Fixed workspace detection assertions to match actual error messages
- Updated test_cache_from_github_branch to expect BinaryOnly error
- Updated test_cache_from_local_path to wait for async completion
- Updated test_workspace_crate_detection with proper assertions
- Updated test_cache_update to handle two sequential async operations
- Updated test_invalid_inputs with mixed sync/async error handling
- Updated test_concurrent_caching for parallel async operations
- Updated test_workspace_member_caching for async workspace handling
- Updated test_cache_bevy_with_feature_fallback for large crate timeout
Test Results:
✅ All 21 integration tests passing
✅ Verified async caching with background tasks
✅ Verified workspace detection behavior
✅ Verified error handling for invalid inputs
✅ Verified concurrent caching operations
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
* feat: Replace percentage-based progress with step-based tracking
Replace misleading percentage calculations with honest step-based progress tracking.
Each caching stage now reports discrete steps instead of calculated percentages.
Changes:
- Replace progress_percent with current_step and step_description in CachingTask
- Add total_steps() method to CachingStage (Download: 1, Docs: 2, Index: 3)
- Update TaskManager with update_step() method
- Modify formatters to display "Step X of Y: Description"
- Update cache_crate_with_source to call update_step() at key points
- Remove percentage callbacks from downloader, docgen, and indexer
- Add integration test to verify step tracking behavior
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
* fix: Remove unused import and fix formatting issues for CI
- Remove unused HashMap import from task_manager.rs
- Fix await formatting in integration_tests.rs line 1418-1420
Co-authored-by: Michael Assaf <[email protected]>
---------
Co-authored-by: Claude <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Michael Assaf <[email protected]>1 parent 1b0bc28 commit 606b82f
File tree
13 files changed
+1695
-286
lines changed- rust-docs-mcp
- src
- cache
- search
- tests
13 files changed
+1695
-286
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| |||
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
| 46 | + | |
45 | 47 | | |
46 | 48 | | |
47 | 49 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
43 | | - | |
| 44 | + | |
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
| |||
57 | 58 | | |
58 | 59 | | |
59 | 60 | | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
60 | 64 | | |
61 | 65 | | |
62 | 66 | | |
| |||
66 | 70 | | |
67 | 71 | | |
68 | 72 | | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
69 | 78 | | |
70 | 79 | | |
71 | 80 | | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
72 | 86 | | |
73 | 87 | | |
74 | 88 | | |
| |||
82 | 96 | | |
83 | 97 | | |
84 | 98 | | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
85 | 104 | | |
86 | | - | |
| 105 | + | |
87 | 106 | | |
88 | 107 | | |
89 | 108 | | |
| |||
109 | 128 | | |
110 | 129 | | |
111 | 130 | | |
| 131 | + | |
112 | 132 | | |
113 | 133 | | |
114 | 134 | | |
| |||
184 | 204 | | |
185 | 205 | | |
186 | 206 | | |
187 | | - | |
| 207 | + | |
188 | 208 | | |
189 | 209 | | |
190 | 210 | | |
| |||
368 | 388 | | |
369 | 389 | | |
370 | 390 | | |
| 391 | + | |
371 | 392 | | |
372 | 393 | | |
373 | 394 | | |
| |||
395 | 416 | | |
396 | 417 | | |
397 | 418 | | |
398 | | - | |
399 | | - | |
| 419 | + | |
| 420 | + | |
400 | 421 | | |
401 | 422 | | |
402 | 423 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
24 | 28 | | |
25 | 29 | | |
26 | 30 | | |
| |||
87 | 91 | | |
88 | 92 | | |
89 | 93 | | |
| 94 | + | |
90 | 95 | | |
91 | 96 | | |
92 | 97 | | |
93 | 98 | | |
94 | | - | |
| 99 | + | |
95 | 100 | | |
96 | 101 | | |
97 | 102 | | |
| |||
110 | 115 | | |
111 | 116 | | |
112 | 117 | | |
113 | | - | |
| 118 | + | |
114 | 119 | | |
115 | 120 | | |
116 | 121 | | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
117 | 125 | | |
118 | 126 | | |
119 | 127 | | |
| |||
188 | 196 | | |
189 | 197 | | |
190 | 198 | | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
191 | 203 | | |
192 | 204 | | |
193 | 205 | | |
| 206 | + | |
| 207 | + | |
194 | 208 | | |
195 | 209 | | |
196 | 210 | | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
197 | 219 | | |
198 | 220 | | |
199 | 221 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
10 | 32 | | |
11 | 33 | | |
12 | 34 | | |
| |||
0 commit comments