Skip to content

fix: keep MCP stdio clean on routine update errors - #330

Merged
chrisdoc merged 1 commit into
mainfrom
charlie/fix-issue-327-stdio-update-routine
Jun 1, 2026
Merged

fix: keep MCP stdio clean on routine update errors#330
chrisdoc merged 1 commit into
mainfrom
charlie/fix-issue-327-stdio-update-routine

Conversation

@charliecreates

@charliecreates charliecreates Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor
  • Route Axios/tool error diagnostics to stderr only (no stdout debug line)
  • Omit rep_range from update-routine payload when range is not valid/present
  • Add regression tests for both behaviors

Resolves #327

✨ PR Description

Purpose: Fix MCP stdio cleanliness by conditionally including rep_range and consolidating error logging to prevent debug output pollution.

Main changes:

  • Conditionally include rep_range in set payload only when repRange contains valid values using spread operator
  • Consolidate error logging from separate debug and error calls into single console.error with formatted error code suffix
  • Update tests to verify rep_range omission when empty and error code inclusion in single console.error call

Generated by LinearB AI and added by gitStream.
AI-generated content may contain inaccuracies. Please verify before using.
💡 Tip: You can customize your AI Description using Guidelines Learn how

@gitstream-cm gitstream-cm Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✨ PR Review

LGTM

Generated by LinearB AI and added by gitStream.
AI-generated content may contain inaccuracies. Please verify before using.
💡 Tip: You can customize your AI Review using Guidelines Learn how

@sentry

sentry Bot commented Jun 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.03%. Comparing base (f19f494) to head (d972515).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #330      +/-   ##
==========================================
+ Coverage   69.34%   70.03%   +0.68%     
==========================================
  Files          15       15              
  Lines         584      584              
  Branches      197      198       +1     
==========================================
+ Hits          405      409       +4     
+ Misses        101      100       -1     
+ Partials       78       75       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@greptile-apps

greptile-apps Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes two sources of stdout pollution in the MCP stdio server: a stray console.debug call in the error handler (which Node.js routes to stdout) and a rep_range: null field sent in routine-update payloads when no range is set. Both are tightly scoped one-line fixes backed by new regression tests.

  • error-handler.ts: Removes the separate console.debug for error codes and appends the code as , Code: … in the existing console.error call, keeping all diagnostic output on stderr.
  • routines.ts: Replaces the unconditional rep_range: repRange assignment with a conditional spread (...(repRange ? { rep_range: repRange } : {})), so the field is absent from the payload when buildRepRange returns null.
  • Tests: Adds a regression test for the rep_range-omission case and updates the error-handler test to assert the new console.debug-free, code-in-stderr behavior.

Confidence Score: 5/5

Safe to merge — both changes are tightly scoped, directly address the reported issue, and are covered by new regression tests.

The error-handler change is a straightforward log-channel consolidation with no behavioral impact on the returned MCP response. The routines change removes a null field from an outgoing API payload, which matches the API's expected contract and is validated end-to-end in the new test. No logic paths, auth boundaries, or data-persistence flows are affected beyond what is explicitly tested.

No files require special attention.

Important Files Changed

Filename Overview
src/utils/error-handler.ts Removes standalone console.debug call for error codes; merges the code into the existing console.error message as a , Code: … suffix — ensuring all error diagnostics go only to stderr.
src/tools/routines.ts Switches rep_range: repRange to a conditional spread so rep_range is omitted entirely from the API payload when buildRepRange returns null, preventing null fields from reaching the Hevy API.
src/utils/error-handler.test.ts Updates the error-code test to assert console.debug is never called and console.error now carries the code suffix; matches the new implementation exactly.
src/tools/routines.test.ts Adds a regression test that sends repRange: { start: null, end: null } and asserts rep_range is absent from the update payload; removes the stale rep_range: null assertion from the existing no-range test.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[MCP Tool Call] --> B{withErrorHandling}
    B -->|success| C[Return tool response]
    B -->|throws| D[createErrorResponse]
    D --> E{Extract errorCode?}
    E -->|yes| F["console.error(msg + Type + Code, err) → stderr"]
    E -->|no| G["console.error(msg + Type, err) → stderr"]
    F --> H[Return isError MCP response to stdout]
    G --> H

    subgraph routines_ts ["routines.ts: update-routine set mapping"]
    I[set.repRange input] --> J[buildRepRange]
    J -->|both null/undefined| K["returns null → rep_range OMITTED from payload"]
    J -->|at least one value| L["returns {start,end} → rep_range included in payload"]
    end
Loading

Reviews (1): Last reviewed commit: "fix: keep MCP stdio clean on routine upd..." | Re-trigger Greptile

@chrisdoc
chrisdoc merged commit 540c5eb into main Jun 1, 2026
18 checks passed
github-actions Bot pushed a commit that referenced this pull request Jun 1, 2026
## [1.23.14](v1.23.13...v1.23.14) (2026-06-01)

### Bug Fixes

* keep MCP stdio clean on routine update errors ([#330](#330)) ([540c5eb](540c5eb))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: update-routine crashes the MCP server and corrupts JSON-RPC stream

2 participants