Skip to content

Commit 2eb5ec6

Browse files
committed
reduced some noisy debug logging, also adjusted context window calculation a bit
1 parent 987dbad commit 2eb5ec6

File tree

5 files changed

+5
-124
lines changed

5 files changed

+5
-124
lines changed

crates/pattern_core/src/context/mod.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ impl Default for ModelAdjustments {
242242
native_thinking: false,
243243
use_xml_tags: true,
244244
max_context_tokens: None,
245-
token_multiplier: 1.5, // Rough estimate: 1 token ≈ 0.75 words
245+
token_multiplier: 1.0, // Rough estimate: 1 token ≈ 0.75 words
246246
}
247247
}
248248
}
@@ -505,10 +505,7 @@ impl ContextBuilder {
505505
</value>
506506
</{}>",
507507
block.label,
508-
block
509-
.description
510-
.as_deref()
511-
.unwrap_or("No description provided"),
508+
block.description.as_deref().unwrap_or("No description"),
512509
block.permission,
513510
block.memory_type,
514511
char_count,

crates/pattern_core/src/context/state.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,7 +1613,7 @@ impl AgentContext {
16131613
let total_tokens = system_tokens + message_tokens;
16141614

16151615
// Leave some buffer (use 80% of limit to trigger compression)
1616-
total_tokens > (max_tokens * 2 / 3)
1616+
total_tokens > (max_tokens * 5 / 6)
16171617
} else {
16181618
false
16191619
};
@@ -1675,10 +1675,6 @@ impl AgentContext {
16751675
context.len(),
16761676
context.system_prompt.len()
16771677
);
1678-
for msg in &context.messages() {
1679-
tracing::debug!("{:?}", msg);
1680-
}
1681-
16821678
Ok(context)
16831679
}
16841680

crates/pattern_core/src/data_source/bluesky.rs

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2538,15 +2538,12 @@ impl BlueskyFirehoseSource {
25382538
if let Some(cached) = self.thread_cache.get(thread_root) {
25392539
let now = std::time::Instant::now();
25402540
if now.duration_since(cached.cached_at) < self.thread_cache_ttl {
2541-
tracing::debug!("📁 Cache HIT for thread {}", thread_root);
25422541
return Some(cached.context.clone());
25432542
} else {
2544-
tracing::debug!("🕐 Cache EXPIRED for thread {}", thread_root);
25452543
// Remove expired entry
25462544
self.thread_cache.remove(thread_root);
25472545
}
25482546
} else {
2549-
tracing::debug!("📁 Cache MISS for thread {}", thread_root);
25502547
}
25512548
None
25522549
}
@@ -2559,7 +2556,6 @@ impl BlueskyFirehoseSource {
25592556
};
25602557

25612558
self.thread_cache.insert(thread_root.clone(), cached);
2562-
tracing::debug!("💾 Cached thread context for {}", thread_root);
25632559
}
25642560

