Skip to content

Add error handling to agent output ingestion for better failure diagnostics#11093

Merged
pelikhan merged 4 commits intomainfrom
copilot/debug-instructions-janitor-failure
Jan 21, 2026
Merged

Add error handling to agent output ingestion for better failure diagnostics#11093
pelikhan merged 4 commits intomainfrom
copilot/debug-instructions-janitor-failure

Conversation

Copy link
Contributor

Copilot AI commented Jan 21, 2026

Fix: Instructions Janitor Workflow Failure (#11089)

Status: ✅ Ready for Review

  • Identify failing workflow run (21224671739) and affected step
  • Review workflow configuration and scripts
  • Check recent code changes that could affect the failure
  • Add error handling to collect_ndjson_output.cjs to prevent uncaught exceptions
  • Add try-catch wrapper around main() to ensure graceful failure
  • Test the fix locally
  • Verify formatting and linting
  • Code review (no issues found)
  • Security scan (no concerns)
  • Refactor JSON repair logic to separate helper file
  • Add comprehensive tests for JSON repair functionality

Recent Changes

Addressed feedback from @pelikhan:

  1. ✅ Formatted and linted all code
  2. ✅ Moved repairJson function to separate helper file json_repair_helpers.cjs
  3. ✅ Added 40 comprehensive tests covering:
    • Basic repairs (quotes, keys, trimming)
    • Control character escaping
    • Embedded quote handling
    • Brace and bracket balancing
    • Trailing comma removal
    • Array closing fixes
    • Complex scenarios and edge cases
    • Real-world agent output patterns

Files Modified:

  • actions/setup/js/collect_ndjson_output.cjs - Imports repairJson from helper
  • actions/setup/js/json_repair_helpers.cjs - NEW: JSON repair logic with documentation
  • actions/setup/js/json_repair_helpers.test.cjs - NEW: 40 comprehensive tests

Test Results:

  • ✅ All 40 JSON repair helper tests pass
  • ✅ All 101 collect_ndjson_output tests pass
  • ✅ TypeScript compilation succeeds
  • ✅ Formatting and linting pass

Problem

The "Instructions Janitor" workflow (run #125 - 21224671739) failed on the "Ingest agent output" step. The workflow runs daily and had been succeeding (run #124 succeeded), indicating an intermittent failure rather than a systematic issue.

Root Cause

The main() function in actions/setup/js/collect_ndjson_output.cjs lacked comprehensive error handling. While the script properly handles validation errors (logging them as warnings), it was vulnerable to uncaught exceptions from:

  1. JSON parsing failures - when agent output contains malformed JSON that cannot be repaired
  2. File system errors - when reading or writing files
  3. Other runtime errors - any unexpected exceptions during execution

Solution

  1. Error Handling: Added comprehensive error handling to collect_ndjson_output.cjs:

    • Wrapped the entire main() function body in a try-catch block
    • Use core.error() to log error messages and stack traces
    • Call core.setFailed() to explicitly fail with clear, actionable messages
    • Re-throw errors to maintain failure behavior
    • TypeScript-compliant error handling with proper type guards
  2. Code Organization: Extracted JSON repair logic to separate helper module:

    • Created json_repair_helpers.cjs with well-documented repairJson function
    • Added 40 comprehensive tests covering all repair strategies
    • Improved code maintainability and testability

Benefits

  1. Better diagnostics: Future failures will include error messages, stack traces, and context
  2. Easier troubleshooting: Failures will be immediately identifiable
  3. Better testability: JSON repair logic is now independently testable
  4. Better maintainability: Separated concerns make the code easier to understand and modify
  5. Maintains existing behavior: Validation errors remain as warnings (by design)

Note: This fix improves error reporting, diagnostics, and code organization. The workflow may still fail intermittently if the agent produces malformed output, but failures will now include detailed error information for debugging.

Original prompt

This section details on the original issue you should resolve

<issue_title>[agentics] Instructions Janitor failed</issue_title>
<issue_description>### Workflow Failure

Workflow: Instructions Janitor
Branch: main
Run URL: https://github.com/githubnext/gh-aw/actions/runs/21224671739

Action Required

Debug this workflow failure using the agentic-workflows agent:

/agent agentic-workflows

When prompted, instruct the agent to debug this workflow failure.

Generated from Instructions Janitor

  • expires on Jan 28, 2026, 8:36 PM UTC

Comments on the Issue (you are @copilot in this section)


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

…xceptions

Co-authored-by: mnkiefer <8320933+mnkiefer@users.noreply.github.com>
Copilot AI changed the title [WIP] Debug Instructions Janitor workflow failure Add error handling to agent output ingestion for better failure diagnostics Jan 21, 2026
Copilot AI requested a review from mnkiefer January 21, 2026 21:37
@pelikhan pelikhan marked this pull request as ready for review January 21, 2026 21:47
Copy link
Contributor

@pelikhan pelikhan left a comment

Choose a reason for hiding this comment

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

@copilot format, lint

if (content.includes("\n") || content.includes("\r") || content.includes("\t")) {
const escaped = content.replace(/\\/g, "\\\\").replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t");
return `"${escaped}"`;
function repairJson(jsonStr) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@copilot move json repairing to separate helper file, add tests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! Moved repairJson to json_repair_helpers.cjs with 40 comprehensive tests covering:

  • Basic repairs (quotes, keys, trimming)
  • Control character escaping
  • Embedded quote handling
  • Brace/bracket balancing
  • Trailing comma removal
  • Real-world agent output patterns

All 40 tests pass ✅

Commit: 49353d5

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

Copilot AI commented Jan 21, 2026

@copilot format, lint

Done! All code has been formatted and linted. ✅

Commit: 49353d5

Copilot AI requested a review from pelikhan January 21, 2026 21:56
@pelikhan pelikhan merged commit 170de7d into main Jan 21, 2026
48 checks passed
@pelikhan pelikhan deleted the copilot/debug-instructions-janitor-failure branch January 21, 2026 22:24
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.

[agentics] Instructions Janitor failed

3 participants