affaan-m/ECC · error · SyntaxError

Malformed coordination JSON in body: ${error.message} — raw:

Error message

Malformed coordination JSON in body: ${error.message} — raw: ${match[1].slice(0, 120)}

What it means

Thrown as a SyntaxError by extractCoordinationState (parsing.js) when the coordination JSON block inside an issue body is found (the marker-delimited ```json fence matches) but its contents fail JSON.parse. This indicates the embedded coordination state was hand-edited or corrupted — the structure is recognizable but the payload is invalid JSON, so it cannot be read or updated safely.

Source

Thrown at scripts/lib/github-coordination/parsing.js:26

function normalizeBodyForComparison(body) {
  return (body || '').replace(/"lastSyncAt"\s*:\s*[^,}\n]+/g, '"lastSyncAt": NORMALIZED');
}

function extractCoordinationState(body, policy = DEFAULT_POLICY) {
  const marker = escapeRegExp(policy.sectionMarker || DEFAULT_SECTION_MARKER);
  const regex = new RegExp(`<!--\\s*${marker}:start\\s*-->\\s*` + '```json\\s*([\\s\\S]*?)\\s*```' + `\\s*<!--\\s*${marker}:end\\s*-->`, 'm');
  const match = String(body || '').match(regex);

  if (!match) {
    return null;
  }

  try {
    const parsed = JSON.parse(match[1]);
    return parsed && typeof parsed === 'object' ? parsed : null;
  } catch (error) {
    throw new SyntaxError(`Malformed coordination JSON in body: ${error.message} — raw: ${match[1].slice(0, 120)}`);
  }
}

function extractIssueReferences(text) {
  const refs = new Set();
  const source = String(text || '');
  for (const match of source.matchAll(/(?:^|[^\d])#(\d+)\b/g)) {
    refs.add(Number.parseInt(match[1], 10));
  }
  return Array.from(refs)
    .filter(Number.isFinite)
    .sort((a, b) => a - b);
}

function extractTasks(body) {
  const lines = String(body || '').split(/\r?\n/);
  const tasks = [];
  let inTasks = false;

View on GitHub (pinned to 01e15490f0)

Solutions

  1. Open the issue body and fix the JSON inside the coordination:start/coordination:end fence; the message shows the first 120 chars of the offending payload.
  2. Validate the block with a JSON linter before saving the issue body.
  3. Use the coordination tooling to write the block rather than editing it by hand, so it is always valid.
  4. If the block is unrecoverable, regenerate it via the coordination state builder from the issue's labels/refs.

Example fix

// before (in the issue body)
<!-- coordination:start -->
```json
{ "status": "draft", "dependencies": [12, 13, }  // <- stray comma + unclosed brace
```
<!-- coordination:end -->

// after
<!-- coordination:start -->
```json
{ "status": "draft", "dependencies": [12, 13] }
```
<!-- coordination:end -->
Defensive patterns

Strategy: try-catch

Validate before calling

function safeExtract(body) {
  try { return extractCoordinationState(body); }
  catch (e) { if (e instanceof SyntaxError) { console.warn('coordination block malformed — will regenerate'); return null; } throw e; }
}

Type guard

function isJsonObject(v) {
  return v !== null && typeof v === 'object' && !Array.isArray(v);
}

Try / catch

try {
  extractCoordinationState(body);
} catch (e) {
  if (e instanceof SyntaxError && /Malformed coordination JSON/.test(e.message)) {
    // regenerate the block from labels/refs rather than trusting the broken body
    return rebuildCoordinationBlock(issue);
  }
  throw e;
}

Prevention

When it happens

Trigger: A user edited the coordination block in the issue body and introduced a syntax error (trailing comma, unquoted key, missing brace); a bot wrote a truncated block; mixed smart-quotes; a copy-paste dropped a character.

Common situations: Manual edits to the coordination section; a tool that writes partial/async state got interrupted; an editor auto-'corrected' quotes; locale-specific punctuation in JSON.

Understand the failure class

Related errors


AI-assisted analysis of affaan-m/ECC@01e15490f0 (2026-08-13). Data as JSON: /api/errors/dccb2e87f1287efe. Report an issue: GitHub.