fix(market-data): hot-reload provider + credentials when config changes#136
Merged
luokerenx4 merged 1 commit intomasterfrom Apr 21, 2026
Merged
fix(market-data): hot-reload provider + credentials when config changes#136luokerenx4 merged 1 commit intomasterfrom
luokerenx4 merged 1 commit intomasterfrom
Conversation
Changing marketData.providers via the UI had no effect — every
/api/market-data-v1/* request kept resolving to the provider that was
live at server boot. The resolver closure and the defaultCredentials
value were both snapshotted at mountOpenTypeBB time, and ctx.config
itself is never reassigned when the config-write route persists edits
to disk; only the Telegram / MCP-Ask reconnect path was wired to the
PUT handler, and it doesn't touch opentypebb.
Three mechanical changes close the loop:
- packages/opentypebb mountToHono's defaultCredentials widens to
`value | null | (() => value | null)` and re-evaluates the getter on
each request, mirroring the resolveProvider callback that was
already lazy.
- src/server/opentypebb.ts MountOpenTypeBBOptions accepts either static
values or getters for both defaultProviders and defaultCredentials;
makeProviderResolver reads via getter per request.
- src/connectors/web/web-plugin.ts passes closures that read
ctx.config.marketData.{providers,providerKeys} on each invocation.
- src/connectors/web/routes/config.ts: after writeConfigSection, reload
the full config and Object.assign onto ctx.config so in-memory state
stays in sync with disk. Preserves ctx.config's object identity.
Verified live: flipping equity provider via PUT /api/config/marketData
flips the response's `provider` field on the very next request to the
market-data endpoints, both directions, no restart.
TODO.md gets an Architecture entry flagging that this is a band-aid —
three different config-sync strategies now coexist, and the right fix
is a unified pub/sub config bus plus a file watcher for out-of-band
edits. Worth doing one focused pass next time something goes stale.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
Changing `marketData.providers` via the UI had no effect — every `/api/market-data-v1/*` request kept resolving to the provider that was live at server boot, because the resolver closure and the `defaultCredentials` value were both snapshotted at `mountOpenTypeBB` time, and `ctx.config` itself is never reassigned when the config-write route persists edits to disk (only the Telegram / MCP-Ask reconnect path was wired to the PUT handler, and it doesn't touch opentypebb).
Three mechanical changes close the loop:
TODO.md gets an Architecture entry flagging this as a band-aid — three different config-sync strategies now coexist (connector reconnect, opentypebb lazy getter + Object.assign, sub-reference capture that just goes stale), and the right fix is a unified pub/sub config bus plus a file watcher for out-of-band edits. Worth one focused pass next time something goes stale.
Test plan
🤖 Generated with Claude Code