Reset the LLM config when the last tool is torn down - #6295
Merged
Conversation
Bedrock compat is persisted so a later plain "thv llm setup" keeps it, but it applies to no client other than Claude Code. Tearing Claude Code down therefore left the setting with no consumer, and only an explicit --bedrock-compat=false could clear it. A subsequent setup — possibly against a gateway that no longer forwards to Bedrock — silently re-pinned the Bedrock model IDs and CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS the user had just removed, which reads as setup forcing Bedrock unconditionally. Clear the persisted Bedrock config when Claude Code is among the reverted tools. Stickiness across ordinary re-runs is unchanged.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6295 +/- ##
==========================================
+ Coverage 72.85% 72.90% +0.04%
==========================================
Files 743 742 -1
Lines 77681 77835 +154
==========================================
+ Hits 56596 56742 +146
+ Misses 17118 17102 -16
- Partials 3967 3991 +24 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Bedrock compat was not the only persisted setting that could outlive the client it configures. Models has the same shape: it is read only by Claude Desktop and, under Bedrock compat, Claude Code, yet it survived a full teardown and was silently re-applied by the next setup. Replace the Bedrock-specific check with a registry of client-scoped settings, each naming the clients that consume it. Teardown clears any entry left with no consumer among the still-configured tools and reports what it removed, so a later setup no longer re-applies settings the user tore down. A setting is preserved while any of its consumers remains, so Models outlives a Claude Code teardown when Claude Desktop is still set up. Settings that apply to every client, such as TLSSkipVerify, are not registered and are unaffected.
jerm-dro
marked this pull request as draft
August 13, 2026 17:21
Replace the per-setting stranded-value pruning with a single rule: teardown resets the whole LLM config once no configured tool remains. Settings like Bedrock compat and the model list are deliberately sticky so an ordinary "thv llm setup" re-run keeps them. Nothing ended that stickiness, so a value could outlive every tool that read it and be silently re-applied by the next setup, possibly against a gateway the user had since repointed elsewhere. Resetting wholesale drops the need to track which client consumes which setting, and matches what "thv llm config reset" already does. A targeted teardown that leaves other tools configured keeps the config, which those tools still need to reach the gateway. Cached token state survives the reset unless --purge-tokens is passed: the secret lives in the keyring, and dropping the only reference without deleting it would strand it once the gateway URL changes.
jerm-dro
marked this pull request as ready for review
August 13, 2026 18:17
JAORMX
approved these changes
Aug 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
thv llm setupre-applied Bedrock settings that the user had already torn down. Settings likeBedrockandModelsare persisted so a plainsetupre-run keeps them (#5832), but nothing ever ended that stickiness — a value outlived every tool that read it and got re-applied by the next setup, even against a gateway since repointed elsewhere.Modelssurvived a full teardown;Bedrockcould only be cleared with an explicit--bedrock-compat=false.Teardown now resets the LLM config once no configured tool remains, the same thing
thv llm config resetalready does. A teardown that leaves other tools configured is unchanged — they still need the gateway settings to work.Cached OIDC tokens survive the reset unless
--purge-tokensis passed, so the keyring secret is never left orphaned.Type of change
Test plan
task test)task test-e2e) — not run locally; CI'sE2E Tests Core (llm)passedtask lint-fix)Three teardown tests cover the rule: last tool reverted resets the config, a targeted teardown preserves it for the tools that remain, and
--purge-tokensstill clears the token refs. Also drovesetup → teardown → setupend-to-end to confirm the second setup no longer re-pins the Bedrock model IDs.Does this introduce a user-facing change?
Yes. After tearing down every tool,
thv llm setupneeds the connection settings supplied again — the same state as a fresh install. Cached tokens are untouched unless--purge-tokensis passed.Special notes for reviewers
Reset-when-empty is deliberately coarser than tracking which client reads which setting, so one case remains: tearing down
claude-codewhileclaude-desktopis still configured leavesBedrockset with no consumer. Nothing reads it until Claude Code is set up again, and the next full teardown clears it.Not fixed here — changing
--gateway-urlwithout a teardown still re-applies Bedrock keys. Same root cause, worth its own PR.Best reviewed squashed; the branch history walks through three earlier approaches.
Generated with Claude Code