Skip to content

Verify TypeScript type error fix in handle_agent_failure.cjs#10437

Closed
Copilot wants to merge 1 commit intomainfrom
copilot/fix-type-error-in-handle-agent-failure
Closed

Verify TypeScript type error fix in handle_agent_failure.cjs#10437
Copilot wants to merge 1 commit intomainfrom
copilot/fix-type-error-in-handle-agent-failure

Conversation

Copy link
Contributor

Copilot AI commented Jan 17, 2026

Context

CI failure #21089288909 reported TypeScript type errors in handle_agent_failure.cjs where boolean values were passed to renderTemplate(), which expects Record<string, string|number|undefined>.

Status

No changes required. The fix is already present in the main branch.

Verification

Both occurrences at lines 286 and 332 correctly use String() conversion:

const templateContext = {
  // ... other fields
  secret_verification_failed: String(secretVerificationResult === "failed"),
  secret_verification_context: secretVerificationResult === "failed" ? "\n**⚠️ ...\n" : "",
};

TypeScript compilation passes. The boolean-to-string conversion maintains type safety while preserving the intended template behavior.

Original prompt

This section details on the original issue you should resolve

<issue_title>[CI Failure Doctor] TypeScript type error in handle_agent_failure.cjs - boolean passed to renderTemplate</issue_title>
<issue_description># 🏥 CI Failure Investigation - Run githubnext/gh-aw#21089288909

Summary

The CI workflow failed due to TypeScript type errors in handle_agent_failure.cjs. The code passes a boolean value (secret_verification_failed) to the renderTemplate() function, which expects only string | number | undefined types.

Failure Details

Root Cause Analysis

Error Messages

handle_agent_failure.cjs:292:61 - error TS2345: Argument of type '{ ...; secret_verification_failed: boolean; ... }' is not assignable to parameter of type 'Record<string, string | number | undefined>'.
  Property 'secret_verification_failed' is incompatible with index signature.
    Type 'boolean' is not assignable to type 'string | number | undefined'.

292         const commentBody = renderTemplate(commentTemplate, templateContext);
                                                                ~~~~~~~~~~~~~~~

handle_agent_failure.cjs:338:64 - error TS2345: [Same error at different location]
338         const issueBodyContent = renderTemplate(issueTemplate, templateContext);
                                                                   ~~~~~~~~~~~~~~~

Technical Details

The renderTemplate() function in messages_core.cjs (line 69) has the following signature:

function renderTemplate(template: string, context: Record<string, string|number|undefined>): string

However, handle_agent_failure.cjs creates template contexts with a boolean field:

Line 286-289 (Comment context):

const templateContext = {
  // ... other string fields ...
  secret_verification_failed: secretVerificationResult === "failed",  // ❌ boolean
  secret_verification_context: secretVerificationResult === "failed" ? "\n**⚠️ ...\n" : "",
};

Line 325-335 (Issue context):

const templateContext = {
  // ... other string fields ...
  secret_verification_failed: secretVerificationResult === "failed",  // ❌ boolean
  secret_verification_context: secretVerificationResult === "failed" ? "\n**⚠️ ...\n" : "",
};

Why This Wasn't Caught Earlier

  1. The JavaScript code is syntactically valid - the type error only appears during TypeScript compilation
  2. The npm test command runs npm run typecheck && vitest run --no-file-parallelism
  3. TypeScript's tsc --noEmit check is run before tests, catching the type error
  4. The PR Store secret verification result in step/job output for agent failure context #10408 added the secret_verification_failed field but didn't account for TypeScript's type constraints

Recommended Actions

Fix #1: Convert Boolean to String (Recommended)

Change the boolean to a string representation:

// Line 286
const templateContext = {
  run_url: runUrl,
  run_id: runId,
  workflow_name: workflowName,
  workflow_source: workflowSource,
  workflow_source_url: workflowSourceURL,
  secret_verification_failed: String(secretVerificationResult === "failed"),  // ✅ Convert to string
  secret_verification_context:
    secretVerificationResult === "failed" ? "\n**⚠️ Secret Verification Failed**: ...\n" : "",
};

// Line 325
const templateContext = {
  workflow_name: sanitizedWorkflowName,
  run_url: runUrl,
  workflow_source_url: workflowSourceURL || "#",
  branch: currentBranch,
  pull_request_info: pullRequest ? `  \n**Pull Request:** [#${pullRequest.number}](${pullRequest.html_url})` : "",
  secret_verification_failed: String(secretVerificationResult === "failed"),  // ✅ Convert to string
  secret_verification_context:
    secretVerificationResult === "failed" ? "\n**⚠️ Secret Verification Failed**: ...\n" : "",
};

Fix #2: Update renderTemplate Type Signature (Alternative)

Alternatively, update renderTemplate() to accept booleans:

// messages_core.cjs, line 66
function renderTemplate(template: string, context: Record<string, string|number|boolean|undefined>): string {
  return template.replace(/\{(\w+)\}/g, (match, key) => {
    const value = context[key];
    return value !== undefined && value !== null ? String(value) : match;
  });
}

Recommendation: Fix #1 is preferred because it's more explicit and maintains stricter type safety.

Prevention Strategies

1. Pre-commit Hooks

Add TypeScript type checking to pre-commit hooks:

# In .git/hooks/pre-commit or via husky
cd actions/setup/js && npm run typecheck

2. GitHub Actions Job Order

The js job already...


💡 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 AI changed the title [WIP] Fix TypeScript type error in handle_agent_failure.cjs Verify TypeScript type error fix in handle_agent_failure.cjs Jan 17, 2026
Copilot AI requested a review from mnkiefer January 17, 2026 10:03
@pelikhan pelikhan closed this Jan 17, 2026
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.

[CI Failure Doctor] TypeScript type error in handle_agent_failure.cjs - boolean passed to renderTemplate

3 participants