Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

debug(a11y): trace logs for line capture + AX FFI failure surfacing

Louis Beaumontbdfdef17f984
diff --git a/crates/screenpipe-a11y/src/tree/macos.rs b/crates/screenpipe-a11y/src/tree/macos.rs
index 9d597a51a..c8ac44530 100644
--- a/crates/screenpipe-a11y/src/tree/macos.rs
+++ b/crates/screenpipe-a11y/src/tree/macos.rs
@@ -924,10 +924,20 @@ fn capture_lines_for_node(
// Only spend IPC on visually-present text — off-screen scroll-buffer
// content can't be highlighted by the user anyway (issue #2436's premise).
if on_screen != Some(true) {
+ debug!(
+ "lines: skip (off-screen) text_chars={} on_screen={:?}",
+ text.chars().count(),
+ on_screen
+ );
return None;
}
let bounds_ref = bounds.as_ref()?;
if !super::node_looks_multiline(text, bounds_ref, state.line_min_height_ratio) {
+ debug!(
+ "lines: skip (single-line) text_chars={} aspect={:.2}",
+ text.chars().count(),
+ bounds_ref.width / bounds_ref.height.max(1e-6),
+ );
return None;
}
@@ -937,7 +947,19 @@ fn capture_lines_for_node(
let max_per_node = state.line_max_calls_per_node;
let budget = state.line_budget.as_mut()?;
- macos_lines::capture_line_spans(elem, text, &refs, budget, max_per_node)
+ let calls_before = budget.calls_used();
+ let result = macos_lines::capture_line_spans(elem, text, &refs, budget, max_per_node);
+ let calls_after = budget.calls_used();
+ debug!(
+ "lines: capture text_chars={} calls={} result={}",
+ text.chars().count(),
+ calls_after - calls_before,
+ match &result {
+ Some(v) => format!("Some({} lines)", v.len()),
+ None => "None".to_string(),
+ }
+ );
+ result
}
/// Fill automation properties on an AccessibilityTreeNode from an AX element.
diff --git a/crates/screenpipe-a11y/src/tree/macos_lines.rs b/crates/screenpipe-a11y/src/tree/macos_lines.rs
index d016cd894..6357857eb 100644
--- a/crates/screenpipe-a11y/src/tree/macos_lines.rs
+++ b/crates/screenpipe-a11y/src/tree/macos_lines.rs
@@ -34,6 +34,8 @@
use super::{LineBudget, LineSpan, NodeBounds};
use cidre::{arc, ax, cf, cg};
use std::ffi::c_void;
+use std::sync::atomic::{AtomicBool, Ordering};
+use tracing::warn;
// ---------------------------------------------------------------------------
// FFI shim — `AXUIElementCopyParameterizedAttributeValue` is in
@@ -61,7 +63,25 @@ fn copy_param_attr(
let status = unsafe {
AXUIElementCopyParameterizedAttributeValue(elem, attr_name, parameter, &mut out)
};
- if status.is_ok() { out } else { None }
+ if status.is_ok() {
+ out
+ } else {
+ // Surface the AX status code once per process so we can tell whether
+ // browsers/apps support these param attrs. Once-only because a busy
+ // page can hit this thousands of times — the first failure already
+ // tells us whether to keep trying or fall back to a different path.
+ static WARNED: AtomicBool = AtomicBool::new(false);
+ if !WARNED.swap(true, Ordering::Relaxed) {
+ warn!(
+ "lines: AXUIElementCopyParameterizedAttributeValue({}) failed status={:?} \
+ — first failure (further failures suppressed); search highlights will fall \
+ back to paragraph bbox on this app",
+ attr_name.to_string(),
+ status,
+ );
+ }
+ None
+ }
}
// ---------------------------------------------------------------------------
diff --git a/crates/screenpipe-engine/src/cli/debug.rs b/crates/screenpipe-engine/src/cli/debug.rs
index e9824c0f0..92c851718 100644
--- a/crates/screenpipe-engine/src/cli/debug.rs
+++ b/crates/screenpipe-engine/src/cli/debug.rs
@@ -87,6 +87,46 @@ async fn a11y_walk(app_filter: Option<&str>, settle_ms: u64) -> anyhow::Result<(
let label = format!("walk {} (t+{}ms)", i + 1, elapsed);
match result {
TreeWalkResult::Found(snap) => {
+ // Line-capture stats: for each AXStaticText node, count how
+ // many had `lines` populated and how many were on-screen
+ // multi-line candidates that did NOT get lines (eligibility
+ // gap = AX call failure or budget exhaustion).
+ let mut static_text_total = 0usize;
+ let mut static_text_onscreen = 0usize;
+ let mut static_text_multiline_candidates = 0usize;
+ let mut nodes_with_lines = 0usize;
+ let mut total_lines: usize = 0;
+ let mut sample_lines_text: Option<String> = None;
+ for node in &snap.nodes {
+ if node.role != "AXStaticText" {
+ continue;
+ }
+ static_text_total += 1;
+ if node.on_screen == Some(true) {
+ static_text_onscreen += 1;
+ }
+ if let Some(b) = &node.bounds {
+ // Same heuristic as the walker uses to gate capture.
+ if node.on_screen == Some(true)
+ && screenpipe_a11y::tree::node_looks_multiline(&node.text, b, 1.5)
+ {
+ static_text_multiline_candidates += 1;
+ }
+ }
+ if let Some(lines) = &node.lines {
+ nodes_with_lines += 1;
+ total_lines += lines.len();
+ if sample_lines_text.is_none() {
+ let preview: String =
+ node.text.chars().take(60).collect::<String>().replace('\n', " ↵ ");
+ sample_lines_text = Some(format!(
+ " └─ sample: {} lines on '{}…'",
+ lines.len(),
+ preview
+ ));
+ }
+ }
+ }
println!(
"{label:<25} Found: app={:?} window={:?} nodes={} text_len={} truncated={}",
snap.app_name,
@@ -95,6 +135,17 @@ async fn a11y_walk(app_filter: Option<&str>, settle_ms: u64) -> anyhow::Result<(
snap.text_content.len(),
snap.truncated,
);
+ println!(
+ " AXStaticText: {} total, {} on-screen, {} multi-line candidates",
+ static_text_total, static_text_onscreen, static_text_multiline_candidates,
+ );
+ println!(
+ " line capture: {} nodes with lines, {} total lines",
+ nodes_with_lines, total_lines,
+ );
+ if let Some(s) = sample_lines_text {
+ println!(" {s}");
+ }
if !snap.text_content.is_empty() {
let preview = snap
.text_content