loop-engineering icon indicating copy to clipboard operation
loop-engineering copied to clipboard

[bug] loop doctor reports healthy when audit or sync checks fail

Open shixi-li opened this issue 3 weeks ago • 0 comments

Describe the bug

On an already-scaffolded project, loop doctor --json can exit 0 with severity: "healthy" when loop-audit or loop-sync fails to produce a usable report. The diagnostic is put in notes, but the missing scores do not participate in the severity decision.

Malformed JSON and incomplete reports can produce the same false healthy result. Missing or unrecognized levels, out-of-range scores, and a missing sync issue list can even be accepted without a diagnostic in notes. A controller that relies on doctor's exit code therefore cannot distinguish completed healthy checks from missing checks.

Steps to reproduce

On main 1de5ca08d60f464b1a745bbf9c898d3bc7f45dd8:

  1. Run cd tools/loop && npm ci && npm run build.
  2. From that package directory, run the following fault-injection reproduction. It copies the real umbrella CLI into a disposable layout and supplies an audit child that fails plus a valid healthy sync child. The actual checkout is not modified and the fake siblings prevent an npx/network fallback.
node --input-type=module <<'JS'
import { cp, mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import path from 'node:path';
import { spawnSync } from 'node:child_process';
const root = await mkdtemp(path.join(tmpdir(), 'loop-doctor-repro-'));
try {
  await writeFile(path.join(root, 'package.json'), '{"type":"module"}');
  await cp('dist', path.join(root, 'tools/loop/dist'), { recursive: true });
  const project = path.join(root, 'project');
  await mkdir(project);
  for (const [file, text] of Object.entries({
    'STATE.md': '# State\n',
    'LOOP.md': '# Loop\nUpdate STATE.md\n',
    'loop-budget.md': 'Max tokens/day: 100000\n',
    'loop-run-log.md': '# Runs\n',
  })) await writeFile(path.join(project, file), text);
  const children = {
    audit: 'console.error("simulated audit failure"); process.exitCode = 1;',
    sync: 'console.log(JSON.stringify({score:100,level:"healthy",issues:[],suggestions:[]}));',
  };
  for (const [tool, body] of Object.entries(children)) {
    const entry = path.join(root, `tools/loop-${tool}/dist/cli.js`);
    await mkdir(path.dirname(entry), { recursive: true });
    await writeFile(entry, body);
  }
  const result = spawnSync(process.execPath,
    [path.join(root, 'tools/loop/dist/cli.js'), 'doctor', project, '--json'],
    { encoding: 'utf8' });
  const report = JSON.parse(result.stdout);
  console.log(JSON.stringify({exit:result.status,severity:report.severity,
    auditScore:report.ready.score,notes:report.notes}, null, 2));
} finally {
  await rm(root, { recursive: true, force: true });
}
JS

Expected behavior

An unavailable check or unusable report must not produce healthy / exit 0. Proposed behavior: blocked / exit 2, with the failed check identified in notes and next actions.

Valid low-score audit and warning/critical sync reports should retain their existing severity. Their documented nonzero child exit codes are results, not execution failures.

Actual behavior

{
  "exit": 0,
  "severity": "healthy",
  "auditScore": null,
  "notes": ["loop-audit failed: simulated audit failure"]
}

The same false healthy result was reproduced with a failed sync child and malformed report output. This is a health-check reliability defect demonstrated with controlled local child processes, not a claim about attacker-controlled policy bypasses.

Environment

macOS; Node 24.21.0; npm 11.19.0; @cobusgreyling/loop 0.2.0; source commit above. No model calls or service credentials are needed for the reproduction.

shixi-li avatar Nov 11 '26 03:11 shixi-li