Skip to content

Commit 774ebee

Browse files
committed
feat: sync full QueryRs implementation from private repo
- Add FetchStats and PersistenceStats for comprehensive tracking - Restore full content enhancement logic with disable_content_enhancement flag - Enable document-level caching for better performance - Add detailed logging for debugging and monitoring - All methods now actively used - no dead code warnings - Fix clippy warnings in terraphim_settings and terraphim_agent_evolution Resolves dead code issues by syncing feature-complete implementation from private repo. Default behavior: content enhancement disabled for performance, but can be enabled via config.
1 parent 4bce62e commit 774ebee

4 files changed

Lines changed: 381 additions & 44 deletions

File tree

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Dead Code Investigation: query_rs.rs
2+
3+
## Issue Summary
4+
The public `terraphim-ai` repository has dead code warnings for several methods in `crates/terraphim_middleware/src/haystack/query_rs.rs`:
5+
- `should_fetch_url()` - line 48
6+
- `get_fetched_count()` - line 72
7+
- `normalize_document_id()` - line 201
8+
- `fetch_and_scrape_content()` - line 336
9+
- `scrape_content()` - line 417
10+
- `is_critical_url()` - line 1107
11+
12+
## Root Cause Analysis
13+
14+
### Comparison with terraphim-private Repository
15+
16+
The private repository at `/Users/alex/projects/terraphim/terraphim-private` contains a MORE COMPLETE implementation where these methods ARE actively used:
17+
18+
**Line 353 in private repo:**
19+
```rust
20+
match self.fetch_and_scrape_content(&enhanced_doc).await {
21+
```
22+
23+
**Line 373 in private repo:**
24+
```rust
25+
if self.is_critical_url(&enhanced_doc.url) {
26+
```
27+
28+
**Line 403 in private repo:**
29+
```rust
30+
let unique_urls_fetched = self.get_fetched_count();
31+
```
32+
33+
**Line 351 in private repo:**
34+
```rust
35+
&& self.should_fetch_url(&enhanced_doc.url)
36+
```
37+
38+
### What Happened
39+
40+
The public repository has a **SIMPLIFIED** version that:
41+
1. Removed the content fetching/scraping logic (lines 346-399 in private)
42+
2. Kept the helper methods but they're no longer called
43+
3. This creates "dead code" that clippy detects
44+
45+
The private repository has:
46+
- `FetchStats` struct (lines 14-25) - tracks fetch success/failure
47+
- `PersistenceStats` struct (lines 28-41) - tracks cache hits/misses
48+
- Full content enhancement logic with `disable_content_enhancement` flag
49+
- Active usage of all the "dead" methods
50+
51+
## Resolution Options
52+
53+
### Option 1: Copy Complete Implementation from Private Repo ✅ RECOMMENDED
54+
**Pros:**
55+
- Restores full functionality
56+
- Methods are actually used
57+
- Better feature parity
58+
- More robust content fetching
59+
60+
**Cons:**
61+
- May expose private features
62+
- Larger codebase
63+
64+
### Option 2: Remove Dead Code (Quick Fix)
65+
**Pros:**
66+
- Clean, minimal codebase
67+
- Passes clippy immediately
68+
69+
**Cons:**
70+
- Loses functionality
71+
- Can't easily re-add features later
72+
73+
### Option 3: Keep with `#[allow(dead_code)]` (Current Approach)
74+
**Pros:**
75+
- Preserves methods for future use
76+
- Minimal changes
77+
78+
**Cons:**
79+
- Keeps unused code
80+
- Clutters codebase
81+
82+
## Recommended Action Plan
83+
84+
1. **Sync from Private Repo** - Copy the complete implementation:
85+
- Add `FetchStats` and `PersistenceStats` structs
86+
- Add `disable_content_enhancement` configuration support
87+
- Restore full content fetching logic (lines 246-400 from private)
88+
- Update logging to use `log::warn!` for better visibility
89+
90+
2. **Test Compatibility** - Ensure the enhanced version works with public config
91+
92+
3. **Update Documentation** - Document the `disable_content_enhancement` flag
93+
94+
## Files to Sync
95+
96+
**Source:** `/Users/alex/projects/terraphim/terraphim-private/crates/terraphim_middleware/src/haystack/query_rs.rs`
97+
98+
**Target:** `/Users/alex/projects/terraphim/terraphim-ai/crates/terraphim_middleware/src/haystack/query_rs.rs`
99+
100+
**Key Sections:**
101+
- Lines 13-41: Add FetchStats and PersistenceStats structs
102+
- Lines 74-103: Methods already present (remove `#[allow(dead_code)]`)
103+
- Lines 246-400: Full content enhancement logic with stats tracking
104+
105+
## Immediate Fix (Before Release)
106+
107+
For the v1.0.0 release, we should either:
108+
1. **Quickly sync from private** (15-20 min) - Better long-term
109+
2. **Keep `#[allow(dead_code)]` annotations** - Current state works
110+
111+
Given time constraints for release, Option 2 is acceptable for now, but schedule Option 1 for v1.0.1.

crates/terraphim_agent_evolution/src/workflows/parallelization.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -688,8 +688,7 @@ impl WorkflowPattern for Parallelization {
688688

689689
// Parallel execution reduces total time but adds overhead
690690
let estimated_tasks: usize = if input.prompt.len() > 2000 { 4 } else { 3 };
691-
let batches = (estimated_tasks + self.parallel_config.max_parallel_tasks - 1)
692-
/ self.parallel_config.max_parallel_tasks;
691+
let batches = estimated_tasks.div_ceil(self.parallel_config.max_parallel_tasks);
693692

694693
base_time_per_task * batches as u32 + Duration::from_secs(10)
695694
// aggregation overhead

0 commit comments

Comments
 (0)