Skip to content

fix(mcp): detect CommonMark fences in the context compressor - #300

Open
haroon0x wants to merge 1 commit into
kubeflow:mainfrom
haroon0x:fix/compressor-fence-info-string
Open

haroon0x wants to merge 1 commit into
kubeflow:mainfrom
haroon0x:fix/compressor-fence-info-string

Conversation

@haroon0x

@haroon0x haroon0x commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #299.

CODE_BLOCK_RE only matched a fence when the language started right after the backticks. A valid CommonMark fence with a space, like ``` yaml, fell through to the prose path, so _logical_lines() merged its lines into one and the YAML reached the LLM flattened.

This replaces the single regex with a small line-based fence scanner that:

  • accepts 3 or more backticks or tildes, with optional indentation
  • keeps the info string, including one separated by spaces
  • requires a matching closing fence with at least the same length
  • recognizes ~~~ in the join check as well

Verified locally: ``` yaml, ~~~yaml and four-backtick fences now keep their newlines, and tight fences are unchanged. Existing compressor tests pass (10 passed). Full suite: 160 passed, 69 skipped.

This PR does not add tests.

Signed-off-by: haroon0x <haroonbmc0@gmail.com>
@google-oss-prow
google-oss-prow Bot requested a review from chasecadet November 18, 2026 16:16
@google-oss-prow

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign chasecadet for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kmr-rohit

Copy link
Copy Markdown
Contributor

@tarekabouzeid @SanthoshToorpu could one of you add /ok-to-test so CI runs here? This changes answers without a re-ingest, so it will also need /eval once reviewed. I'll follow up with a review.

@SanthoshToorpu

Copy link
Copy Markdown
Contributor

/ok-to-test

@SanthoshToorpu

Copy link
Copy Markdown
Contributor

/eval

@google-oss-prow

Copy link
Copy Markdown

@SanthoshToorpu: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

Details

In response to this:

/ok-to-test

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@github-actions github-actions Bot added eval-sha:160c5edd2180293c6ccb3850b9a0e6f3aabb0997 Commit under /eval for #300 eval Pre-merge eval running (/eval) labels Nov 26, 2026
@github-actions

Copy link
Copy Markdown

Eval of 160c5edd requested by @SanthoshToorpu. Argo CD deploys it to the preview within a few minutes; the comparison with main is posted here when the run finishes (usually 10–20 minutes).

@kmr-rohit

Copy link
Copy Markdown
Contributor

Flo eval for 160c5edd could not run

preview docs-agent-preview not ready after 1200s: kubeflow-debug-agent is still rolling out

@kmr-rohit

Copy link
Copy Markdown
Contributor

Flo eval: #300 at 160c5edd vs main at f953a62

main this PR Δ
Tool routing 1.00 1.00 0
Query fidelity 1.00 1.00 0
Grounded (judge) 0.84 0.87 +0.03
Answers the question (judge) 0.89 0.94 +0.05
Errors 0 0 0
Latency p50 (s) 2.35 2.22 -0.13
Latency p95 (s) 6.88 6.75 -0.13

Gates (routing ≥ 0.85, grounded ≥ 0.65, no errors): ✅ pass

2 case(s) got worse, 4 got better out of 58. One case moves a rate by 0.02, and the model and judge vary a little between runs, so a single changed case is weak evidence; look at what changed in its trace.

Got worse (2)
case main this PR judge on this PR
docs-kserve-isvc routing ok, grounded yes routing ok, grounded partial The answer correctly identifies what a KServe InferenceService is and mentions its relation to the Model Registry and the Models Web App, but does not provide t trace
docs-katib-trial-limits routing ok, grounded yes routing ok, grounded partial The answer addresses the question but does not directly state where to set resource limits, which is implied rather than explicitly stated. trace
Got better (4)
case main this PR judge on this PR
docs-install-1.10 routing ok, grounded partial routing ok, grounded yes The answer correctly states that no specific installation instructions were found for Kubeflow 1.10, which aligns with the provided search results. trace
docs-model-registry routing ok, grounded partial routing ok, grounded yes The answer accurately summarizes the information provided about installing and checking the Kubeflow Model Registry. trace
fid-kfp-v1-v2 routing ok, grounded partial routing ok, grounded yes The answer accurately summarizes the key differences and recommendations from the provided text. trace
dbg-containerop routing ok, grounded – routing ok, grounded yes The answer references the correct issue and provides relevant guidance on diagnosing the problem. trace
All cases (58)
case main this PR traces
docs-katib-config routing ok, grounded yes routing ok, grounded yes main · this PR
docs-install-1.10 routing ok, grounded partial routing ok, grounded yes main · this PR
docs-k8s-support-1.9 routing ok, grounded yes routing ok, grounded yes main · this PR
docs-kfp-v2-component routing ok, grounded yes routing ok, grounded yes main · this PR
docs-kfp-compile routing ok, grounded yes routing ok, grounded yes main · this PR
docs-notebook-pvc routing ok, grounded yes routing ok, grounded yes main · this PR
docs-kserve-isvc routing ok, grounded yes routing ok, grounded partial main · this PR
docs-trainer-elastic routing ok, grounded partial routing ok, grounded partial main · this PR
docs-istio-katib-lower routing ok, grounded yes routing ok, grounded yes main · this PR
docs-kfp-2.4-new routing ok, grounded yes routing ok, grounded yes main · this PR
docs-model-registry routing ok, grounded partial routing ok, grounded yes main · this PR
docs-terse-compile routing ok, grounded yes routing ok, grounded yes main · this PR
docs-katib-trial-limits routing ok, grounded yes routing ok, grounded partial main · this PR
docs-kfp-caching routing ok, grounded yes routing ok, grounded yes main · this PR
docs-notebook-default-size routing ok, grounded yes routing ok, grounded yes main · this PR
fid-latest-release routing ok, grounded yes routing ok, grounded yes main · this PR
fid-current-kfp routing ok, grounded yes routing ok, grounded yes main · this PR
fid-1.8-parallel routing ok, grounded yes routing ok, grounded yes main · this PR
fid-kserve-0.13-raw routing ok, grounded partial routing ok, grounded partial main · this PR
fid-istio-annotation routing ok, grounded yes routing ok, grounded yes main · this PR
fid-parallelfor-v2 routing ok, grounded yes routing ok, grounded yes main · this PR
fid-kfp-v1-v2 routing ok, grounded partial routing ok, grounded yes main · this PR
fid-profile-kind-error routing ok, grounded yes routing ok, grounded yes main · this PR
fid-oom-2.4.1 routing ok, grounded yes routing ok, grounded yes main · this PR
fid-katib-0.17-hyperband routing ok, grounded yes routing ok, grounded yes main · this PR
iss-deploymentmode routing ok, grounded yes routing ok, grounded yes main · this PR
iss-rpc-unavailable routing ok, grounded yes routing ok, grounded yes main · this PR
iss-ui-crashloop routing ok, grounded yes routing ok, grounded yes main · this PR
iss-modulenotfound routing ok, grounded yes routing ok, grounded yes main · this PR
iss-notebook-403 routing ok, grounded yes routing ok, grounded yes main · this PR
iss-katib-pending routing ok, grounded yes routing ok, grounded yes main · this PR
iss-kustomize-accum routing ok, grounded yes routing ok, grounded yes main · this PR
iss-istio-503 routing ok, grounded yes routing ok, grounded yes main · this PR
iss-trainjob-created routing ok, grounded yes routing ok, grounded yes main · this PR
iss-imagepull-kserve routing ok, grounded yes routing ok, grounded yes main · this PR
none-hi routing ok, grounded – routing ok, grounded – main · this PR
none-thanks routing ok, grounded – routing ok, grounded – main · this PR
none-yo routing ok, grounded – routing ok, grounded – main · this PR
none-bye routing ok, grounded – routing ok, grounded – main · this PR
none-morning routing ok, grounded – routing ok, grounded – main · this PR
none-okcool routing ok, grounded – routing ok, grounded – main · this PR
none-hello-there routing ok, grounded – routing ok, grounded – main · this PR
none-ssup routing ok, grounded – routing ok, grounded – main · this PR
none-france routing ok, grounded – routing ok, grounded – main · this PR
none-poem routing ok, grounded – routing ok, grounded – main · this PR
none-prompt-leak routing ok, grounded – routing ok, grounded – main · this PR
none-who-are-you routing ok, grounded – routing ok, grounded – main · this PR
multi-greeting-plus-q routing ok, grounded partial routing ok, grounded partial main · this PR
dbg-katib-yaml routing ok, grounded yes routing ok, grounded yes main · this PR
dbg-isvc-manifest routing ok, grounded yes routing ok, grounded yes main · this PR
dbg-deploymentmode routing ok, grounded yes routing ok, grounded yes main · this PR
dbg-containerop routing ok, grounded – routing ok, grounded yes main · this PR
dbg-suggestion-resources routing ok, grounded yes routing ok, grounded yes main · this PR
dbg-ml-pipeline-namespace routing ok, grounded yes routing ok, grounded yes main · this PR
dbg-notebook-watch routing ok, grounded yes routing ok, grounded yes main · this PR
dbg-katib-clusterrole routing ok, grounded yes routing ok, grounded yes main · this PR
dbg-external-mysql routing ok, grounded partial routing ok, grounded partial main · this PR
dbg-certificate-kind routing ok, grounded yes routing ok, grounded yes main · this PR

Each trace link opens without a login and shows the agent's tool calls, the retrieved text and the answer. both runs in Langfuse (experiments pr-300 main f953a62 pr-309 @kmr-rohit 20261126-160549 and pr-300 160c5ed @haroon0x 20261126-160705) (maintainer login).

Same model, index and judge for both runs; the dataset and this script come from main. Commits pushed after /eval are not included; a maintainer can run /eval again.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

eval Pre-merge eval running (/eval) eval-sha:160c5edd2180293c6ccb3850b9a0e6f3aabb0997 Commit under /eval for #300 size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(mcp): compressor flattens YAML fences that have a space before the language

3 participants