Repository navigation
fix(bin): refuse Kimi launch when the directory declares project MCP servers - #6741
tiago-peixoto wants to merge 8 commits into
Conversation
Answering the folder prompt can start those targets without a consent decision that covers them. Directories with no project MCP servers still get past the folder prompt, and kimi -p is unchanged. Refs kunchenguid#5226 This does not close the issue. A directory that declares project MCP servers still cannot reach the Kimi composer until a later consent design.
…HOME; falsifiable marker
|
…ss.test.sh; no production code changed. Invariant: a project MCP declaration that Firstmate cannot read must refuse the Kimi launch, and each refusal cause must have a test named for that cause. The causes in kimi_project_mcp_blocks_launch are: not a regular file, no read permission, malformed JSON, and an undocumented mcpServers shape. Only the no-read-permission cause had no test, and the malformed JSON test carried the wrong name. Changes: - Renamed test_kimi_unreadable_project_mcp_refuses_before_launch to test_kimi_malformed_json_project_mcp_refuses_before_launch, and reworded its failure and pass messages to say malformed JSON. - Added a new test_kimi_unreadable_project_mcp_refuses_before_launch. It writes a valid empty server map ({"mcpServers":{}}) into the worktree, sets the file to mode 000, and asserts the spawn exits non-zero, Kimi never starts, no key is sent, and the output says "could not be read". The content is an empty map on purpose: a readable empty map launches, so only the missing read permission can cause the refusal. - When the test runs as root, that one case reports a pass line that states it was skipped because mode 000 does not restrict root. This follows the existing idiom in tests/fm-control-relaunch.test.sh. The root-proof variant (a directory where the file is expected) already exists as test_kimi_directory_in_place_of_project_mcp_refuses_before_launch, so I did not duplicate it. Verification, run locally as uid 1000: - bash tests/fm-kimi-harness.test.sh passed every case, including both the renamed case and the new one. - I temporarily removed the chmod 000 line and reran the suite: the new case failed with "an unreadable project MCP declaration should refuse the launch". I then restored the line. So the case can fail. - The root skip branch was not exercised, because the run was not as root. One environment note, not caused by this change: with the mise shim directory on PATH, the suite stops at an earlier case ("Kimi hook install refused a realistic config"), because mise tries to install python 3.12.14 under the test HOME and GitHub returns a rate limit 403. I ran the suite with the mise shim directory removed from PATH for that shell only, and changed no configuration
|
Speaking as Kun's firstmate: first look at head What I checked: the whole diff and the thread on #5226. Before the Kimi launch line is sent, Gates: CI green on Contract-class: new-default. This differs from the "restore" note I left on #5226. Here is why. Main's specified Kimi path ( VISION.md, rule by rule
Next step: waiting on the captain to merge or leave. The question is whether to adopt Design 3 now: refuse Kimi launches in a directory that declares project MCP servers, leave MCP-free directories and |
# Conflicts: # bin/fm-spawn.sh
# Conflicts: # .agents/skills/harness-adapters/references/harness/kimi.md
…oject MCP refusal
|
Speaking as Kun's firstmate: thanks @tiago-peixoto for keeping this current with main. I checked the new tip CI: everything passed except Unchanged: contract-class new-default, for the reason in my Oct 7 note (an MCP-declaring directory goes from launch to refuse on the unconfigured Kimi path). VISION still aligns rule by rule. This is a standing captain hold for Kun's merge-or-leave decision, tied to the design question on #5226. It's not waiting on you. |
|
Speaking as Kun's firstmate: thanks @tiago-peixoto. Head My contract-class read is unchanged: new-default (an MCP-declaring directory goes from launch to refuse on the unconfigured Kimi path). So I won't merge it on my own: it now goes to Kun as a merge-or-leave decision. This is the standing captain hold tied to #5226; the serial 6 re-run came back green. For Kun's decision: your new #7658 shows Kimi 2.3.0 drops the This is with Kun now, not waiting on you. Nothing more is needed from you unless he asks for a change. |
# Conflicts: # .agents/skills/harness-adapters/references/harness/kimi.md # bin/fm-spawn.sh # docs/configuration.md # tests/fm-kimi-harness.test.sh
|
Speaking as Kun's firstmate: thanks @tiago-peixoto for bringing this up to date again. New head
All 19 checks are green on this head, the no-mistakes attestation binds it (live 6/8 go), and GitHub reports it CLEAN. The diff touches no workflows or secrets. Contract-class: still new-default. A directory that declares project MCP servers now goes from launch, or a refused prompt, to a refusal before Kimi starts. That now includes any repo with a root This stays a standing captain hold for Kun's merge-or-leave decision, tied to #5226. It's not waiting on you. |
Intent
Refs #5226.
Contribute the corrective part of #5226, which the maintainer scoped on the issue as a restore that can land on its own: stop pressing Enter on a Kimi workspace trust dialog that lists project MCP targets, and refuse the launch with a clear reason when the directory declares project MCP servers. Directories with no project MCP servers still get past the folder prompt, and
kimi -pkeeps skipping untrusted project servers.This does not close the issue. A directory that declares project MCP servers still cannot reach the Kimi composer after this change; an operator-consent design for that is a separate, later, opt-in contribution that the maintainer said would be reviewed on its own.
No fix may start project MCP stdio or HTTP targets without an explicit consent decision that covers those targets. Tests use an isolated
KIMI_CODE_HOME.What Changed
bin/fm-spawn.shnow reads.kimi-code/mcp.jsonand the root.mcp.jsonbefore starting Kimi and refuses the launch with a named reason when either declares a project MCP server (including one withenabled: false) or cannot be proven empty (unreadable, not a regular file, malformed JSON, a non-objectmcpServers, or nojqon the host). A missing file, a missingmcpServerskey, or an empty server map still launches, and the interactive launch stayskimi --auto.bin/fm-kimi-trust-lib.shalso treats aProject MCP targets:header (the wording Kimi 2.1.1 and 0.43.1 use) as an announcing prompt, so the readiness loop sends no Enter on it; the not-ready diagnostic for a clipped dialog now states that no key was sent.tests/fm-kimi-harness.test.shadds twelve cases covering each refusal cause, the two still-launching cases, and the un-answered listed-targets dialogs, all under an isolatedKIMI_CODE_HOMEwith an assertion that no launch wrote to the ambient home; the Kimi adapter reference anddocs/configuration.mddescribe the refusal and its backstop.Risk Assessment
✅ Low: The change adds one bounded pre-launch read that fails closed on every unprovable shape, one additional pane pattern for the recorded 2.1.1 and 0.43.1 target list, and behavior-driven tests through the spawn's executable interface; I traced the declared, disabled, malformed, unreadable, non-object, root .mcp.json, empty-map, and no-file inputs through kimi_project_mcp_file_blocks_launch and found no path that lets a declaring directory reach Enter, the merged 2.3.0 tests do not publish declarations so the new read does not pre-empt them, and the only findings are test-quality and placement notes.
Testing
Ran the portable Kimi harness suite (48 ok, exit 0, with real interpreter dirs ahead of mise shims) against a fake kimi binary, so its disabled/unreadable/directory/undocumented-shape/empty-map branches are recorded as not live. Built a disposable lab (bin/fm-lab-home.sh, private tmux socket, fixture projects with bare origins, pinned Kimi 2.3.1 verified against the vendor manifest sha256) and drove real fm-spawn.sh on the tmux backend: declared .kimi-code/mcp.json, root .mcp.json, and malformed JSON were all refused before Kimi started with the expected reason in state/<id>.status and the pane transcript showing no kimi command; the plain directory launched real Kimi, whose 2.3.1 folder prompt was captured, answered, cleared, and the brief pointer typed and submitted (trust record and user-history in the lab home confirm it), after which delivery confirmation failed only because no Kimi model/login exists in the lab. Ran tests/fm-kimi-trust-prompt-live-e2e.test.sh against the real binary (all ok: plain prompt cleared by Enter, root and .kimi-code declarations announced and never answered, marker command never ran, short/paged panes refused). Ran realkimi -pin a declaring directory: Kimi printed it skipped the untrusted project server and the marker never ran. Isolation checks: real ~/.kimi-code absent, no lab projects in real ~/.treehouse, no lab windows on the default tmux server. Lab, Kimi prefix, and spawn temp dirs removed; worktree clean. No UI screenshot: the surface is a terminal TUI, captured as pane transcripts/frames.Evidence: Real spawn refused: .kimi-code/mcp.json declares project MCP servers
Source: Real spawn refused: .kimi-code/mcp.json declares project MCP servers
Evidence: Real spawn refused: root .mcp.json declares project MCP servers
Source: Real spawn refused: root .mcp.json declares project MCP servers
Evidence: Real spawn refused: malformed .kimi-code/mcp.json could not be read
Source: Real spawn refused: malformed .kimi-code/mcp.json could not be read
Evidence: Real spawn, plain directory: Kimi 2.3.1 prompt answered, trust record and submitted brief pointer
Source: Real spawn, plain directory: Kimi 2.3.1 prompt answered, trust record and submitted brief pointer
Evidence: Plain directory viewport frames (frame 7 prompt, frame 8 cleared composer, frame 9 brief pointer)
Source: Plain directory viewport frames (frame 7 prompt, frame 8 cleared composer, frame 9 brief pointer)
Evidence: Live guard against installed Kimi 2.3.1: announcing prompts never answered, marker never ran
Source: Live guard against installed Kimi 2.3.1: announcing prompts never answered, marker never ran
ok - kimi 2.3.1: a plain directory's folder prompt is the complete dialog, and Enter clears it into a ready pane # kimi 2.3.1: root-mcp-json prompt announces: Start 1 MCP server automatically;Config: .mcp.json; ok - kimi 2.3.1: a root-mcp-json declaration is announced on the folder prompt, which receives no answer, and its command never ran ok - kimi 2.3.1: a kimi-code-mcp-json declaration is announced on the folder prompt, which receives no answer, and its command never ran ok - kimi 2.3.1: a short pane collapses the prompt below the complete dialog, and a slightly taller one pages it with the page marker on screenEvidence: Real kimi -p 2.3.1 in a declaring directory skips the untrusted project server
Source: Real kimi -p 2.3.1 in a declaring directory skips the untrusted project server
Warning: this folder is not trusted; skipped 1 project-level MCP server: lab-marker (stdio: /tmp/fm-lab.xcB3QD/marker-p.sh --from-kimi-p). Runkimihere and choose "Trust this folder", or set KIMI_CODE_TRUST_WORKSPACE=1, to enable them. === marker-p.log (end marker)Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
⏭️ **Rebase** - skipped
Step was skipped.
tests/fm-kimi-harness.test.sh:131- The fake Kimi'sfake_start_project_mcpruns commands only from$FM_FAKE_PANE_PATH/.kimi-code/mcp.jsonunlessFM_FAKE_KIMI_PROJECT_MCPis set.test_kimi_root_mcp_json_declaration_refuses_before_launch(line 1388) publishes its declaration at the root.mcp.json(line 1398) and runs withFM_FAKE_KIMI_TRUST=remembered, so if the.mcp.jsonentry were dropped fromkimi_project_mcp_blocks_launch, the fake would launch, go ready, and never run the marker:assert_project_command_stayed_idleat line 1407 cannot fail there. Thelaunch.logassertion is what carries that case. This is the same vacuous-marker pattern the round-1 decision asked to make falsifiable for the other declaration tests. Remedy: make the fake read both.kimi-code/mcp.jsonand.mcp.jsonat the pane path, mirroring what tests/captures/kimi-code-2.3.0/README.md records Kimi 2.3.0 doing.tests/fm-kimi-harness.test.sh:410-assert_project_command_stayed_idle(line 410, checks! -e marker.log) duplicates the pre-existingassert_project_server_stayed_idle(line 1501, checks! -s marker.logand prints the log). Both read the same$CASE_DIR/marker.logthatrun_spawnwires viaFM_FAKE_MCP_MARKER_LOG, and the marker script only ever appends a line, so the-eand-schecks are equivalent in practice. Keep one helper (the-svariant with the log in its failure message is the more useful one) and use it at lines 1282, 1301, 1365, 1407, 1460, 1478, 1497.bin/fm-spawn.sh:7201- The declaration read runs after the endpoint is opened (line 4894), the task metadata is published (line 6715), and the launch file is staged (line 7192), so a refused directory leaves an open window holding only a shell, a leased worktree, a staged launch file, a metadata record, and a status line that ends withinspect window $T. That mirrors the existing readiness-failure path, where a worker is actually running in the window, and it is how the supervisor sees the reason, so it satisfies the intent. The worktree content is available from line 4870 (validate_spawn_worktree) and line 3700 for secondmates, which is where the read could run instead to refuse before any endpoint or record exists. Noting the tradeoff only; no change required.✅ **Test** - passed
✅ No issues found.
bash tests/fm-kimi-harness.test.sh(PATH prefixed with the real python3/node dirs) - 48 ok, exit 0 (fake kimi binary, not live)realbin/fm-spawn.sh kd1 <lab>/proj-declared --harness kimi --mode local-only --yolo offin a lab home with Kimi 2.3.1 on PATH - refused before launchrealbin/fm-spawn.sh kr1 <lab>/proj-rootmcp --harness kimi ...(root .mcp.json) - refused before launchrealbin/fm-spawn.sh km1 <lab>/proj-malformed --harness kimi ...(malformed .kimi-code/mcp.json) - refused with 'could not be read'realbin/fm-spawn.sh kp1 <lab>/proj-plain --harness kimi ...with 1s viewport frame capture - prompt shown, answered, cleared, brief pointer typedFM_KIMI_TRUST_PROMPT_LIVE=1 bash tests/fm-kimi-trust-prompt-live-e2e.test.shwith the pinned Kimi 2.3.1 on PATH - all okrealkimi -p 'Reply with the word hello.'in a directory declaring a stdio project MCP server, disposable HOME - skipped the untrusted server, marker idlesha256 of the downloaded kimi binary matched the vendor manifest checksum for 2.3.1isolation checks:ls ~/.kimi-codeabsent, real ~/.treehouse has no lab projects, default tmux server has no fm-k*1 windows,git status --shortclean✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.