graceful-degradation
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGraceful Degradation with Helpful Messages
带实用提示信息的优雅降级
When optional services are unavailable, degrade gracefully with actionable fallback messages.
当可选服务不可用时,通过可执行的回退提示信息实现优雅降级。
Pattern
模式
Check availability at the start, cache the result, and provide helpful messages that explain what's missing and how to fix it.
在启动时检查服务可用性,缓存结果,并提供实用提示信息,说明缺失的内容以及修复方法。
DO
建议做法
- Check service availability early (before wasting compute)
- Cache health check results for the session (e.g., 60s TTL)
- Provide actionable fallback messages:
- What service is missing
- What features are degraded
- How to enable the service
- Continue with reduced functionality when possible
- 尽早检查服务可用性(避免浪费计算资源)
- 为会话缓存健康检查结果(例如:60秒TTL)
- 提供可执行的回退提示信息:
- 说明缺失的服务
- 说明哪些功能会降级
- 说明如何启用服务
- 尽可能在功能受限的情况下继续运行
DON'T
不建议做法
- Silently fail or return empty results
- Check availability on every call (cache it)
- Assume the user knows how to start missing services
- 静默失败或返回空结果
- 每次调用都检查可用性(请缓存结果)
- 假设用户知道如何启动缺失的服务
Example: LMStudio Check Pattern
示例:LMStudio检查模式
typescript
let lmstudioAvailable: boolean | null = null;
let lastCheck = 0;
const CACHE_TTL = 60000; // 60 seconds
async function checkLMStudio(): Promise<boolean> {
const now = Date.now();
if (lmstudioAvailable !== null && now - lastCheck < CACHE_TTL) {
return lmstudioAvailable;
}
try {
const response = await fetch('http://localhost:1234/v1/models', {
signal: AbortSignal.timeout(2000)
});
lmstudioAvailable = response.ok;
} catch {
lmstudioAvailable = false;
}
lastCheck = now;
return lmstudioAvailable;
}
// Usage
if (!await checkLMStudio()) {
return {
result: 'continue',
message: `LMStudio not available at localhost:1234.
To enable Godel-Prover tactic suggestions:
1. Install LMStudio from https://lmstudio.ai/
2. Load "Goedel-Prover-V2-8B" model
3. Start the local server on port 1234
Continuing without AI-assisted tactics...`
};
}typescript
let lmstudioAvailable: boolean | null = null;
let lastCheck = 0;
const CACHE_TTL = 60000; // 60 seconds
async function checkLMStudio(): Promise<boolean> {
const now = Date.now();
if (lmstudioAvailable !== null && now - lastCheck < CACHE_TTL) {
return lmstudioAvailable;
}
try {
const response = await fetch('http://localhost:1234/v1/models', {
signal: AbortSignal.timeout(2000)
});
lmstudioAvailable = response.ok;
} catch {
lmstudioAvailable = false;
}
lastCheck = now;
return lmstudioAvailable;
}
// Usage
if (!await checkLMStudio()) {
return {
result: 'continue',
message: `LMStudio not available at localhost:1234.
To enable Godel-Prover tactic suggestions:
1. Install LMStudio from https://lmstudio.ai/
2. Load "Goedel-Prover-V2-8B" model
3. Start the local server on port 1234
Continuing without AI-assisted tactics...`
};
}Fallback Message Template
回退提示信息模板
[Service] not available at [endpoint].
To enable [feature]:
1. [Step to install/start]
2. [Configuration step if needed]
3. [Verification step]
Continuing without [degraded feature]...[服务名称] 在 [端点] 不可用。
要启用[功能]:
1. [安装/启动步骤]
2. [如需配置的步骤]
3. [验证步骤]
将在无[降级功能]的情况下继续运行...Source Sessions
来源会话
- This session: LMStudio availability check with 60s caching and helpful fallback
- 174e0ff3: Environment variable debugging - print computed paths for troubleshooting
- 当前会话:带60秒缓存和实用回退提示的LMStudio可用性检查
- 174e0ff3:环境变量调试 - 打印计算路径以进行故障排查