Skip to content

add membase timeout in setting#1311

Merged
Oceania2018 merged 1 commit intoSciSharp:masterfrom
yileicn:master
Mar 18, 2026
Merged

add membase timeout in setting#1311
Oceania2018 merged 1 commit intoSciSharp:masterfrom
yileicn:master

Conversation

@yileicn
Copy link
Member

@yileicn yileicn commented Mar 18, 2026

No description provided.

@qodo-code-review
Copy link
Contributor

Review Summary by Qodo

Make Membase HTTP client timeout configurable

✨ Enhancement

Grey Divider

Walkthroughs

Description
• Add configurable timeout setting for Membase HTTP client
• Replace hardcoded 5-second timeout with configurable value
• Default timeout set to 10 seconds via settings
Diagram
flowchart LR
  A["MembaseSettings"] -->|"TimeoutSecond property"| B["MembasePlugin"]
  B -->|"uses configured timeout"| C["HttpClient configuration"]
  D["Hardcoded 5 seconds"] -.->|"replaced by"| A
Loading

Grey Divider

File Changes

1. src/Plugins/BotSharp.Plugin.Membase/Settings/MembaseSettings.cs ✨ Enhancement +1/-0

Add TimeoutSecond property to settings

• Added TimeoutSecond property to MembaseSettings class
• Default value set to 10 seconds
• Allows configuration of HTTP client timeout via settings

src/Plugins/BotSharp.Plugin.Membase/Settings/MembaseSettings.cs


2. src/Plugins/BotSharp.Plugin.Membase/MembasePlugin.cs ✨ Enhancement +1/-1

Use configurable timeout in HTTP client setup

• Changed hardcoded timeout from 5 seconds to configurable value
• Now uses settings.TimeoutSecond for HTTP client timeout
• Enables dynamic timeout configuration without code changes

src/Plugins/BotSharp.Plugin.Membase/MembasePlugin.cs


Grey Divider

Qodo Logo

@qodo-code-review
Copy link
Contributor

qodo-code-review bot commented Mar 18, 2026

Code Review by Qodo

🐞 Bugs (2) 📘 Rule violations (0) 📎 Requirement gaps (0) 📐 Spec deviations (0)

Grey Divider


Action required

1. Invalid timeout crashes startup 🐞 Bug ⛯ Reliability
Description
RegisterDI sets HttpClient.Timeout from MembaseSettings.TimeoutSecond without validating it; if
config provides 0 or a negative value, setting HttpClient.Timeout throws during DI setup and can
prevent the host from starting.
Code

src/Plugins/BotSharp.Plugin.Membase/MembasePlugin.cs[33]

+                    c.Timeout = TimeSpan.FromSeconds(settings.TimeoutSecond);
Evidence
MembaseSettings is populated directly from configuration via config.Bind("Membase", settings) and
then used to set HttpClient.Timeout with no guard. Elsewhere in the repo, timeout values are
explicitly validated to be > 0 before being used, indicating this code path should similarly protect
against invalid configuration values.

src/Plugins/BotSharp.Plugin.Membase/MembasePlugin.cs[18-34]
src/Infrastructure/BotSharp.Abstraction/Coding/Utils/CodingUtil.cs[11-19]
src/Plugins/BotSharp.Plugin.OpenAI/Providers/Realtime/RealTimeCompletionProvider.cs[111-117]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`MembasePlugin.RegisterDI` sets `HttpClient.Timeout` from `settings.TimeoutSecond` without validating the configured value. A non-positive value (e.g., `0`/`-1`) can throw during DI startup and prevent the application from starting.

### Issue Context
`MembaseSettings` is bound directly from configuration (`config.Bind("Membase", settings)`), so invalid values are possible.

### Fix Focus Areas
- src/Plugins/BotSharp.Plugin.Membase/MembasePlugin.cs[18-34]
- src/Plugins/BotSharp.Plugin.Membase/Settings/MembaseSettings.cs[3-9]

### Suggested fix
- Clamp or default invalid values before calling `TimeSpan.FromSeconds(...)` and assigning `c.Timeout` (e.g., `var timeoutSeconds = settings.TimeoutSecond > 0 ? settings.TimeoutSecond : 10;`).
- Optionally add an upper bound guard as well.
- Alternatively migrate to the options pattern and add validation (`Validate(...)`) so invalid configuration fails fast with a clear message.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

2. Timeout setting easy to misconfigure 🐞 Bug ⚙ Maintainability
Description
The new Membase timeout setting is not present in the shipped WebStarter appsettings sample and uses
a singular name (TimeoutSecond) unlike the existing TimeoutSeconds convention, increasing the chance
of users adding a non-binding config key and silently getting the default.
Code

src/Plugins/BotSharp.Plugin.Membase/Settings/MembaseSettings.cs[8]

+    public int TimeoutSecond { get; set; } = 10;
Evidence
WebStarter's sample configuration includes a Membase section but does not include any timeout key,
so users won't discover/configure it from the sample. Additionally, the repo already uses the
pluralized TimeoutSeconds naming in other settings, so TimeoutSecond is inconsistent and more
likely to be mistyped as TimeoutSeconds in config (which would not bind to this property).

src/WebStarter/appsettings.json[918-921]
src/Plugins/BotSharp.Plugin.Membase/Settings/MembaseSettings.cs[3-9]
src/Infrastructure/BotSharp.Abstraction/Coding/Settings/CodingSettings.cs[16-22]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
The new Membase timeout setting is easy to misconfigure because it is (1) missing from the shipped sample configuration and (2) named `TimeoutSecond` (singular), which is inconsistent with other `TimeoutSeconds` settings in the repo.

### Issue Context
Users typically copy settings from `src/WebStarter/appsettings.json`, which currently has a `Membase` section but no timeout entry.

### Fix Focus Areas
- src/Plugins/BotSharp.Plugin.Membase/Settings/MembaseSettings.cs[3-9]
- src/WebStarter/appsettings.json[918-921]

### Suggested fix
- Prefer renaming to `TimeoutSeconds` for consistency.
- Update `src/WebStarter/appsettings.json` to include the timeout setting under `"Membase"`.
- If you need to preserve both key spellings, consider using `ConfigurationKeyName` (or equivalent approach) so the binder can accept the intended config key name consistently.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

{
c.BaseAddress = new Uri(settings.Host);
c.Timeout = TimeSpan.FromSeconds(5);
c.Timeout = TimeSpan.FromSeconds(settings.TimeoutSecond);
Copy link
Contributor

Choose a reason for hiding this comment

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

Action required

1. Invalid timeout crashes startup 🐞 Bug ⛯ Reliability

RegisterDI sets HttpClient.Timeout from MembaseSettings.TimeoutSecond without validating it; if
config provides 0 or a negative value, setting HttpClient.Timeout throws during DI setup and can
prevent the host from starting.
Agent Prompt
### Issue description
`MembasePlugin.RegisterDI` sets `HttpClient.Timeout` from `settings.TimeoutSecond` without validating the configured value. A non-positive value (e.g., `0`/`-1`) can throw during DI startup and prevent the application from starting.

### Issue Context
`MembaseSettings` is bound directly from configuration (`config.Bind("Membase", settings)`), so invalid values are possible.

### Fix Focus Areas
- src/Plugins/BotSharp.Plugin.Membase/MembasePlugin.cs[18-34]
- src/Plugins/BotSharp.Plugin.Membase/Settings/MembaseSettings.cs[3-9]

### Suggested fix
- Clamp or default invalid values before calling `TimeSpan.FromSeconds(...)` and assigning `c.Timeout` (e.g., `var timeoutSeconds = settings.TimeoutSecond > 0 ? settings.TimeoutSecond : 10;`).
- Optionally add an upper bound guard as well.
- Alternatively migrate to the options pattern and add validation (`Validate(...)`) so invalid configuration fails fast with a clear message.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

@JackJiang1234
Copy link
Contributor

reviewed

@Oceania2018 Oceania2018 merged commit 4295bd6 into SciSharp:master Mar 18, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants