Skip to content

fix: keep word spacing in minified descriptions - #864

Merged
inanna-apollo merged 1 commit into
mainfrom
fix/minify-description-whitespace
Oct 5, 2026
Merged

inanna-apollo merged 1 commit into
mainfrom
fix/minify-description-whitespace

Conversation

@inanna-apollo

Copy link
Copy Markdown
Contributor

Problem

normalize_description in introspection/minify.rs deleted every whitespace run, so minified introspect and search output ran descriptions together:

"Therichtextconvertedtoplaintext(nonwiki),takingthefieldrendererintoaccount."

That is hard to read for people and models alike, and descriptions are often where schemas put essential usage information. For example, Atlassian's beta fields document the @optIn(to: "...") directive they require only in their description. Merging words also changes how models tokenize them, so the token savings are smaller than they look.

Found while running Apollo MCP Server against the Atlassian GraphQL gateway schema.

Fix

Each whitespace run collapses to a single space, and leading and trailing whitespace is trimmed. This covers type, field, argument and input field descriptions, and @deprecated reasons.

Against the Atlassian schema, introspect JiraRichText now returns:

T:"Represents the rich text format of a rich text field."JiraRichText:"Text in Atlassian Document Format."adfValue:JiraADF,...

Tests

  • Updated the minify_schema snapshot. It's the only snapshot that changes.
  • Added normalize_description_collapses_whitespace_runs, which covers tabs, CRLF, runs of spaces, and leading and trailing whitespace.
  • Added deprecation_reason_is_normalized, which uses a multi-line block-string description and @deprecated reason.
  • cargo fmt, cargo clippy --all-targets -- --deny warnings and cargo test -p apollo-mcp-server pass.

Not in scope

Minified descriptions are wrapped in "..." without escaping, so a description that contains " can't be read unambiguously. That was already true before this change. Fixing it would change the output format, so it's left for a separate change.

@apollo-librarian

apollo-librarian Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

✅ Docs preview has no changes

The preview was not built because there were no changes.

Build ID: cda16b523594a5988347f4f4
Build Logs: View logs


✅ AI Style Review — No Changes Detected

No MDX files were changed in this pull request.

Review Log: View detailed log

This review is AI-generated. Please use common sense when accepting these suggestions, as they may not always be accurate or appropriate for your specific context.

@coderabbitai

coderabbitai Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 27 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: daf37967-cc65-4f19-a0e3-5b493f4e87d9

📥 Commits

Reviewing files that changed from the base of the PR and between 8f176dc and 8c734da.

⛔ Files ignored due to path filters (1)
  • crates/apollo-mcp-server/src/introspection/snapshots/apollo_mcp_server__introspection__minify__tests__minify_schema.snap is excluded by !**/*.snap
📒 Files selected for processing (2)
  • .changeset/minify_description_whitespace.md
  • crates/apollo-mcp-server/src/introspection/minify.rs
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@inanna-apollo
inanna-apollo marked this pull request as ready for review October 1, 2026 21:49
@inanna-apollo
inanna-apollo requested a review from a team as a code owner October 1, 2026 21:49
@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

✅ Changeset file added - thank you!

@claude

claude Bot commented Oct 1, 2026

Copy link
Copy Markdown

Review Summary

Overall: normalize_description now collapses each whitespace run to a single space and trims the ends, instead of deleting all whitespace. Minified introspect and search descriptions stay readable and compact.

Findings: None blocking. The desc.trim() call before replace_all is correct. The regex is built once through OnceLock. Cow::into_owned avoids the extra to_string copy.

Test coverage: Good. The new unit test covers tabs, CRLF, space runs, and leading and trailing whitespace. The second test covers block-string descriptions and @deprecated reasons end to end. The snapshot update matches the intended change. The changeset is present.

Recommendation: Approve


Reviewed by Claude Code Sonnet 5.5

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM. Straightforward, well-tested fix: normalize_description now trims and collapses whitespace runs to a single space instead of deleting all whitespace, with the snapshot and changeset updated to match, and two new unit tests covering whitespace-run collapsing and @ deprecated reason normalization.

What was reviewed: the regex/trim logic in normalize_description (crates/apollo-mcp-server/src/introspection/minify.rs), the updated minify_schema.snap fixture for correct spacing, the new unit tests for tabs/CRLF/multi-space runs and deprecated-reason normalization, and the changeset entry describing the patch-level fix.

Extended reasoning...

The diff is confined to one small function (normalize_description) plus its tests, a snapshot fixture, and a changeset file — no security-sensitive surface (no auth, crypto, injection, or data exposure concerns). The fix correctly replaces desc.trim() + regex collapse-to-single-space logic in place of the old strip-all-whitespace behavior, matches the PR description exactly, and is backed by new targeted unit tests plus an updated snapshot that visibly demonstrates the corrected output. No outstanding objections appear in the timeline (only automated bot comments after the fix commit), and the change is small, mechanical, and self-contained with clear intent.

@DaleSeo DaleSeo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for finding and fixing this, @inanna-apollo!

Comment on lines 248 to 256
/// Normalize description formatting
#[allow(clippy::expect_used)]
fn normalize_description(desc: &str) -> String {
// LLMs can typically process descriptions just fine without whitespace
// Each whitespace run collapses to a single space, and leading and trailing whitespace is
// removed, so descriptions stay on one line while words remain separated.
static WHITESPACE_PATTERN: OnceLock<Regex> = OnceLock::new();
let re = WHITESPACE_PATTERN.get_or_init(|| Regex::new(r"\s+").expect("regex pattern compiles"));
re.replace_all(desc, "").to_string()
re.replace_all(desc.trim(), " ").into_owned()
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wonder if the standard library can do this without using a regex.

@inanna-apollo
inanna-apollo merged commit ea36847 into main Oct 5, 2026
23 checks passed
@inanna-apollo
inanna-apollo deleted the fix/minify-description-whitespace branch October 5, 2026 18:42
@DaleSeo DaleSeo mentioned this pull request Oct 5, 2026
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.

2 participants