Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 21, 2025

Problem

When the logs command times out before fetching all available workflow runs, agents using the MCP server have no way to know that more data is available or how to continue fetching from where the timeout occurred. This makes it difficult for agents to retrieve complete log data when working with large repositories.

Solution

This PR adds a continuation field to the JSON output of the logs command that appears when a timeout occurs. The continuation field provides all necessary parameters for agents to seamlessly continue fetching logs from where the previous request stopped.

Changes

  1. New ContinuationData struct (pkg/cli/logs_report.go)

    • Contains all parameters needed to resume fetching: message, workflow_name, count, start_date, end_date, engine, branch, after_run_id, before_run_id, timeout
    • Only included in JSON output when timeout occurs (using omitempty tag)
  2. Enhanced timeout handling (pkg/cli/logs.go)

    • When timeout is reached and runs have been processed, creates continuation data
    • Sets before_run_id to the oldest processed run ID for proper pagination
    • Preserves all filter parameters from the original request
  3. Updated MCP server documentation (pkg/cli/mcp_server.go)

    • Enhanced logs tool description to explain continuation field behavior
    • Documents that presence of continuation indicates more data is available
    • Notes that continuation includes all parameters needed to resume fetching
  4. Comprehensive test coverage (pkg/cli/logs_json_test.go)

    • Tests continuation field population when timeout occurs
    • Tests continuation field omission when no timeout
    • Validates JSON serialization/deserialization

Example Output

With timeout (continuation present):

{
  "summary": { "total_runs": 5, ... },
  "runs": [ ... ],
  "continuation": {
    "message": "Timeout reached. Use these parameters to continue fetching more logs.",
    "workflow_name": "weekly-research",
    "count": 100,
    "before_run_id": 12341,
    "timeout": 50
  }
}

Without timeout (continuation omitted):

{
  "summary": { "total_runs": 100, ... },
  "runs": [ ... ]
}

Usage Pattern

Agents can now implement a simple pattern to fetch all logs:

  1. Call logs tool with timeout parameter
  2. Check response for continuation field
  3. If present, make follow-up call with before_run_id from continuation
  4. Repeat until no continuation field is present

This enables agents to efficiently retrieve complete log data regardless of repository size or network conditions.

Benefits

  • Agent-friendly: Clear signal when more data is available
  • Seamless pagination: All parameters provided for follow-up queries
  • Backwards compatible: Optional field doesn't affect existing consumers
  • Well documented: MCP server description explains the feature
  • Fully tested: Comprehensive test coverage ensures reliability

Fixes the issue where agents had no way to detect or handle incomplete log data due to timeouts.

Original prompt

When the "logs" command stops because of timeout, add a "continuation" field to the JSON they provides an updated argument to hint the agent to continue querying. The description of the logs tool in mcp-server should mention that the presence of continuation means there is more data.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits October 21, 2025 03:40
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Add continuation field to logs command timeout response Add continuation field to logs JSON output when timeout is reached Oct 21, 2025
Copilot AI requested a review from pelikhan October 21, 2025 03:45
@pelikhan pelikhan marked this pull request as ready for review October 21, 2025 04:33
@github-actions
Copy link
Contributor

Agentic Changeset Generator triggered by this pull request.

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

Co-Authored-By: Claude <noreply@anthropic.com>
@pelikhan pelikhan merged commit cb01eea into main Oct 21, 2025
3 checks passed
@pelikhan pelikhan deleted the copilot/add-continuation-field-logs branch October 21, 2025 04:36
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