Skip to content

acc: record aitools mcp entries lost to concurrent writes and older CLIs - #8147

Open
denik wants to merge 2 commits into
mainfrom
pmr/mcp-concurrency-tests
Open

denik wants to merge 2 commits into
mainfrom
pmr/mcp-concurrency-tests

Conversation

@denik

@denik denik commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Changes

Two acceptance tests that record what aitools mcp add and aitools mcp remove do today when another process writes at the same time, and what is left after a CLI older than v1.28.0 touches the state file. No production code changes. Each wrong result has a Badness note; the undefined case has an Undefined note.

cmd/aitools/mcp/agent-cli-concurrent-edit (agent-CLI path, introduced in #7595; no lock across runs, introduced in #7539)

The test puts a stand-in claude in front of the harness's one. It does what Claude Code 2.1.325 does where the harness's stand-in does not: mcp add-json refuses a name that the user config already holds (MCP server <name> already exists in user config, exit 1), and mcp remove deletes the entry of that name whoever wrote it. Before it reads the config it runs one script, which is the concurrent change. That orders the race without sleeps or background processes.

# Case Output today
1 add: the user adds their own github-logfood server while the claude CLI starts. Claude refuses to replace it. claude-code installed, without --force; the user's entry now holds the Databricks server.
2 remove: the user replaces the Databricks entry with their own while the claude CLI starts. Removed github-logfood ... (Claude Code); .mcpServers is {}, so the user's entry is deleted.
3 Two add --name github runs for two profiles. One after the other, the second is refused (--name github is used by another installed server). At the same time, the second finishes while the first waits for the claude CLI. Both report installed. The agent has one github server, for the first profile. State holds github twice.
4 After case 3, remove --all. Removed github ... profile logfood, and the record that is dropped is the other profile's: records are matched by name.

cmd/aitools/mcp/state-across-cli-versions (MCP records in the shared state file, introduced in #7537, where the description lists it as a decision to review)

# Case Output today
5 A CLI older than v1.28.0 runs aitools uninstall, which deletes a state file that holds no skills or plugins. The script deletes the file, since no such binary is in the test. mcp list shows both entries as unmanaged. mcp remove --names fails with no installed MCP server named ..., remove --all says No Databricks MCP servers to remove, and both agent configs keep the entry.
6 Same state, and the profile now points at another host. With the record, serve exits 2 (was set up for ..., but profile "logfood" now points at ...). Without it, serve starts against the new host and prints No install record ...; using its current host.
7 Undefined: a state file with a newer schema_version and a section this CLI does not know. The next mcp add writes the file back with schema_version 4 and without the section.

Why

These paths have unit tests for each step and no test for what happens when two writers meet. The tests pin today's behavior so that a fix shows up as a golden change.

Tests

  • Both tests pass three times in a row locally, and the outputs are the same each time.
  • Cases 1 and 2 follow what Claude Code 2.1.325 does in a throwaway home: mcp add-json --scope user on an existing name exits 1 and leaves the entry, and mcp remove --scope user removes an entry it did not write.
  • Case 5 follows v1.27.0 built from its tag: aitools uninstall deletes a state file that holds only the mcp section, and aitools uninstall --skills <name> writes the file back without it.

Gaps and risks

  • Risk: low. Test-only.
  • agent-cli-concurrent-edit does not run on Windows: its stand-in is a shell script, which a PATH lookup there does not find.
  • Not covered: two mcp add processes that interleave inside one read-modify-write of an agent config or of the state file. That needs real concurrency, so its outcome depends on timing. Eight parallel mcp add runs for eight services into Claude Code, Cursor and Codex, ten rounds: every run reported 24 of 24 installed; Cursor was missing an entry in 4 rounds, Codex in 3, and the state file a record in 2. Claude Code, whose file is locked, lost none.
  • Cases 1 to 4 use Claude Code only. Gemini CLI and Copilot CLI take the same path and are not covered.

🤖 AI agent (fable5.2, isaac_claude)

This pull request and its description were written by Isaac.

Two acceptance tests that record what `aitools mcp add` and `remove` do today
when something else writes at the same time, and what is left after a CLI
older than v1.28.0 touches the shared state file.

agent-cli-concurrent-edit puts a stand-in for the claude CLI in front of the
harness's one. It runs a script between the moment databricks starts claude
and the moment claude reads its config, which orders a concurrent change
without timing.

state-across-cli-versions deletes the state file as v1.27.0's
`aitools uninstall` does, and edits it as a newer CLI would.

Co-authored-by: Isaac <no-reply@databricks.com>
@github-actions github-actions Bot added aitools AI tools (databricks aitools) related changes test-only-fix PRs that update failing of flaky tests without changing CLI code. labels Nov 27, 2026
@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Regression test report ✅

Commit: d233b3a7a | Workflow run

Selected 2 changed tests (limit=20, 0 not selected)

2 tests: regression=0 unreleased=1 coverage=1 failing=0
test branch main (905b0f7) latest (v1.28.0)
TestAccept/cmd/aitools/mcp/agent-cli-concurrent-edit ✅ ✅ ✅
TestAccept/cmd/aitools/mcp/state-across-cli-versions ✅ ✅ ❌
TestAccept/cmd/aitools/mcp/state-across-cli-versions: branch ✅ | main (905b0f7) ✅ | latest (v1.28.0) ❌

latest (v1.28.0):

acceptance_test.go:1402: Diff:
        --- cmd/aitools/mcp/state-across-cli-versions/output.txt
        +++ /tmp/TestAcceptcmdaitoolsmcpstate-across-cli-versions488942666/002/output.txt
        @@ -18,7 +18,7 @@
         
         Exit code: 2
         
        -=== A CLI older than v1.28.0 runs aitools uninstall
        +=== A CLI older than v[CLI_VERSION] runs aitools uninstall
         
         >>> [CLI] aitools mcp list
         Profile logfood  ([DATABRICKS_URL], config file [TEST_TMP_DIR]/.databrickscfg)
        
    acceptance_test.go:1180: 
        LOG.add-again: Profile logfood (http://127.0.0.1:38255)
        LOG.add-again: Agents (named with --agents): claude-code, cursor
        LOG.add-again: 
        LOG.add-again: genie_one_mcp-logfood  system.ai.genie_one_mcp
        LOG.add-again:   claude-code  already installed, re-asserted  /tmp/TestAcceptcmdaitoolsmcpstate-across-cli-versions488942666/001/home/.claude.json
        LOG.add-again:   cursor       already installed, re-asserted  /tmp/TestAcceptcmdaitoolsmcpstate-across-cli-versions488942666/001/home/.cursor/mcp.json
    acceptance_test.go:1180: 
        LOG.create-genie_one_mcp-logfood: {
        LOG.create-genie_one_mcp-logfood:   "comment": "Ask questions about your data",
        LOG.create-genie_one_mcp-logfood:   "create_time": "2026-11-28T02:17:00.766430220Z",
        LOG.create-genie_one_mcp-logfood:   "created_by": "tester@databricks.com",
        LOG.create-genie_one_mcp-logfood:   "effective_owner": "tester@databricks.com",
        LOG.create-genie_one_mcp-logfood:   "metastore_id": "7a1112cd-6eb7-dfb4-7a11-12cd6eb7e0d7",
        LOG.create-genie_one_mcp-logfood:   "name": "mcp-services/system.ai.genie_one_mcp",
        LOG.create-genie_one_mcp-logfood:   "updated_by": "tester@databricks.com"
        LOG.create-genie_one_mcp-logfood: }
    acceptance_test.go:1180: 
        LOG.frames: {"id":1,"jsonrpc":"2.0","result":{"capabilities":{"tools":{"listChanged":true}},"instructions":"Fake Databricks MCP service for tests.\n\nThis server is bound to Databricks workspace http://localhost:38255 (CLI profile \"logfood\"). Its tools act on that workspace only.","protocolVersion":"2025-06-18","serverInfo":{"name":"fake_system.ai.genie_one_mcp"}}}
        LOG.frames: {"id":3,"jsonrpc":"2.0","result":{"content":[{"text":"hello","type":"text"}],"isError":false}}
        LOG.frames: {"id":2,"jsonrpc":"2.0","result":{"tools":[{"description":"Returns the text argument","inputSchema":{"properties":{"text":{"type":"string"}},"type":"object"},"name":"echo"}]}}
    acceptance_test.go:1180: 
        LOG.stderr: 
        LOG.stderr: >>> /home/runner/work/cli/cli/acceptance/build/linux_amd64/1.28.0/databricks aitools mcp serve --profile logfood --service system.ai.genie_one_mcp --agent claude-code
        LOG.stderr: No install record for system.ai.genie_one_mcp on profile "logfood"; using its current host http://localhost:38255
    acceptance_test.go:1180: LOG.stdout: 
FAIL

@eng-dev-ecosystem-bot

eng-dev-ecosystem-bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Integration test report

Commit: d233b3a

Run: 46096775155

Env ✅​pass 🙈​skip Time
✅​ aws linux-2core-8gb 174 19 4:20
✅​ aws-windows-latest-4core-16gb 174 19 3:33
✅​ azure linux-2core-8gb 173 19 4:06
✅​ azure-windows-latest-4core-16gb 173 19 3:48
✅​ gcp linux-2core-8gb 174 19 4:02
✅​ gcp-windows-latest-4core-16gb 174 19 3:59
Top 6 slowest tests (at least 2 minutes):
duration env testname
4:06 azure linux-2core-8gb TestAccept
3:58 gcp-windows-latest-4core-16gb TestAccept
3:46 azure-windows-latest-4core-16gb TestAccept
3:32 aws-windows-latest-4core-16gb TestAccept
3:16 aws linux-2core-8gb TestAccept
3:14 gcp linux-2core-8gb TestAccept

@review-oss-bot review-oss-bot 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.

Automated review at 4941086. Each finding was verified against the code.

No blocking issues found. 4 non-blocking comment(s) below.

This PR adds two acceptance tests that pin what aitools mcp add/remove do today when another writer changes the agent config while the agent CLI runs, and what is left after an older CLI drops the MCP section of the state file. The goldens match what addViaCLI/removeViaCLI do today. The main issue is that the concurrent-edit test is switched off on Windows because its claude stand-in is a bash script, when the cross-platform fakeagent could do the same job. There are also some smaller problems with the readability of the goldens and the reuse of helpers.

Badness = "aitools mcp add replaces, and remove deletes, a same-name entry that another process wrote while the agent's CLI ran, and both report success; two concurrent adds of one server name both report installed while one server is lost and state holds the name twice"

# bin/claude is a shell script, which a PATH lookup on Windows does not find.
GOOS.windows = false

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[nice to have] AGENTS.md says tests also run on Windows, but GOOS.windows = false turns off all four cases there. The only reason is that bin/claude is a bash script that a Windows PATH lookup won't find. The Go stand-in in acceptance/internal/fakeagent/main.go already handles claude mcp add-json/mcp remove and is put on PATH for msys by acceptance/cmd/aitools/script.prepare. Could claude() there refuse a name that already exists and run a pre-read hook named by an env var? Then the test runs on Windows too. It would also stop the bash mcp remove branch (bin/claude line 32) from skipping the $FAKE_AGENT_LOG argv log that every aitools test sets up.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not changed in this PR, and the gap is listed under "Gaps and risks". You are right that the Go stand-in could carry this. It needs three changes to the shared stand-in: a hook that runs before the read, mcp add-json refusing a taken name, and mcp remove deleting an entry it did not write (today it goes through RemoveAt, which refuses one). The last two change what every cmd/aitools test runs against, so I kept them out of a PR that only records behavior. Where this lands depends on the fix: #8151 removes the agent-CLI path, and this test with it; #8150 keeps the path for add, and moving the stand-in into fakeagent belongs there. The code under test is the order of the config check and the agent CLI run in agentconfig, which has no Windows-specific branch on this path.

The stand-in logs each add, refusal and removal to concurrent.log, so the
golden records that claude refused the name before databricks replaced the
entry. The re-pointed profile uses setup_custom_host and update_file.py
instead of a sed and a replacement of its own, and the serve command is
shown above its output.

Co-authored-by: Isaac <no-reply@databricks.com>
@denik
denik requested a review from andrewnester November 28, 2026 02:13

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

aitools AI tools (databricks aitools) related changes factory-generated test-only-fix PRs that update failing of flaky tests without changing CLI code.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants