Skip to content

mcpx: shared 100-value completion cap on both daemon /v1/complete paths (#2878) - #3505

Merged
dezren39 merged 2 commits into
mainfrom
queue/5456-2878-completion-cap
Nov 1, 2026
Merged

dezren39 merged 2 commits into
mainfrom
queue/5456-2878-completion-cap

Conversation

@dezren39

@dezren39 dezren39 commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Fixes #2878.

Problem

The daemon /v1/complete surface never applied the MCP 100-value completion cap, while the MCP surface clamped the same setting (triage task 4061, CONFIRMED on main; register CMP-06):

  • Local fallback: truncated only to the raw completion.maxValues — setting 250 returned up to 250 values; setting 0 (including the unset default, since the settings Int() is a bare Atoi) disabled truncation entirely.
  • Upstream passthrough: the server's completion payload was forwarded verbatim.

Fix (pinned by triage)

One shared computation in internal/settings: SpecCompletionCap = 100 and EffectiveCompletionCap(n) — a setting in [1,100] lowers the cap; unset/zero/negative/over-cap resolves to 100.

  • Daemon local path passes settings.EffectiveCompletionCap(cs.Int("completion.maxValues")) into localCompletion (total/hasMore still report the full ranked count).
  • Daemon upstream path runs the payload through the new capUpstreamCompletion: truncates values to the cap, keeps the upstream total, recomputes hasMore; undecodable payloads pass through byte-identical.
  • internal/mcpserver routes its existing clamp through the same helper and drops its private specMaxCompletions constant, so the surfaces cannot drift again.

Tests

  • New internal/daemon/completion_cap_test.go: cap table (250/101/100/99/50/1/0/-5), local path over 150 candidates for settings 250/0/-1/100/50, upstream truncation to 100 with total 150/hasMore true, under-cap and undecodable payloads unchanged.
  • go test ./internal/daemon/ full package: ok. go test ./internal/mcpserver/: ok. internal/settings: 4 failures byte-identical to clean main (pre-existing: compendium/env/effect-probe registry tests), no new failures.

Queue task 5456 (repo-health-code-pilot), Lane D.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

…hs (#2878)

The daemon applied no spec cap: local fallback truncated only to the raw completion.maxValues (250 returned 250; 0/unset was unlimited), and upstream replies passed through verbatim, while the MCP surface clamped to 100. Adds settings.SpecCompletionCap + settings.EffectiveCompletionCap (setting in [1,100] lowers, anything else resolves to 100) used by the daemon local path, a new capUpstreamCompletion on the passthrough path, and the mcpserver clamp, so the surfaces share one computation. Daemon regression tests cover the cap table, local settings 250/0/-1/100/50 over 150 candidates, and upstream truncation/passthrough.
@dezren39
dezren39 requested a review from a team as a code owner November 1, 2026 10:39
@coderabbitai

coderabbitai Bot commented Nov 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 3 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 04fd28aa-677a-4b29-811b-f72236bbf1cf
Commits

Reviewing files that changed from the base of the PR and between 9f48e29 and 6cba232.

Files selected for processing: 8
  • pkgs/mcpx/internal/cli/serve.go
  • pkgs/mcpx/internal/cli/serve_ask_raw_test.go
  • pkgs/mcpx/internal/daemon/completion_cap_test.go
  • pkgs/mcpx/internal/daemon/ops.go
  • pkgs/mcpx/internal/mcpserver/server.go
  • pkgs/mcpx/internal/mcpserver/server_test.go
  • pkgs/mcpx/internal/mcpserver/wp11_test.go
  • pkgs/mcpx/internal/settings/completion_cap.go
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-01T10:55:11.498376Z 6cba232 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cadd8f5823

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +386 to +387
payload = capUpstreamCompletion(payload,
settings.EffectiveCompletionCap(cs.Int("completion.maxValues")))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve completion metadata through the MCP backend

When an upstream returns more values than the configured cap (for example, 100 matches with completion.maxValues=50), truncating here causes the MCP surface to incorrectly report total: 50 and hasMore: false. In internal/cli/serve.go, mcpBackend.Complete extracts only completion.values, discarding the daemon's preserved total and hasMore; internal/mcpserver/server.go then recomputes both from that already-truncated slice. Previously, the upstream values reached the MCP server before truncation, so it correctly reported total: 100 and hasMore: true. Preserve the metadata through the backend interface so MCP clients can still detect additional matches.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in 6cba232 — thank you, the regression was real.

The Backend.Complete contract now returns mcpserver.Completion{Values, Total, TotalKnown} instead of just []string. mcpBackend.Complete (internal/cli/serve.go) carries the daemon reply's total through, and the MCP surface (internal/mcpserver/server.go complete()) uses the backend's total when known — still applying its own cap to the values page — falling back to len(values) only for backends that report no count.

So the cited case now reports correctly end to end: upstream 100 matches with completion.maxValues=50 → daemon returns 50 values with total: 100, hasMore: true → MCP surface reports total: 100, hasMore: true (and with a lower MCP-side cap of 10: 10 values, total: 100, hasMore: true).

Regression coverage: TestCompletionPreservesTheBackendsTotal (internal/mcpserver/wp11_test.go) drives a backend page of 50 values with total 150 through the full completion/complete handler at the default cap and at cap 10. Full internal/mcpserver, internal/cli, and internal/daemon test packages pass on the laptop.

… P2 on #3505)

The daemon now caps /v1/complete replies, so mcpBackend.Complete forwarding only values made the MCP surface recompute total/hasMore from the already-capped slice (total=50, hasMore=false for a 150-match set capped at 50). The Backend.Complete contract now returns mcpserver.Completion{Values, Total, TotalKnown}: the CLI backend carries the daemon-reported total, and the MCP surface uses it when known (falling back to len(values) for direct answers), still applying its own cap to the values page. Regression test: a backend page of 50 with total 150 reports total=150/hasMore=true at caps 100 and 10.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant