Skip to content

Extract agent timeout message to markdown template#22088

Merged
pelikhan merged 2 commits intomainfrom
copilot/create-agent-failure-comment
Mar 21, 2026
Merged

Extract agent timeout message to markdown template#22088
pelikhan merged 2 commits intomainfrom
copilot/create-agent-failure-comment

Conversation

Copy link
Contributor

Copilot AI commented Mar 21, 2026

The timeout error text in buildTimeoutContext() was hardcoded as JavaScript string concatenation, inconsistent with how other error contexts (inference access, app token minting, lockdown) are handled via markdown templates in actions/setup/md/.

Changes

  • actions/setup/md/agent_timeout.md — new template file with {current_minutes} and {suggested_minutes} placeholders:
    **⏱️ Agent Timed Out**: The agent job exceeded the maximum allowed execution time ({current_minutes} minutes).
    
    To increase the timeout, add or update the `timeout-minutes` setting in your workflow's frontmatter:
    
    ```yaml
    ---
    timeout-minutes: {suggested_minutes}
    ---
    
    
  • buildTimeoutContext() in handle_agent_failure.cjs — replaced hardcoded string building with a fs.readFileSync + renderTemplate call, matching the pattern of buildInferenceAccessErrorContext and buildLockdownCheckFailedContext. setup.sh already copies all actions/setup/md/*.md files to ${RUNNER_TEMP}/gh-aw/prompts/ at runtime, so no setup changes are needed.

Move the hardcoded timeout message from buildTimeoutContext() in
handle_agent_failure.cjs into actions/setup/md/agent_timeout.md.

The new template uses {current_minutes} and {suggested_minutes}
placeholders rendered via renderTemplate(), following the same
pattern used by buildInferenceAccessErrorContext() and
buildLockdownCheckFailedContext().

The setup.sh script already copies all md/*.md files to
${RUNNER_TEMP}/gh-aw/prompts/ at runtime, so the file is
automatically available to the conclusion job.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Agent-Logs-Url: https://github.com/github/gh-aw/sessions/2718c9d9-d8d3-4899-8818-0818d6bde90a
@pelikhan pelikhan marked this pull request as ready for review March 21, 2026 04:56
Copilot AI review requested due to automatic review settings March 21, 2026 04:56
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR standardizes the agent-timeout failure messaging by moving the timeout text from inline string concatenation into a reusable markdown template, aligning it with other failure contexts that use templates.

Changes:

  • Added a new markdown template for agent timeout messaging with placeholder substitution.
  • Updated buildTimeoutContext() to load and render the timeout template from the runtime prompts directory.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
actions/setup/md/agent_timeout.md Adds a new markdown template for the agent timeout failure context with {current_minutes} / {suggested_minutes} placeholders.
actions/setup/js/handle_agent_failure.cjs Switches buildTimeoutContext() to read the new template and render it via renderTemplate.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

const template = fs.readFileSync(templatePath, "utf8");
return "\n" + renderTemplate(template, { current_minutes: currentMinutes, suggested_minutes: suggestedMinutes });
}

Copy link

Copilot AI Mar 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

buildTimeoutContext() behavior changed to load and render agent_timeout.md, but actions/setup/js/handle_agent_failure.test.cjs currently doesn’t cover this path (it covers other context builders). To prevent regressions (missing template, placeholder mismatch, wrong path), add a unit test that stubs fs.readFileSync for agent_timeout.md and asserts the rendered output includes the expected current_minutes / suggested_minutes values. Since buildTimeoutContext isn’t exported today, consider exporting it (non-breaking) similar to the other context builders so it can be tested directly.

Suggested change
module.exports.buildTimeoutContext = buildTimeoutContext;

Copilot uses AI. Check for mistakes.
@pelikhan
Copy link
Contributor

@copilot review comments

Export buildTimeoutContext from handle_agent_failure.cjs so it can be
tested directly, following the same pattern as other exported context
builders.

Add unit tests that stub fs.readFileSync for agent_timeout.md and
assert correct rendering of {current_minutes} and {suggested_minutes}
placeholders, including the default-minutes fallback and the +10
suggestion logic.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Agent-Logs-Url: https://github.com/github/gh-aw/sessions/991ce53a-a7f5-4337-845b-de6f685d5d0f
Copy link
Contributor Author

Copilot AI commented Mar 21, 2026

@copilot review comments

Addressed in ad31df1: exported buildTimeoutContext from the module and added 4 unit tests that stub fs.readFileSync for agent_timeout.md and verify placeholder substitution ({current_minutes}, {suggested_minutes}), the default-minutes fallback, and the +10 suggestion logic — following the same pattern as the buildAppTokenMintingFailedContext and buildLockdownCheckFailedContext tests.

Copilot AI requested a review from pelikhan March 21, 2026 05:05
@github-actions
Copy link
Contributor

Hey @Copilot 👋 — great refactor! Extracting the hardcoded timeout message into actions/setup/md/agent_timeout.md brings buildTimeoutContext() in line with buildInferenceAccessErrorContext, buildLockdownCheckFailedContext, and the other template-driven context builders.

The PR is clean, well-described, and comes with solid test coverage (four scenarios: not-timed-out guard, basic formatted output, empty timeoutMinutes default, and current + 10 suggestion math). No new dependencies, no scope creep, and the setup.sh wildcard copy means no extra wiring is needed. Looks ready for maintainer review! 🚀

Note

🔒 Integrity filtering filtered 1 item

Integrity filtering activated and filtered the following item during workflow execution.
This happens when a tool call accesses a resource that does not meet the required integrity or secrecy level of the workflow.

  • issue:#unknown (search_issues: has secrecy requirements that agent doesn't meet. The agent is not authorized to access private-scoped data.)

Generated by Contribution Check ·

@pelikhan pelikhan merged commit c40342f into main Mar 21, 2026
51 checks passed
@pelikhan pelikhan deleted the copilot/create-agent-failure-comment branch March 21, 2026 05:21
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.

3 participants