Skip to content

Add debug logging for JSON parse errors in ACP handler - #1071

Merged
tbrandenburg merged 3 commits into
mainfrom
copilot/add-debug-logging-json-errors
Feb 2, 2026
Merged

Add debug logging for JSON parse errors in ACP handler#1071
tbrandenburg merged 3 commits into
mainfrom
copilot/add-debug-logging-json-errors

Conversation

Copilot AI commented Feb 2, 2026

Copy link
Copy Markdown
Contributor

The ACP handler silently ignores JSON parse errors when processing messages line-by-line (line 121). This makes protocol issues difficult to diagnose during development.

Changes

  • ACP handler: Add environment-gated debug logging (DEBUG or WORK_DEBUG) that emits parse errors and problematic lines (truncated to 200 chars)
  • Tests: Add 4 unit tests covering debug/non-debug modes, both env vars, and line truncation with proper isolation

Usage

DEBUG=1 work notify send TASK-123 to acp-target

Output when invalid JSON is received:

ACP message parse error: Unexpected token 'i', "invalid json" is not valid JSON
Problematic line: invalid json

Normal operation unaffected when env vars not set.

Original prompt

Enhance the ACP message handling by adding debug logging for JSON parse errors. Currently, the acp-handler.ts implementation ignores parse errors for partial messages (line 121). The PoC implementation reports these errors for debugging (refer to dev/poc-opencode-server/complete-acp-test.js:35-39).

Proposed Change
Introduce debug logging for JSON parse errors, enabled by environment variables DEBUG or WORK_DEBUG, without changing normal operation. Debug logs should identify the error details and the problematic line. Here's the suggested change:

try {
    const msg = JSON.parse(line) as ACPMessage;
    this.handleMessage(msg);
} catch (err) {
    // NEW: Log parse errors in debug mode
    if (process.env.DEBUG || process.env.WORK_DEBUG) {
        console.warn('ACP message parse error:', err instanceof Error ? err.message : String(err));
        console.warn('Problematic line:', line.substring(0, 200));
    }
}

Benefits

  1. Easier diagnosis of protocol issues during development or debugging.
  2. Normal operation remains unaffected since logging is environment-controlled.
  3. Aligns with the PoC debugging pattern.

References:
PoC: dev/poc-opencode-server/complete-acp-test.js:35-39 (or updated PoC location that reflects related/debugging concepts).
Proposed update target: src/core/target-handlers/acp-handler.ts:118-123.

This pull request was created from Copilot chat.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits February 2, 2026 17:53
Co-authored-by: tbrandenburg <40181002+tbrandenburg@users.noreply.github.com>
Co-authored-by: tbrandenburg <40181002+tbrandenburg@users.noreply.github.com>
@tbrandenburg
tbrandenburg marked this pull request as ready for review February 2, 2026 17:55
Copilot AI changed the title [WIP] Add debug logging for JSON parse errors in ACP message handling Add debug logging for JSON parse errors in ACP handler Feb 2, 2026
Copilot AI requested a review from tbrandenburg February 2, 2026 17:57
@tbrandenburg
tbrandenburg merged commit c24b276 into main Feb 2, 2026
4 checks passed
@tbrandenburg tbrandenburg linked an issue Feb 2, 2026 that may be closed by this pull request
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.

Enhancement: Add debug logging for ACP message parse errors

2 participants