Skip to content

feat(mcpx): sampling.answerLocally — answer upstream sampling from the configured provider layer (#1925 slice 3) - #4947

Merged
dezren39 merged 1 commit into
mainfrom
queue/8019-1925-sampling-answer-locally
Nov 3, 2026
Merged

dezren39 merged 1 commit into
mainfrom
queue/8019-1925-sampling-answer-locally

Conversation

@dezren39

@dezren39 dezren39 commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

What

Slice 3 of #1925: sampling.answerLocally — when enabled, mcpx answers an upstream server's sampling/createMessage request from its own configured provider layer instead of relaying it through the broker to a caller that (per #1925) never declares the sampling capability.

Queue task 8019. Slices 1–2 are landed: slice 1 PR #2592 (internal/model provider layer + model.* settings), slice 2 PR #4836 (provider-keyed model.providers, named ordered model.profiles, cross-provider fallback in internal/model Resolve).

Changes

  • internal/settings: new daemon setting sampling.answerLocally (bool, default false) in the one settings registry; docs/configuration.md regenerated; effect-coverage exemption added with the same model-layer rationale as model.*, and EffectExemptionPin deliberately raised 201 → 202 with the reason recorded here and in the pin comment.
  • internal/daemon: ConsumerPolicy.SamplingAnswerLocally populated from the set; Registry.answerServer diverts sampling/createMessage to the new sampleLocally when the setting is on (before the broker check — a local answer needs no broker). Default off: the relay path is byte-for-byte unchanged.
  • internal/daemon/sampling_local.go: the local answer path.
    • Validates the request against the negotiated era exactly like the broker path (elicit.ValidateSampleRequest, -32602 on shape errors), and validates its own answer with elicit.ValidateSampleResult.
    • Resolves the provider via internal/model.Resolve over the model.* policy with Sampler deliberately nil — resolving the sampling backend here would relay to the caller, the path this setting replaces; a sampling-only configuration therefore resolves to unavailable, honestly.
    • Bounds: the request's maxTokens capped by model.budget (modelMaxTokens), model.timeout as the Generate deadline.
    • Enabled with no provider configured, an unresolvable provider, or a whole chain that cannot answer → a clean deterministic internal error naming the cause. No broker fallback, no hang, no invented answer.
    • The model layer is text-only, so a request carrying tools or non-text content blocks fails as invalid params for this path instead of being silently flattened. modelPreferences hints name the model when given; otherwise model.default applies through Resolve/Generate.

Tests

New internal/daemon/sampling_local_test.go:

  • End-to-end local answer through a configured OpenAI-compatible provider (httptest): result shape, model id (default, prefix stripped), system prompt + message forwarding.
  • Enabled + no provider → the clean no-provider failure.
  • Enabled + model.provider=sampling only → clean failure, never a silent relay.
  • Setting off → the pre-existing no-broker relay behaviour is unchanged.
  • Conversion: preference hint wins, model.budget caps maxTokens, tools / non-text blocks are refused.

Verified on the laptop worktree: go test ./internal/daemon/ -run 'TestSample|TestSampling|TestConsumer|TestHook|TestElicit' passes; go vet ./internal/daemon/ ./internal/settings/ passes; internal/model passes.

Pre-existing failures, verified on clean main (not this PR): internal/settings fails on main in TestEveryDocumentHasAChapter, TestNoUndeclaredEnvRead (MCPX_ADAPTER_DECLARATION_SHA256), TestEverySettingHasAnEffectProbeOrAnExemption (proto.* / script.* entries only, after this PR's exemption), TestTheScriptEnvironmentIsWhatTheCodeSets, and TestTheEnvironmentDocIsCurrent (the generated table's padding differs). This PR deliberately does not regenerate docs/environment.md — that churn is unrelated to this change.

Out of scope


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

@dezren39
dezren39 requested a review from a team as a code owner November 3, 2026 14:08
@chatgpt-codex-connector

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 ⚠️ Failed 2026-11-03T14:08:11.706057Z
We couldn’t complete this review. Comment @codex review to try again.
4ced4c8 PR opened
ℹ️ 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.

@coderabbitai

coderabbitai Bot commented Nov 3, 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 53 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: 30b40c99-9d1f-48f5-bf3b-ee9ec912e248
Commits

Reviewing files that changed from the base of the PR and between a8dbda7 and 4ced4c8.

Files selected for processing: 7
  • pkgs/mcpx/docs/configuration.md
  • pkgs/mcpx/internal/daemon/consumer.go
  • pkgs/mcpx/internal/daemon/hooks.go
  • pkgs/mcpx/internal/daemon/sampling_local.go
  • pkgs/mcpx/internal/daemon/sampling_local_test.go
  • pkgs/mcpx/internal/settings/effect.go
  • pkgs/mcpx/internal/settings/model.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

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@dezren39

dezren39 commented Nov 3, 2026

Copy link
Copy Markdown
Member Author

🤖 Agent note · done

Codex findings disposition (merge gate): the Codex code review on head 4ced4c81 did not complete — it failed with "You have reached your Codex usage limits for code reviews" (2026-11-03T14:08Z). It produced no findings (no inline review comments, no review body); the summary's unresolved flag reflects the failed run, not an open code finding. There is nothing to fix or rebut; the blocker is an external usage limit, not this change. Proceeding under the standing merge criteria: checks present are green (production line limit pass; CodeRabbit neutral), targeted tests verified on the laptop (go test ./internal/daemon/ -run 'TestSample|TestSampling|TestConsumer|TestHook|TestElicit', go vet, internal/model — per PR body), and the internal/settings failures are the pre-existing clean-main set verified independently on 2026-11-03.

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.

1 participant