Skip to content

fix: redirect LCM diagnostic log output to stderr#283

Merged
jalehman merged 2 commits intoMartian-Engineering:mainfrom
mvanhorn:fix/165-log-stdout-contamination
Apr 6, 2026
Merged

fix: redirect LCM diagnostic log output to stderr#283
jalehman merged 2 commits intoMartian-Engineering:mainfrom
mvanhorn:fix/165-log-stdout-contamination

Conversation

@mvanhorn
Copy link
Copy Markdown
Contributor

@mvanhorn mvanhorn commented Apr 6, 2026

Summary

Route all deps.log calls through console.error() instead of api.logger.info/warn/error. The host application writes api.logger.info() to stdout, so when the host runs with --json, LCM's [lcm] diagnostic lines contaminate the JSON output and break JSON.parse() in downstream consumers like ClawKitchen's agents page.

Changes

  • src/plugin/index.ts: Changed log wiring in createLcmDependencies() from api.logger.* to console.error() for all log levels (info, warn, error, debug)
  • test/plugin-config-registration.test.ts: Updated test assertions to spy on console.error for [lcm] messages that now route through stderr

console.error() writes to fd 2 (stderr) regardless of what the host logger does, so LCM diagnostic output can never contaminate stdout JSON.

Testing

All 17 tests in plugin-config-registration.test.ts pass. The migration log messages now correctly appear in stderr (visible as stderr | prefix in vitest output).

Fixes #165

This contribution was developed with AI assistance (Codex).

@rjdjohnston
Copy link
Copy Markdown
Contributor

bummer, won't get contrib credit. at least its done.

Route all deps.log calls through console.error() instead of api.logger.*
so that [lcm] diagnostic lines never contaminate stdout JSON output.

Fixes Martian-Engineering#165

Co-authored-by: RJ Johnston <293686+rjdjohnston@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mvanhorn mvanhorn force-pushed the fix/165-log-stdout-contamination branch from 816101f to fe701bc Compare April 6, 2026 05:12
@mvanhorn
Copy link
Copy Markdown
Contributor Author

mvanhorn commented Apr 6, 2026

Hey @rjdjohnston, totally fair. Your issue report nailed the root cause and your PR #166 paved the way for this fix. I've added a Co-authored-by trailer to the commit to make sure you get credit. Thanks for the thorough diagnosis.

@jalehman
Copy link
Copy Markdown
Contributor

jalehman commented Apr 6, 2026

Thanks to both of you!

@jalehman jalehman merged commit 6e2e722 into Martian-Engineering:main Apr 6, 2026
1 check passed
pull bot pushed a commit to gerrampard/lossless-claw that referenced this pull request Apr 6, 2026
…g#283)

* fix: redirect LCM diagnostic log output to stderr

Route all deps.log calls through console.error() instead of api.logger.*
so that [lcm] diagnostic lines never contaminate stdout JSON output.

Fixes Martian-Engineering#165

Co-authored-by: RJ Johnston <293686+rjdjohnston@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: keep LCM diagnostics on stderr

---------

Co-authored-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
Co-authored-by: RJ Johnston <293686+rjdjohnston@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Josh Lehman <josh@martian.engineering>
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.

Title: LCM log output contaminates --json CLI stdout, breaking downstream JSON consumers

3 participants