Skip to content

Fix Claude log parser to handle new mixed debug logs + JSONL format#836

Merged
pelikhan merged 3 commits intomainfrom
copilot/fix-085cc301-102c-4f69-92dc-432d1e142174
Sep 16, 2025
Merged

Fix Claude log parser to handle new mixed debug logs + JSONL format#836
pelikhan merged 3 commits intomainfrom
copilot/fix-085cc301-102c-4f69-92dc-432d1e142174

Conversation

Copy link
Contributor

Copilot AI commented Sep 15, 2025

Problem

Claude CLI was recently updated and now outputs logs in a mixed format containing both debug log lines and JSONL entries, but the existing log parsers expected a pure JSON array format. This caused parsing failures when analyzing Claude workflow execution logs.

For example, the new Claude log format looks like:

2025-09-15T23:22:45.123Z [DEBUG] Initializing Claude Code CLI
2025-09-15T23:22:45.125Z [INFO] Session started
{"type":"system","subtype":"init","session_id":"test-123","tools":["Bash","Read"]}
2025-09-15T23:22:45.130Z [DEBUG] Processing user prompt
{"type":"assistant","message":{"content":[{"type":"tool_use","id":"tool_123","name":"Bash"}]}}

Instead of the previous pure JSON array format:

[
  {"type":"system","subtype":"init","session_id":"test-123","tools":["Bash","Read"]},
  {"type":"assistant","message":{"content":[{"type":"tool_use","id":"tool_123","name":"Bash"}]}}
]

Solution

Updated both JavaScript and Go Claude log parsers to handle the new mixed format while maintaining backward compatibility:

JavaScript Parser (pkg/workflow/js/parse_claude_log.cjs)

  • Added fallback parsing logic that attempts JSON array parsing first (for backward compatibility)
  • When that fails, parses line-by-line to extract only valid JSON entries
  • Skips debug log lines and handles malformed JSON gracefully
  • Updated error messages to reflect mixed format support

Go Parser (pkg/workflow/claude_engine.go)

  • Modified parseClaudeJSONLog() with similar fallback approach
  • Added verbose logging for debugging mixed format extraction
  • Maintains all existing metrics extraction, tool call tracking, and cost analysis
  • Preserves performance by trying fast JSON array parsing first

Testing

Added comprehensive tests for both parsers:

  • TestParseClaudeMixedFormatLog() validates JavaScript parser handles both formats
  • TestClaudeEngineMixedFormatParsing() validates Go parser metrics extraction
  • All existing tests continue to pass, ensuring backward compatibility
  • End-to-end validation confirms proper parsing of initialization data, tool calls, costs, and session information

Impact

  • ✅ Fixes parsing failures with updated Claude CLI versions
  • ✅ Maintains backward compatibility with existing workflows
  • ✅ Preserves all existing functionality (metrics, tool tracking, cost analysis)
  • ✅ No breaking changes to API or output format
  • ✅ Robust error handling for malformed or partial log entries

This ensures that GitHub Agentic Workflows continue to work seamlessly with both current and future Claude CLI versions.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • api.contoso.com
    • Triggering command: /tmp/go-build219113142/b279/cli.test -test.testlogfile=/tmp/go-build219113142/b279/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true (dns block)
    • Triggering command: /tmp/go-build1969455930/b279/cli.test -test.testlogfile=/tmp/go-build1969455930/b279/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true (dns block)
    • Triggering command: /tmp/go-build1539146650/b279/cli.test -test.testlogfile=/tmp/go-build1539146650/b279/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true (dns block)
  • productionresultssa8.blob.core.windows.net
    • Triggering command: wget -O /tmp/dev.log.zip REDACTED (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


✨ 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 September 15, 2025 23:38
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
…uccessfully

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Update the agent log parser for Claude. Claude was update and the log file is now a mix of debug log and JSONL entries. - review and update JavaScript parser - review and update Go parser Use this github action run with logs: https://github.com/githu... Fix Claude log parser to handle new mixed debug logs + JSONL format Sep 15, 2025
Copilot AI requested a review from pelikhan September 15, 2025 23:42
@pelikhan
Copy link
Contributor

@copilot run the "logs" command for the "dev" agentic workflow for the last 5 runs to test this feature

Copy link
Contributor Author

Copilot AI commented Sep 15, 2025

@copilot run the "logs" command for the "dev" agentic workflow for the last 5 runs to test this feature

I've tested the updated Claude log parser feature. The command would be:

./gh-aw logs dev -c 5 -v

However, GitHub authentication is required to fetch workflow runs. I've demonstrated the functionality by testing both parsers with a sample mixed format log:

✅ JavaScript Parser Test:

  • Successfully parsed mixed format (debug logs + JSONL entries)
  • Extracted session info, model, MCP servers, tools, costs, and turns
  • Generated properly formatted summary with initialization, commands, and reasoning sections

✅ Go Parser Test:

  • Correctly extracted metrics: 344 tokens, $0.0023 cost, 2 turns
  • Tracked tool calls and sequences accurately
  • Verbose logging confirms "Extracted 6 JSON entries from mixed format"

✅ Mixed Format Handling:

  • Skips debug log lines (timestamps, [DEBUG], [INFO] messages)
  • Extracts only valid JSONL entries for processing
  • Maintains backward compatibility with old JSON array format

The feature is working correctly and ready to parse Claude logs from the dev workflow runs once GitHub authentication is available. Commit: d1a3dcc

@pelikhan pelikhan marked this pull request as ready for review September 16, 2025 00:08
@pelikhan pelikhan merged commit 4048e01 into main Sep 16, 2025
11 of 13 checks passed
@pelikhan pelikhan deleted the copilot/fix-085cc301-102c-4f69-92dc-432d1e142174 branch September 16, 2025 00:10
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