Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions sentience/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,11 @@ def act( # noqa: C901
"signals": verify_signals,
}

# Build elements data for pre field (include diff_status from snap_with_diff)
# Use the same format as build_snapshot_event for consistency
snapshot_event_data = TraceEventBuilder.build_snapshot_event(snap_with_diff)
pre_elements = snapshot_event_data.get("elements", [])

# Build complete step_end event
step_end_data = TraceEventBuilder.build_step_end_event(
step_id=step_id,
Expand All @@ -498,6 +503,7 @@ def act( # noqa: C901
llm_data=llm_data,
exec_data=exec_data,
verify_data=verify_data,
pre_elements=pre_elements,
)

_safe_tracer_call(
Expand Down Expand Up @@ -1045,6 +1051,11 @@ async def act( # noqa: C901
"signals": verify_signals,
}

# Build elements data for pre field (include diff_status from snap_with_diff)
# Use the same format as build_snapshot_event for consistency
snapshot_event_data = TraceEventBuilder.build_snapshot_event(snap_with_diff)
pre_elements = snapshot_event_data.get("elements", [])

# Build complete step_end event
step_end_data = TraceEventBuilder.build_step_end_event(
step_id=step_id,
Expand All @@ -1057,6 +1068,7 @@ async def act( # noqa: C901
llm_data=llm_data,
exec_data=exec_data,
verify_data=verify_data,
pre_elements=pre_elements,
)

_safe_tracer_call(
Expand Down
6 changes: 3 additions & 3 deletions sentience/extension/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,13 @@ async function handleScreenshotCapture(_tabId, options = {}) {
async function handleSnapshotProcessing(rawData, options = {}) {
const MAX_ELEMENTS = 10000; // Safety limit to prevent hangs
const startTime = performance.now();

try {
// Safety check: limit element count to prevent hangs
if (!Array.isArray(rawData)) {
throw new Error('rawData must be an array');
}

if (rawData.length > MAX_ELEMENTS) {
console.warn(`[Sentience Background] ⚠️ Large dataset: ${rawData.length} elements. Limiting to ${MAX_ELEMENTS} to prevent hangs.`);
rawData = rawData.slice(0, MAX_ELEMENTS);
Expand Down Expand Up @@ -186,7 +186,7 @@ async function handleSnapshotProcessing(rawData, options = {}) {
// Add timeout protection (18 seconds - less than content.js timeout)
analyzedElements = await Promise.race([
wasmPromise,
new Promise((_, reject) =>
new Promise((_, reject) =>
setTimeout(() => reject(new Error('WASM processing timeout (>18s)')), 18000)
)
]);
Expand Down
2 changes: 1 addition & 1 deletion sentience/extension/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function handleSnapshotRequest(data) {
if (responded) return; // Already responded via timeout
responded = true;
clearTimeout(timeoutId);

const duration = performance.now() - startTime;

// Handle Chrome extension errors (e.g., background script crashed)
Expand Down
Loading
Loading