Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 23, 2025

This PR addresses timing measurement accuracy in goal execution by separating scheduling overhead from actual function execution time. Previously, the timing measurement included overhead from function imports, transaction setup, and context preparation, making it difficult to get accurate performance metrics for goal handlers.

Problem

The existing timing measurement in _pursue_goal_core() captured the total time from the start of goal processing to completion, which included:

  • import_string() overhead for loading the handler function
  • Transaction setup and context preparation
  • Thread local context management
  • Argument extraction and preparation

This made it impossible to distinguish between scheduling/setup time and actual execution time, especially for goals that were initially blocked and later unblocked.

Solution

This PR moves timing measurement deeper into the execution flow to capture only the actual function execution time:

  1. Precise timing in follow_instructions(): Timing now starts just before the actual handler function call and ends immediately after, excluding all setup overhead.

  2. Thread-local timing storage: Added execution_time field to GoalsThreadLocal to pass precise timing from follow_instructions() to _pursue_goal_core().

  3. Robust exception handling: Ensures timing is captured correctly even when exceptions occur during execution.

Example

def my_handler(goal):
    # Only this execution time is now measured
    time.sleep(0.1)  # Will show ~100ms, not 100ms + import/setup overhead
    return AllDone()

# Schedule as blocked for clean timing separation
goal = schedule(my_handler, blocked=True)

# Later unblock and execute - timing captures only handler execution
unblocked_goal = unblock_retry_goal(goal.id)

Benefits

  • Accurate performance metrics: Goal execution timing no longer includes scheduling overhead
  • Better debugging: Clear separation between scheduling time and execution time
  • Improved monitoring: More precise performance measurements for optimization
  • Backward compatibility: Existing blocked parameter behavior is preserved

The changes are minimal (27 lines added, 3 modified) and maintain full backward compatibility while providing significantly more accurate timing data for goal execution monitoring and optimization.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] make the initial goal blocked when scheduling, then unblck and measure only the execution time, not scheduling time Improve goal execution timing precision by excluding scheduling overhead Aug 23, 2025
Copilot finished work on behalf of SupraSummus August 23, 2025 12:25
@Copilot Copilot AI requested a review from SupraSummus August 23, 2025 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants