Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 21, 2025

Problem

The logs command can take a long time to download workflow artifacts, especially when fetching logs for multiple runs or workflows with large artifacts. When running as an MCP server, this can cause timeouts that prevent the tool from completing successfully.

Solution

This PR adds a --timeout option to the logs command that limits execution time by stopping the download process when the specified time limit is reached. Any runs that were successfully downloaded before the timeout are processed and returned, providing partial results rather than failing completely.

Key Changes

  • New --timeout flag: Accepts timeout value in seconds (0 = no timeout, default)
  • MCP server integration: Automatically sets a 50-second timeout when running as an MCP tool
  • Graceful degradation: Returns partial results if timeout is reached instead of failing
  • Backward compatible: When timeout is not specified, behavior is unchanged

Implementation Details

The timeout is implemented using time.Since() to track elapsed time at the start of each download iteration. When the elapsed time exceeds the specified timeout:

  1. The download loop exits immediately
  2. Any already-downloaded runs are processed normally
  3. A message indicates how many runs were processed before timeout
  4. The command returns successfully with partial results

In the MCP server, the logs tool automatically applies a 50-second timeout unless explicitly overridden via the timeout parameter in the tool arguments.

Usage Examples

Command Line:

# Download logs with 50 second timeout
gh aw logs --timeout 50

# Combine with other filters
gh aw logs --timeout 60 -c 10 --engine claude -v

MCP Server:

{
  "workflow_name": "test-workflow",
  "count": 10
  // Uses 50 second timeout by default
}

Or override the default:

{
  "workflow_name": "test-workflow",
  "count": 10,
  "timeout": 120
}

Testing

  • Added comprehensive unit tests for timeout functionality
  • Updated existing tests to maintain compatibility
  • All tests pass successfully
  • Verified MCP server integration

Fixes the issue where long-running log downloads could timeout when running as an MCP server.

Original prompt

Add option to "logs" command, --timeout, to limit the tool execution to a specified number of seconds. The goal is to prevent timeouts when running as mcp. When the time is up, stop downloading runs and process them.

Set timeout to 50 seconds when running in the mcp server.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

- Add --timeout flag to logs command in pkg/cli/logs.go
- Implement timeout handling in DownloadWorkflowLogs function
- Set default timeout to 50 seconds in MCP server logs tool
- Add comprehensive unit tests for timeout functionality
- Update existing tests to include timeout parameter

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@pelikhan
Copy link
Contributor

@copilot

  • add the --tool-timeout on mcp-server command to set the logs timeout
  • the compiler should configure the gh-aw mcp server with the timeout from the engine

Copilot AI changed the title [WIP] Add --timeout option to logs command for execution limit Add --timeout option to logs command for MCP server timeout prevention Oct 21, 2025
Copilot AI requested a review from pelikhan October 21, 2025 01:46
@pelikhan pelikhan marked this pull request as ready for review October 21, 2025 01:59
@pelikhan pelikhan merged commit 0942c78 into main Oct 21, 2025
5 of 6 checks passed
@pelikhan pelikhan deleted the copilot/add-timeout-option-logs-command branch October 21, 2025 01:59
@github-actions
Copy link
Contributor

Agentic Changeset Generator triggered by this pull request.

Copilot AI requested a review from pelikhan October 21, 2025 02:00
github-actions bot added a commit that referenced this pull request Oct 21, 2025
Update CLI and MCP server documentation to reflect recent feature additions:

- Add --timeout option documentation for logs command with caching details
- Add --parse option documentation for audit command
- Add URL support documentation for audit command (cross-repo, GitHub Enterprise)
- Document continuation field in MCP server logs tool for pagination
- Document large output automatic file handling in MCP server (16K token threshold)

These changes document features from PRs #2066, #2064, #2060, #2058, #2052, and #2051.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
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