25652561
/// Check if thread was recently shown to agent (within TTL window)
@@ -2588,19 +2584,7 @@ impl BlueskyFirehoseSource {
25882584
if let Ok(pending_posts) = self.pending_batch.pending_posts.try_read() {
25892585
if let Some(post) = pending_posts.iter().find(|p| p.uri == uri) {
25902586
if post.hydration >= required_hydration {
2591-
tracing::debug!(
2592-
"📁 Post cache HIT for {} (hydration: {:?})",
2593-
uri,
2594-
post.hydration
2595-
);
25962587
return Some(post.clone());
2597-
} else {
2598-
tracing::debug!(
2599-
"🔄 Post cache PARTIAL for {} (has: {:?}, need: {:?})",
2600-
uri,
2601-
post.hydration,
2602-
required_hydration
2603-
);
26042588
}
26052589
}
26062590
}
@@ -2609,24 +2593,10 @@ impl BlueskyFirehoseSource {
26092593
for entry in self.pending_batch.posts_by_thread.iter() {
26102594
if let Some(post) = entry.value().iter().find(|p| p.uri == uri) {
26112595
if post.hydration >= required_hydration {
2612-
tracing::debug!(
2613-
"📁 Post cache HIT (batched) for {} (hydration: {:?})",
2614-
uri,
2615-
post.hydration
2616-
);
26172596
return Some(post.clone());
2618-
} else {
2619-
tracing::debug!(
2620-
"🔄 Post cache PARTIAL (batched) for {} (has: {:?}, need: {:?})",
2621-
uri,
2622-
post.hydration,
2623-
required_hydration
2624-
);
26252597
}
26262598
}
26272599
}
2628-
2629-
tracing::debug!("📁 Post cache MISS for {}", uri);
26302600
None
26312601
}
26322602

@@ -2662,12 +2632,6 @@ impl BlueskyFirehoseSource {
26622632
{
26632633
pending_posts.push(post.clone());
26642634
}
2665-
2666-
tracing::debug!(
2667-
"🌐 Fetched and cached post {} (hydration: {:?})",
2668-
uri,
2669-
required_hydration
2670-
);
26712635
return Ok(Some(post));
26722636
}
26732637
}
@@ -2725,11 +2689,6 @@ impl BlueskyFirehoseSource {
27252689
cached_posts.push(post);
27262690
}
27272691
}
2728-
tracing::debug!(
2729-
"🌐 Batch fetched {} posts (hydration: {:?})",
2730-
need_fetch.len(),
2731-
required_hydration
2732-
);
27332692
}
27342693
Err(e) => {
27352694
tracing::warn!("Failed to batch fetch posts: {}", e);

crates/pattern_core/src/message.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -949,12 +949,12 @@ impl Message {
949949
self.content.clone()
950950
}
951951
MessageContent::ToolResponses(_) => {
952-
tracing::debug!("Converting ToolResponses message with role {:?}", role);
952+
tracing::trace!("Converting ToolResponses message with role {:?}", role);
953953
self.content.clone()
954954
}
955955
MessageContent::Parts(parts) => match role {
956956
ChatRole::System | ChatRole::Assistant | ChatRole::Tool => {
957-
tracing::debug!("Combining Parts message with role {:?}", role);
957+
tracing::trace!("Combining Parts message with role {:?}", role);
958958
let string = parts
959959
.into_iter()
960960
.map(|part| match part {

crates/pattern_core/src/oauth/resolver.rs

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,12 @@ pub fn create_oauth_auth_resolver<C: Connection + 'static>(
3434

3535
// Only handle Anthropic OAuth for now
3636
if adapter_kind == AdapterKind::Anthropic {
37-
tracing::debug!("Checking OAuth token for Anthropic, user: {}", user_id);
3837
// Use OAuthModelProvider to handle token refresh automatically
3938
let provider =
4039
crate::oauth::integration::OAuthModelProvider::new(db.clone(), user_id.clone());
4140

4241
match provider.get_token("anthropic").await {
4342
Ok(Some(token)) => {
44-
// Token is automatically refreshed if needed by get_token()
45-
tracing::debug!(
46-
"Using OAuth token for Anthropic (expires: {})",
47-
token.expires_at
48-
);
49-
5043
// Return bearer token with "Bearer " prefix so genai detects OAuth
5144
return Ok(Some(AuthData::Key(format!(
5245
"Bearer {}",
@@ -57,9 +50,6 @@ pub fn create_oauth_auth_resolver<C: Connection + 'static>(
5750
// No OAuth token found
5851
// Check if API key is available as fallback
5952
if std::env::var("ANTHROPIC_API_KEY").is_ok() {
60-
tracing::debug!(
61-
"No OAuth token found for Anthropic, falling back to API key"
62-
);
6353
// Return None to use default auth (API key)
6454
return Ok(None);
6555
} else {
@@ -102,67 +92,6 @@ pub fn create_service_target_resolver() -> ServiceTargetResolver {
10292
ServiceTargetResolver::from_resolver_async_fn(resolver_fn)
10393
}
10494

105-
/// Load OAuth token for a provider from the database
106-
#[allow(dead_code)]
107-
async fn get_oauth_token<C: Connection>(
108-
db: &Surreal<C>,
109-
user_id: &UserId,
110-
provider: &str,
111-
) -> Result<Option<OAuthToken>, CoreError> {
112-
// Query for OAuth token belonging to this user and provider
113-
let query = r#"
114-
SELECT * FROM oauth_token
115-
WHERE owner_id = $user_id
116-
AND provider = $provider
117-
ORDER BY last_used_at DESC
118-
LIMIT 1
119-
"#;
120-
121-
// Clone to avoid borrow issues
122-
let user_id = user_id.clone();
123-
let provider = provider.to_string();
124-
125-
let mut result = db
126-
.query(query)
127-
.bind(("user_id", RecordId::from(user_id.clone())))
128-
.bind(("provider", provider.clone()))
129-
.await
130-
.map_err(|e| CoreError::DatabaseQueryFailed {
131-
query: query.to_string(),
132-
table: "oauth_token".to_string(),
133-
cause: e,
134-
})?;
135-
136-
let tokens: Vec<<OAuthToken as DbEntity>::DbModel> =
137-
result.take(0).map_err(|e| CoreError::DatabaseQueryFailed {
138-
query: query.to_string(),
139-
table: "oauth_token".to_string(),
140-
cause: e,
141-
})?;
142-
143-
let mut tokens = tokens
144-
.into_iter()
145-
.map(|tok| OAuthToken::from_db_model(tok).expect("should be the db model"));
146-
147-
let token = tokens.next();
148-
149-
if token.is_none() {
150-
tracing::info!(
151-
"No OAuth token found for user {} provider {}",
152-
user_id,
153-
provider
154-
);
155-
} else {
156-
tracing::info!(
157-
"Found OAuth token for user {} provider {}",
158-
user_id,
159-
provider
160-
);
161-
}
162-
163-
Ok(token)
164-
}
165-
16695
/// Builder for creating a genai client with OAuth support
16796
pub struct OAuthClientBuilder<C: Connection> {
16897
db: Arc<Surreal<C>>,

0 commit comments

Comments
 (0)