fix: enable image recognition runtime checks#9203
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a comprehensive local runtime stability and diagnostics suite for AstrBot, including a troubleshooting runbook, a health diagnosis script, a configuration alignment script, and PowerShell/batch startup wrappers. The review feedback highlights several critical improvements: resolving a hardcoded user path for uv.exe in the PowerShell script, replacing absolute paths in the documentation with placeholders, optimizing log reading in the health script to avoid loading entire large files into memory, adding a connection timeout for SQLite to handle potential database locks, and handling potential race conditions in process termination.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| } | ||
|
|
||
| $Root = $PSScriptRoot | ||
| $UvPath = "C:\Users\mai\.local\bin\uv.exe" |
There was a problem hiding this comment.
| Set-Location "D:\Project files\AstrBotCore" | ||
| powershell -NoProfile -ExecutionPolicy Bypass -File ".\start_astrbot.ps1" |
There was a problem hiding this comment.
The runbook contains hardcoded absolute paths like D:\Project files\AstrBotCore. This makes the documentation less portable and confusing for other users who might clone the repository to a different directory. Consider using relative paths or placeholders like <path_to_astrbot_core> instead.
| Set-Location "D:\Project files\AstrBotCore" | |
| powershell -NoProfile -ExecutionPolicy Bypass -File ".\start_astrbot.ps1" | |
| Set-Location "<path_to_astrbot_core>" | |
| powershell -NoProfile -ExecutionPolicy Bypass -File ".\start_astrbot.ps1" |
| text = "\n".join( | ||
| path.read_text(encoding="utf-8", errors="replace")[-200_000:] for path in paths | ||
| ) |
There was a problem hiding this comment.
Reading the entire log file into memory with path.read_text() and then slicing the last 200,000 characters can cause high memory usage and performance degradation if the log files grow very large. Consider reading only the end of the file or streaming it.
def _read_tail(p: Path) -> str:
try:
with open(p, "rb") as f:
f.seek(0, 2)
f.seek(max(0, f.tell() - 200000))
return f.read().decode("utf-8", errors="replace")
except Exception:
return ""
text = "\n".join(_read_tail(p) for p in paths)| return [] | ||
|
|
||
| changed: list[str] = [] | ||
| with sqlite3.connect(DB_PATH) as conn: |
There was a problem hiding this comment.
If the AstrBot database is locked (e.g., if the bot is currently running or performing a transaction), sqlite3.connect will raise an OperationalError. Since this script is run as a pre-startup check, setting a connection timeout is recommended to prevent the script from crashing abruptly.
| with sqlite3.connect(DB_PATH) as conn: | |
| with sqlite3.connect(DB_PATH, timeout=10.0) as conn: |
| $ProcessIds = Get-AstrBotStopPlan -Owners $Owners | ||
| foreach ($ProcessId in $ProcessIds) { | ||
| Write-Host "Stopping old AstrBot process PID $ProcessId ..." -ForegroundColor Yellow | ||
| Stop-Process -Id $ProcessId -Force |
There was a problem hiding this comment.
Since $ErrorActionPreference = "Stop" is set at the beginning of the script, if the process exits on its own just before Stop-Process is executed, the script will throw a terminating error and crash. Add -ErrorAction SilentlyContinue to prevent this race condition.
Stop-Process -Id $ProcessId -Force -ErrorAction SilentlyContinue
Summary
Validation
Summary by Sourcery
Add runtime configuration guards, health diagnostics, and startup scripts to support stable AstrBot operation with Gemini image recognition and QQTools browser search.
New Features:
Enhancements: