Repository navigation
fix(mcp,openrouter): enforce the filtered MCP child env and report content-filter 403s accurately - #1354
fix(mcp,openrouter): enforce the filtered MCP child env and report content-filter 403s accurately#1354ianalitis wants to merge 3 commits into
Conversation
|
|
Rebased onto |
0dcd875 to
07db086
Compare
This comment has been minimized.
This comment has been minimized.
|
The red checks on this PR are not from the change: every failing job (Build & Test on all three OSes, Quality Guardrails, Windows Cross-Target Check) stops at the Configure SSH for cargo git dependencies step before compiling, because repository secrets are not exposed to workflows on fork PRs. Format, TypeScript SDK and the other secret-free jobs pass. Locally on macOS, |
07db086 to
cea3daa
Compare
|
@greptile review |
cea3daa to
4734772
Compare
Ratchet and red-CI attribution for head
|
| Gate | master 04c7d2b04 |
this branch 4ceceaa8b |
|---|---|---|
python3 scripts/check_code_size_budget.py |
45 violations, exit 1 | 44, exit 1 |
python3 scripts/check_test_size_budget.py |
10 violations, exit 1 | 10, exit 1 |
cargo fmt --all -- --check |
exit 1 (3 hunks, 2 files) | exit 0 |
Correction: this comment first said 46/45 for the code-size counts; those were off by one. The measured counts are above.
- Code-size: this branch's set is a strict subset of master's. The only file master lists and this branch does not is
crates/jcode-tui/src/tui/app/onboarding_flow_control.rs, tracked at 1766 LOC: master sits at 1767, and this branch's reflow is back under the baseline, so the script omits the file. Two files appear on both lists with different sizes:crates/jcode-base/src/auth/lifecycle.rs(branch 3098 vs master 3093, +5 for the clippy-1.99 type alias) andcrates/jcode-provider-openai-runtime/src/lib.rs(branch 1525 vs master 1526, -1). Both are already over their baselines on master, so neither adds a violation. - Test-size: the 10-file sets match. Before
4ceceaa8bthis branch had 11, because the file-local#![allow(clippy::await_holding_lock)]added by7a5e1c393pushedagent_tests.rsto 3023 against its tracked 3021. Removing it puts the file back on 3021, so it is absent from both lists: the module that declares it (agent.rs:1306,#[cfg(test)] #[path = "agent_tests.rs"] mod tests;) already carries#![cfg_attr(test, allow(clippy::await_holding_lock))]on master, lint levels are inherited by child modules, andcargo clippy -p jcode-app-core --all-targets --all-features -- -D warningsis clean without it.crates/jcode-app-core/src/tool/tests.rsis 15 LOC larger than master's on both lists (1956 vs 1941), already red either way.
So Quality Guardrails stays red on this PR for exactly the ratchets that already fail on master; this branch adds no violation and removes one. The job fails at the oversized-file step, which runs before the oversized-test step, so its log only ever shows the code-size gate.
Master reds this PR clears
| Master job | Master failure at 04c7d2b04 |
In this branch |
|---|---|---|
Format |
cargo fmt --all -- --check exit 1: jcode-provider-openai-runtime/src/lib.rs:966, onboarding_flow_control.rs:633, onboarding_flow_control.rs:874 |
branch tree is fmt-clean (whole-tree check) |
Build & Test (ubuntu-latest) |
tui::app::tests::answering_no_on_continue_prompt_lands_on_regular_session panicked at crates/jcode-tui/src/tui/app/tests/onboarding_flow.rs:660 |
7571a3e64 asserts the rendered body plus onboarding_flow_active() / onboarding_welcome_kind() == Suggestions instead of the ambient-auth accessors |
Build & Test (macos-latest) |
Warning budget exceeded: current=2 baseline=0 |
the two counted sites (use std::path::PathBuf; in state_ui_input_helpers.rs, the onboarding Suggestions site in onboarding_flow.rs) are removed/absorbed |
Build & Test (windows-latest) is green on master and on this branch.
Overlap with #1772
#1772 (fix(ci): restore the Format job on master) is the same three rustfmt hunks in the same two files. This branch already carries a fmt-clean tree and touches both files, so #1772 looks redundant once this lands. I'd rather you decide than assume: say the word and I'll close #1772 with a pointer to this PR.
Run
|
| Job | master 04c7d2b04 |
4ceceaa8b |
|---|---|---|
Build & Test (ubuntu-latest) |
failure | success |
Build & Test (macos-latest) |
failure | success |
Format |
failure | success |
Build & Test (windows-latest) |
success | success |
Quality Guardrails |
failure | failure |
Quality Guardrails is the only red, and its job log (job 113859859345) fails at the code-size step with exit 1 on the 44 files already over their tracked baselines on master (45 there; the extra one is onboarding_flow_control.rs, which this branch brings back under). Nothing here adds a violation.
Independent check of the ubuntu failure this PR targets, on the branch, locally:
scripts/dev_cargo.sh test -p jcode-tui --lib answering_no_on_continue_prompt_lands_on_regular_session
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 2498 filtered out
So the merge blocker is a guardrail that is already red on master rather than anything this branch does.
#1772 overlap, re-verified against its current headBoth PRs carry byte-identical patch bodies for the same two files: It differs for Conclusion unchanged: this PR carries #1772's rustfmt hunks unchanged, on current master, and passes Format. #1772 therefore adds nothing and would need a rebase first. Closing it is your call. |
Current master
|
Failing step on master 02ae3edc0 |
master | this branch | hunk that removes it |
|---|---|---|---|
Format -> Check formatting |
failure | success | rustfmt hunks in onboarding_flow_control.rs + jcode-provider-openai-runtime/src/lib.rs (3 diffs -> 0, on a clean git archive of 02ae3edc0) |
Quality Guardrails -> Check formatting |
failure | success | same drift |
Build & Test (ubuntu-latest) -> Run TUI library tests (Linux only) |
failure | success | tests/onboarding_flow.rs: replaces the credential-dependent assertion |
Build & Test (macos-latest) -> Enforce warning budget (Linux, macOS) |
failure | success | the two warnings this branch deletes |
Each row is the same line of code, not a coincidence.
ubuntu, job 114067723709: master fails on exactly the assertion this branch rewrites.
thread 'tui::app::tests::answering_no_on_continue_prompt_lands_on_regular_session' panicked at crates/jcode-tui/src/tui/app/tests/onboarding_flow.rs:660:9:
assertion failed: app.suggestion_prompts().is_empty() || !app.onboarding_welcome_active()
This branch replaces that line with matches!(app.onboarding_welcome_kind(), OnboardingWelcomeKind::Suggestions), because both old helpers read AuthStatus::check_fast(), which is why the test only failed on the Linux runner. Verified on this branch locally: test tui::app::tests::answering_no_on_continue_prompt_lands_on_regular_session ... ok, 1 passed; 0 failed; 2498 filtered out.
macos, job 114067723668: master's warning budget names exactly the two warnings this branch deletes.
warning: unused import: `std::path::PathBuf`
warning: variant `Suggestions` is never constructed
Warning budget exceeded: current=2 baseline=0
state_ui_input_helpers.rs drops the unused std::path::PathBuf import; onboarding_flow.rs marks the dead Suggestions variant #[allow(dead_code)].
Every guardrail budget is already red on master
Quality Guardrails on master stops at step 6 (Check formatting) and steps 7-19 come back skipped, so none of the budget steps below have ever run there. Measured locally on a clean git archive of 02ae3edc0, using master's own scripts/*_budget.json:
| budget step | master 02ae3edc0 |
02ae3edc0 + this branch |
|---|---|---|
Enforce oversized-file ratchet |
fail, 50 items | fail, 49 items |
Enforce test-file size budget |
fail | fail, identical item list |
Enforce panic-prone budget |
fail (166 -> 167) |
fail, identical |
Enforce swallowed-error budget |
fail, 11 items | fail, identical item list |
Enforce wildcard re-export budget |
pass (17) | pass (17) |
The branch changes none of these and improves one of them: onboarding_flow_control.rs is 1767 lines on master against a 1766 baseline (an item), and 1764 lines here (no item). Fixing the format step is what lets the budget steps run for the first time, which is why master's existing backlog becomes visible on this PR. Refreshing those baselines is a maintainer call; this PR deliberately does not touch any scripts/*_budget.json.
Net: this branch clears every step that fails on master today, and leaves the guardrail steps red exactly as red as master already is.
|
Head Measured on a clean
The 44 are a strict subset of master's by file ( Two of the 44 are files this PR edits, and both already regressed on master: The three ratchets behind it ( Everything else on this head passes: |
Merge-order check against #1511
Checked with One follow-up, not a blocker: |
`McpClient::connect_in_dir` built the scrubbed environment with `mcp_child_env` (issue #771: a credential must be opted into a server through its config) and then applied it with `envs()`. `envs()` adds or overrides keys; it never removes them, so the scrubbed map was layered on top of the inherited environment and every credential the filter dropped still reached the MCP child. The filter was only enforced against the map, not against the child. `env_clear()` now runs before `envs()`, so a server sees exactly the inherited non-sensitive entries plus the keys its config names. The new test asserts both directions against a real child: a credential named in the config is present with its configured value, and credentials the parent holds but the config does not name are absent. It re-executes itself as an isolated process carrying synthetic inherited secrets rather than mutating the shared test runner's global environment.
OpenRouter answers a blocked prompt with HTTP 403 and a body naming the filter:
`{"error":{"message":"Request blocked by content filter: [CREDIT_CARD]"}}`.
OpenAI-style endpoints report `code: "content_filter"` instead. Both fell
through to the generic 403 hint, so the error block told the reader to check an
API key two lines below a body that named a content filter (FU-149).
Match the body markers first, and answer with a hint that says the request text
was refused: retrying, or failing over to another lane, resends the same text,
so the fix is to change the text rather than the credential.
A 403 from a local endpoint had the same contradiction: the error block prints
`auth: local endpoint (no auth)`, and the hint blamed a hosted provider's key.
Local endpoints now get a hint that matches that line.
Tests cover the measured guardrail body, the OpenAI-style code, a plain 403 on a
hosted endpoint, and a local 403.
macos_computer_use is registered under cfg(target_os = "macos") and its
description carries the live-machine safety policy (act only on the requested
task, prefer background AX over moving the cursor). On a Mac it exceeds both
caps, so `cargo test -p jcode-app-core --lib` fails on master:
tool_descriptions_stay_under_token_cap: macos_computer_use (~159 tokens)
tool_parameter_descriptions_stay_under_token_cap:
$.properties.action (~93), $.properties.element (~28)
No CI job runs the app-core lib suite on macOS (the runner only compiles it),
so this has stayed green upstream. Each entry is load-bearing there: dropping
the description entry fails the first test, dropping either parameter entry
fails the second.
The exemption lines plus their one-line justifications are 5 LOC, so the
oversized-test baseline moves 1944 -> 1949 for
crates/jcode-app-core/src/tool/tests.rs, the documented "accept size growth
from a named change" refresh.
c9712a3 to
2a306fb
Compare
Clear inherited MCP subprocess variables before applying the filtered configuration. Distinguish content-filter refusals and unauthenticated endpoint policies from hosted API-key failures. Port of 1jehuang#1354 Upstream-PR: 1jehuang#1354 Co-authored-by: Iraklis Analitis <[email protected]>
Three commits on top of
master(a705f842d): two bug fixes and one test-environment fix. Diff is 4 files,+182 / -2.4c4fd3ec7fix(mcp): enforce the filtered subprocess environment for MCP childrenfdec1e2e5fix(openrouter): stop reporting a content-filter block as a bad API key2a306fbe3fix(test): exempt the macOS-gatedmacos_computer_usefrom the token capsThis PR previously also carried a Rust 1.98 clippy/rustfmt sweep and a ratchet refresh. Those commits are dropped:
masterfixed every one of those sites independently, andQuality Guardrails(the job that runscargo clippy --all-targets --all-features -- -D warningsonubuntu-latest,.github/workflows/ci.yml:52) is green onmasterata705f842d, 31/31 checks. Details under Scope reduction.1. MCP children inherited the credentials the filter removed
One of the findings in #771 (this PR does not close that issue; it has other findings).
McpClient::connect_in_dirbuilt the scrubbed environment withmcp_child_envand then applied it withenvs().envs()adds or overrides keys; it never removes them, so the scrubbed map was layered on top of the inherited environment and every credential the filter dropped still reached the MCP child. The filter was enforced against the map, not against the child.env_clear()now runs beforeenvs(), so a server sees exactly the inherited non-sensitive entries plus the keys its config names.connect_enforces_child_environmentasserts both directions against a real child: a credential named in the config is present with its configured value, and credentials the parent holds but the config does not name are absent. It re-executes itself as an isolated process carrying synthetic inherited secrets rather than mutating the shared test runner's global environment.2. A content-filter block was reported as a bad API key
OpenRouter answers a blocked prompt with HTTP 403 and a body naming the filter:
OpenAI-style endpoints report
code: "content_filter"instead. Both fell through to the generic 403 hint, so the error block told the reader to check an API key printed two lines below a body that named a content filter (FU-149).The body markers are now matched first, and the hint says the request text was refused: retrying, or failing over to another lane, resends the same text, so the fix is to change the text rather than the credential.
A 403 from a local endpoint had the same contradiction: the error block prints
auth: local endpoint (no auth), and the hint blamed a hosted provider's key. Local endpoints now get a hint that matches that line.Tests cover the measured guardrail body, the OpenAI-style code, a plain 403 on a hosted endpoint, and a local 403.
3.
macos_computer_usefailed the token caps on a Macmacos_computer_useis registered undercfg(target_os = "macos")and its description carries the live-machine safety policy (act only on the requested task, prefer background AX over moving the cursor). On a Mac it exceeds both caps, socargo test -p jcode-app-core --libfails onmaster:No CI job runs the app-core lib suite on macOS (the runner only compiles it), so this has stayed green upstream. Each entry is load-bearing: dropping the description entry fails the first test, dropping either parameter entry fails the second. The exemption lines plus their one-line justifications are 5 LOC, so the oversized-test baseline moves
1944 -> 1949forcrates/jcode-app-core/src/tool/tests.rs, the documented "accept size growth from a named change" refresh.Verification
macOS
aarch64-apple-darwin,rustc 1.98.1, at2a306fbe3:Scope reduction
The branch originally had 9 commits on top of its base: 6
fix(lint)commits, a test-environment fix (answering_no_on_continue_prompt, whichmasteralso carries), and these two fixes; the token-cap fix was added after the rebase. I re-checked whether the dropped commits were still unique value, and they are not:master's content (browser_fast.rs,compile_remote/source.rs,discover.rs,memory.rs,todo.rs,allocator.rs,translate.rs,launch.rs,structured.rs,linux_env.rs,mermaid_content.rs) and re-running clippy with-D warningsacross the affected crates stayed clean (rc=0), with those crates re-Checking/Compilingin the same run, so the run was not a cache hit.masteralready carries theonboarding_flow.rstest fix, thelifecycle.rstype, thePathBufandSuggestionschanges,google.rs'sis_multiple_of,scratch_maintenance.rs:225's call, andpart_01.rs:1822'slet press =.master'sQuality Guardrailsjob passes the exact gate CI: cargo clippy -D warnings fails on stable 1.98 at 12 sites that are unchanged on master #1348 was filed against, on Linux, ata705f842d.So #1348 and #1294 were stale rather than open work, and both are now closed with the evidence above (#1348 as no-longer-reproducible, #1294 as fixed by the upstream tail expression, verified with the exact macOS repro command from the report). The ratchet refresh (
check_code_size_budget.pyand the three ratchets behind it) is also unrelated to these fixes and is not needed: every ratchet step inQuality Guardrailspasses onmasterand on this branch.